Struct PID

Source
pub struct PID<F, const W: usize> {
    pub kp: F,
    pub ki: F,
    pub kd: F,
    pub kf: F,
    pub kv: F,
    /* private fields */
}
Expand description

PID controller

§Examples

use pid_loop::PID;

let target = 42.0;
let mut controller = PID::<f64, 1>::new(2.0, 0.7, 0.3, 0.0, 0.0);
let correction = controller.next(target, measure());

fn measure() -> f64 { todo!() }

Fields§

§kp: F

Proportional gain.

§ki: F

Integral gain.

§kd: F

Derivative gain.

§kf: F

Feed forward gain

§kv: F

Velocity

Implementations§

Source§

impl<F, const W: usize> PID<F, W>
where F: Default + Add<Output = F> + Sub<Output = F> + Mul<Output = F> + PartialOrd + Copy,

Source

pub fn new( kp: impl Into<F>, ki: impl Into<F>, kd: impl Into<F>, kf: impl Into<F>, kv: impl Into<F>, ) -> Self

Create a new instance of PID.

§Examples
#![allow(unused_assignments)]
use pid_loop::PID;

let mut controller = PID::<f32, 1>::new(0.7, 0.034, 0.084, 0.1, 0.0);
Source

pub fn reset(&mut self)

Reset controller internal state.

§Examples
#![allow(unused_assignments)]
use pid_loop::PID;

let target = 30.0;
let mut controller = PID::<f32, 1>::new(0.7, 0.034, 0.084, 0.1, 0.0);
controller.next(target, 42.0);
controller.reset();
Source

pub fn next(&mut self, sp: impl Into<F>, fb: impl Into<F>) -> F

Push next measurement into the controller and return correction.

§Examples
#![allow(unused_assignments)]
use pid_loop::PID;

let target = 30.0;
let mut controller = PID::<f64, 1>::new(0.7, 0.034, 0.084, 0.1, 0.1);
let correction = controller.next(target, 42.0);

Auto Trait Implementations§

§

impl<F, const W: usize> Freeze for PID<F, W>
where F: Freeze,

§

impl<F, const W: usize> RefUnwindSafe for PID<F, W>
where F: RefUnwindSafe,

§

impl<F, const W: usize> Send for PID<F, W>
where F: Send,

§

impl<F, const W: usize> Sync for PID<F, W>
where F: Sync,

§

impl<F, const W: usize> Unpin for PID<F, W>
where F: Unpin,

§

impl<F, const W: usize> UnwindSafe for PID<F, W>
where F: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.