Trapezoidal

Struct Trapezoidal 

Source
pub struct Trapezoidal<Num = DefaultNum> { /* 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§

Source§

impl<Num> Trapezoidal<Num>
where Num: Copy + One + Add<Output = Num> + Div<Output = Num> + Sqrt,

Source

pub fn new(target_accel: Num) -> Self

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§

Source§

impl<Num> MotionProfile for Trapezoidal<Num>
where Num: Copy + PartialOrd + Cast<u32> + Zero + One + Inv<Output = Num> + Add<Output = Num> + Sub<Output = Num> + Mul<Output = Num> + Div<Output = Num> + Ceil,

Source§

type Velocity = Num

The type used for representing velocities
Source§

type Delay = Num

The type used for representing delay values
Source§

fn enter_position_mode(&mut self, max_velocity: Self::Velocity, num_steps: u32)

Enter position mode Read more
Source§

fn next_delay(&mut self) -> Option<Self::Delay>

Return the next step delay Read more
Source§

fn delays(&mut self) -> Delays<'_, Self>

Return an iterator over delay values of each step Read more
Source§

fn velocities(&mut self) -> Velocities<'_, Self>

Return an iterator over velocity values of each step Read more
Source§

fn accelerations<Accel>(&mut self) -> Accelerations<'_, Self, Accel>

Return an iterator over the acceleration values between steps Read more

Auto Trait Implementations§

§

impl<Num> Freeze for Trapezoidal<Num>
where Num: Freeze,

§

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§

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> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
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<Src, Dst> LosslessTryInto<Dst> for Src
where Dst: LosslessTryFrom<Src>,

Source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
Source§

impl<Src, Dst> LossyInto<Dst> for Src
where Dst: LossyFrom<Src>,

Source§

fn lossy_into(self) -> Dst

Performs the conversion.
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
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.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.