This repository contains a ROS2 node intended for communication with ODrive motor controllers via CAN bus.
For information about installation, prerequisites, and getting started, checkout the ODrive ROS CAN Package Guide.
Compatible Devices:
(not compatible with ODrive 3.x)
System Requirements:
- Ubuntu >= 20.04
- ROS2 >= Humble
node_id
: The node_id of the device this node will attach tointerface
: the network interface name for the can bus
-
/control_message
: Input setpoints for the ODrive.The ODrive will interpret the values of input_pos, input_vel and input_torque depending on the control mode.
For example: In velocity control mode (2) input_pos is ignored, and input_torque is used as a feedforward term.
Note: When changing
input_mode
orcontrol_mode
, it is advised to set the ODrive to IDLE before doing so. Changing these values during CLOSED_LOOP_CONTROL is not advised.
-
/odrive_status
: Provides ODrive/system level status updates.For this topic to work, the ODrive must be configured with the following cyclic messages enabled:
error_msg_rate_ms
temperature_msg_rate_ms
bus_voltage_msg_rate_ms
The ROS node will wait until one of each of these CAN messages has arrived before it emits a message on the
odrive_status
topic. Therefore, the largest period set here will dictate the period of the ROS2 message as well. -
/controller_status
: Provides Controller level status updates.For this topic to work, the ODrive must be configured with the following cyclic messages enabled:
heartbeat_msg_rate_ms
encoder_msg_rate_ms
iq_msg_rate_ms
torques_msg_rate_ms
The ROS node will wait until one of each of these CAN messages has arrived before it emits a message on the
controller_status
topic. Therefore, the largest period set here will dictate the period of the ROS2 message as well.
-
/request_axis_state
: Sets the axes requested state.This service requires regular heartbeat messages from the ODrive to determine the procedure result and will block until the procedure completes, with a minimum call time of 1 second.
All of the Message/Service fields are directly related to their corresponding CAN message. For more detailed information about each type, and how to interpet the data, please refer to the ODrive CAN protocol documentation.
Python Example Node coming soon!
In the meantime, here is how you can use the odrive python package to display the enums:
from odrive_can.msgs import ControllerStatus # remember to include odrive_can as a package dependency
from odrive.enums import ProcedureResult
... # Node setup
ctrl_stat = ControllerStatus()
... # receive message data
print(ProcedureResult(ctrl_stat.procedure_result))
For user instructions, see this guide instead.
You can build this node on a non-ROS developer PC by using the DevContainer configurations in this repository. For example with VSCode:
-
Clone repository
-
Open the repository folder in VSCode. It should automatically present an option "Reopen in Dev Container". Click on that and select the desired ROS version.
-
Once it's re-opened, in the VSCode terminal, run:
colcon build --packages-select odrive_can source ./install/setup.bash
-
Running the node requires hardware access and only works if the container host is Linux.