EasyStack Docs

EasyPIDFCoefficients

Esta página aún no está traducida. Se muestra la versión en inglés.

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:

Java
PIDFCoefficients coefficients =
        new PIDFCoefficients(kP, kI, kD, kF);

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.
kFFeedforward gain. Its use depends on the receiving controller.

For example:

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

Java
PIDFCoefficients coefficients new PIDFCoefficients();

This initializes all four values to zero:

Java
     0.0
kl -0.0
10 0.0
   -0.0

It is equivalent to:

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

Java
 = coefficients.kP;
 = coefficients.kl;
 = coefficients.kD;
 = coefficients.kF;

For example:

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

Java
coefficients.kP = 0.00025;
coefficients.kI = 0.0;
coefficients.kD = 0.0;
coefficients.kF = 0.00016;

You can also change a single gain independently:

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

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

Java
coefficients.kF o. 00018;

To apply the updated values:

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

Java
feedforward kF * target;

For example, with:

Java
coefficients.kF

and a target of 3000, the feedforward contribution is:

Java
0.00015 * 0.45

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

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

Java
controller.setPID(coefficients);

updates only the three PID gains, while:

Java
controller.setPIDF(coefficients);

updates all four gains.

Reusing Coefficients

The same object can configure multiple PIDF controllers:

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

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

Java
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;
Java
// Apply all four gains to the controller.
controller.setPIDF(coefficients);

For a velocity-control loop using an FTC DcMotorEx:

Java
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 actualización 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.