This module implements the motor driver for ODrive Robotics' ODrive S1 and ODrive Pro motors to be used with viam-server. This driver supports either a serial or canbus motor.
To use this module, follow the instructions to add a module from the Viam registry, choose the Motor component, and select the odrive:serial or odrive:canbus model from the odrive module, depending on the type of motor you are using.
Note
Before configuring your motor, you must create a robot.
Navigate to the Config tab of your robot’s page in the Viam app. Click on the Components subtab and click Create component. Select the motor type, then select the odrive:serial or odrive:canbus model. Enter a name for your motor and click Create.
- Install
odrivetool
[NOTE] When making the initial connection to set up the ODrive, you must make a serial connection. If you intend to use a canbus connection, you can either leave the serial connection plugged in, or remove it and just leave the CANH and CANL pins wired after you initially set up the ODrive.
Use odrivetool to configure and tune your motor properly. This configuration remains on the same ODrive motor controller across reboots, but you can run odrivetool again to make changes to the configuration as needed. See the ODrive documentation for more information.
- Note that
iq_msg_rate_msin the config defaults to0, and you must set this to around100to use the motor API'sSetPowermethod. - See the section Add an
odrive_config_filefor more information on dynamic configuration. - See the ODrive CAN documentation for detailed information on how to set up CAN on your ODrive.
Connect your ODrive motor to your single-board computer by plugging the USB Isolator for ODrive into a USB port on your board, and then plug a USB-A to USB-C cable from the isolator to the ODrive.
On the new component panel, copy and paste the following attribute template into your motor’s Attributes box:
{
"serial_number": "NUM000",
"odrive_config_file": "local/path/to/motor/config.json"
}Update the serial_number field with the specific serial number of your ODrive motor (if you are using more than one), and replace the odrive_config_file path with the path to your file, as written by odrivetool when you configured the hardware.
The following attributes are available for the motor resources available in the Viam ODrive module:
| Name | Type | Inclusion | Description |
|---|---|---|---|
odrive_config_file |
string | Optional | Filepath of a separate JSON file containing your ODrive's native configuration. See the Odrive S1 Modular Component repository for an example of this file. |
serial_number |
string | Optional | The serial number of the ODrive. Note that this is not necessary if you only have one ODrive connected. See Troubleshooting for help finding this value. |
To add an odrive_config_file and reconfigure your ODrive natively each time the motor is initialized on the robot:
- Using
odrivetool, run theodrivetool backup-config config.jsoncommand on your single-board computer to extract your configurations from your ODrive to a file namedconfig.json. See the ODrive documentation for more info. - Set
iq_msg_rate_msin the configuration file to around100to use the motor API'sSetPowermethod. - If you add an
odrive_config_fileto ancanbusmotor, you must leave the serial connection established with your ODrive plugged in to the USB port, in addition to wiring the CANH and CANL pins. Alternatively, you can run theodrivetool restore-config /path/to/config.jsoncommand in your terminal instead of adding anodrive_config_file.
See the ODrive sample config.json file for an example of an odrive_config_file.
This example shows the configuration for an ODrive motor using a serial connection, including an odrive_config_file.
{
"odrive_config_file": "/path/to/my/config.json"
}- Install
odrivetool,python-can, andcantools - Enable SPI communication on your single-board computer to support the use of several common CANHats. If you are using a Raspberry Pi, see these instructions. Other single-board computers may have other ways of setting up CANBus communications; consult the documentation for your specific board for further guidance.
[NOTE] When making the initial connection to set up the ODrive, you must make a serial connection. If you intend to use a canbus connection, you can either leave the serial connection plugged in, or remove it and just leave the CANH and CANL pins wired after you initially set up the ODrive.
Use odrivetool to configure and tune your motor properly. This configuration remains on the same ODrive motor controller across reboots, but you can run odrivetool again to make changes to the configuration as needed. See the ODrive documentation for more information.
- Note that
iq_msg_rate_msin the config defaults to0, and you must set this to around100to use the motor API'sSetPowermethod. - See the section Add an
odrive_config_filefor more information on dynamic configuration. - See the ODrive CAN documentation for detailed information on how to set up CAN on your ODrive.
Connect your ODrive motor to your single-board computer in one of the following ways:
- For a
serialconnection: plug the USB Isolator for ODrive into a USB port on your board, and then plug a USB-A to USB-C cable from the isolator to the ODrive. - For a
canbusconnection: wire the CANH and CANL pins from your board to your ODrive. Refer to the ODrive pinout diagram for further guidance.- You must make a
serialconnection initially to set up your ODrive, even if you intend to use acanbusconnection eventually. After setting up the ODrive using aserialconnection, if you wish to use thecanbusmodel, you can either leave the serial connection plugged in or remove it and leave only the CANH and CANL pins wired. - If you are using a Raspberry Pi, you must run
sudo ip link set can0 up type can bitrate <baud_rate>in the terminal on your single-board computer in order to receive CAN messages. See Troubleshooting: CAN Link Issues for more details.
- You must make a
On the new component panel, copy and paste the following attribute template into your motor’s Attributes box:
Update the serial_number field with the specific serial number of your ODrive motor (if you are using more than one), and replace the odrive_config_file path with the path to your file, as written by odrivetool when you configured the hardware.
{
"serial_number": "NUM000",
"odrive_config_file": "local/path/to/motor/config.json",
"canbus_node_id": 0
}Update the canbus_node_id (int) to the node ID of whichever CAN node you'd like to use.
The following attributes are available for the motor resources available in the Viam ODrive module:
| Name | Type | Inclusion | Description |
|---|---|---|---|
canbus_node_id |
int | Optional | Required for successful initialization of the "canbus" type. Node ID of the CAN node you would like to use. You configured this when setting up your ODrive. Example: 0 |
odrive_config_file |
string | Optional | Filepath of a separate JSON file containing your ODrive's native configuration. See the Odrive S1 Modular Component repository for an example of this file. |
serial_number |
string | Optional | The serial number of the ODrive. Note that this is not necessary if you only have one ODrive connected. See Troubleshooting for help finding this value. |
canbus_baud_rate |
string | Optional | Baud rate of the ODrive CAN protocol. This attribute is only available for "canbus" connections. Use odrivetool to obtain this value with <odrv>.can.config.baud_rate. Format the string as a multiple of 1000 (k). Example: "250k" |
To add an odrive_config_file and reconfigure your ODrive natively each time the motor is initialized on the robot:
- Using
odrivetool, run theodrivetool backup-config config.jsoncommand on your single-board computer to extract your configurations from your ODrive to a file namedconfig.json. See the ODrive documentation for more info. - Set
iq_msg_rate_msin the configuration file to around100to use the motor API'sSetPowermethod. - If you add an
odrive_config_fileto ancanbusmotor, you must leave the serial connection established with your ODrive plugged in to the USB port, in addition to wiring the CANH and CANL pins. Alternatively, you can run theodrivetool restore-config /path/to/config.jsoncommand in your terminal instead of adding anodrive_config_file.
See the ODrive sample config.json file for an example of an odrive_config_file.
This example shows the configuration for two ODrive motors using a canbus connection, where each motor specifies its own odrive_config_file.
You can add or edit this configuration on your robot's page on the Viam app. Navigate to the Config tab on your robot's page and select Raw JSON mode.
{
"canbus_node_id": 0,
"odrive_config_file": "/path/to/first/config.json",
"serial_number": "NUM0001"
}- To test your ODrive motor, go to the Control tab.
- To write code against your ODrive motor, use one of the available SDKs.
- To view examples using a motor component, explore these tutorials.
- The motor is likely not properly tuned. See the ODrive documentation for instructions on how to tune.
- If you have provided a serial number, make sure it is the correct serial number. ODrives have 2 serial numbers: one that will be printed out when you start
odrivetool, and one that can be accessed inodrivetoolby runningodrv0.serial_number. The correct serial number is the one that is printed out when you startodrivetool. - If you have not provided a serial number or you are sure you have provided the correct serial number, you are likely connected to the ODrive elsewhere. Make sure any connections via Python,
odrivetoolor the GUI are closed.
- If you get an error of
"Device or resource busy", try setting CAN down and back up with the commandsudo ip link set can0 downfollowed bysudo ip link set can0 up type can bitrate <baud_rate>- You will have to do this any time you want to change the baud rate
- If you get an error of
"Network is down", try setting CAN up with the commandsudo ip link set can0 up type can bitrate <baud_rate>
Copyright 2021-2023 Viam Inc.
Apache 2.0 - See LICENSE file