Skip to main content

Class FloatPIDController

PID controller for scalar (Single) quantities such as vehicle speed.

[Serializable]
public sealed class FloatPIDController : PIDController<float>

Inheritance​

Inherited Members​

Remarks​

Used by the AI drive system to regulate longitudinal speed: the error is targetSpeed - currentSpeed and the output drives the throttle input to PrometeoCarController. The integral term corrects for the steady-state speed deficit that a pure P-controller would leave on uphill road segments.

Methods​

ComputeOutput(float, float)​

Performs the type-specific PID computation: calculates the proportional, integral, and derivative contributions and combines them according to the tuning coefficients.

protected override float ComputeOutput(float error, float deltaTime)

Parameters​

NameTypeDescription
errorfloatThe current error value.
deltaTimefloatTime in seconds since the last update.

Returns​

float — The raw PID output before any external scaling or clamping.

Remarks​

I-term accumulation: iTerm accumulates raw error multiplied by delta-time (pTerm * deltaTime), not Kp * error. This is intentional — the gain coefficient Coefficients.i is applied at the final summation, which is the standard parallel-form PID formulation. Some textbook implementations instead fold the gain into the accumulation step; that would require different coefficient tuning and is not used here.

deltaTime Although [Single)](../index.mdx) already validates that deltaTimeis positive before calling this method, the check is repeated here as a defensive measure. Subclasses or future callers that invokeComputeOutputdirectly (bypassingGetOutput`) would otherwise risk a divide-by-zero in the derivative term.

previousError = pTerm: Because pTerm is assigned error with no transformation, this statement is semantically identical to previousError = error. The intermediate variable is retained for readability — it makes the parallel structure of the three terms (p, i, d) explicit.