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::Motor wrapping MotorError::Init if the
configuration is invalid. No controller task or driver writes are started
on validation failure; constructing the driver itself may access hardware.
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.
Finite values are clamped to [-1.0, 1.0], multiplied by the motor factors
from RobotConfig, then clamped again to the supported output range.
A non-finite input rejects the entire command without changing targets.
§Errors
Returns RobotError::Shutdown if the robot has been shut down.
Returns RobotError::Motor wrapping MotorError::Pwm for a non-finite
input, retaining the existing error API.
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.