Struct stspin220::ramp_maker::Trapezoidal
[−]pub struct Trapezoidal<Num = FixedU64<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>>> { /* private fields */ }
Expand description
Trapezoidal motion profile
Generates an approximation of a trapezoidal ramp, following the algorithm laid out here: http://hwml.com/LeibRamp.htm
A PDF version of that page is available: http://hwml.com/LeibRamp.pdf
This implementation makes the following simplifications:
- The unit of time used is left to the user (see “Unit of Time” below), so
the frequency variable
F
is ignored. - The initial velocity
v0
is assumed to be zero, meaning you can’t construct an instance of this struct to take over an ongoing movement.
Create an instance of this struct using Trapezoidal::new
, then use the
API defined by MotionProfile
(which this struct implements) to generate
the acceleration ramp.
Acceleration Ramp
This struct will generate a trapezoidal acceleration ramp with the following attributes:
- The velocity will always be equal to or less than the maximum velocity passed to the constructor.
- While ramping up or down, the acceleration will be an approximation of the target acceleration passed to the constructor.
Unit of Time
This code is agnostic on which unit of time is used. If you provide the target acceleration and maximum velocity in steps per second, the unit of the delay returned will be seconds.
This allows you to pass the parameters in steps per number of timer counts for the timer you’re using, completely eliminating any conversion overhead for the delay.
Type Parameter
The type parameter Num
defines the type that is used to represent the
target acceleration, maximum velocity, and delays per step. It is set to a
64-bit fixed-point number type by default.
You can override the default with f32
, f64
, or any other type from the
fixed
crate. Please note that this code uses a very naive approach
regarding its use of numeric types, which does not play well lower-accuracy
fixed-point types. Please be very careful when using any other other type
than the default or a floating-point type. The code might not even generate
a proper trapezoidal ramp, if accuracy is too low!
Please note that you need to enable support for f32
/f64
explicitly.
Check out the section on Cargo features from the documentation in the root
module for more information.
Implementations
impl<Num> Trapezoidal<Num> where
Num: One + Add<Num, Output = Num> + Div<Num, Output = Num> + Sqrt + Copy,
impl<Num> Trapezoidal<Num> where
Num: One + Add<Num, Output = Num> + Div<Num, Output = Num> + Sqrt + Copy,
pub fn new(target_accel: Num) -> Trapezoidal<Num>
pub fn new(target_accel: Num) -> Trapezoidal<Num>
Create a new instance of Trapezoidal
Accepts the target acceleration in steps per (unit of time)^2 as an argument. It must not be zero. See the struct documentation for information about units of time.
Panics
Panics, if target_accel
is zero.
Trait Implementations
impl<Num> MotionProfile for Trapezoidal<Num> where
Num: One<Output = Num> + Inv<Output = Num> + Add<Num, Output = Num> + Sub<Num, Output = Num> + Mul<Num> + Div<Num, Output = Num> + Ceil + Copy + PartialOrd<Num> + Cast<u32> + Zero,
impl<Num> MotionProfile for Trapezoidal<Num> where
Num: One<Output = Num> + Inv<Output = Num> + Add<Num, Output = Num> + Sub<Num, Output = Num> + Mul<Num> + Div<Num, Output = Num> + Ceil + Copy + PartialOrd<Num> + Cast<u32> + Zero,
type Velocity = Num
type Velocity = Num
The type used for representing velocities
type Delay = Num
type Delay = Num
The type used for representing delay values
fn enter_position_mode(
&mut self,
max_velocity: <Trapezoidal<Num> as MotionProfile>::Velocity,
num_steps: u32
)
fn enter_position_mode(
&mut self,
max_velocity: <Trapezoidal<Num> as MotionProfile>::Velocity,
num_steps: u32
)
Enter position mode Read more
fn next_delay(&mut self) -> Option<<Trapezoidal<Num> as MotionProfile>::Delay>
fn next_delay(&mut self) -> Option<<Trapezoidal<Num> as MotionProfile>::Delay>
Return the next step delay Read more
fn delays(&mut self) -> Delays<'_, Self>ⓘNotable traits for Delays<'r, Profile>impl<'r, Profile> Iterator for Delays<'r, Profile> where
Profile: MotionProfile, type Item = <Profile as MotionProfile>::Delay;
fn delays(&mut self) -> Delays<'_, Self>ⓘNotable traits for Delays<'r, Profile>impl<'r, Profile> Iterator for Delays<'r, Profile> where
Profile: MotionProfile, type Item = <Profile as MotionProfile>::Delay;
Profile: MotionProfile, type Item = <Profile as MotionProfile>::Delay;
Return an iterator over delay values of each step Read more
fn velocities(&mut self) -> Velocities<'_, Self>ⓘNotable traits for Velocities<'r, Profile>impl<'r, Profile> Iterator for Velocities<'r, Profile> where
Profile: MotionProfile,
<Profile as MotionProfile>::Delay: Inv,
<<Profile as MotionProfile>::Delay as Inv>::Output == <Profile as MotionProfile>::Velocity, type Item = <Profile as MotionProfile>::Velocity;
fn velocities(&mut self) -> Velocities<'_, Self>ⓘNotable traits for Velocities<'r, Profile>impl<'r, Profile> Iterator for Velocities<'r, Profile> where
Profile: MotionProfile,
<Profile as MotionProfile>::Delay: Inv,
<<Profile as MotionProfile>::Delay as Inv>::Output == <Profile as MotionProfile>::Velocity, type Item = <Profile as MotionProfile>::Velocity;
Profile: MotionProfile,
<Profile as MotionProfile>::Delay: Inv,
<<Profile as MotionProfile>::Delay as Inv>::Output == <Profile as MotionProfile>::Velocity, type Item = <Profile as MotionProfile>::Velocity;
Return an iterator over velocity values of each step Read more
fn accelerations<Accel>(&mut self) -> Accelerations<'_, Self, Accel>ⓘNotable traits for Accelerations<'r, Profile, Accel>impl<'r, Profile, Accel> Iterator for Accelerations<'r, Profile, Accel> where
Profile: MotionProfile,
<Profile as MotionProfile>::Delay: Inv,
<Profile as MotionProfile>::Delay: Add<<Profile as MotionProfile>::Delay>,
<Profile as MotionProfile>::Delay: Div<<Profile as MotionProfile>::Delay>,
<Profile as MotionProfile>::Velocity: Sub<<Profile as MotionProfile>::Velocity>,
<Profile as MotionProfile>::Velocity: Div<<Profile as MotionProfile>::Delay>,
<Profile as MotionProfile>::Delay: Copy,
<Profile as MotionProfile>::Delay: One,
<<Profile as MotionProfile>::Delay as Inv>::Output == <Profile as MotionProfile>::Velocity,
<<Profile as MotionProfile>::Delay as Add<<Profile as MotionProfile>::Delay>>::Output == <Profile as MotionProfile>::Delay,
<<Profile as MotionProfile>::Delay as Div<<Profile as MotionProfile>::Delay>>::Output == <Profile as MotionProfile>::Delay,
<<Profile as MotionProfile>::Velocity as Sub<<Profile as MotionProfile>::Velocity>>::Output == <Profile as MotionProfile>::Velocity,
<<Profile as MotionProfile>::Velocity as Div<<Profile as MotionProfile>::Delay>>::Output == Accel, type Item = Accel;
fn accelerations<Accel>(&mut self) -> Accelerations<'_, Self, Accel>ⓘNotable traits for Accelerations<'r, Profile, Accel>impl<'r, Profile, Accel> Iterator for Accelerations<'r, Profile, Accel> where
Profile: MotionProfile,
<Profile as MotionProfile>::Delay: Inv,
<Profile as MotionProfile>::Delay: Add<<Profile as MotionProfile>::Delay>,
<Profile as MotionProfile>::Delay: Div<<Profile as MotionProfile>::Delay>,
<Profile as MotionProfile>::Velocity: Sub<<Profile as MotionProfile>::Velocity>,
<Profile as MotionProfile>::Velocity: Div<<Profile as MotionProfile>::Delay>,
<Profile as MotionProfile>::Delay: Copy,
<Profile as MotionProfile>::Delay: One,
<<Profile as MotionProfile>::Delay as Inv>::Output == <Profile as MotionProfile>::Velocity,
<<Profile as MotionProfile>::Delay as Add<<Profile as MotionProfile>::Delay>>::Output == <Profile as MotionProfile>::Delay,
<<Profile as MotionProfile>::Delay as Div<<Profile as MotionProfile>::Delay>>::Output == <Profile as MotionProfile>::Delay,
<<Profile as MotionProfile>::Velocity as Sub<<Profile as MotionProfile>::Velocity>>::Output == <Profile as MotionProfile>::Velocity,
<<Profile as MotionProfile>::Velocity as Div<<Profile as MotionProfile>::Delay>>::Output == Accel, type Item = Accel;
Profile: MotionProfile,
<Profile as MotionProfile>::Delay: Inv,
<Profile as MotionProfile>::Delay: Add<<Profile as MotionProfile>::Delay>,
<Profile as MotionProfile>::Delay: Div<<Profile as MotionProfile>::Delay>,
<Profile as MotionProfile>::Velocity: Sub<<Profile as MotionProfile>::Velocity>,
<Profile as MotionProfile>::Velocity: Div<<Profile as MotionProfile>::Delay>,
<Profile as MotionProfile>::Delay: Copy,
<Profile as MotionProfile>::Delay: One,
<<Profile as MotionProfile>::Delay as Inv>::Output == <Profile as MotionProfile>::Velocity,
<<Profile as MotionProfile>::Delay as Add<<Profile as MotionProfile>::Delay>>::Output == <Profile as MotionProfile>::Delay,
<<Profile as MotionProfile>::Delay as Div<<Profile as MotionProfile>::Delay>>::Output == <Profile as MotionProfile>::Delay,
<<Profile as MotionProfile>::Velocity as Sub<<Profile as MotionProfile>::Velocity>>::Output == <Profile as MotionProfile>::Velocity,
<<Profile as MotionProfile>::Velocity as Div<<Profile as MotionProfile>::Delay>>::Output == Accel, type Item = Accel;
Return an iterator over the acceleration values between steps Read more
Auto Trait Implementations
impl<Num> RefUnwindSafe for Trapezoidal<Num> where
Num: RefUnwindSafe,
impl<Num> Send for Trapezoidal<Num> where
Num: Send,
impl<Num> Sync for Trapezoidal<Num> where
Num: Sync,
impl<Num> Unpin for Trapezoidal<Num> where
Num: Unpin,
impl<Num> UnwindSafe for Trapezoidal<Num> where
Num: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> CheckedAs for T
impl<T> CheckedAs for T
sourcefn checked_as<Dst>(self) -> Option<Dst> where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst> where
T: CheckedCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> CheckedCastFrom<Src> for Dst where
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dst where
Src: CheckedCast<Dst>,
sourcefn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
sourceimpl<Src, Dst> LosslessTryInto<Dst> for Src where
Dst: LosslessTryFrom<Src>,
impl<Src, Dst> LosslessTryInto<Dst> for Src where
Dst: LosslessTryFrom<Src>,
sourcefn lossless_try_into(self) -> Option<Dst>
fn lossless_try_into(self) -> Option<Dst>
Performs the conversion.
sourceimpl<Src, Dst> LossyInto<Dst> for Src where
Dst: LossyFrom<Src>,
impl<Src, Dst> LossyInto<Dst> for Src where
Dst: LossyFrom<Src>,
sourcefn lossy_into(self) -> Dst
fn lossy_into(self) -> Dst
Performs the conversion.
sourceimpl<T> OverflowingAs for T
impl<T> OverflowingAs for T
sourcefn overflowing_as<Dst>(self) -> (Dst, bool) where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool) where
T: OverflowingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> OverflowingCastFrom<Src> for Dst where
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dst where
Src: OverflowingCast<Dst>,
sourcefn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Casts the value.
sourceimpl<T> SaturatingAs for T
impl<T> SaturatingAs for T
sourcefn saturating_as<Dst>(self) -> Dst where
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dst where
T: SaturatingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> SaturatingCastFrom<Src> for Dst where
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dst where
Src: SaturatingCast<Dst>,
sourcefn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
sourceimpl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
sourcefn unwrapped_as<Dst>(self) -> Dst where
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dst where
T: UnwrappedCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> UnwrappedCastFrom<Src> for Dst where
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dst where
Src: UnwrappedCast<Dst>,
sourcefn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
Casts the value.
sourceimpl<T> WrappingAs for T
impl<T> WrappingAs for T
sourcefn wrapping_as<Dst>(self) -> Dst where
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dst where
T: WrappingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> WrappingCastFrom<Src> for Dst where
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dst where
Src: WrappingCast<Dst>,
sourcefn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
Casts the value.