MagneticSensorAnalog: Fix angle calculation#526
MagneticSensorAnalog: Fix angle calculation#526austin-bowen wants to merge 2 commits intosimplefoc:devfrom
Conversation
|
Oh wow, nice catch!
EDIT: I read it too quickly, we already divide by the range. |
|
@askuric I realized another thing: cpr needs 1 added to it. Right now, if raw_count is max_raw_count, the equation becomes: But that's not accurate -- the angle represented by max_raw_count isn't 0°, it's one tick before the wraparound to 0°. Adding 1 to cpr fixes this: If you agree with this, I can update my PR to add 1 to Lmk what you think |
|
I went ahead and added the cpr calculation change to the PR |
Description
MagneticSensorAnalog::getSensorAnglehas a slightly incorrect implementation for convertingraw_countto degrees:It should first subtract
min_raw_countfromraw_countso it is properly in the range[0, cpr]before dividing bycpr.Also, the
cprcalculation is slightly incorrect; it should be:cpr = _min_raw_count - _max_raw_count + 1;Reasoning in comments below.
Type of change
^ Not sure which of the two it is. I'd expect it to only make things better due to more accurate position calculations, but hard to be sure somebody's current code doesn't somehow depend on the slightly incorrect original implementation.
How Has This Been Tested?
Ran velocity control, which was working before my change, and worked after as well.
Test Configuration/Setup: