Skip to main content

PidController

Struct PidController 

Source
pub struct PidController { /* private fields */ }
Expand description

A stateful PID controller.

Implementations§

Source§

impl PidController

A stateful PID controller.

Source

pub fn new(config: PidConfig) -> Self

Initializes a new controller with the provided gains and zeroed state.

Source

pub fn update(&mut self, setpoint: f32, measurement: f32, dt: f32) -> f32

Calculates the corrective signal based on a setpoint and measurement.

§Parameters
  • setpoint - The desired value (Target).
  • measurement - The current estimated value (Feedback).
  • dt - Time delta since the last update in seconds.
Source

pub fn update_with_error(&mut self, error: f32, dt: f32) -> f32

Primary calculation engine for the PID signal.

This method performs the following:

  1. Proportional: $K_p \times error$
  2. Integral: Accumulates $error \times dt$, clamped by max_integral.
  3. Derivative: $K_d \times \frac{\Delta error}{dt}$
Source

pub fn reset(&mut self)

Resets the controller’s internal memory (Integral and Last Error).

CRITICAL: This should be called whenever the controller is re-engaged (Armed) to prevent “jumpy” initial behavior from stale data.

Auto Trait Implementations§

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.