This is an experimental feature. It has not yet been tested with a wide range of motors or ODrive settings. You are encouraged to reach out to us and tell us how it goes, especially if you run into problems.
When turning a BLDC motor by hand, one can usually feel a bit of “bumpiness”. This is called “cogging torque” and stems from the internal magnet and stator geometry.
Anticogging refers to an algorithm that runs on the motor controller and actively cancels out the motor’s cogging torque in order to get smoother, more accurate motion control.
ODrive’s anticogging algorithm works by first running a one-time calibration that measures the cogging torque map of the motor. This map is then used to add a position-dependent feedforward term to the torque command generated by the controller.
Make sure the velocity gain is tuned to a level where it doesn’t vibrate or oscillate. You can do this either in the GUI’s Dashboard, or in
Additionally, the absolute position estimate
<axis>.pos_vel_mapper.pos_absmust be available and not shift between reboots (except by integer numbers). In other words, you need to do one of the following:
Run index search on every start (typically when using an incremental encoder).
odrv0.axis0.controller.config.circular_setpoints = Trueand
odrv0.axis0.pos_vel_mapper.config.offset_valid = True, followed by calling
Configure an approximate startup position by following the instructions here.
odrv0.axis0.set_abs_pos(angle)on every start, where
angleis the current angle of the axis. For example if you’re using the onboard encoder:
odrv0.axis0.set_abs_pos(odrv0.onboard_encoder0.raw). If you’re using an AMT21 encoder:
Even though a homing procedure would also make
<axis>.pos_vel_mapper.pos_absavailable, it is not suitable for anticogging because it is usually not precise enough. Compatibility between homing and anticogging will be improved in a future update.
<axis>.controller.config.circular_setpoint_rangemust be kept at the default of
1. This limitation will be removed in future versions.
Configure your ODrive according to the preparation instructions above.
Configure the anticogging parameters. See
herefor a full list or parameters and their descriptions.
Below you can find examples for some selected motors. If you’re using a different motor, you can use these values as an orientation.
odrv0.axis0.controller.config.vel_gain = 0.5 odrv0.axis0.config.anticogging.max_torque = 0.15 odrv0.axis0.config.anticogging.calib_start_vel = 0.5 odrv0.axis0.config.anticogging.calib_end_vel = 0.15 odrv0.axis0.config.anticogging.calib_coarse_integrator_gain = 10
odrv0.axis0.controller.config.vel_gain = 0.25 odrv0.axis0.config.anticogging.max_torque = 0.15 odrv0.axis0.config.anticogging.calib_start_vel = 0.5 odrv0.axis0.config.anticogging.calib_end_vel = 0.05 odrv0.axis0.config.anticogging.calib_coarse_integrator_gain = 10
odrv0.axis0.controller.config.vel_gain = 0.8 odrv0.axis0.config.anticogging.max_torque = 0.4 odrv0.axis0.config.anticogging.calib_start_vel = 0.5 odrv0.axis0.config.anticogging.calib_end_vel = 0.05 odrv0.axis0.config.anticogging.calib_coarse_integrator_gain = 25
Run the calibration:
odrv0.axis0.requested_state = AxisState.ANTICOGGING_CALIBRATION. The calibration takes six minutes by default. The motor will start by spinning moderately fast, then slow down, and then do the same in the other direction. During this time it iteratively builds a map of the motor’s cogging torque. The motor should not come to a stop during the calibration even for an instant. If it does, you need to tweak the parameters and try again.
After the calibration has completed, enable anticogging:
odrv0.axis0.config.anticogging.enabled = True.
Save the calibrated torque map and configuration changes:
For more details, including customization options, refer to the API reference for
While anticogging does the best it can to cancel out the cogging torque, it is not perfect. It introduces a feedforward term in the controller which depends on the position estimate, which itself can be delayed or inaccurate. Thereby it can reduce stability margins for your system and require you to tune down gains to be less aggressive.
Therefore, if you find anticogging to give unsatisfactory results for your application, consider selecting a motor that is specifically designed for low cogging torque. Such motors are typically recognized by their skewed magnet or stator arrangement.
controller.configduring an ongoing calibration causes undefined behavior.