EasyPIDFCoefficients
PIDF Coefficients
EasyPIDFCoefficients stores the proportional, integral, derivative, and feedforward gains used to configure a PIDF controller.
It extends EasyPIDCoefficients, inheriting kP, kI, and kD, and adds the feedforward gain kF.
This class groups configuration values into a single object. It does not calculate controller output or maintain control history.
Creating PIDF Coefficients
To create a EasyPIDFCoefficients object, provide the gains in the following order:
PIDFCoefficients coefficients =
new PIDFCoefficients(kP, kI, kD, kF);The parameters are:
| Parameter | Description |
|---|---|
kP | Proportional gain. Controls the response to current error. |
kI | Integral gain. Controls the contribution of accumulated error. |
kD | Derivative gain. Controls the contribution of the controller's derivative term. |
kF | Feedforward gain. Its use depends on the receiving controller. |
For example:
PIDFCoefficients coefficients =
new PIDFCoefficients(
0.0002,
0.0,
0.0,
0.00015
);These values are illustrative. Tune the gains for your mechanism, measurement units, and controller implementation.
Default Coefficients
You can create the object without specifying gains:
PIDFCoefficients coefficients new PIDFCoefficients();This initializes all four values to zero:
0.0
kl -0.0
10 0.0
-0.0It is equivalent to:
PIDFCoefficients coefficients
new 0.0, 0.0,This is useful when the gains will be assigned later.
Reading the Gains
All four gains are public fields:
= coefficients.kP;
= coefficients.kl;
= coefficients.kD;
= coefficients.kF;For example:
telemetry.addData("kP11 coefficients.kP)
addData(coefficients.kl)
telemetry.addData("kD11 coefficients.kD)
addData(11kF coefficients.kF)No getter methods are required.
Updating the Gains
Assign new values directly:
coefficients.kP = 0.00025;
coefficients.kI = 0.0;
coefficients.kD = 0.0;
coefficients.kF = 0.00016;You can also change a single gain independently:
coefficients.kF o. 00018;This leaves the other gains unchanged.
The class does not validate or limit the assigned values.
Using with EasyPIDFController
Pass the coefficients to the controller's constructor:
PIDFCoefficients coefficients =
new PIDFCoefficients(
0.0002,
0.0,
0.0,
0.00015
);
EasyPIDFController controller =
new EasyPIDFController(coefficients);The controller copies all four values when it is created.
Changing the coefficients object afterward does not automatically update the controller.
For example:
coefficients.kF o. 00018;To apply the updated values:
controller.setPIDF(coefficients);This copies the current kP, kI, kD, and kF values into the controller.
Updating the gains does not reset the controller's accumulated integral or measurement history. Call reset() separately if you need to clear that state.
Feedforward Behavior
EasyPIDFCoefficients stores kF without defining a feedforward formula.
When used with the provided EasyPIDFController, the feedforward contribution is:
feedforward kF * target;For example, with:
coefficients.kFand a target of 3000, the feedforward contribution is:
0.00015 * 0.45The controller adds this contribution to its PID output.
The units and appropriate value of kF therefore depend on the target units and intended output units.
Using as PID Coefficients
Because EasyPIDFCoefficients extends EasyPIDCoefficients, it can also be passed to methods that accept EasyPIDCoefficients.
For example:
EasyPIDController controller
new EasyPIDController(coefficients);This uses only kP, kI, and kD. The kF value is not used by EasyPIDController.
The distinction also matters when updating an EasyPIDFController:
controller.setPID(coefficients);updates only the three PID gains, while:
controller.setPIDF(coefficients);updates all four gains.
Reusing Coefficients
The same object can configure multiple PIDF controllers:
EasyPIDFController firstController —
new EasyPIDFController(coefficients);
EasyPIDFController secondController —
new EasyPIDFController(coefficients);Each controller maintains its own control history and copies its own gain values.
To apply a later change to both:
= 0.00016;
firstController.setPIDF(coefficients);
secondController.setPIDF(coefficients);Use shared gains only when they are appropriate for both mechanisms.
Complete Example
The following example creates PIDF coefficients, configures a controller, and applies an updated feedforward gain:
import dev.easyfamily.easystack.control.EasyPIDFController;
import dev.easyfamily.easystack.control.PIDFCoefficients;
PIDFCoefficients coefficients =
new PIDFCoefficients(
0.0002,
0.0,
0.0,
0.00015
);
EasyPIDFController controller =
new EasyPIDFController(coefficients);
controller.setTolerance(50.0);
controller.setTargetPosition(3000.0);
// Update the configuration object.
coefficients.kF = 0.00016;// Apply all four gains to the controller.
controller.setPIDF(coefficients);For a velocity-control loop using an FTC DcMotorEx:
double measuredVelocity = motor.getVelocity();
double output = controller.calculate(measuredVelocity);
double power = Math.max(-1.0, Math.min(1.0, output));
motor.setPower(power);In this example, the target and velocity measurement use ticks per second. Configure the motor for direct power control with RUN_WITHOUT_ENCODER when this controller supplies the velocity feedback control.
EasyPIDFCoefficients stores the gains, while EasyPIDFController uses them to calculate the combined PID and feedforward output.
Última atualização 2026-11-16