sbgisen / vesc

VESC Interface for ROS
Apache License 2.0
47 stars 34 forks source link

rpm calculation is not correct #53

Closed Tacha-S closed 1 year ago

Tacha-S commented 1 year ago

Abstract

Motor does not rotate at correct speed even though gear_ratio and num_motor_pole_pairs are set correctly.

How to Reproduce the Bug

Problem due to the Bug

Factors

Suggestion

nyxrobotics commented 1 year ago
nyxrobotics commented 1 year ago

I haven't tried it, but maybe something like this will fix it.

nyxrobotics commented 1 year ago
nyxrobotics commented 1 year ago

There are three hall-effect-sensor on the stator. One pair of poles on the rotor should trigger 2 counts on the rise and fall in one rotation. I think 6 is correct unless vesc divides by half internally. I would like to name it rotor_pole_pairs instead of motor_pole_pairs.

jsupratman13 commented 1 year ago

Ok, so vesc_hw_interface assumes that you are using FOC and hall sensors. Here, vesc_interface's getPosition function returns vesc's tachometer, which is the number of steps the motor has rotated (different from the usual tachometer definition?) as described in https://github.com/vedderb/bldc/blob/50e1aee9c929e0e43afbd332e5a9a29df933e795/motor/mcpwm_foc.c#L1298-L1307

Reading the function description (and personally testing), the relation between vesc's tachometer and revolution is probably

revolution = vesc tachometer / (number of hall sensors * number of rotor poles)

where the number of hall sensors is usually 3 and number of rotor poles is the number of poles, not pole pairs. Therefore, we can convert revolution to radians (including gear_ratio) with the following:

rad = revolution * 2 * pi * gear_ratio
jsupratman13 commented 1 year ago

With that said, I believe @nyxrobotics approach is correct, motor_hall_ppr = 3 * num_motor_pole_pairs will fix it (6 if we use number of poles instead of pairs)

nyxrobotics commented 1 year ago

motor_hall_ppr = 3 * num_rotor_poles or motor_hall_ppr = 6 * num_rotor_pole_pairs