CAN protocol help


I’m fairly new to electronics and would like an explanation on how to set up CAN protocol. Currently, I control the Odrive with a raspberry pi and python. I have been running into USB connectivity issues and read on this site that CAN is recommended.

I would like to know the following:

  • How to wire up the Odrive to the raspberry pi CAN hat
  • How to select an appropriate Baud rate for my application
  • Once it’s wired up correctly, do I need to change my code to accommodate CAN? If so, what do I need to change?

My code starts out as follows:

import odrive

print("finding an odrive...")
odrv0 = odrive.find_any()
print("voltage is ")

and then I proceed to control the motor with commands such as…

odrv0.axis0.controller.input_vel = 0
odrv0.axis0.requested_state = AXIS_STATE_IDLE
odrv0.axis0.controller.config.control_mode = CONTROL_MODE_VELOCITY_CONTROL

Thanks in advance! I appreciate any help!

Hi Phil,

The CAN Protocol is described here
I’m not sure if anyone has an ODrive CAN library for Raspberry Pi; you will likely have to write one from scratch.

Until you’re more comfortable with ODrive in general, I would recommend trying the ferrite rings on the shop, since it’s common that the USB drops out once you enter closed loop control without them.