Struct Tolerances

Source
pub struct Tolerances {
    pub duration: Option<Duration>,
    pub error_tolerance: Option<f64>,
    pub velocity_tolerance: Option<f64>,
    /* private fields */
}
Expand description

Describes when a control system has stabilized reasonably near its setpoint.

This struct monitors both position error and velocity to determine if a system has reached and stabilized at its target. It can be configured with tolerances for both error and velocity, a required duration to maintain those tolerances, and an optional timeout for if the target isn’t reached in a reasonable amount of time.

§Settling Logic

A system is considered settled if either:

  • The specified timeout has elapsed since the first call to Tolerances::check, OR
  • Both:
    1. The error and velocity are within their respective tolerances.
    2. The system has maintained these tolerances for the specified duration.

If the system leaves the tolerance window before the duration is met, the tolerance timer resets.

Fields§

§duration: Option<Duration>

Duration for which error_tolerance and velocity_tolerance must be satisfied.

§error_tolerance: Option<f64>

Minimum error range.

§velocity_tolerance: Option<f64>

Minimum velocity range.

Implementations§

Source§

impl Tolerances

Source

pub const fn new() -> Self

Creates a new Tolerances instance with no configured tolerances or timings.

Until tolerances are configured using the builder methods, all tolerance checks will pass immediately.

Source

pub const fn error(&mut self, tolerance: f64) -> Self

Sets the maximum acceptable error value for settling.

The error tolerance defines how close to the target position the system must be to be considered “within tolerance”.

Source

pub const fn velocity(&mut self, tolerance: f64) -> Self

Sets the maximum acceptable velocity for settling.

The velocity tolerance defines how slow the system must be moving to be considered “stable”.

Source

pub const fn duration(&mut self, duration: Duration) -> Self

Sets how long the system must remain within tolerances to be considered settled.

This duration acts as a “debounce” to ensure the system has truly stabilized and isn’t just passing through the tolerance window momentarily.

Source

pub fn check(&mut self, error: f64, velocity: f64) -> bool

Checks if the system has settled based on current error and velocity.

This method should be called periodically (typically in a control loop) with current system measurements. It will return true when either:

  • The specified timeout has elapsed since the first call to this function, OR
  • Both:
    1. The error and velocity are within their respective tolerances.
    2. The system has maintained these tolerances for the specified duration.
§Parameters
  • error - Difference between the setpoint and measured state of the system.
  • velocity - Measurement of how fast the system response is changing over time.

Trait Implementations§

Source§

impl Clone for Tolerances

Source§

fn clone(&self) -> Tolerances

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Tolerances

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Tolerances

Source§

fn default() -> Tolerances

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Tolerances

Source§

fn eq(&self, other: &Tolerances) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Tolerances

Source§

fn partial_cmp(&self, other: &Tolerances) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for Tolerances

Source§

impl StructuralPartialEq for Tolerances

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.