[−][src]Struct pid_lite::Controller
PID controller
The target param sets the value we want to reach. The
proportional_gain, integral_gain and derivative_gain parameters are all
tuning parameters.
Examples
use pid_lite::Controller; use std::thread; use std::time::Duration; let target = 80.0; let mut controller = Controller::new(target, 0.5, 0.1, 0.2); loop { let correction = controller.update(measure()); apply_correction(correction); thread::sleep(Duration::from_secs(1)); }
Implementations
impl Controller[src]
pub const fn new(
target: f64,
proportional_gain: f64,
integral_gain: f64,
derivative_gain: f64
) -> Self[src]
target: f64,
proportional_gain: f64,
integral_gain: f64,
derivative_gain: f64
) -> Self
Create a new instance of Controller.
Examples
use pid_lite::Controller; let target = 80.0; let mut controller = Controller::new(target, 0.20, 0.02, 0.04);
pub const fn target(&self) -> f64[src]
Get the target.
Examples
use pid_lite::Controller; let target = 80.0; let mut controller = Controller::new(target, 0.20, 0.02, 0.04); assert_eq!(controller.target(), 80.0);
pub fn set_target(&mut self, target: f64)[src]
Set the target.
Examples
use pid_lite::Controller; let target = 80.0; let mut controller = Controller::new(target, 0.20, 0.02, 0.04); controller.set_target(60.0); assert_eq!(controller.target(), 60.0);
#[must_use = "A PID controller does nothing if the correction is not applied"]pub fn update(&mut self, current_value: f64) -> f64[src]
Push an entry into the controller.
Examples
use pid_lite::Controller; let target = 80.0; let mut controller = Controller::new(target, 0.0, 0.0, 0.0); assert_eq!(controller.update(60.0), 0.0);
Panics
This function may panic if the time_delta in millis no longer fits in
an f64. This limit can be encountered when the PID controller is updated on the scale of
hours, rather than on the scale of minutes to milliseconds.
#[must_use = "A PID controller does nothing if the correction is not applied"]pub fn update_elapsed(&mut self, current_value: f64, elapsed: Duration) -> f64[src]
Push an entry into the controller with a time delta since the last update.
The time_delta value will be rounded down to the closest millisecond
with a minimum of 1 millisecond.
Examples
use pid_lite::Controller; use std::time::Duration; let target = 80.0; let mut controller = Controller::new(target, 0.5, 0.1, 0.2); let dur = Duration::from_millis(2); assert_eq!(controller.update_elapsed(60.0, dur), 16.0);
Panics
This function may panic if the time_delta in millis no longer fits in
an f64. This limit can be encountered when the PID controller is updated on the scale of
hours, rather than on the scale of minutes to milliseconds.
pub fn reset(&mut self)[src]
Reset the internal state.
Examples
use pid_lite::Controller; use std::time::Duration; let target = 80.0; let mut controller = Controller::new(target, 0.0, 0.0, 0.0); let dur = Duration::from_secs(2); let correction = controller.update_elapsed(60.0, dur); controller.reset();
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Controller[src]
impl Send for Controller[src]
impl Sync for Controller[src]
impl Unpin for Controller[src]
impl UnwindSafe for Controller[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,