Brushed Odrive Control Help

I am building a robot with 4 BLDC motors, and 2 brushed motors with 2000p encoders. I’ve taken the time to learn how to set up tlalexander’s amazing firmware for this. I have it mostly working, but am having some control issues.

I have messed with the signs of the position, velocity, and current gains in an attempt to fix the issue, but no matter what I try the motor will spin continuously in the wrong direction and never reach it’s position set point.

Here’s the script i’m using to test

#!/usr/bin/env python3
Example usage of the ODrive python library to monitor and control ODrive devices

from future import print_function

import odrive
from odrive.enums import *
from odrive.utils import dump_errors
import time
import math
import sys
import fibre

def idle_wait():
while odrv0.axis1.current_state != AXIS_STATE_IDLE:

Find a connected ODrive (this will block until you connect one)

print(“finding an odrive…”)
odrv0 = odrive.find_any()

print(dump_errors(odrv0, True))

Find an ODrive that is connected on the serial port /dev/ttyUSB0

odrv0 = odrive.find_any(“serial:/dev/ttyUSB0”)

odrv0.axis1.motor.config.current_control_bandwidth = 100
odrv0.axis1.encoder.config.bandwidth = 100

odrv0.axis1.requested_state = 11
odrv0.axis1.motor.current_control.p_gain = 50.0
odrv0.axis1.motor.current_control.i_gain = 0.0

odrv0.axis1.motor.current_control.final_v_beta = 0.1 # Voltage Ramp Rate


odrv0.axis1.controller.current_setpoint = 5.0

This is a current-based hard block homing routine.

print(dump_errors(odrv0, True))

odrv0.axis1.requested_state = AXIS_STATE_ENCODER_INDEX_SEARCH
print(“Index Search complete”)


timer = time.time()


if True:
odrv0.axis1.encoder.config.bandwidth = 100
odrv0.axis1.controller.config.vel_ramp_rate = 100
odrv0.axis1.controller.config.vel_gain = 0.001
odrv0.axis1.controller.config.vel_integrator_gain = 1
odrv0.axis1.controller.vel_integrator_current = 5
odrv0.axis1.requested_state = AXIS_STATE_IDLE
odrv0.axis1.controller.config.control_mode = CTRL_MODE_POSITION_CONTROL
odrv0.axis1.requested_state = AXIS_STATE_CLOSED_LOOP_CONTROL
odrv0.axis1.controller.config.pos_gain = 1
odrv0.axis1.controller.vel_ramp_enable = True
odrv0.axis1.controller.config.vel_ramp_rate = 1

odrv0.axis1.motor.config.current_lim = 10.00
odrv0.axis1.controller.config.vel_limit_tolerance = 2.5
odrv0.axis1.controller.config.vel_limit = 512000
odrv0.axis0.trap_traj.config.vel_limit = 128000
odrv0.axis0.trap_traj.config.accel_limit = 200
odrv0.axis0.trap_traj.config.decel_limit = 200
odrv0.axis0.trap_traj.config.A_per_css = 0




while True:


print(dump_errors(odrv0, True))
# odrv0.axis1.controller.move_to_pos(0)