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:
- The error and velocity are within their respective tolerances.
- 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
impl Tolerances
Sourcepub const fn new() -> Self
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.
Sourcepub const fn error(&mut self, tolerance: f64) -> Self
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”.
Sourcepub const fn velocity(&mut self, tolerance: f64) -> Self
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”.
Sourcepub const fn duration(&mut self, duration: Duration) -> Self
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.
Sourcepub fn check(&mut self, error: f64, velocity: f64) -> bool
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:
- The error and velocity are within their respective tolerances.
- 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
impl Clone for Tolerances
Source§fn clone(&self) -> Tolerances
fn clone(&self) -> Tolerances
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more