Skip to Content
VectorLib

Pid

vectorlib::Pid — fields, methods, parameters and return types.


pub struct Pid

PID controller.


// kP = 5, kI = 0.01, kD = 20, no anti-windup, no sign-flip reset
let mut pid = Pid::new(5.0, 0.01, 20.0, 0.0, false);
let output = pid.update(10.0);
assert_eq!(output, 5.0 * 10.0 + 0.01 * 10.0 + 20.0 * 10.0);

View source

Fields

Prop

Type

Methods

Prop

Type

new

pub const fn new(
        k_p: f32,
        k_i: f32,
        k_d: f32,
        windup_range: f32,
        sign_flip_reset: bool,
    ) -> Self

Construct a new PID.

  • k_p — proportional gain
  • k_i — integral gain
  • k_d — derivative gain
  • windup_range — integral anti-windup range (LemLib default 0, disabled)
  • sign_flip_reset — whether to reset the integral when the sign of the error flips (LemLib default false)

Parameters

Prop

Type

Returns

Self

View source

update

pub fn update(&mut self, error: f32) -> f32

Update the PID with the latest error and return the output.

Parameters

Prop

Type

Returns

f32

View source

reset

pub fn reset(&mut self)

Reset the integral and the previous error.

Returns

()

View source