DriveBase

Struct DriveBase 

Source
pub struct DriveBase {
    pub left: TachoMotor,
    pub right: TachoMotor,
    pub current_speed: i32,
    pub left_sensor: Option<ColorSensor>,
    pub right_sensor: Option<ColorSensor>,
    pub left_meta: Motor,
    pub right_meta: Motor,
    pub circumference: f64,
    pub axle_track: f64,
}
Expand description

The DriveBase struct which holds all the needed fields

Fields§

§left: TachoMotor

The left motor of the DriveBase

§right: TachoMotor

The right motor of the DriveBase

§current_speed: i32

Current speed of the robot

§left_sensor: Option<ColorSensor>

left color sensor if specified, useful for line following methods

§right_sensor: Option<ColorSensor>

right color sensor if specified, useful for line following methods

§left_meta: Motor

Metadata of the left motor

§right_meta: Motor

Metadata of the right motor

§circumference: f64

The circumference of the wheels in mm

§axle_track: f64

The distance between the points where both wheels touch the ground.

Implementations§

Source§

impl DriveBase

Source

pub fn set_brake_mode(&self, brake_mode: BrakeMode) -> Result<&Self, Ev3Error>

Sets the brake mode of both motors. Its either Coast, Brake or Hold.

§Errors

Errors if it can’t set the command

Source

pub fn get_brake_mode(&self) -> Result<BrakeMode, Ev3Error>

Gets the brake mode for both motors. If the motors have different brake modes, this sets the right motor’s brake mode to match the left motor’s.

§Errors

Errors if it can’t read the brake mode

Source§

impl DriveBase

Source

pub fn drive( &mut self, speed: i32, distance: impl Into<i32>, stop: bool, ) -> Result<&Self, Ev3Error>

Drives the robot forward or backward at the specified speed.

§Parameters
  • speed: The speed at which to drive the robot, in tacho counts per second (positive for forward, negative for backward).
  • distance: Optional distance to drive, in millimeters.
    • If Some(mm), the robot drives that distance and then stops.
    • If None, the robot will drive indefinitely until another command stops it.
§Errors

Returns an Ev3Error if the motor cannot be started or a command fails.

§Example

Drive forward 500 mm at speed 200:

robot.drive(200, 500)?;
Source§

impl DriveBase

Source

pub fn set_acceleration(&self, acceleration: i32) -> Result<&Self, Ev3Error>

Sets the acceleration of the drivebase in deg/s^2

§Errors

Errors if the value is negative or it can’t set the value

Source

pub fn set_deceleration(&self, deceleration: i32) -> Result<&Self, Ev3Error>

Sets the deceleration of the drivebase in deg/s^2

§Errors

Errors if the value is negative or it can’t set the value

Source§

impl DriveBase

Source

pub fn turn( &mut self, speed: i32, degree: i32, radius: impl Into<Option<f64>>, ) -> Result<&mut Self, Ev3Error>

Source§

impl DriveBase

Source

pub fn stop(&self) -> Result<&Self, Ev3Error>

Stops both motors and is called on drop.

§Errors

Errors if it can’t set the stop command.

Source

pub fn reset(&self) -> Result<&Self, Ev3Error>

Resets all of the parameters of both motors and the DriveBase. Has the added effect of stopping.

§Errors

Errors if it can’t reset the DriveBase.

Source

pub fn is_running(&self) -> Result<bool, Ev3Error>

If power is being sent to both motors.

§Errors

Errors if it can’t set the stop command.

Source

pub fn is_ramping(&self) -> Result<bool, Ev3Error>

If any one of the motors are still ramping up.

§Errors

Errors if it can’t read the sysfs

Source

pub fn is_holding(&self) -> Result<bool, Ev3Error>

If any one of the motors are holding.

§Errors

Errors if it can’t read the sysfs

Source

pub fn is_overloaded(&self) -> Result<bool, Ev3Error>

If any one of the motors are overloaded.

§Errors

Errors if it can’t read the sysfs

Source

pub fn is_stalled(&self) -> Result<bool, Ev3Error>

If any one of the motors are stalled.

§Errors

Errors if it can’t read the sysfs

Source§

impl DriveBase

Source

pub fn wait<F>(&self, cond: F, timeout: Option<Duration>)
where F: Fn(&TachoMotor, &TachoMotor) -> bool + Send + Sync,

Wait until condition cond returns true or the timeout is reached.

The condition is checked when to the state attribute has changed. If the timeout is None it will wait an infinite amount of time.

Source§

impl DriveBase

Source

pub fn new( left_meta: Motor, right_meta: Motor, wheel_diameter: f64, axle_track: f64, ) -> Result<Self, Ev3Error>

Creates a new DriveBase using the provided Motor structs for the left and right motor.

§Errors

Errors if the port is not used or used by another device.

Source

pub fn add_colorsensor( &mut self, left_sensor: ColorSensor, right_sensor: ColorSensor, ) -> &Self

Add left and right colorsensors

Trait Implementations§

Source§

impl Clone for DriveBase

Source§

fn clone(&self) -> DriveBase

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DriveBase

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for DriveBase

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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> 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.