odrive_rs/enumerations/
errors.rs

1use std::io;
2
3/// The `ODriveResult` type is used as a return type for operations which read to
4/// or write from the ODrive.
5pub type ODriveResult<T> = Result<T, ODriveError>;
6
7#[derive(Debug)]
8pub enum ODriveError {
9    Axis(AxisError),
10    Motor(MotorError),
11    Encoder(EncoderError),
12    Controller(ControllerError),
13    /// Used when the ODrive sends us an invalid message.
14    /// If you see this, file an issue.
15    InvalidMessageReceived(String),
16    NoMessageReceived,
17    Io(io::Error)
18}
19
20#[repr(u16)]
21#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Copy, Clone)]
22pub enum AxisError {
23    ErrorNone = 0x00,
24    /// An invalid state was requested
25    ErrorInvalidState = 0x01,
26    ErrorDcBusUnderVoltage = 0x02,
27    ErrorDcBusOverVoltage = 0x04,
28    ErrorCurrentMeasurementTimeout = 0x08,
29    /// The brake resistor was unexpectedly disarmed
30    ErrorBrakeResistorDisarmed = 0x10,
31    /// The motor was unexpectedly disarmed
32    ErrorMotorDisarmed = 0x20,
33    ErrorMotorFailed = 0x40,
34    ErrorSensorlessEstimatorFailed = 0x80,
35    ErrorEncoderFailed = 0x100,
36    ErrorControllerFailed = 0x200,
37    ErrorPosCtrlDuringSensorless = 0x400,
38    ErrorWatchdogTimerExpired = 0x800,
39}
40
41#[repr(u16)]
42#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Copy, Clone)]
43pub enum MotorError {
44    ErrorNone = 0,
45    ErrorPhaseResistanceOutOfRange = 0x0001,
46    ErrorPhaseInductanceOutOfRange = 0x0002,
47    ErrorAdcFailed = 0x0004,
48    ErrorDrvFault = 0x0008,
49    ErrorControlDeadlineMissed = 0x0010,
50    ErrorNotImplementedMotorType = 0x0020,
51    ErrorBrakeCurrentOutOfRange = 0x0040,
52    ErrorModulationMagnitude = 0x0080,
53    ErrorBrakeDeadTimeViolation = 0x0100,
54    ErrorUnexpectedTimerCallback = 0x0200,
55    ErrorCurrentSenseSaturation = 0x0400,
56    ErrorCurrentUnstable = 0x1000,
57}
58
59#[repr(u8)]
60#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Copy, Clone)]
61pub enum EncoderError {
62    ErrorNone = 0,
63    ErrorUnstableGain = 0x01,
64    ErrorCprOutOfRange = 0x02,
65    ErrorNoResponse = 0x04,
66    ErrorUnsupportedEncoderMode = 0x08,
67    ErrorIllegalHallState = 0x10,
68    ErrorIndexNotFoundYet = 0x20,
69}
70
71#[repr(u8)]
72#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Copy, Clone)]
73pub enum ControllerError {
74    ErrorNone = 0,
75    ErrorOverspeed = 0x01,
76}