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§
Source§impl<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.