pub struct Robot { /* private fields */ }Expand description
A two-motor differential-drive robot controller.
The robot smoothly ramps motor speeds from the current value to the target
in a background task. Call drive to set target speeds and
stop to decelerate to zero.
§Shutdown
Call shutdown to cancel the background task and stop all motors.
The robot also stops motors when dropped, but explicit shutdown is preferred.
Implementations§
Source§impl Robot
impl Robot
Sourcepub fn new(
motor_board: Arc<Mutex<dyn MotorDriver>>,
config: RobotConfig,
) -> Result<Arc<Self>, RobotError>
pub fn new( motor_board: Arc<Mutex<dyn MotorDriver>>, config: RobotConfig, ) -> Result<Arc<Self>, RobotError>
Create a new robot with the given motor driver and configuration.
Spawns a background task for smooth motor ramping. The task runs until
shutdown is called or the Robot is dropped.
§Errors
Returns RobotError if the configuration is invalid.
Sourcepub async fn drive(&self, left: f32, right: f32) -> Result<(), RobotError>
pub async fn drive(&self, left: f32, right: f32) -> Result<(), RobotError>
Set target motor speeds.
Values are clamped to [-1.0, 1.0]. Motor factors from RobotConfig
are applied automatically.
§Errors
Returns RobotError::Shutdown if the robot has been shut down.
Sourcepub async fn stop(&self) -> Result<(), RobotError>
pub async fn stop(&self) -> Result<(), RobotError>
Set target speeds to zero (motors will ramp down smoothly).
§Errors
Returns RobotError::Shutdown if the robot has been shut down.