calculate

fun calculate(timestamp: ComparableTimeMark = TimeSource.Monotonic.markNow(), error: Double, errorDerivative: Double? = null): Double(source)

Calculates the PID output

Return

the PID output

Parameters

timestamp

the current time (default: TimeSource.Monotonic.markNow())

error

the error in the target state; the difference between the desired state and the current state

errorDerivative

the derivative of the error, or null to compute it automatically from the change in error over time. This is typically the difference between the desired and current velocity when controlling position, or the difference in acceleration when controlling velocity.


fun calculate(timestamp: ComparableTimeMark = TimeSource.Monotonic.markNow(), error: MotionState<*>): Double(source)

Calculates the PID output from an error MotionState.

This overload extracts the error and error derivative from the motion state's position and velocity components. The position magnitude is used as the error, and the velocity magnitude is used as the error derivative.

Return

the PID output

Parameters

timestamp

the current time (default: TimeSource.Monotonic.markNow())

error

the error motion state containing position (error) and velocity (error derivative)


@JvmName(name = "calculateFromReference")
fun calculate(timestamp: ComparableTimeMark = TimeSource.Monotonic.markNow(), reference: Double, measured: Double, measuredDerivative: Double? = null): Double(source)

Calculates the PID output from a reference (setpoint) and measured value.

This overload assumes the reference derivative is zero (i.e., the setpoint is constant).

Return

the PID output

Parameters

timestamp

the current time (default: TimeSource.Monotonic.markNow())

reference

the desired/target value (setpoint)

measured

the current measured value

measuredDerivative

the derivative of the measured value, or null to compute the error derivative automatically from the change in error over time.


@JvmName(name = "calculateFromReference")
fun calculate(timestamp: ComparableTimeMark = TimeSource.Monotonic.markNow(), reference: Double, measured: Double, referenceDerivative: Double, measuredDerivative: Double): Double(source)

Calculates the PID output from a reference (setpoint) and measured value, with their respective derivatives.

Return

the PID output

Parameters

timestamp

the current time (default: TimeSource.Monotonic.markNow())

reference

the desired/target value (setpoint)

measured

the current measured value

referenceDerivative

the derivative of the reference value (e.g., desired velocity)

measuredDerivative

the derivative of the measured value (e.g., current velocity)


fun <U : Unit<U>> calculate(timestamp: ComparableTimeMark = TimeSource.Monotonic.markNow(), reference: MotionState<U>, measured: MotionState<U>): Double(source)

Calculates the PID output from reference and measured MotionStates.

This overload computes the error motion state by subtracting the measured state from the reference state. The position difference becomes the error, and the velocity difference becomes the error derivative.

Return

the PID output

Parameters

timestamp

the current time (default: TimeSource.Monotonic.markNow())

reference

the desired/target motion state (setpoint)

measured

the current measured motion state

Type Parameters

U

the unit type for the motion states (must be the same for both)