How to debug encoder calibration problem in 0.5.3?

I converted my 0.4.x code to 0.5.3 and now encoder calibration fails. I most probably did something wrong or forgot to add something that was not in 0.4.x but is required by 0.5.3.

Anyhow, a simple odrv0.axis1.requested_state=AXIS_STATE_ENCODER_OFFSET_CALIBRATION fails with axis1.encoder.error ENCODER_ERROR_CPR_POLEPAIRS_MISMATCH (literal value 2).

Yes, I have checked that polepairs is configured correctly to 2 (motor is DC brushless SM57L114 with Hall sensors), specs on page 18 here in this PDF and AMT102-V encoders (normal odrive encoders sold on the website).

My configuration is:

# I am a bit hesitant about this block, I have no resistor connected
odrv.config.enable_brake_resistor = False
odrv.config.brake_resistance = 0.0 # full regenerative braking
odrv.config.dc_max_negative_current = -30 # same as config.current_lim as we have no brake resistor

a = axis1 

a.motor.config.current_lim = 30
a.motor.config.calibration_current = 5
a.motor.config.pole_pairs = 2
a.motor.config.requested_current_range = 60
a.motor.config.phase_inductance = 0.0005079241818748415
a.motor.config.phase_resistance = 0.22080011665821075
a.motor.config.pre_calibrated = True

cpr = 4 * 2048
torque_const = 0.063
a.motor.config.torque_constant = torque_const
a.encoder.config.cpr = cpr
a.controller.config.pos_gain = 96.53617858886719

vel_gain = 0.0001250000059371814 * torque_const * cpr
a.controller.config.vel_gain = vel_gain
a.controller.config.vel_integrator_gain = 0.5 * bandwidth * vel_gain * torque_const * cpr
a.controller.config.vel_limit = 200000.0 / cpr # division according to migration guide
a.controller.config.vel_limit_tolerance = 1.2000000476837158
a.controller.config.vel_ramp_rate = 10000.0 / cpr

I took the formulas from migration guide, e.g., my vel_gain was previously just 0.0001250000059371814, now it is multiplied by torque_constant and cpr.

Do you see anything obviously wrong or missing that should cause ENCODER_ERROR_CPR_POLEPAIRS_MISMATCH error?

You can skip the cpr setting if you’re using the default encoders - 8192 is correct and the default.

For 2 pole_pairs you may have to adjust (increase, usually) the encoder.config.calib_scan_distance. By default this is 16 pi, and has a 2% tolerance. You might also consider adjusting the axis.config.calibration_lockin.current or the scan speeds if you find the motor doesn’t turn very smoothly during calibration.