Tuning the Controller

Tuning the motor controller is an essential step to unlock the full potential of the ODrive. Tuning allows for the controller to quickly respond to disturbances or changes in the system (such as an external force being applied or a change in the setpoint) without becoming unstable. Correctly setting the three tuning parameters (called gains) ensures that ODrive can control your motors in the most effective way possible. The three (starting) values are:

  • pos_gain [(turn/s) / turn]:

    odrv0.axis0.controller.config.pos_gain = 20.0
  • vel_gain [Nm/(turn/s)]:

    odrv0.axis0.controller.config.vel_gain = 0.16
  • vel_integrator_gain [Nm/((turn/s) * s)]:

    odrv0.axis0.controller.config.vel_integrator_gain = 0.32
An upcoming feature will enable automatic tuning. Until then, here is a rough tuning procedure:
  1. Set vel_integrator_gain gain to 0

  2. Make sure you have a stable system. If it is not, decrease all gains until you have one.

  3. Increase vel_gain by around 30% per iteration until the motor exhibits some vibration.

  4. Back down vel_gain to 50% of the vibrating value.

  5. Increase pos_gain by around 30% per iteration until you see some overshoot.

  6. Back down pos_gain until you do not have overshoot anymore.

  7. The integrator can be set to 0.5 * bandwidth * vel_gain, where bandwidth is the overall resulting tracking bandwidth of your system. Say your tuning made it track commands with a settling time of 100ms (the time from when the setpoint changes to when the system arrives at the new setpoint); this means the bandwidth was \(\frac{1}{100ms} = \frac{1}{0.1s} = 10Hz\). In this case you should set

    vel_integrator_gain = 0.5 * 10 * <vel_gain>

The liveplotter tool can be immensely helpful in dialing in these values. To display a graph that plots the position setpoint vs the measured position value run the following in the ODrive tool:

start_liveplotter(lambda:[odrv0.axis0.pos_estimate, odrv0.axis0.controller.pos_setpoint])

Other Parameters to Tweak

Advanced users may consider also tuning the following: