A few bits and pieces I’ve picked up playing with the ODrive 3.X
In no particular order, here are some of the ODrive commands I’ve found most valueable. My hope is that by putting these here it saves you some of the headaches I’ve endured over time with the Odrive.
Pre-calibrating an Odrive and Startup routine
If you want to have your odrive start up with a index offiset calibration automatically every time, execute the following commands . this code assumes two odrives with two motors each.
odrv0.axis0.requested_state = AXIS_STATE_FULL_CALIBRATION_SEQUENCE
odrv0.axis0.motor.config.pre_calibrated = True
odrv0.axis0.config.startup_encoder_offset_calibration = True
odrv0.axis0.config.startup_closed_loop_control = True
odrv0.axis1.requested_state = AXIS_STATE_FULL_CALIBRATION_SEQUENCE
odrv0.axis1.motor.config.pre_calibrated = True
odrv0.axis1.config.startup_encoder_offset_calibration = True
odrv0.axis1.config.startup_closed_loop_control = True
odrv1.axis0.requested_state = AXIS_STATE_FULL_CALIBRATION_SEQUENCE
odrv1.axis0.motor.config.pre_calibrated = True
odrv1.axis0.config.startup_encoder_offset_calibration = True
odrv1.axis0.config.startup_closed_loop_control = True
odrv1.axis1.requested_state = AXIS_STATE_FULL_CALIBRATION_SEQUENCE
odrv1.axis1.motor.config.pre_calibrated = True
odrv1.axis1.config.startup_encoder_offset_calibration = True
odrv1.axis1.config.startup_closed_loop_control = True
odrv0.save_configuration()
odrv1.save_configuration()
Code language: PHP (php)
Getting moving up after a pr-calibrated startup
4 motors across 2 odrives
odrv0.axis0.controller.config.control_mode = CONTROL_MODE_VELOCITY_CONTROL
odrv0.axis1.controller.config.control_mode = CONTROL_MODE_VELOCITY_CONTROL
odrv1.axis0.controller.config.control_mode = CONTROL_MODE_VELOCITY_CONTROL
odrv1.axis1.controller.config.control_mode = CONTROL_MODE_VELOCITY_CONTROL
odrv0.axis0.requested_state = AXIS_STATE_CLOSED_LOOP_CONTROL
odrv0.axis1.requested_state = AXIS_STATE_CLOSED_LOOP_CONTROL
odrv1.axis0.requested_state = AXIS_STATE_CLOSED_LOOP_CONTROL
odrv1.axis1.requested_state = AXIS_STATE_CLOSED_LOOP_CONTROL
odrv0.axis0.controller.input_vel = 1
odrv0.axis1.controller.input_vel = 1
odrv1.axis0.controller.input_vel = 1
odrv1.axis1.controller.input_vel = 1
Seeing the error state of the Odrive and clearing errors
View Errors and clear errors on two odrives at once:
dump_errors(odrv0)
dump_errors(odrv1)
odrv0.clear_errors()
odrv1.clear_errors()
Code language: CSS (css)
Read the bus voltage (i.e. battery) from the Odrive
odrv0.vbus_voltage
Code language: CSS (css)
If you cant save because the motors are not idle do this
if save returns false, you likely need to idle your axis. I have written the code for 2 odrives, 2 motors below.
odrv0.axis0.requested_state = AXIS_STATE_IDLE
odrv0.axis1.requested_state = AXIS_STATE_IDLE
odrv1.axis0.requested_state = AXIS_STATE_IDLE
odrv1.axis1.requested_state = AXIS_STATE_IDLE
Saving and rebooting the ODrive
This is for two connected odrives.
odrv0.save_configuration()
odrv1.save_configuration()
odrv0.reboot()
odrv1.reboot()
Code language: CSS (css)