Motor

Struct Motor 

Source
pub struct Motor { /* private fields */ }
Expand description

NXT motor, EV3 large and medium motors

Implementations§

Source§

impl Motor

Source

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)?;
Source

pub fn set_stop_action(&self, action: Stop) -> Ev3Result<()>

sets the stop action for the Motor

Source

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.

Source

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.

Source

pub fn reset(&self) -> Ev3Result<()>

Resets all the motor parameters to their default values.

This also has the effect of stopping the motor.

Source

pub fn stop_prev_action(&self) -> Ev3Result<()>

Stops the motor with the previously selected stop action.

Source

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.

Source

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.

Source

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.

Source

pub fn angle(&self) -> Ev3Result<i32>

Gets the rotation angle of the motor.

Source

pub async fn run_angle(&self, speed: i32, rotation_angle: i32) -> Ev3Result<()>

Runs the motor at a constant speed by a given angle.

Source

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.

Source

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.

Source

pub async fn run_time(&self, speed: i32, time: Duration) -> Ev3Result<()>

Runs the motor at a constant speed for a given duration.

Source

pub async fn run_until_stalled(&self, power: i32) -> Ev3Result<()>

Runs at a given duty cycle percentage (-100 to 100) until stalled.

Source

pub fn dc(&self, duty: i32) -> Ev3Result<()>

Rotates the motor at a given duty cycle percentage (-100 to 100) until stopped, or you give it a new command.

Auto Trait Implementations§

§

impl !Freeze for Motor

§

impl !RefUnwindSafe for Motor

§

impl Send for Motor

§

impl !Sync for Motor

§

impl Unpin for Motor

§

impl UnwindSafe for Motor

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<Src, Dst> LosslessTryInto<Dst> for Src
where Dst: LosslessTryFrom<Src>,

Source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
Source§

impl<Src, Dst> LossyInto<Dst> for Src
where Dst: LossyFrom<Src>,

Source§

fn lossy_into(self) -> Dst

Performs the conversion.
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> StrictAs for T

Source§

fn strict_as<Dst>(self) -> Dst
where T: StrictCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> StrictCastFrom<Src> for Dst
where Src: StrictCast<Dst>,

Source§

fn strict_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.