Skip to content

Fix heading calculation #3669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2023
Merged

Conversation

haslinghuis
Copy link
Member

@haslinghuis haslinghuis commented Dec 12, 2023

Complements #3668

Fixes:

  • gps heading was divided by 100 instead of 10
  • use radians for icon rotation
  • convert heading to radians and add 180 degrees to make icon point in the right direction

Thanks to @ctzsnooze for testing and suggestions.

@haslinghuis haslinghuis added this to the 10.10.0 milestone Dec 12, 2023
@haslinghuis haslinghuis self-assigned this Dec 12, 2023

This comment has been minimized.

@haslinghuis
Copy link
Member Author

#define RAD                       (M_PIf / 180.0f)
#define DECIDEGREES_TO_RADIANS    (angle) ((angle) / 10.0f * 0.0174532925f)
#define DEGREES_TO_RADIANS(angle) ((angle) * RAD)
#define RADIANS_TO_DEGREES(angle) ((angle) / RAD)

This comment has been minimized.

This comment has been minimized.

@haslinghuis haslinghuis force-pushed the heading-calc branch 8 times, most recently from 0124cdc to c5bf184 Compare December 12, 2023 22:25
Copy link

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link
Contributor

Do you want to test this code? Here you have an automated build:
Betaflight-Configurator-Android
Betaflight-Configurator-Linux
Betaflight-Configurator-macOS
Betaflight-Configurator-Windows
WARNING: It may be unstable and result in corrupted configurations or data loss. Use only for testing!

@haslinghuis haslinghuis merged commit 3dcc41f into betaflight:master Dec 12, 2023
@haslinghuis haslinghuis deleted the heading-calc branch December 12, 2023 22:46
@ctzsnooze
Copy link
Member

This is AWESOME! A Mag user can now easily validate that it is working properly, by checking the position of the icon in the centre of the map. When the Mag is oriented and calibrated correctly, the icon angle should be about right, and remain about the same even if the quad is pitched up or down.

With this PR, the icon points upwards when Mag heading is North (around 350-0-10 range), and points to the right when Mag heading is East, down for South, etc. Perfect!

Note that when Mag is connected, the IMU favours Mag, and this is correct; the Mag value is used over the GPS value by the IMU.

If Mag is not connected, the icon angle is consistent with the angle value shown for IMU in the Setup tab.

Also this PR fixes the reported GPS heading value is now correct.

If a quad with a properly Mag and GPS is connected to a laptop, and we walk with the laptop, with the quad facing 'forward' (in the direction we are walking), then the IMU (mag) and GPS headings are nearly identical. This confirms that the Mag is reasonably accurate.

Both the Mag heading and the GPS Heading values can be validated by looking in Sensors when the GPS_RESCUE_HEADING debug is enabled and displayed.

chmelevskij pushed a commit to chmelevskij/betaflight-configurator that referenced this pull request Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: COMPLETED
Development

Successfully merging this pull request may close these issues.

3 participants