Hi there, i am confused about the motor error enums.
Everywhere i looked there were many motor errors and the values for the last enum values are very large. So large that is is in fact too large for a 32-bit integer. However, all error codes are supposedly int32’s. What am I not seeing or is this a mistake and no one has seen it since ODrive exists?
This is an example from the ODriveArduino library ‘ODriveEnums.h’:
enum MotorError {
MOTOR_ERROR_NONE = 0x00000000,
MOTOR_ERROR_PHASE_RESISTANCE_OUT_OF_RANGE = 0x00000001,
MOTOR_ERROR_PHASE_INDUCTANCE_OUT_OF_RANGE = 0x00000002,
MOTOR_ERROR_DRV_FAULT = 0x00000008,
MOTOR_ERROR_CONTROL_DEADLINE_MISSED = 0x00000010,
MOTOR_ERROR_MODULATION_MAGNITUDE = 0x00000080,
MOTOR_ERROR_CURRENT_SENSE_SATURATION = 0x00000400,
MOTOR_ERROR_CURRENT_LIMIT_VIOLATION = 0x00001000,
MOTOR_ERROR_MODULATION_IS_NAN = 0x00010000,
MOTOR_ERROR_MOTOR_THERMISTOR_OVER_TEMP = 0x00020000,
MOTOR_ERROR_FET_THERMISTOR_OVER_TEMP = 0x00040000,
MOTOR_ERROR_TIMER_UPDATE_MISSED = 0x00080000,
MOTOR_ERROR_CURRENT_MEASUREMENT_UNAVAILABLE = 0x00100000,
MOTOR_ERROR_CONTROLLER_FAILED = 0x00200000,
MOTOR_ERROR_I_BUS_OUT_OF_RANGE = 0x00400000,
MOTOR_ERROR_BRAKE_RESISTOR_DISARMED = 0x00800000,
MOTOR_ERROR_SYSTEM_LEVEL = 0x01000000,
MOTOR_ERROR_BAD_TIMING = 0x02000000,
MOTOR_ERROR_UNKNOWN_PHASE_ESTIMATE = 0x04000000,
MOTOR_ERROR_UNKNOWN_PHASE_VEL = 0x08000000,
MOTOR_ERROR_UNKNOWN_TORQUE = 0x10000000,
MOTOR_ERROR_UNKNOWN_CURRENT_COMMAND = 0x20000000,
MOTOR_ERROR_UNKNOWN_CURRENT_MEASUREMENT = 0x40000000,
MOTOR_ERROR_UNKNOWN_VBUS_VOLTAGE = 0x80000000,
MOTOR_ERROR_UNKNOWN_VOLTAGE_COMMAND = 0x100000000,
MOTOR_ERROR_UNKNOWN_GAINS = 0x200000000,
MOTOR_ERROR_CONTROLLER_INITIALIZING = 0x400000000,
MOTOR_ERROR_UNBALANCED_PHASES = 0x800000000,
};
These error codes are also in the documentation, so I assume they are correct.
In C++, enums are by default interpreted as ints, which is in many cases by default int32, just like the endpoints say. But when putting this code into Visual Studio it screams that the last 4 enum values are too large and are all interpreted as 0!
What am I overlooking?
If I’m not mistaking this would result in the last 4 errors never getting called (and not even handled, simply ignored as if nothing happened)