robot_control/error.rs
1//! Error types for the robot-control crate.
2
3use thiserror::Error;
4
5/// Errors that can occur when interacting with a motor driver.
6#[derive(Debug, Error)]
7pub enum MotorError {
8 /// An I2C bus operation failed.
9 #[error("I2C error: {0}")]
10 I2c(String),
11
12 /// A PWM controller operation, drive input validation, or stopping failed.
13 /// Stop failures may collect multiple operation diagnostics in the message.
14 #[error("PWM error: {0}")]
15 Pwm(String),
16
17 /// The motor driver failed to initialize, or robot configuration was invalid.
18 #[error("initialization failed: {0}")]
19 Init(String),
20}
21
22/// Errors that can occur when controlling the robot.
23#[derive(Debug, Error)]
24pub enum RobotError {
25 /// A motor driver operation or controller validation failed.
26 #[error(transparent)]
27 Motor(#[from] MotorError),
28
29 /// The robot has already been shut down.
30 #[error("robot has been shut down")]
31 Shutdown,
32}