1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
mod error;

pub use error::{AxisError, EncoderError, MotorError};

pub type AxisId = u16;

#[repr(u32)]
#[derive(Debug, PartialEq, Eq, FromPrimitive, Copy, Clone)]
pub enum AxisState {
    Undefined,
    Idle,
    StartupSequence,
    FullCalibrationSequence,
    MotorCalibration,
    SensorlessControl,
    EncoderIndexSearch,
    EncoderOffsetCalibration,
    ClosedLoopControl,
    LockinSpin,
    EncoderDirFind,
    Homing,
}

#[repr(u32)]
#[derive(Debug, Copy, Clone)]
pub enum Command {
    Undefined,
    OdriveHeartbeat,
    OdriveEstop,
    GetMotorError,
    GetEncoderError,
    GetSensorlessError,
    SetAxisNodeId,
    SetAxisRequestedState,
    SetAxisStartupConfig,
    GetEncoderEstimates,
    GetEncoderCount,
    SetControllerModes,
    SetInputPos,
    SetInputVel,
    SetInputCurrent,
    SetVelLimit,
    StartAnticogging,
    SetTrajVelLimit,
    SetTrajAccelLimits,
    SetTrajAPerCss,
    GetIq,
    GetSensorlessEstimates,
    ResetOdrive,
    GetVbusVoltage,
    ClearErrors,
    Custom(u32),
}

impl From<u32> for Command {
    fn from(n: u32) -> Command {
        match n {
            0 => Command::Undefined,
            1 => Command::OdriveHeartbeat,
            2 => Command::OdriveEstop,
            3 => Command::GetMotorError,
            4 => Command::GetEncoderError,
            5 => Command::GetSensorlessError,
            6 => Command::SetAxisNodeId,
            7 => Command::SetAxisRequestedState,
            8 => Command::SetAxisStartupConfig,
            9 => Command::GetEncoderEstimates,
            10 => Command::GetEncoderCount,
            11 => Command::SetControllerModes,
            12 => Command::SetInputPos,
            13 => Command::SetInputVel,
            14 => Command::SetInputCurrent,
            15 => Command::SetVelLimit,
            16 => Command::StartAnticogging,
            17 => Command::SetTrajVelLimit,
            18 => Command::SetTrajAccelLimits,
            19 => Command::SetTrajAPerCss,
            20 => Command::GetIq,
            21 => Command::GetSensorlessEstimates,
            22 => Command::ResetOdrive,
            23 => Command::GetVbusVoltage,
            24 => Command::ClearErrors,
            _ => Command::Custom(n),
        }
    }
}

impl From<Command> for u32 {
    fn from(command: Command) -> u32 {
        match command {
            Command::Undefined => 0,
            Command::OdriveHeartbeat => 1,
            Command::OdriveEstop => 2,
            Command::GetMotorError => 3,
            Command::GetEncoderError => 4,
            Command::GetSensorlessError => 5,
            Command::SetAxisNodeId => 6,
            Command::SetAxisRequestedState => 7,
            Command::SetAxisStartupConfig => 8,
            Command::GetEncoderEstimates => 9,
            Command::GetEncoderCount => 10,
            Command::SetControllerModes => 11,
            Command::SetInputPos => 12,
            Command::SetInputVel => 13,
            Command::SetInputCurrent => 14,
            Command::SetVelLimit => 15,
            Command::StartAnticogging => 16,
            Command::SetTrajVelLimit => 17,
            Command::SetTrajAccelLimits => 18,
            Command::SetTrajAPerCss => 19,
            Command::GetIq => 20,
            Command::GetSensorlessEstimates => 21,
            Command::ResetOdrive => 22,
            Command::GetVbusVoltage => 23,
            Command::ClearErrors => 24,
            Command::Custom(n) => n,
        }
    }
}

#[repr(u32)]
#[derive(Debug, FromPrimitive)]
pub enum ControlMode {
    VoltageControl = 0,
    CurrentControl = 1,
    VelocityControl = 2,
    PositionControl = 3,
}

#[repr(u32)]
#[derive(Debug, FromPrimitive)]
pub enum InputMode {
    Inactive,
    PassThrough,
    VelocityRamp,
    PositionFilter,
    MixChannels,
    TrapezoidalTrajectory,
    CurrentRamp,
    Mirror,
}