pub struct Pid { /* private fields */ }Expand description
PID controller with tunable gains and output clamping.
Implementations§
Source§impl Pid
impl Pid
Sourcepub fn new(kp: f32, ki: f32, kd: f32) -> Self
pub fn new(kp: f32, ki: f32, kd: f32) -> Self
Create a new PID controller.
kp, ki, kd are the gain constants.
Sourcepub fn with_output_limits(self, min: f32, max: f32) -> Self
pub fn with_output_limits(self, min: f32, max: f32) -> Self
Set output limits.
Sourcepub fn with_integral_limits(self, min: f32, max: f32) -> Self
pub fn with_integral_limits(self, min: f32, max: f32) -> Self
Set integral limits for anti-windup.
Sourcepub fn update(&mut self, setpoint: f32, measurement: f32, dt: f32) -> f32
pub fn update(&mut self, setpoint: f32, measurement: f32, dt: f32) -> f32
Update the controller.
setpoint — desired value
measurement — current value
dt — timestep in seconds (e.g. 0.02 for 50 Hz control loop)
Returns a normalized command in [out_min, out_max] which can be mapped to motor drive.
Auto Trait Implementations§
impl Freeze for Pid
impl RefUnwindSafe for Pid
impl Send for Pid
impl Sync for Pid
impl Unpin for Pid
impl UnwindSafe for Pid
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more