Struct stepper::motion_control::SoftwareMotionControl
source · [−]pub struct SoftwareMotionControl<Driver, Timer, Profile: MotionProfile, Convert, const TIMER_HZ: u32> { /* private fields */ }
Expand description
Software implementation of motion control capability
Some driver natively support motion control capability. This is a software
implementation of the MotionControl
trait for those drivers that don’t.
It wraps a driver that implements SetDirection
and Step
, and in turn
acts like a driver itself, adding to the wrapped driver’s capabilities.
You can use SoftwareMotionControl
directly, but like a driver, it is
designed to be used through the Stepper
API.
Implementations
sourceimpl<Driver, Timer, Profile, Convert, const TIMER_HZ: u32> SoftwareMotionControl<Driver, Timer, Profile, Convert, TIMER_HZ> where
Profile: MotionProfile,
impl<Driver, Timer, Profile, Convert, const TIMER_HZ: u32> SoftwareMotionControl<Driver, Timer, Profile, Convert, TIMER_HZ> where
Profile: MotionProfile,
sourcepub fn new(
driver: Driver,
timer: Timer,
profile: Profile,
convert: Convert
) -> Self
pub fn new(
driver: Driver,
timer: Timer,
profile: Profile,
convert: Convert
) -> Self
Construct a new instance of SoftwareMotionControl
Instead of using this constructor directly, you can instead use
Stepper::enable_motion_control
with any driver that implements
SetDirection
and Step
, providing timer and a motion profile.
This module provides a blanket implementation of EnableMotionControl
to make this work.
sourcepub fn driver(&self) -> Option<&Driver>
pub fn driver(&self) -> Option<&Driver>
Access a reference to the wrapped driver
This is only possible if there is no ongoing movement.
sourcepub fn driver_mut(&mut self) -> Option<&mut Driver>
pub fn driver_mut(&mut self) -> Option<&mut Driver>
Access a mutable reference to the wrapped driver
This is only possible if there is no ongoing movement.
sourcepub fn timer(&self) -> Option<&Timer>
pub fn timer(&self) -> Option<&Timer>
Access a reference to the wrapped timer
This is only possible if there is no ongoing movement.
sourcepub fn timer_mut(&mut self) -> Option<&mut Timer>
pub fn timer_mut(&mut self) -> Option<&mut Timer>
Access a mutable reference to the wrapped timer
This is only possible if there is no ongoing movement.
sourcepub fn profile_mut(&mut self) -> &mut Profile
pub fn profile_mut(&mut self) -> &mut Profile
Access a mutable reference to the wrapped motion profile
sourcepub fn current_step(&self) -> i32
pub fn current_step(&self) -> i32
Access the current step
sourcepub fn current_direction(&self) -> Direction
pub fn current_direction(&self) -> Direction
Access the current direction
sourcepub fn set_step_mode(
&mut self,
step_mode: Driver::StepMode
) -> Result<SetStepModeFuture<RefMut<'_, Driver>, RefMut<'_, Timer>, TIMER_HZ>, BusyError<Infallible>> where
Driver: SetStepMode,
Timer: TimerTrait<TIMER_HZ>,
pub fn set_step_mode(
&mut self,
step_mode: Driver::StepMode
) -> Result<SetStepModeFuture<RefMut<'_, Driver>, RefMut<'_, Timer>, TIMER_HZ>, BusyError<Infallible>> where
Driver: SetStepMode,
Timer: TimerTrait<TIMER_HZ>,
Set step mode of the wrapped driver
This method is a more convenient alternative to
Stepper::set_step_mode
, which requires a timer, while this methods
reuses the timer that SoftwareMotionControl
already owns.
However, while Stepper::set_step_mode
is part of the generic API,
this method is only available, if you statically know that you’re
working with a driver wrapped by SoftwareMotionControl
.
Errors
Returns BusyError::Busy
, if a motion is ongoing.
sourcepub fn set_direction(
&mut self,
direction: Direction
) -> Result<SetDirectionFuture<RefMut<'_, Driver>, RefMut<'_, Timer>, TIMER_HZ>, BusyError<Infallible>> where
Driver: SetDirection,
Timer: TimerTrait<TIMER_HZ>,
pub fn set_direction(
&mut self,
direction: Direction
) -> Result<SetDirectionFuture<RefMut<'_, Driver>, RefMut<'_, Timer>, TIMER_HZ>, BusyError<Infallible>> where
Driver: SetDirection,
Timer: TimerTrait<TIMER_HZ>,
Set direction of the wrapped driver
This method is a more convenient alternative to
Stepper::set_direction
, which requires a timer, while this methods
reuses the timer that SoftwareMotionControl
already owns.
However, while Stepper::set_direction
is part of the generic API,
this method is only available, if you statically know that you’re
working with a driver wrapped by SoftwareMotionControl
.
Errors
Returns BusyError::Busy
, if a motion is ongoing.
sourcepub fn step(
&mut self
) -> Result<StepFuture<RefMut<'_, Driver>, RefMut<'_, Timer>, TIMER_HZ>, BusyError<Infallible>> where
Driver: Step,
Timer: TimerTrait<TIMER_HZ>,
pub fn step(
&mut self
) -> Result<StepFuture<RefMut<'_, Driver>, RefMut<'_, Timer>, TIMER_HZ>, BusyError<Infallible>> where
Driver: Step,
Timer: TimerTrait<TIMER_HZ>,
Tell the wrapped driver to move the motor one step
This method is a more convenient alternative to Stepper::step
, which
requires a timer, while this methods reuses the timer that
SoftwareMotionControl
already owns.
However, while Stepper::step
is part of the generic API, this method
is only available, if you statically know that you’re working with a
driver wrapped by SoftwareMotionControl
.
Errors
Returns BusyError::Busy
, if a motion is ongoing.
Trait Implementations
sourceimpl<Driver, Timer, Profile, Convert, const TIMER_HZ: u32> MotionControl for SoftwareMotionControl<Driver, Timer, Profile, Convert, TIMER_HZ> where
Driver: SetDirection + Step,
Profile: MotionProfile,
Timer: TimerTrait<TIMER_HZ>,
Profile::Velocity: Copy,
Convert: DelayToTicks<Profile::Delay, TIMER_HZ>,
impl<Driver, Timer, Profile, Convert, const TIMER_HZ: u32> MotionControl for SoftwareMotionControl<Driver, Timer, Profile, Convert, TIMER_HZ> where
Driver: SetDirection + Step,
Profile: MotionProfile,
Timer: TimerTrait<TIMER_HZ>,
Profile::Velocity: Copy,
Convert: DelayToTicks<Profile::Delay, TIMER_HZ>,
type Velocity = <Profile as MotionProfile>::Velocity
type Velocity = <Profile as MotionProfile>::Velocity
The type used by the driver to represent velocity
type Error = Error<<Driver as SetDirection>::Error, <<Driver as SetDirection>::Dir as ErrorType>::Error, <Driver as Step>::Error, <<Driver as Step>::Step as ErrorType>::Error, <Timer as Timer<TIMER_HZ>>::Error, <Convert as DelayToTicks<<Profile as MotionProfile>::Delay, TIMER_HZ>>::Error>
type Error = Error<<Driver as SetDirection>::Error, <<Driver as SetDirection>::Dir as ErrorType>::Error, <Driver as Step>::Error, <<Driver as Step>::Step as ErrorType>::Error, <Timer as Timer<TIMER_HZ>>::Error, <Convert as DelayToTicks<<Profile as MotionProfile>::Delay, TIMER_HZ>>::Error>
The type error that can happen when using this trait
sourcefn move_to_position(
&mut self,
max_velocity: Self::Velocity,
target_step: i32
) -> Result<(), Self::Error>
fn move_to_position(
&mut self,
max_velocity: Self::Velocity,
target_step: i32
) -> Result<(), Self::Error>
Move to the given position Read more
sourceimpl<Driver, Timer, Profile, Convert, const TIMER_HZ: u32> SetDirection for SoftwareMotionControl<Driver, Timer, Profile, Convert, TIMER_HZ> where
Driver: SetDirection,
Profile: MotionProfile,
impl<Driver, Timer, Profile, Convert, const TIMER_HZ: u32> SetDirection for SoftwareMotionControl<Driver, Timer, Profile, Convert, TIMER_HZ> where
Driver: SetDirection,
Profile: MotionProfile,
sourceconst SETUP_TIME: Nanoseconds = Driver::SETUP_TIME
const SETUP_TIME: Nanoseconds = Driver::SETUP_TIME
The time that the DIR signal must be held for a change to apply
type Dir = <Driver as SetDirection>::Dir
type Dir = <Driver as SetDirection>::Dir
The type of the DIR pin
type Error = BusyError<<Driver as SetDirection>::Error>
type Error = BusyError<<Driver as SetDirection>::Error>
The error that can occur while accessing the DIR pin
sourceimpl<Driver, Timer, Profile, Convert, const TIMER_HZ: u32> SetStepMode for SoftwareMotionControl<Driver, Timer, Profile, Convert, TIMER_HZ> where
Driver: SetStepMode,
Profile: MotionProfile,
impl<Driver, Timer, Profile, Convert, const TIMER_HZ: u32> SetStepMode for SoftwareMotionControl<Driver, Timer, Profile, Convert, TIMER_HZ> where
Driver: SetStepMode,
Profile: MotionProfile,
sourceconst SETUP_TIME: Nanoseconds = Driver::SETUP_TIME
const SETUP_TIME: Nanoseconds = Driver::SETUP_TIME
The time the mode signals need to be held before re-enabling the driver
sourceconst HOLD_TIME: Nanoseconds = Driver::HOLD_TIME
const HOLD_TIME: Nanoseconds = Driver::HOLD_TIME
The time the mode signals need to be held after re-enabling the driver
type Error = BusyError<<Driver as SetStepMode>::Error>
type Error = BusyError<<Driver as SetStepMode>::Error>
The error that can occur while using this trait
type StepMode = <Driver as SetStepMode>::StepMode
type StepMode = <Driver as SetStepMode>::StepMode
The type that defines the microstepping mode Read more
sourcefn apply_mode_config(
&mut self,
step_mode: Self::StepMode
) -> Result<(), Self::Error>
fn apply_mode_config(
&mut self,
step_mode: Self::StepMode
) -> Result<(), Self::Error>
Apply the new step mode configuration Read more
sourcefn enable_driver(&mut self) -> Result<(), Self::Error>
fn enable_driver(&mut self) -> Result<(), Self::Error>
Re-enable the driver after the mode has been set
sourceimpl<Driver, Timer, Profile, Convert, const TIMER_HZ: u32> Step for SoftwareMotionControl<Driver, Timer, Profile, Convert, TIMER_HZ> where
Driver: Step,
Profile: MotionProfile,
impl<Driver, Timer, Profile, Convert, const TIMER_HZ: u32> Step for SoftwareMotionControl<Driver, Timer, Profile, Convert, TIMER_HZ> where
Driver: Step,
Profile: MotionProfile,
sourceconst PULSE_LENGTH: Nanoseconds = Driver::PULSE_LENGTH
const PULSE_LENGTH: Nanoseconds = Driver::PULSE_LENGTH
The minimum length of a STEP pulse
Auto Trait Implementations
impl<Driver, Timer, Profile, Convert, const TIMER_HZ: u32> RefUnwindSafe for SoftwareMotionControl<Driver, Timer, Profile, Convert, TIMER_HZ> where
Convert: RefUnwindSafe,
Driver: RefUnwindSafe,
Profile: RefUnwindSafe,
Timer: RefUnwindSafe,
<Profile as MotionProfile>::Delay: RefUnwindSafe,
impl<Driver, Timer, Profile, Convert, const TIMER_HZ: u32> Send for SoftwareMotionControl<Driver, Timer, Profile, Convert, TIMER_HZ> where
Convert: Send,
Driver: Send,
Profile: Send,
Timer: Send,
<Profile as MotionProfile>::Delay: Send,
impl<Driver, Timer, Profile, Convert, const TIMER_HZ: u32> Sync for SoftwareMotionControl<Driver, Timer, Profile, Convert, TIMER_HZ> where
Convert: Sync,
Driver: Sync,
Profile: Sync,
Timer: Sync,
<Profile as MotionProfile>::Delay: Sync,
impl<Driver, Timer, Profile, Convert, const TIMER_HZ: u32> Unpin for SoftwareMotionControl<Driver, Timer, Profile, Convert, TIMER_HZ> where
Convert: Unpin,
Driver: Unpin,
Profile: Unpin,
Timer: Unpin,
<Profile as MotionProfile>::Delay: Unpin,
impl<Driver, Timer, Profile, Convert, const TIMER_HZ: u32> UnwindSafe for SoftwareMotionControl<Driver, Timer, Profile, Convert, TIMER_HZ> where
Convert: UnwindSafe,
Driver: UnwindSafe,
Profile: UnwindSafe,
Timer: UnwindSafe,
<Profile as MotionProfile>::Delay: 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.