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: TachoMotorThe left motor of the DriveBase
right: TachoMotorThe right motor of the DriveBase
current_speed: i32Current 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: MotorMetadata of the left motor
right_meta: MotorMetadata of the right motor
circumference: f64The circumference of the wheels in mm
axle_track: f64The distance between the points where both wheels touch the ground.
Implementations§
Source§impl DriveBase
impl DriveBase
Source§impl DriveBase
impl DriveBase
Sourcepub fn drive(
&mut self,
speed: i32,
distance: impl Into<i32>,
stop: bool,
) -> Result<&Self, Ev3Error>
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.
- If
§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
impl DriveBase
Source§impl DriveBase
impl DriveBase
Sourcepub fn reset(&self) -> Result<&Self, Ev3Error>
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.
Sourcepub fn is_running(&self) -> Result<bool, Ev3Error>
pub fn is_running(&self) -> Result<bool, Ev3Error>
Sourcepub fn is_ramping(&self) -> Result<bool, Ev3Error>
pub fn is_ramping(&self) -> Result<bool, Ev3Error>
Sourcepub fn is_holding(&self) -> Result<bool, Ev3Error>
pub fn is_holding(&self) -> Result<bool, Ev3Error>
Sourcepub fn is_overloaded(&self) -> Result<bool, Ev3Error>
pub fn is_overloaded(&self) -> Result<bool, Ev3Error>
Source§impl DriveBase
impl DriveBase
Source§impl DriveBase
impl DriveBase
Sourcepub fn new(
left_meta: Motor,
right_meta: Motor,
wheel_diameter: f64,
axle_track: f64,
) -> Result<Self, Ev3Error>
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.
Sourcepub fn add_colorsensor(
&mut self,
left_sensor: ColorSensor,
right_sensor: ColorSensor,
) -> &Self
pub fn add_colorsensor( &mut self, left_sensor: ColorSensor, right_sensor: ColorSensor, ) -> &Self
Add left and right colorsensors