Skip to content

Fix fake GPS velocity frame and COG units - #2261

Open
Daniiiil1 wants to merge 2 commits into
mavlink:ros2from
Daniiiil1:codex/fix-fake-gps-ned-velocity
Open

Fix fake GPS velocity frame and COG units#2261
Daniiiil1 wants to merge 2 commits into
mavlink:ros2from
Daniiiil1:codex/fix-fake-gps-ned-velocity

Conversation

@Daniiiil1

Copy link
Copy Markdown

Summary

Fixes the fake GPS velocity and course fields reported in #2091.

Root cause

send_fake_gps() differentiated ECEF positions, reversed the displacement sign, and then wrote those ECEF components directly into MAVLink fields documented as North/East/Down. The HIL_GPS course calculation also produced radians but stored the result as centidegrees. The first sample additionally used uninitialized previous-position state.

Changes

  • derive the ECEF velocity with the correct displacement sign
  • rotate ECEF velocity into the local ENU frame and then into NED
  • emit course over ground clockwise from north in centidegrees
  • treat the first sample and non-increasing timestamps as zero velocity
  • use the corrected NED velocity for both HIL_GPS and GPS_INPUT
  • add focused tests for ECEF-to-NED axes, timestamp guards, and cardinal/intercardinal courses

Validation

  • git diff --check
  • added deterministic gtests covering north/east/up transforms and 0/45/90/180/270 degree courses

The ROS 2 toolchain is not available on the local macOS host, so the package test target is left for the repository CI matrix.

Closes #2091

Signed-off-by: Daniil Mordanov <mordanovdania@gmail.com>
@Daniiiil1
Daniiiil1 marked this pull request as ready for review August 10, 2026 08:39
@vooon

vooon commented Aug 10, 2026

Copy link
Copy Markdown
Member

@Daniiiil1 please fix cmake includes for this test.

}

return static_cast<uint16_t>(std::lround(course_deg * 100.0)) % 36000;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe worth to move to generic frame_tf.hpp?

@shupx

shupx commented Aug 12, 2026

Copy link
Copy Markdown

@Daniiiil1 Great! Thank you for resolving this issue that has been troubling me for a long time. Prior to this, I could only work around it by writing a separate module to bypass MAVROS's fake GPS.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong velocity and cog in the fake_gps plugin

3 participants