Post · 21 min read· pp. 132–148

CAN Protocol

Note

This document describes the CAN Protocol. For examples of usage, check out our CAN Bus Guide.

Overview

  • The ODrive CANSimple protocol uses standard 11-bit message identifiers.

    CANSimple Message ID

    CANSimple Message ID

  • Messages prefixed with Set_ are messages that the host can send to the ODrive.

  • Messages prefixed with Get_ are messages that the ODrive can send to the host. These messages can be enabled as Cyclic Messages or requested explicitly by the master. To explicitly request a message, the master sends a message with the RTR bit set, and the ODrive responds with the same ID and corresponding payload. (A message with of RTR=0 and an empty payload can also be used, but is susceptible to collisions with the ODrive’s response.)

  • All values are encoded in little endian (aka Intel format, aka least significant byte first).

  • Floats are encoded with the standard IEEE 754 Float format.

  • Reserved fields and padding in Host → ODrive messages must be set to 0.

  • Reserved fields and padding in ODrive → Host messages must be ignored.

  • Beyond the predefined messages below, all parameters and functions of the ODrive are accessible via RxSdo / TxSdo. See Arbitrary Parameter Access for examples.

CAN Messages - click on the message name for details

CMD IDNameDirectionSignals
0x000Get_VersionODrive → HostProtocol_Version Hw_Version_Major Hw_Version_Minor Hw_Version_Variant Fw_Version_Major Fw_Version_Minor Fw_Version_Revision Fw_Version_Unreleased
0x001HeartbeatODrive → HostAxis_Error Axis_State Procedure_Result Trajectory_Done_Flag
0x002EstopHost → ODrive
0x003Get_ErrorODrive → HostActive_Errors Disarm_Reason
0x004RxSdoHost → ODriveOpcode Endpoint_ID Reserved Value
0x005TxSdoODrive → HostReserved0 Endpoint_ID Reserved1 Value
0x006AddressHost → ODrive, ODrive → HostNode_ID Serial_Number Connection_ID
0x007Set_Axis_StateHost → ODriveAxis_Requested_State
0x009Get_Encoder_EstimatesODrive → HostPos_Estimate Vel_Estimate
0x00bSet_Controller_ModeHost → ODriveControl_Mode Input_Mode
0x00cSet_Input_PosHost → ODriveInput_Pos Vel_FF Torque_FF
0x00dSet_Input_VelHost → ODriveInput_Vel Input_Torque_FF
0x00eSet_Input_TorqueHost → ODriveInput_Torque
0x00fSet_LimitsHost → ODriveVelocity_Limit Current_Limit
0x011Set_Traj_Vel_LimitHost → ODriveTraj_Vel_Limit
0x012Set_Traj_Accel_LimitsHost → ODriveTraj_Accel_Limit Traj_Decel_Limit
0x013Set_Traj_InertiaHost → ODriveTraj_Inertia
0x014Get_IqODrive → HostIq_Setpoint Iq_Measured
0x015Get_TemperatureODrive → HostFET_Temperature Motor_Temperature
0x016RebootHost → ODriveAction
0x017Get_Bus_Voltage_CurrentODrive → HostBus_Voltage Bus_Current
0x018Clear_ErrorsHost → ODriveIdentify
0x019Set_Absolute_PositionHost → ODrivePosition
0x01aSet_Pos_GainHost → ODrivePos_Gain
0x01bSet_Vel_GainsHost → ODriveVel_Gain Vel_Integrator_Gain
0x01cGet_TorquesODrive → HostTorque_Target Torque_Estimate
0x01dGet_PowersODrive → HostElectrical_Power Mechanical_Power
0x01fEnter_DFU_ModeHost → ODrive

Cyclic Messages

The ODrive can be configured to send some messages periodically without a request from the host. This is done by setting the desired send intervals in <odrv>.axis.config.can. An interval of 0 disables the message. If the ODrive is unaddressed (node_id = 0x3f), all cyclic messages are disabled regardless of their configured interval.

Watchdog

The ODrive’s watchdog timer can be used as a safety feature to disable the motor when CAN communication is disrupted.

See axis.config.enable_watchdog on how to enable the watchdog timer.

The watchdog is reset by every Set_Input_Pos, Set_Input_Vel and Set_Input_Torque message, as well as when entering CLOSED_LOOP_CONTROL through Set_Axis_State.

Baudrate & Autobaud

The ODrive’s baudrate (can.config.baud_rate) can either be explicitly configured by the user or left at 0 (default) to enable automatic baudrate detection (new in Firmware 0.6.11).

When using automatic baudrate detection, the ODrive starts in a “scanning mode” where it does not handle any CAN commands and does not send any CAN messages, but relies on incoming CAN traffic to detect the baudrate. For quick initialization, users are recommended to send a “beacon message” (any message ID / payload) at 10Hz or faster.

Once the scan completes, the ODrive responds normally to CAN messages and sends Cyclic Messages if applicable.

When the ODrive runs into a bus-off condition, it drops back into scanning mode.

In production systems it is recommended to configure the baudrate explicitily to guarantee deterministic startup time.

Supported baudrates for autodetection: 40kbps, 125kbps, 250kbps, 500kbps, 1Mbps.

Bit Timing

The ODrive uses the following fixed bit timing parameters for all baudrates, for both nominal and data phases:

  • Bit length: 8 time quanta (1 sync + 6 propagation/phase1 + 1 phase2)
  • Sample point: 87.5%
  • Synchronization Jump Width (SJW): 1 time quantum

CAN-FD

⇒ New in Firmware 0.6.10

ODrive Pro, S1 and Micro support CAN-FD. Classic CAN and CAN-FD frames can be mixed on the same bus, provided that all other bus nodes tolerate CAN-FD traffic.

  • Receiving: To receive CAN-FD frames with the Bit Rate Switch (BRS) flag set, you must set can.config.data_baud_rate.
  • Transmitting: By default, the ODrive sends all of its messages as Classic CAN frames. Set can.config.tx_brs to True to send all messages as CAN-FD frames.

Usage notes:

  • The CANSimple protocol is identical over Classic CAN and CAN-FD; all message payloads fit within 8 bytes, and the larger payload sizes of CAN-FD are currently not supported or utilized.
  • The CAN-FD frame format does not support the RTR bit. Hosts that transmit exclusively in CAN-FD format can request Get_ messages by sending a data frame with an empty payload instead (see Overview).
  • The data phase baudrate is not covered by automatic baudrate detection. When using BRS, all nodes must be explicitly configured to the same data baudrate. The maximum supported data baudrate depends on the hardware, see can.config.data_baud_rate for details.
  • The bit timing parameters above apply to the data phase as well.

Warning

Since can.config.data_baud_rate defaults to 0 and is not autodetected, an unconfigured ODrive cannot join a bus that carries BRS traffic. Commissioning a new ODrive and firmware update over CAN therefore require temporarily stopping all BRS traffic on the bus.

Note

Firmware versions 0.6.10 and 0.6.11 could run into spurious bus-off events when CAN-FD frames were present on the bus. Firmware version 0.6.12 or newer is recommended when using CAN-FD.

Broadcast

⇒ New in Firmware 0.6.9

The node ID 0x3f is a special broadcast address. When the host sends a message with this ID, it is received by all ODrives on the bus. If the broadcast message yields a response (typically Get_ messages with RTR=1), each ODrive responds with its own node_id.

If an ODrive is configured with node_id = 0x3f, it does not send out any cyclic messages or responses, except for the special message Address.

Discovery & Addressing

⇒ New in Firmware 0.6.9

By default, an unconfigured ODrive starts with node_id = 0x3f, which represents an unaddressed state. In this state the ODrive does not send any cyclic messages (heartbeats, feedback, …).

The node ID can be configured using odrivetool or the Web GUI, connected over either USB or CAN. Both will automatically assign a temporary node ID when they connect over CAN to an unaddressed ODrive. Once connected, the user can change <axis>.config.can.node_id to the desired value. The ODrive will briefly disconnect and reconnect with the new node ID.

Alternatively, a user application can use the Address message to enumerate ODrives and assign node IDs:

  • Enumerate all ODrives on the bus:

    Send (node_id = 0x3f, cmd_id = 0x06, RTR=1).

    All ODrives that are already addressed (node_id != 0x3f) will respond immediately with their serial number and node_id.

    All unaddressed ODrives (node_id == 0x3f) will respond after a small random delay, averaging 250 ms between each message.

  • Assign a new node ID (N) to an ODrive with unknown node ID and known serial number (SN):

    Send (node_id = 0x3f, cmd_id = 0x06, Node_ID = N, Serial_Number = SN).

    If the ODrive was at its default configuration, it will now start periodically sending Heartbeat and Get_Encoder_Estimates messages.

  • Assign a new node ID (new_N) to an ODrive with known node ID (old_N) and unknown serial number:

    Send (node_id = old_N, cmd_id = 0x06, Node_ID = new_N, Serial_Number = 0).

Furthermore, the Identify field in Clear_Errors can be used to blink the status LED. This allows for setting up an interactive procedure that lets the user associate newly discovered unconfigured ODrives with their location in a multi-axis robot.

A new node ID (whether assigned explicitly by the user or auto-assigned by odrivetool or the Web GUI) takes effect immediately but must be saved (save_configuration() / Reboot with Action = 1) to remain persistent across reboots.

Bus-off handling

“Bus-off” events are part of the CAN specification and are usually the result of a persistent fault condition on the CAN bus (e.g. short, disconnect or faulty bus node).

When the ODrive encounters a bus-off event, it reacts as follows:

  • if autobaud is enabled: Drops into scanning mode.
  • if autobaud is disabled: Restarts its CAN interface. If the fault condition persists, the CAN interface is restarted repeatedly. See also n_restarts.

DBC Files

DBC files are machine-readable database files that describe CAN message formats.

The CANSimple .dbc file for each firmware version can be downloaded here.

Several tools and libraries exist to ingest DBC files. For example you can use the free CANdb++ software from Vector to view the database.

Interoperability with CANopen

ODrives can coexist with CANopen devices on the same bus if caution is taken with the node ID assignment.

The following table lists the valid combinations of node IDs for both CANopen and CANsimple.

CANOpen node IDsODrive CANSimple node IDs
32 … 1270x10, 0x18, 0x20, 0x28
64 … 1270x10, 0x11, 0x18, 0x19, 0x20, 0x21, 0x28, 0x29
96 … 1270x10, 0x11, 0x12, 0x18, 0x19, 0x1A, 0x20, 0x21, 0x22, 0x28, 0x29, 0x2A

Messages

Get_Version

  • Command ID: 0x00
  • Direction: ODrive → Host
Start ByteNameTypeDescription
0Protocol_Versionuint8Always reported as 2
1Hw_Version_Majoruint8hw_version_major
2Hw_Version_Minoruint8hw_version_minor
3Hw_Version_Variantuint8hw_version_variant
4Fw_Version_Majoruint8fw_version_major
5Fw_Version_Minoruint8fw_version_minor
6Fw_Version_Revisionuint8fw_version_revision
7Fw_Version_Unreleaseduint8fw_version_unreleased

Heartbeat

  • Command ID: 0x01
  • Direction: ODrive → Host
Start ByteNameTypeDescription
0Axis_Erroruint32<axis>.active_errors
4Axis_Stateuint8<axis>.current_state
5Procedure_Resultuint8<axis>.procedure_result
6Trajectory_Done_Flaguint8<axis>.controller.trajectory_done (0: false, 1: true)

Estop

  • Command ID: 0x02
  • Direction: Host → ODrive
  • Empty Payload

Causes the axis to disarm with ESTOP_REQUESTED.

Get_Error

  • Command ID: 0x03
  • Direction: ODrive → Host
Start ByteNameTypeDescription
0Active_Errorsuint32active_errors
4Disarm_Reasonuint32disarm_reason

RxSdo

  • Command ID: 0x04
  • Direction: Host → ODrive
Start ByteNameTypeDescription
0Opcodeuint80: read, 1: write
1Endpoint_IDuint16Endpoint ID as found in flat_endpoints.json
3Reserveduint8Must be set to 0
4Valueuint32Data type and length depend on endpoint ID

Sent by the host to read or write from/to arbitrary parameters. See Arbitrary Parameter Access for details.

TxSdo

  • Command ID: 0x05
  • Direction: ODrive → Host
Start ByteNameTypeDescription
0Reserved0uint8Must be ignored by host
1Endpoint_IDuint16Endpoint ID as found in flat_endpoints.json
3Reserved1uint8Must be ignored by host
4Valueuint32Data type and length depend on endpoint ID

Sent by the ODrive in response to any RxSdo. See Arbitrary Parameter Access for details.

Address

  • Command ID: 0x06
  • Direction: Host → ODrive, ODrive → Host
Start ByteNameTypeDescription
0Node_IDuint8node_id
1Serial_Numberuint48ODrive → Host: Serial number of the sending ODrive Host → ODrive: The serial number that shall be associated with the specified Node_ID
7Connection_IDuint8Connection ID. Can be left 0

Main section: Discovery & Addressing.

When an ODrive receives this message (subject to receive filters, that means node_id contained in the message ID must matches its own or be 0x3f), it takes the following action:

  • RTR=1 (or empty payload): Respond with own serial number and node_id.
  • Matching Serial_Number: Take on the new Node_ID.
  • Mismatching Serial_Number but matching Node_ID: Go to unaddressed state (node_id = 0x3f).
  • Mismatching Serial_Number and mismatching Node_ID: Ignore message.

Serial_Number == 0 is considered a wildcard that always matches.

Responses on this message are sent even if the ODrive is unaddressed (node_id = 0x3f). In this case, the response is sent after a random delay to avoid collisions.

Set_Axis_State

  • Command ID: 0x07
  • Direction: Host → ODrive
Start ByteNameTypeDescription
0Axis_Requested_Stateuint32requested_state

Get_Encoder_Estimates

  • Command ID: 0x09
  • Direction: ODrive → Host
Start ByteNameTypeUnitDescription
0Pos_Estimatefloat32rev<axis>.pos_vel_mapper.pos_rel or <axis>.pos_vel_mapper.pos_abs, depending on ODrive.Controller.Config.absolute_setpoints
4Vel_Estimatefloat32rev/s<axis>.pos_vel_mapper.vel

This message is sent by the ODrive periodically by default. See also Cyclic Messages.

Set_Controller_Mode

  • Command ID: 0x0b
  • Direction: Host → ODrive
Start ByteNameTypeDescription
0Control_Modeuint32control_mode
4Input_Modeuint32input_mode

Set_Input_Pos

  • Command ID: 0x0c
  • Direction: Host → ODrive
Start ByteNameTypeUnitDescription
0Input_Posfloat32revinput_pos
4Vel_FFint160.001 rev/s (default) [1]input_vel
6Torque_FFint160.001 Nm (default) [2]input_torque

[1]

Scale configurable in input_vel_scale. Interpreted as input_vel = Vel_FF/input_vel_scale

[2]

Scale configurable in input_torque_scale. Interpreted as input_torque = Torque_FF/input_torque_scale

Set_Input_Vel

  • Command ID: 0x0d
  • Direction: Host → ODrive
Start ByteNameTypeUnitDescription
0Input_Velfloat32rev/sinput_vel
4Input_Torque_FFfloat32Nminput_torque

Set_Input_Torque

  • Command ID: 0x0e
  • Direction: Host → ODrive
Start ByteNameTypeUnitDescription
0Input_Torquefloat32Nminput_torque

Set_Limits

  • Command ID: 0x0f
  • Direction: Host → ODrive
Start ByteNameTypeUnitDescription
0Velocity_Limitfloat32rev/svel_limit
4Current_Limitfloat32Acurrent_soft_max

Set_Traj_Vel_Limit

  • Command ID: 0x11
  • Direction: Host → ODrive
Start ByteNameTypeUnitDescription
0Traj_Vel_Limitfloat32rev/svel_limit

Set_Traj_Accel_Limits

  • Command ID: 0x12
  • Direction: Host → ODrive
Start ByteNameTypeUnitDescription
0Traj_Accel_Limitfloat32rev/s^2accel_limit
4Traj_Decel_Limitfloat32rev/s^2decel_limit

Set_Traj_Inertia

  • Command ID: 0x13
  • Direction: Host → ODrive
Start ByteNameTypeUnitDescription
0Traj_Inertiafloat32Nm/(rev/s^2)inertia

Get_Iq

  • Command ID: 0x14
  • Direction: ODrive → Host
Start ByteNameTypeUnitDescription
0Iq_Setpointfloat32AIq_setpoint
4Iq_Measuredfloat32AIq_measured

Get_Temperature

  • Command ID: 0x15
  • Direction: ODrive → Host
Start ByteNameTypeUnitDescription
0FET_Temperaturefloat32deg C<axis>.motor.fet_thermistor.temperature
4Motor_Temperaturefloat32deg C<axis>.motor.motor_thermistor.temperature

Reboot

  • Command ID: 0x16
  • Direction: Host → ODrive
Start ByteNameTypeDescription
0Actionuint80: reboot() 1: save_configuration() 2: erase_configuration() 3: enter_dfu_mode2()

Reboots the ODrive according to Action. This requires the axis to be in IDLE.

Get_Bus_Voltage_Current

  • Command ID: 0x17
  • Direction: ODrive → Host
Start ByteNameTypeUnitDescription
0Bus_Voltagefloat32Vvbus_voltage
4Bus_Currentfloat32Aibus

Clear_Errors

  • Command ID: 0x18
  • Direction: Host → ODrive
Start ByteNameTypeDescription
0Identifyuint8identify

Equivalent to calling clear_errors().

Set_Absolute_Position

  • Command ID: 0x19
  • Direction: Host → ODrive
Start ByteNameTypeUnitDescription
0Positionfloat32revpos_estimate

See also Custom User Reference Frame.

Set_Pos_Gain

  • Command ID: 0x1a
  • Direction: Host → ODrive
Start ByteNameTypeUnitDescription
0Pos_Gainfloat32(rev/s) / revpos_gain

Set_Vel_Gains

  • Command ID: 0x1b
  • Direction: Host → ODrive
Start ByteNameTypeUnitDescription
0Vel_Gainfloat32Nm / (rev/s)vel_gain
4Vel_Integrator_Gainfloat32Nm / revvel_integrator_gain

Get_Torques

  • Command ID: 0x1c
  • Direction: ODrive → Host
Start ByteNameTypeUnitDescription
0Torque_Targetfloat32Nmeffective_torque_setpoint
4Torque_Estimatefloat32Nmtorque_estimate

Get_Powers

  • Command ID: 0x1d
  • Direction: ODrive → Host
Start ByteNameTypeUnitDescription
0Electrical_Powerfloat32Welectrical_power
4Mechanical_Powerfloat32Wmechanical_power

Enter_DFU_Mode

  • Command ID: 0x1f
  • Direction: Host → ODrive
  • Empty Payload

Puts the ODrive into DFU mode (see Firmware Update). Equivalent to calling enter_dfu_mode2().