EasyStack Docs

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:

Java
PIDCoefficients coefficients
        new PIDCoefficients(kP, kl, 10);

The parameters are:

ParameterDescription
kPProportional gain. Controls the response to current error.
kIIntegral gain. Controls the contribution of accumulated error.
kDDerivative gain. Controls the contribution of the controller's derivative term.

For example:

Java
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:

Java
PIDCoefficients coefficients new PIDCoefficients();

This initializes all three values to zero:

Java
     0.0
kl 0.0
     0.0

It is equivalent to:

Java
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:

Java
double proportional = coefficients.kP;
double integral = coefficients.kl;
 = coefficients.kD;

For example:

Java
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:

Java
coefficients.kP = 9.006
coefficients.kl
 = 0.0003;

You can also change one gain independently:

Java
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:

Java
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:

Java
coefficients.kP 0.008;

To apply the changed values, call:

Java
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:

Java
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:

Java
 = 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:

Java
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:

Java
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

EasyStack - FTC Java library

This site records page views of visitors to understand how the documentation is used. Nothing is sold or shared with third parties.