PDController

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

This class controls a motor using proportional and derivative coefficients to calculate the power that the motor should be set to during any given time.

Parameters

kP

the proportional coefficient

kD

the derivative coefficient

Constructors

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

This class controls a motor using proportional and derivative coefficients to calculate the power that the motor should be set to during any given time.

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

Functions

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

Calculates the ideal motor power.

Link copied to clipboard
open override fun initialize()

Initializes the motor controller.

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.