ROS2 CAN Package

Prerequisite

This Guide requires that you have an ODrive running and are able to communicate over CAN. If you have not already, please follow the Getting Started Guide and the CAN Bus Guide before continuing.

Note

The following documentation assumes a basic understanding of ROS2 concepts, workspaces, and tools. For a refresher on these topics, you can find the ROS2 documentation here.

Compatibility

This package was developed and tested for Ubuntu 23.04 and ROS2 Iron. Older versions (Ubuntu / ROS2) may require additional modifications to function properly. Mac and Windows are not currently supported.

Setting Up the ODrive

  1. Set the <axis>.config.can.node_id to 0 (default)

  2. Enable all the necessary cyclic messages for each ODrive:

  3. Verify these messages are working properly with:

    • candump can0 -xct z -n 10, or

    • python3 -m can.viewer -c "can0" -i "socketcan".

Installing the odrive_can Package

  1. Clone the official odrive_can repository into the src folder of your ROS2 workspace.

  2. Navigate to the top level of the ROS2 workspace folder and run;

    colcon build --packages-select odrive_can
    
  3. Source the workspace:

    source ./install/setup.bash
    
  4. Run the example launch file:

    ros2 launch odrive_can example_launch.yaml
    

    Hint

    This example assumes the axis node_id is 0, and the CAN network interface is “can0”. These expected values can be changed in ./launch/example_launch.yaml

Inspection

Note

The following commands assume the odrive_can_node is within the namespace odrive_axis0 (set in ./launch/example_launch.yaml).

Once the node is running you can verify everything is setup correctly by echoing the published topics:

ros2 topic echo /odrive_axis0/controller_status
ros2 topic echo /odrive_axis0/odrive_status

You can also verify the service is functioning by setting the axis state to IDLE:

ros2 service call /odrive_axis0/request_axis_state /odrive_can/srv/AxisState "{axis_requested_state: 1}"`

Hint

Make sure you have sourced the workspace that odrive_can was built in.