PWM Position control

Hello there
I am trying to position control my motor using PWM.
Somehow I managed to get it running but then I changed the code and since then it won’t work any more.
I have not done any other configurations except those from the PWM interface tutorial.

When I plug the battery in, the calibration sequence starts. The motor does only beep, but does not move. It also doesn’t enter in the closed loop mode.

Connected to ODrive 20763868304E as odrv0
In [1]: odrv0.config.gpio4_pwm_mapping.endpoint = None

In [2]: odrv0.axis0.config.startup_motor_calibration = True

In [3]: odrv0.axis0.config.startup_closed_loop_control = True

In [4]: odrv0.config.gpio4_pwm_mapping.min = -15000

In [5]: odrv0.config.gpio4_pwm_mapping.max = 1500

In [6]: odrv0.config.gpio4_pwm_mapping.endpoint = odrv0.axis0.controller._remote_attributes[‘pos_setpoint’]

In [7]: odrv0.save_configuration()

In [8]: odrv0.reboot()
Downloading json data from ODrive… (this might take a while)

Motor: Robbe ro-power torque 305Kv
Encoder: CUI AMT102 encoder
Odrive 3.6 56V

I hope someone can help me

Try the dump_errors command - it sounds like your set up is failing at encoder_offser_calibration. You might see an error CPR_POLEPAIRS_MISMATCH.
Maybe your encoder is slipping on the shaft?

1 Like

I first got the newest firmware running. The odrivetool dfu did not work but with forcing it according to the tutorial it now runs with 4.6.

I tried again but it did not work again.

The code I used is the following:

In [53]: odrv0.axis0.config.startup_motor_calibration = True

In [54]: odrv0.axis0.config.startup_encoder_offset_calibration = True

In [55]: odrv0.axis0.config.startup_closed_loop_control = True

In [56]: odrv0.axis0.motor.config.current_lim = 30

In [57]: odrv0.axis0.controller.config.vel_limit = 30

In [58]: odrv0.axis0.motor.config.pole_pairs = 7

In [59]: odrv0.axis0.motor.config.motor_type = MOTOR_TYPE_HIGH_CURRENT

In [60]: odrv0.axis0.encoder.config.cpr = 4000

In [61]: odrv0.config.gpio4_pwm_mapping.endpoint = None

In [62]: odrv0.config.gpio4_pwm_mapping.min = -100

In [63]: odrv0.config.gpio4_pwm_mapping.max = 100

In [64]: odrv0.config.gpio4_pwm_mapping.endpoint = odrv0.axis0.controller._remote_attributes[‘input_pos’]

In [65]: odrv0.save_configuration()

In [66]: odrv0.reboot()

The calibration failed again but the motor durned in one direction and then stopped.
The dump_errors showed the following:In [67]: dump_errors(odrv0)
axis: Error(s):
motor: no error
fet_thermistor: no error
motor_thermistor: no error
encoder: Error(s):
controller: no error
axis: no error
motor: no error
fet_thermistor: no error
motor_thermistor: no error
encoder: no error
controller: no error

As you said I got a CPR_POLEPAIRS_DISMATCH but the parameters should be setted right.
CPR = 4000 (PPR *4 )
And Polepairs= 7 ( Number of permanent magnets / 2)

I have been trying a lot but did not find any solution

Can you check that the encoder is working properly?
axis0.encoder.pos_estimate shows the current position. Reset it with axis0.encoder.set_linear_count(0) and then manually move the motor by exactly one turn.
Check that axis0.encoder.pos_estimate shows 2000 as expected.


Now its working, I guess i managed to set the cpr wrong even after checking more than once… whatever :slightly_smiling_face:

Thx for support

did you ever figure out what was giving you the encoder errors? im having the same issue and using the same configuration for both motors and encoders and one axis is failing and the other is not. I checked possible hardware issues like cables, swapping encoders etc. and made sure all the dip switches were off so my CPR is 2048*4=8192 and there are 14 magnets in my BLDC motors so 7 pole pairs.

Sorry, I cant realy tell you how I overcame this problem. I got the same errors with the Dump_errors comand.

My Odrive was running with an older firmware. I am not sure, if right after flashing the newer firmware, the issue was gone or if did anything else.

1 Like

i got the same issue, it worked well after correcting the value of config.pole_pairs

1 Like