pub struct PidController { /* private fields */ }Expand description
A standard PID controller with output clamping and integral anti-windup.
Call PidController::update once per control tick with the current setpoint, measurement,
and elapsed time (dt, in seconds) since the previous call; it returns the control output.
Implementations§
Source§impl PidController
impl PidController
Sourcepub fn new(gains: PidGains, output_limits: (f64, f64)) -> PidController
pub fn new(gains: PidGains, output_limits: (f64, f64)) -> PidController
Create a new controller with the given gains and output clamp. Integral wind-up is
clamped to the same range as the output by default - see Self::with_integral_limits
to widen/narrow that independently.
Sourcepub fn with_integral_limits(self, integral_limits: (f64, f64)) -> PidController
pub fn with_integral_limits(self, integral_limits: (f64, f64)) -> PidController
Override the integral anti-windup clamp independently of the output clamp.
Sourcepub fn update(&mut self, setpoint: f64, measurement: f64, dt: f64) -> f64
pub fn update(&mut self, setpoint: f64, measurement: f64, dt: f64) -> f64
Advance the controller by one tick and return the (clamped) control output.
dt is the elapsed time in seconds since the previous call. A non-positive dt skips
the integral/derivative terms for this tick (treated as a proportional-only response)
rather than dividing by zero or integrating backwards.
Trait Implementations§
Source§impl Clone for PidController
impl Clone for PidController
Source§fn clone(&self) -> PidController
fn clone(&self) -> PidController
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for PidController
impl RefUnwindSafe for PidController
impl Send for PidController
impl Sync for PidController
impl Unpin for PidController
impl UnsafeUnpin for PidController
impl UnwindSafe for PidController
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more