Robot

Trait Robot 

Source
pub trait Robot: AngleProvider {
Show 13 methods // Required methods fn drive( &self, distance: impl Into<Distance>, speed: impl Into<Speed>, ) -> Result<()>; fn turn(&self, angle: Heading, speed: impl Into<Speed>) -> Result<()>; fn turn_named( &self, angle: Heading, speed: impl Into<Speed>, turn: TurnType, ) -> Result<()>; fn set_heading(&self, angle: Heading) -> Result<()>; fn motor(&self, motor: MotorId) -> Option<RefMut<'_, dyn Motor>>; fn color_sensor( &self, port: SensorPort, ) -> Option<RefMut<'_, dyn ColorSensor>>; fn process_buttons(&self) -> Result<Input>; fn battery(&self) -> Result<Percent>; fn await_input(&self, timeout: Option<Duration>) -> Result<Input>; fn stop(&self) -> Result<()>; fn reset(&self) -> Result<()>; fn spec(&self) -> &RobotSpec; // Provided method fn handle_interrupt(&self) -> Result<()> { ... }
}
Expand description

Represents a simple robot with 2 wheels to move and a method to sense direction

Required Methods§

Source

fn drive( &self, distance: impl Into<Distance>, speed: impl Into<Speed>, ) -> Result<()>

Drive the robot using the gyro to correct for errors

§Returns

Returns an error if an interrupt has been requested Otherwise, returns Ok(())

Source

fn turn(&self, angle: Heading, speed: impl Into<Speed>) -> Result<()>

Turns the robot using the gyro sensor Guesses the turn type from the turn direction

§Inputs

speed should be greater than 0.0

§Returns

Returns an error if an interrupt has been requested Otherwise, returns Ok(())

§Panics

This function may panic if speed is less than or equal to 0

Source

fn turn_named( &self, angle: Heading, speed: impl Into<Speed>, turn: TurnType, ) -> Result<()>

Turns the robot Uses specified turn type using the gyro sensor

§Inputs

speed should be greater than 0.0

§Returns

Returns an error if an interrupt has been requested Otherwise, returns Ok(())

§Panics

This function may panic if speed is less than or equal to 0

Source

fn set_heading(&self, angle: Heading) -> Result<()>

Source

fn motor(&self, motor: MotorId) -> Option<RefMut<'_, dyn Motor>>

Retereives a motor

Source

fn color_sensor(&self, port: SensorPort) -> Option<RefMut<'_, dyn ColorSensor>>

Source

fn process_buttons(&self) -> Result<Input>

Returns the status of the robot’s buttons

Source

fn battery(&self) -> Result<Percent>

Retrieves the battery percentage Ranges from 0.0 -> 1.0

Source

fn await_input(&self, timeout: Option<Duration>) -> Result<Input>

Waits for the status of the robot’s buttons and returns that new status

Source

fn stop(&self) -> Result<()>

Stops the robot’s motors

Source

fn reset(&self) -> Result<()>

Resets the robot’s state

Source

fn spec(&self) -> &RobotSpec

Returns information about the robot

Provided Methods§

Source

fn handle_interrupt(&self) -> Result<()>

Returns an error if an interrupt has been requested Otherwise, returns Ok(())

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§