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

Instantiate a new Motor with the defined pins. This also automatically enables the PWM pin. The initial state of the motor will be stopped.

Usage example:

use tb6612fng::Motor;

let motor = Motor::new(
    motor_in1,
    motor_in2,
    motor_pwm,
);

Drive forward with the defined speed. Note that the speed is a percentage between 0 and 100!

Drive backwards with the defined speed. Note that the speed is a percentage between 0 and 100!

Actively brake.

Stop the motor but don’t brake (let it coast).

Drive with the defined speed (or brake or stop the motor).

Get the currently active drive command.

If you only want to know the speed consider calling Motor::current_speed instead.

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.

Trait Implementations

Formats the value using the given formatter. Read more
Writes the defmt representation of self to fmt.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.