PIDController

class PIDController(kP: () -> Double = { 0.005 }, kI: () -> Double = { 0.0 }, kD: () -> Double = { 0.0 }) : ControlLoop

This is a control class using proportional, integral, and derivative coefficients to calculate an optimal output.

Parameters

kP

the proportional coefficient

kI

the integral coefficient

kD

the derivative coefficient

Constructors

Link copied to clipboard
constructor(kP: Double, kI: Double, kD: Double)

This is a control class using proportional, integral, and derivative coefficients to calculate an optimal output.

constructor(coefficients: PIDTriplet)

This is a control class using proportional, integral, and derivative coefficients to calculate an optimal output.

constructor(kP: () -> Double = { 0.005 }, kI: () -> Double = { 0.0 }, kD: () -> Double = { 0.0 })

Functions

Link copied to clipboard
open override fun calculate(state: Double, target: Double): Double

Calculates the ideal output state.

Link copied to clipboard
open override fun initialize()

Initializes the control loop.

Link copied to clipboard
open override fun isWithinThreshold(state: Double, target: Double, threshold: Double): Boolean

Checks if the motor is within a certain threshold of the target. Used when calculating if the motor should be running still. Checks the absolute value of the error (because it doesn't need to be calculating the direction the motor needs to move) against a threshold.

Link copied to clipboard
open override fun reset()

Reset the control loop. Primarily used for timers but can be as complex as needed.