Skip to content

MagneticSensorAnalog: Correct angle calculation by subtracting min_raw_count from raw_count#526

Open
austin-bowen wants to merge 1 commit intosimplefoc:devfrom
austin-bowen:dev
Open

MagneticSensorAnalog: Correct angle calculation by subtracting min_raw_count from raw_count#526
austin-bowen wants to merge 1 commit intosimplefoc:devfrom
austin-bowen:dev

Conversation

@austin-bowen
Copy link
Copy Markdown

Description

MagneticSensorAnalog::getSensorAngle has a slightly incorrect implementation for converting raw_count to degrees:

return ( (float) (raw_count) / (float)cpr) * _2PI;

It should first subtract min_raw_count from raw_count so it is properly in the range [0, cpr] before dividing by cpr.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
    ^ 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:

  • Hardware:
    • SimpleFOC Mini
    • 2804 gimbal motor
    • AS5600 magnetic encoder (using analog OUT)
    • All from this Amazon listing
  • IDE: Arduino
  • MCU package version: XIAO RP2040

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant