odrive_rs/enumerations/
mod.rs

1//! This file was derived from [the python library](https://github.com/madcowswe/ODrive/blob/master/tools/odrive/enums.py)
2
3/// Contains error enums that can be sent from the ODrive.
4///
5/// At the current moment, error handling is not fully implemented, so not all errors received from
6/// the ODrive will be caught.
7pub mod errors;
8
9/// Used to indicate one of the two motors controlled by the ODrive.
10#[repr(u8)]
11#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Copy, Clone)]
12pub enum AxisID {
13    Zero = 0,
14    One = 1,
15}
16
17/// # State Machine
18/// From the official docs:
19/// > The current state of an axis is indicated by `<axis>.current_state`.
20/// > The user can request a new state by assigning a new value to `<axis>.requested_state`.
21/// > The default state after startup is `Idle`.
22/// >
23/// > 1. `Idle`
24/// > 2. `StartupSequence`
25/// > 3. `FullCalibrationSequence`
26/// > 4. `MotorCalibration`
27/// > 5. `SensorlessControl`
28/// > 6. `EncoderIndexSearch`
29/// > 7. `EncoderOffsetCalibration`
30/// > 8. `ClosedLoopControl`
31#[repr(u8)]
32#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Copy, Clone)]
33pub enum AxisState {
34    /// Used for
35    Undefined = 0,
36    /// Disable motor PWM and do nothing
37    Idle = 1,
38    /// Run the startup procedure.
39    StartupSequence = 2,
40    /// Run motor calibration and then encoder offset calibration
41    /// (or encoder index search if `<axis>.encoder.config.use_index` is `true`).
42    FullCalibrationSequence = 3,
43    /// Measure phase resistance and phase inductance of the motor.
44    ///
45    /// To store the results set <`axis>.motor.config.pre_calibrated` to `true` and save the configuration.
46    /// After that you don’t have to run the motor calibration on the next start up.
47    /// This modifies the variables `<axis>.motor.config.phase_resistance` and `<axis>.motor.config.phase_inductance`.
48    MotorCalibration = 4,
49    /// Run sensorless control.
50    ///
51    /// The motor must be calibrated (`<axis>.motor.is_calibrated`).
52    /// `<axis>.controller.control_mode` must be `true`.
53    SensorlessControl = 5,
54    /// Turn the motor in one direction until the encoder index is traversed.
55    ///
56    /// This state can only be entered if `<axis>.encoder.config.use_index` is `true`.
57    EncoderIndexSearch = 6,
58    /// Turn the motor in one direction for a few seconds and then back
59    /// to measure the offset between the encoder position and the electrical phase.
60    ///
61    /// Can only be entered if the motor is calibrated (`<axis>.motor.is_calibrated`).
62    /// A successful encoder calibration will make the `<axis>.encoder.is_ready` go to `true`.
63    EncoderOffsetCalibration = 7,
64    /// Run closed loop control.
65    ///
66    /// The action depends on the control mode.
67    /// Can only be entered if the motor is calibrated (`<axis>.motor.is_calibrated`)
68    /// and the encoder is ready (`<axis>.encoder.is_ready`).
69    ClosedLoopControl = 8,
70}
71
72#[repr(u8)]
73#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Copy, Clone)]
74pub enum MotorType {
75    HighCurrent = 0,
76    LowCurrent = 1,
77    MotorTypeGimbal = 2,
78}
79
80#[repr(u8)]
81#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Copy, Clone)]
82pub enum ControlMode {
83    VoltageControl = 0,
84    CurrentControl = 1,
85    VelocityControl = 2,
86    PositionControl = 3,
87    TrajectoryControl = 4,
88}
89
90#[repr(u8)]
91#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Copy, Clone)]
92pub enum EncoderMode {
93    EncoderModeIncremental = 0,
94    EncoderModeHall = 1,
95}