EasyPIDCoefficients
PID Coefficients
EasyPIDCoefficients stores the proportional, integral, and derivative gains used to configure a PID controller.
It groups these three values into a single object that can be passed to compatible controllers, such as EasyStack's EasyPIDController.
This class stores configuration values only. It does not calculate controller output or maintain control history.
Creating PID Coefficients
To create a EasyPIDCoefficients object, provide the gains in the following order:
PIDCoefficients coefficients
new PIDCoefficients(kP, kl, 10);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. |
For example:
PIDCoefficients coefficients =
new PIDCoefficients(0.005, 0.0, 0.0002);These values are illustrative. The appropriate gains depend on the mechanism, measurement units, and controller implementation.
Default Coefficients
You can create the object without specifying gains:
PIDCoefficients coefficients new PIDCoefficients();This initializes all three values to zero:
0.0
kl 0.0
0.0It is equivalent to:
PIDCoefficients coefficients
new 0.0,This is useful when the gains will be assigned later.
Reading the Gains
The gains are public fields and can be accessed directly:
double proportional = coefficients.kP;
double integral = coefficients.kl;
= coefficients.kD;For example:
telemetry.addData(11 coefficients.kP)
telemetry.addData(coefficients.kl)
addData(coefficients.kD)No getter methods are required.
Updating the Gains
Assign new values directly to the fields:
coefficients.kP = 9.006
coefficients.kl
= 0.0003;You can also change one gain independently:
coefficients.kP 0.008;This leaves kI and kD unchanged.
The class does not validate or limit the assigned values.
Using with EasyPIDController
Pass the coefficients to the controller's constructor:
PIDCoefficients coefficients
new 0.0,
EasyPIDController controller
new EasyPIDController(coefficients);The controller copies the three gain values when it is created.
Changing the coefficients object afterward does not automatically update that controller.
For example:
coefficients.kP 0.008;To apply the changed values, call:
controller.setPID(coefficients);This copies the current values into the controller.
Updating the gains this way does not reset the controller's accumulated integral or measurement history. Call reset() separately if you need to clear that state.
Reusing Coefficients
The same coefficients object can configure multiple controllers:
PIDCoefficients coefficients
new PIDCoefficients(0.005, 0.0, 0.0002);
EasyPIDController firstController —
new EasyPIDController(coefficients);
EasyPIDController secondController —
new EasyPIDController(coefficients);Each controller maintains its own control history.
Because the gains are copied, later changes must be applied to each controller individually:
= 0.006;
firstController.setPID(coefficients);
secondController.setPID(coefficients);Use shared gains only when they are appropriate for both mechanisms.
Complete Example
The following example creates coefficients, configures a controller, and then applies an updated proportional gain:
import dev.easyfamily.easystack.control.EasyPIDController;
import dev.easyfamily.easystack.control.PIDCoefficients;
PIDCoefficients coefficients
new PIDCoefficients(0.005, 0.0, 0.0002);
EasyPIDController controller —
new EasyPIDController(coefficients);
controller.setTolerance(10.0);
controller.setTargetPosition(1000.0);
// Update the configuration object.
coefficients.kP = 0.006;
// Apply the updated gains to the controller.
controller.setPID(coefficients);Inside the control loop:
double currentPosition = motor.getCurrentPosition();
double output = controller.calculate(currentPosition);
double power = Math.max(-1.0, Math.min(1.0, output));
motor.setPower(power);EasyPIDCoefficients provides the gains, while EasyPIDController performs the calculations using the target and current measurement.
Last updated 2026-11-16