AS5047P encoder "EncoderError.CPR_POLEPAIRS_MISMATCH" error

Hello again,
I am connecting encoder with AB connection. I am calibrating motor, then encoder, then doing full calibration. After that there is no error. The cpr value is 2000. Then I am putting ‘odrv0.axis0.requested_state = AXIS_STATE_CLOSED_LOOP_CONTROL’. When I try to give an position input motor behave strangely (vibrates) and gives error: “MotorError.CURRENT_LIMIT_VIOLATION”. You can see it here: video

I do not believe that there is an mistake with vel_gain or pos_gain. Because I tried to set them to 0, the error still presents.

My code:

import odrive
import time
import math
from odrive.enums import *

odrv0 = odrive.find_any()
print(str(odrv0.vbus_voltage))

print("Erasing pre-exsisting configuration...")
try:
    odrv0.erase_configuration()
except Exception:
    pass

odrv0 = odrive.find_any()

time.sleep(5)

odrv0.config.enable_brake_resistor = True
odrv0.config.brake_resistance = 2.0 
odrv0.config.dc_max_positive_current = 30  
odrv0.config.dc_max_negative_current = -1  
odrv0.config.max_regen_current = 0  #(usually 0)
odrv0.config.dc_bus_undervoltage_trip_level = 8.0
odrv0.config.dc_bus_overvoltage_trip_level = 26  #(the max current that the Odrive can handle)
odrv0.axis0.config.calibration_lockin.current = 20

#motor config
odrv0.axis0.motor.config.motor_type = odrive.utils.MotorType.HIGH_CURRENT
odrv0.axis0.motor.config.current_lim = 68 
odrv0.axis0.motor.config.pole_pairs = 14
odrv0.axis0.motor.config.calibration_current = 10
odrv0.axis0.motor.config.resistance_calib_max_voltage = 2
odrv0.axis0.motor.config.requested_current_range = 20
odrv0.axis0.motor.config.torque_constant = 8.27 / 340
odrv0.axis0.motor.config.current_control_bandwidth = 500

#controller config
odrv0.axis0.controller.config.pos_gain = 20
odrv0.axis0.controller.config.vel_gain = 0.02
odrv0.axis0.controller.config.vel_integrator_gain = 0.1
odrv0.axis0.controller.config.control_mode = CONTROL_MODE_POSITION_CONTROL
odrv0.axis0.controller.config.vel_limit = 20
odrv0.axis0.controller.config.input_mode = INPUT_MODE_TRAP_TRAJ
odrv0.axis0.trap_traj.config.vel_limit = 30
odrv0.axis0.trap_traj.config.accel_limit = 5
odrv0.axis0.trap_traj.config.decel_limit = 5

odrv0.axis0.requested_state = AXIS_STATE_IDLE
try:
    odrv0.save_configuration()
except:
    pass

odrv0 = odrive.find_any()

odrv0.axis0.requested_state = AXIS_STATE_MOTOR_CALIBRATION
time.sleep(10)

odrv0.axis0.motor.config.pre_calibrated = True

print(str(odrive.utils.dump_errors(odrv0)))
print('Motor Calibrated')

odrv0.axis0.encoder.config.mode = ENCODER_MODE_INCREMENTAL
odrv0.axis0.encoder.config.cpr = 2000
odrv0.axis0.encoder.config.calib_range = 0.05
odrv0.axis0.encoder.config.bandwidth = 3000
odrv0.axis0.encoder.config.use_index = False
odrv0.axis0.encoder.config.pre_calibrated=False

odrv0.axis0.requested_state = AXIS_STATE_IDLE
try:
    odrv0.save_configuration()
except:
    pass

odrv0 = odrive.find_any()

odrv0.axis0.requested_state = AXIS_STATE_ENCODER_OFFSET_CALIBRATION
odrv0.axis0.encoder.config.pre_calibrated = True
time.sleep(10)
print(str(odrive.utils.dump_errors(odrv0)))
print('Encoder Calibrated')

odrv0.axis0.requested_state = AXIS_STATE_IDLE
try:
    odrv0.save_configuration()
except:
    print('Config saved')
odrv0 = odrive.find_any()

odrv0.axis0.encoder.config.pre_calibrated=False
odrv0.axis0.motor.config.pre_calibrated=False
odrv0.axis0.requested_state = AXIS_STATE_FULL_CALIBRATION_SEQUENCE
odrv0.axis0.encoder.config.pre_calibrated=True
odrv0.axis0.motor.config.pre_calibrated=True

time.sleep(15)
print(str(odrive.utils.dump_errors(odrv0)))
print('Full Calibration Sequence')

odrv0.axis0.requested_state = AXIS_STATE_CLOSED_LOOP_CONTROL #odrive.utils.AxisState.SENSORLESS_CONTROL
time.sleep(5)
print(str(odrive.utils.dump_errors(odrv0)))



We did holder for encoder and put the magnet in the centre. We did holder for encoder by its dimensions.

It seems like the encoder IC is still offset with that mount? Or maybe the perspective makes it look wrong. Could you share your CAD?

CPR of 2000 should not be right. If you look at the shadow_count variable, how much does it increase when you rotate the motor one turn?

We made sketch in solid works, we made it concentric. It is not aligned, because the holes in the case of motor are on circular pattern. It is 100% in the center.

Also can it be because of our gains? I am not really sure about everything now.

approximately 1 turn.



Conversation moved to Discord