pub struct SlewRateLimiter<T: Numeric = f64> { /* private fields */ }Expand description
Follows a target without ever moving faster than the rates it was given, so a step in the target comes out as a ramp.
Rising and falling have separate limits, since a machine that can speed up gently often has to slow down harder. The first call jumps straight to its target rather than ramping up from zero.
use multicalc::error::SignalError;
use multicalc::signal_processing::SlewRateLimiter;
// Climbing at one per second, falling at two, a tenth of a second at a time.
let mut limited = SlewRateLimiter::new(1.0_f64, 2.0, 0.1).unwrap();
// The first call goes straight to its target.
assert!(limited.filter(0.0).abs() < 1e-12);
// A jump to 10 comes out as a ramp: a tenth of a unit per call.
assert!((limited.filter(10.0) - 0.1).abs() < 1e-12);
for _ in 0..9 {
let _ = limited.filter(10.0);
}
assert!((limited.value() - 1.0).abs() < 1e-12);
// Turning around, it moves twice as fast.
assert!((limited.filter(-10.0) - 0.8).abs() < 1e-12);
assert_eq!(
SlewRateLimiter::new(0.0_f64, 1.0, 0.1),
Err(SignalError::NonPositiveRate)
);Implementations§
Source§impl<T: Numeric> SlewRateLimiter<T>
impl<T: Numeric> SlewRateLimiter<T>
Sourcepub fn new(
rise_per_second: T,
fall_per_second: T,
dt: T,
) -> Result<Self, SignalError>
pub fn new( rise_per_second: T, fall_per_second: T, dt: T, ) -> Result<Self, SignalError>
Builds a limiter with separate rise and fall rates, in units per second.
Returns SignalError::NonFinite if any argument is not finite,
SignalError::NonPositiveTimestep if dt is not strictly positive, or
SignalError::NonPositiveRate if either rate is not strictly positive.
Sourcepub fn symmetric(rate_per_second: T, dt: T) -> Result<Self, SignalError>
pub fn symmetric(rate_per_second: T, dt: T) -> Result<Self, SignalError>
Builds a limiter that rises and falls at the same rate.
Returns the same errors as new.
Trait Implementations§
Source§impl<T: Clone + Numeric> Clone for SlewRateLimiter<T>
impl<T: Clone + Numeric> Clone for SlewRateLimiter<T>
Source§fn clone(&self) -> SlewRateLimiter<T>
fn clone(&self) -> SlewRateLimiter<T>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl<T: Copy + Numeric> Copy for SlewRateLimiter<T>
impl<T: PartialEq + Numeric> StructuralPartialEq for SlewRateLimiter<T>
Auto Trait Implementations§
impl<T> Freeze for SlewRateLimiter<T>where
T: Freeze,
impl<T> RefUnwindSafe for SlewRateLimiter<T>where
T: RefUnwindSafe,
impl<T> Send for SlewRateLimiter<T>where
T: Send,
impl<T> Sync for SlewRateLimiter<T>where
T: Sync,
impl<T> Unpin for SlewRateLimiter<T>where
T: Unpin,
impl<T> UnsafeUnpin for SlewRateLimiter<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for SlewRateLimiter<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more