Hello,
I recently got a new ODrive 3.6 and have connected my scooter motor with hall sensor to axis 1. I am trying to set it up such that I can control the torque applied by the motor. But when I try to set it up I get an error in the encoder.
This is the error I get.
EncoderError.CPR_POLEPAIRS_MISMATCH
I have tried all the possible pole pairs from 13 to 30 with the following script:
import odrive
import time
import tqdm
import odrive.enums
def checkOdrive(polePiars):
print("Pole Piars:", polePiars)
odrv0 = odrive.find_any()
print("Connected!!")
try:
odrv0.erase_configuration()
except:
pass
time.sleep(5)
print("Erased!!")
odrv0 = odrive.find_any()
print("Connected Again.")
odrv0.config.enable_brake_resistor = True
odrv0.config.brake_resistance = 2.05
odrv0.axis0.motor.config.pole_pairs = polePiars
odrv0.axis1.motor.config.resistance_calib_max_voltage = 4
odrv0.axis1.motor.config.requested_current_range = 25 #Requires config save and reboot
odrv0.axis1.motor.config.current_control_bandwidth = 100
odrv0.axis1.motor.config.torque_constant = 8.27 / 100
odrv0.axis1.encoder.config.mode = odrive.enums.EncoderMode.HALL
odrv0.axis1.encoder.config.cpr = polePiars * 6
odrv0.axis1.encoder.config.calib_scan_distance = 150
odrv0.config.gpio9_mode = odrive.enums.GpioMode.DIGITAL
odrv0.config.gpio10_mode = odrive.enums.GpioMode.DIGITAL
odrv0.config.gpio11_mode = odrive.enums.GpioMode.DIGITAL
odrv0.axis1.encoder.config.bandwidth = 100
odrv0.axis1.controller.config.pos_gain = 1
odrv0.axis1.controller.config.vel_gain = 0.02 * odrv0.axis0.motor.config.torque_constant * odrv0.axis0.encoder.config.cpr
odrv0.axis1.controller.config.vel_integrator_gain = 0.1 * odrv0.axis0.motor.config.torque_constant * odrv0.axis0.encoder.config.cpr
odrv0.axis1.controller.config.vel_limit = 10
odrv0.axis1.controller.config.control_mode = odrive.enums.ControlMode.VELOCITY_CONTROL
print("Confiigured!!")
try:
odrv0.save_configuration()
except:
pass
time.sleep(5)
print("Saved")
odrv0 = odrive.find_any()
print("Found Again!!")
odrv0.axis1.requested_state = odrive.enums.AxisState.MOTOR_CALIBRATION
time.sleep(10)
print("Motor error:", odrv0.axis1.motor.error)
odrv0.axis1.motor.config.pre_calibrated = True
odrv0.axis1.requested_state = odrive.enums.AxisState.ENCODER_HALL_POLARITY_CALIBRATION
time.sleep(15)
odrv0.axis1.encoder.error
print("Hall error 1:", odrv0.axis1.encoder.error)
odrv0.axis1.requested_state = odrive.enums.AxisState.ENCODER_OFFSET_CALIBRATION
time.sleep(15)
odrv0.axis1.encoder.error
print("Hall error 2", odrv0.axis1.encoder.error)
if (odrv0.axis1.encoder.error == 0):
print("Success:", polePiars)
odrv0.axis1.encoder.config.pre_calibrated = True
print("DONE!!!!!!!!!!!!!!!!!!!!!!!")
if __name__ == "__main__":
for idx in range(13, 40):
checkOdrive(idx)
Here is a picture of the motor:
Can someone help me with this?
Thanks