Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/saquer916/odyssey/llms.txt

Use this file to discover all available pages before exploring further.

PIDController is a standard discrete PID controller used by Follower for translational and heading error correction. It derives dt from successive currentTime arguments, supports symmetric output clamping, and prevents integral wind-up via an independently configurable integral cap. Both Follower controllers operate with setPoint = 0. Package: org.firstinspires.ftc.teamcode.odyssey.control

Constructor

public PIDController(
    double setPoint,
    double kP,
    double kI,
    double kD
)
setPoint
double
required
The desired value the controller drives toward. Both Follower controllers use 0.0 — the error is encoded in the sign and magnitude of the input passed to getOutput().
kP
double
required
Proportional gain. Scales the raw error (setPoint - currentValue) directly.
kI
double
required
Integral gain. Scales the accumulated error over time. Start with 0 — integral gain is rarely required when kV and kA feedforward are properly tuned. See tip below.
kD
double
required
Derivative gain. Scales the finite-difference rate of change of error between successive calls. Helps dampen oscillation caused by high kP values.

Methods

getOutput(double currentTime, double currentValue)double

public double getOutput(double currentTime, double currentValue)
Computes the PID output for the current loop iteration. dt is derived internally as currentTime - previousTime; on the very first call dt is treated as 0, making the derivative term 0 and preventing a spike from an undefined initial state. The integral term accumulates as integralError += error * dt. If setMaxIntegral() has been called and kI ≠ 0, the integral contribution kI * integralError is clamped to [-maxIntegral, +maxIntegral] before the gains are applied.
return
double
PID output: kP·error + kI·integralError + kD·derivativeError, clamped to [minLimit, maxLimit] if output limits have been set.

reset()

public void reset()
Zeros the integral accumulator, the last-error value, and resets previousTime to NaN. The next getOutput() call will behave as if it is the first call — dt will be 0 and no derivative spike will occur.

setSetpoint(double setPoint)

public void setSetpoint(double setPoint)
Updates the target setpoint and resets error accumulators (lastError and integralError) to prevent a sudden derivative or integral jolt from the old error state.

setOutputLimits(double minLimit, double maxLimit)

public void setOutputLimits(double minLimit, double maxLimit)
Clamps the value returned by getOutput() to [minLimit, maxLimit]. If minLimit > maxLimit, the arguments are swapped automatically so the smaller value is always the lower bound.

removeOutputLimits()

public void removeOutputLimits()
Disables output clamping by resetting both limits to NaN. getOutput() will return unclamped values until setOutputLimits() is called again.

setMaxIntegral(double maxIntegral)

public void setMaxIntegral(double maxIntegral)
Caps the integral contribution (kI * integralError) to [-maxIntegral, +maxIntegral], preventing integrator wind-up. The stored value is always positive (Math.abs(maxIntegral) is used internally). Wind-up protection is active only when kI ≠ 0.

Gain accessors and mutators

public double getkP()
public void   setkP(double kP)

public double getkI()
public void   setkI(double kI)

public double getkD()
public void   setkD(double kD)
Read or update each gain at runtime. All three setters call resetErrors() internally — zeroing lastError and integralError — so a gain change mid-run does not produce a derivative spike or carry forward a stale integral from the old gain regime.

getSetPoint()double

public double getSetPoint()
Returns the current setpoint value.
return
double
The value most recently set by the constructor or setSetpoint().

Usage example

PIDController pid = new PIDController(0, 0.002, 0, 0.0001);
pid.setOutputLimits(-1.0, 1.0);
pid.setMaxIntegral(0.3);

// Inside the control loop:
double output = pid.getOutput(timer.seconds(), -offsetMagnitude);
Calling setkP(), setkI(), or setkD() resets error accumulators via an internal resetErrors() call. This zeroes lastError and integralError, preventing a derivative spike or integral carry-over when gains are changed while the controller is already running.
Start with kI = 0. Integral gain is rarely needed for FTC path following when kV and kA feedforward in MecanumDrive are tuned correctly — the feedforward terms eliminate most steady-state velocity error before the PID ever needs to compensate for it.

Build docs developers (and LLMs) love