Skip to content

feat(core): expose math_utils helpers in public headers#2873

Merged
julianoes merged 7 commits into
mavlink:mainfrom
g-ampo:feat/2693-public-quaternion-euler-helpers
Apr 29, 2026
Merged

feat(core): expose math_utils helpers in public headers#2873
julianoes merged 7 commits into
mavlink:mainfrom
g-ampo:feat/2693-public-quaternion-euler-helpers

Conversation

@g-ampo

@g-ampo g-ampo commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

Closes #2693.

Move math_utils.hpp to the public include directory so users can convert between Quaternion and EulerAngle without MavlinkPassthrough (and hence without mavlink_conversions.h) .

Also clamp the asinf input in to_euler_angle_from_quaternion to [-1, 1] to prevent NaN when a quaternion approaches gimbal-lock ; same fix landing in ArduPilot/pymavlink#1208 for the upstream C library.

Moves math_utils.hpp to the public include directory so consumers can
convert between Quaternion and EulerAngle without MavlinkPassthrough.
Also clamps asinf input to [-1, 1] to avoid NaN from FP rounding (same
fix as pymavlink mavlink#1208).

Closes mavlink#2693.

@julianoes julianoes left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a test to math_utils_test.cpp that tests the constrain you added?

@julianoes

Copy link
Copy Markdown
Collaborator

Also note that you will have to make sure there are docstrings and you run generate_docs.sh to update the API refernence docs.

g-ampo added 3 commits April 27, 2026 00:40
Verify pitch stays finite when 2*(q.w*q.y - q.z*q.x) is driven outside
[-1, 1] by floating-point rounding (positive and negative case).
Add Doxygen docstrings to math_utils.hpp, register it as an installable
public header in CMakeLists.txt, and regenerate the API reference markdown.
@g-ampo

g-ampo commented Apr 27, 2026

Copy link
Copy Markdown
Contributor Author

@julianoes I've addressed both: added the gimbal-lock constrain test in math_utils_test.cpp and added docstrings + ran generate_docs.sh. Happy to adjust anything !

@g-ampo g-ampo requested a review from julianoes April 27, 2026 08:16

@julianoes julianoes left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the macro, then this is good to go in. Thanks.

Comment thread cpp/src/mavsdk/core/include/mavsdk/math_utils.hpp Outdated
g-ampo added 2 commits April 27, 2026 20:31
These are part of the public API now, not test-only access.
Without an export macro the symbol had hidden visibility and was unreachable
from outside libmavsdk.so. Verified via nm: t -> T at the same offset.
julianoes
julianoes previously approved these changes Apr 27, 2026
@g-ampo

g-ampo commented Apr 27, 2026

Copy link
Copy Markdown
Contributor Author

@julianoes Macro swap done in 1ee6f2e9. Also noticed operator==(const EulerAngle&, const EulerAngle&) had no export macro at all and was emitted with hidden visibility (lowercase t in nm), unreachable from outside libmavsdk.so. Added MAVSDK_PUBLIC there too in b4780cf0 :)

@g-ampo

g-ampo commented Apr 27, 2026

Copy link
Copy Markdown
Contributor Author

@julianoes fac48f46 is just the regenerated cpp/docs/en/cpp/api_reference/namespacemavsdk.md that the docs CI step diff-checks after the macro change. No source changes. Could you approve the pending workflow runs and re-review once they're green? Sorry for the noise...

@g-ampo g-ampo requested a review from julianoes April 27, 2026 20:08
@julianoes julianoes merged commit cf91bf1 into mavlink:main Apr 29, 2026
61 of 62 checks passed
@g-ampo g-ampo deleted the feat/2693-public-quaternion-euler-helpers branch April 29, 2026 07:17
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.

Add euler quaternion conversion functions

2 participants