pub struct Motor<IN1, IN2, PWM> { /* private fields */ }
Expand description
Represents a single motor (either motor A or motor B) hooked up to a TB6612FNG controller.
This is unaware of the standby pin. If you plan on using both motors and the standby feature then use the Tb6612fng
struct instead.
See the crate-level comment for further details on when to use what.
Implementations
sourceimpl<IN1, IN2, PWM> Motor<IN1, IN2, PWM>where
IN1: OutputPin,
IN2: OutputPin,
PWM: PwmPin<Duty = u16>,
impl<IN1, IN2, PWM> Motor<IN1, IN2, PWM>where
IN1: OutputPin,
IN2: OutputPin,
PWM: PwmPin<Duty = u16>,
sourcepub fn drive_forward(&mut self, speed: u8) -> Result<(), DriveError>
pub fn drive_forward(&mut self, speed: u8) -> Result<(), DriveError>
Drive forward with the defined speed. Note that the speed is a percentage between 0 and 100!
sourcepub fn drive_backwards(&mut self, speed: u8) -> Result<(), DriveError>
pub fn drive_backwards(&mut self, speed: u8) -> Result<(), DriveError>
Drive backwards with the defined speed. Note that the speed is a percentage between 0 and 100!
sourcepub fn drive(&mut self, drive_command: DriveCommand) -> Result<(), DriveError>
pub fn drive(&mut self, drive_command: DriveCommand) -> Result<(), DriveError>
Drive with the defined speed (or brake or stop the motor).
sourcepub fn current_drive_command(&self) -> &DriveCommand
pub fn current_drive_command(&self) -> &DriveCommand
Get the currently active drive command.
If you only want to know the speed consider calling Motor::current_speed
instead.
sourcepub fn current_speed(&self) -> i8
pub fn current_speed(&self) -> i8
Return the current speed of the motor (in percentage). Note that driving forward returns a positive number
while driving backwards returns a negative number and both DriveCommand::Brake
and DriveCommand::Stop
return 0.
If you need to know in more details what the current status is consider calling Motor::current_drive_command
instead.