Pid
vectorlib::Pid — fields, methods, parameters and return types.
pub struct PidPID 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);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,
) -> SelfConstruct a new PID.
k_p— proportional gaink_i— integral gaink_d— derivative gainwindup_range— integral anti-windup range (LemLib default0, disabled)sign_flip_reset— whether to reset the integral when the sign of the error flips (LemLib defaultfalse)
Parameters
Prop
Type
Returns
Selfupdate
pub fn update(&mut self, error: f32) -> f32Update the PID with the latest error and return the output.
Parameters
Prop
Type
Returns
f32reset
pub fn reset(&mut self)Reset the integral and the previous error.
Returns
()