pub struct Motor { /* private fields */ }Expand description
NXT motor, EV3 large and medium motors
Implementations§
Source§impl Motor
impl Motor
Sourcepub fn new(port: MotorPort, direction: Direction) -> Ev3Result<Self>
pub fn new(port: MotorPort, direction: Direction) -> Ev3Result<Self>
Tries to find a Motor on the given port
If no motor is found, returns MotorNotFound.
Note that the motor is not reset upon initialization.
#Examples
use ev3dev_rs::pupdevices::Motor;
use ev3dev_rs::parameters::{MotorPort, Direction};
let motor = Motor::new(MotorPort::OutA, Direction::Clockwise);
motor.reset()?;
motor.run_target(300, 360)?;Sourcepub fn set_stop_action(&self, action: Stop) -> Ev3Result<()>
pub fn set_stop_action(&self, action: Stop) -> Ev3Result<()>
sets the stop action for the Motor
Sourcepub fn set_ramp_up_setpoint(&self, sp: u32) -> Ev3Result<()>
pub fn set_ramp_up_setpoint(&self, sp: u32) -> Ev3Result<()>
Units are in milliseconds and must be positive.
When set to a non-zero value, the motor speed will increase from 0 to 100% of max_speed over the span of this setpoint.
This is especially useful for avoiding wheel slip.
Sourcepub fn set_ramp_down_setpoint(&self, sp: u32) -> Ev3Result<()>
pub fn set_ramp_down_setpoint(&self, sp: u32) -> Ev3Result<()>
Units are in milliseconds and must be positive.
When set to a non-zero value, the motor speed will decrease from 0 to 100% of max_speed over the span of this setpoint.
This is especially useful for avoiding wheel slip.
Sourcepub fn reset(&self) -> Ev3Result<()>
pub fn reset(&self) -> Ev3Result<()>
Resets all the motor parameters to their default values.
This also has the effect of stopping the motor.
Sourcepub fn stop_prev_action(&self) -> Ev3Result<()>
pub fn stop_prev_action(&self) -> Ev3Result<()>
Stops the motor with the previously selected stop action.
Sourcepub fn stop(&self) -> Ev3Result<()>
pub fn stop(&self) -> Ev3Result<()>
Stops the motor and lets it spin freely.
This also has the effect of setting the motor’s stop action to coast.
Sourcepub fn brake(&self) -> Ev3Result<()>
pub fn brake(&self) -> Ev3Result<()>
Stops the motor and passively brakes it by generating current.
This also has the effect of setting the motor’s stop action to brake.
Sourcepub fn hold(&self) -> Ev3Result<()>
pub fn hold(&self) -> Ev3Result<()>
Stops the motor and actively holds it at its current angle.
This also has the effect of setting the motor’s stop action to hold.
Sourcepub async fn run_angle(&self, speed: i32, rotation_angle: i32) -> Ev3Result<()>
pub async fn run_angle(&self, speed: i32, rotation_angle: i32) -> Ev3Result<()>
Runs the motor at a constant speed by a given angle.
Sourcepub async fn run_target(&self, speed: i32, target_angle: i32) -> Ev3Result<()>
pub async fn run_target(&self, speed: i32, target_angle: i32) -> Ev3Result<()>
Runs the motor at a constant speed to a towards a target angle.
Note that the angle is continuous and does not wrap around at 360 degrees.
Additionally, the motor’s position is not necessarily zero at the start of your program.
To guarantee that the starting position is zero, you can use the reset method.
Sourcepub fn run(&self, speed: i32) -> Ev3Result<()>
pub fn run(&self, speed: i32) -> Ev3Result<()>
Runs the motor at a constant speed.
The motor will run at this speed until manually stopped, or you give it a new command.
Sourcepub async fn run_time(&self, speed: i32, time: Duration) -> Ev3Result<()>
pub async fn run_time(&self, speed: i32, time: Duration) -> Ev3Result<()>
Runs the motor at a constant speed for a given duration.
Sourcepub async fn run_until_stalled(&self, power: i32) -> Ev3Result<()>
pub async fn run_until_stalled(&self, power: i32) -> Ev3Result<()>
Runs at a given duty cycle percentage (-100 to 100) until stalled.