Skip to content

fix(navigator): keep course setpoint NaN outside Course mode#27807

Open
mrpollo wants to merge 2 commits into
mainfrom
mrpollo/course-setpoint-nan-semantics
Open

fix(navigator): keep course setpoint NaN outside Course mode#27807
mrpollo wants to merge 2 commits into
mainfrom
mrpollo/course-setpoint-nan-semantics

Conversation

@mrpollo

@mrpollo mrpollo commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #27537 and #27487, fixing the course initialization issue at the source so the hotfix guard can be removed.

The PositionSetpoint.course field could end up finite (and get consumed as a course guidance command) in two ways: the reposition triplet was zero-initialized at boot and memset after consumption while none of the reposition command handlers write course, and mission_item_to_position_setpoint() updates the current setpoint in place without ever touching course, so a stale value set by Course mode survived a switch to Hold, RTL, or Mission.

Verified in SIH SITL (airplane) at the uORB level: entering Course mode publishes a finite course, switching back to Hold publishes a LOITER setpoint with course = NaN (previously stale finite), and repeated DO_REPOSITION commands produce loiter setpoints with course/yaw = NaN on both the first-use and post-consumption paths. Built for px4_sitl_sih and px4_fmu-v6x.

Log of the SITL session (the position_setpoint_triplet.current.course transitions are visible in Flight Review; ground roll only, the SIH airplane cannot reach rotation speed): https://logs.px4.io/plot_app?log=d89b1ec6-4cc4-4e92-b115-55a90623052c

Changelog Entry

Bugfix: initialize unused course setpoint to NaN so GCS repositions and mode switches out of Course mode never trigger course guidance

@mahima-yoga this should be the "remaining corner cases" hunt from #27537: the stale-course-after-Course-mode path via mission_item_to_position_setpoint() was the one left, covered here along with the revert of your guard.

mrpollo added 2 commits July 3, 2026 13:43
The reposition triplet was zero-initialized at boot and memset after
consumption, and mission_item_to_position_setpoint() never wrote the
course field, so a finite course (0.0, or stale after leaving Course
mode) could leak into published position setpoints. Reset the
reposition triplet with reset_position_setpoint() and clear course when
converting mission items, so the field is only finite while Course mode
commands it.

Replaces the consumer-side clear from #27537 with a fix at the source.

Signed-off-by: Ramon Roche <mrpollo@gmail.com>
Reverts the hotfix from #27487. The navigator now guarantees the course
field is NaN unless Course mode explicitly commands it, so
PX4_ISFINITE(course) is again a sufficient trigger for course guidance.

Signed-off-by: Ramon Roche <mrpollo@gmail.com>
@github-actions github-actions Bot added kind:bug Something is broken or behaving incorrectly. vehicle:fixed-wing Fixed-wing-specific behavior. scope:control Rate, attitude, position, allocation, or actuator control. scope:navigation Missions, RTL, geofence, takeoff, landing, or navigator behavior. labels Jul 3, 2026
@mrpollo mrpollo requested a review from mahima-yoga July 3, 2026 20:46
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🔎 FLASH Analysis

px4_fmu-v5x [Total VM Diff: 16 byte (0 %)]
    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +16  +0.0%     +16    .text
    +0.8%     +32  +0.8%     +32    Navigator::run()
    +8.6%     +10  +8.6%     +10    Loiter::reposition()
    -0.9%      -2  -0.9%      -2    Loiter::set_loiter_position()
    -0.5%      -4  -0.5%      -4    FixedWingModeManager::vehicle_attitude_poll()
    -3.3%      -8  -3.3%      -8    FixedWingModeManager::control_auto()
    -1.6%     -12  -1.6%     -12    FixedWingModeManager::control_auto_position()
  +0.0%     +68  [ = ]       0    .debug_abbrev
  -0.0%      -4  [ = ]       0    .debug_frame
  +0.0%     +66  [ = ]       0    .debug_info
  +0.0%     +18  [ = ]       0    .debug_line
    +250%      +5  [ = ]       0    [Unmapped]
    +0.0%     +13  [ = ]       0    [section .debug_line]
  +0.0%     +13  [ = ]       0    .debug_loclists
  -0.0%      -1  [ = ]       0    .debug_rnglists
  -0.0%     -16  [ = ]       0    .symtab
   -20.0%     -16  [ = ]       0    Loiter::Loiter()
   -66.7%     -32  [ = ]       0    Loiter::reposition()
    +200%     +32  [ = ]       0    Loiter::set_loiter_position()
     +67%     +32  [ = ]       0    __memcpy_veneer
   -40.0%     -32  [ = ]       0    __param_get_system_default_value_veneer
     +33%     +16  [ = ]       0    __stm32_configxfrints_veneer
   -25.0%     -16  [ = ]       0    __uart_pollnotify_veneer
  -0.1%     -16  [ = ]       0    [Unmapped]
  +0.0%    +144  +0.0%     +16    TOTAL

px4_fmu-v6x [Total VM Diff: 16 byte (0 %)]
    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +16  +0.0%     +16    .text
    +0.8%     +32  +0.8%     +32    Navigator::run()
    +8.6%     +10  +8.6%     +10    Loiter::reposition()
    -0.9%      -2  -0.9%      -2    Loiter::set_loiter_position()
    -0.5%      -4  -0.5%      -4    FixedWingModeManager::vehicle_attitude_poll()
    -3.3%      -8  -3.3%      -8    FixedWingModeManager::control_auto()
    -1.6%     -12  -1.6%     -12    FixedWingModeManager::control_auto_position()
  +0.0%     +68  [ = ]       0    .debug_abbrev
  -0.0%      -4  [ = ]       0    .debug_frame
  +0.0%     +66  [ = ]       0    .debug_info
  +0.0%     +10  [ = ]       0    .debug_line
   -42.9%      -3  [ = ]       0    [Unmapped]
    +0.0%     +13  [ = ]       0    [section .debug_line]
  +0.0%     +13  [ = ]       0    .debug_loclists
  -0.0%      -1  [ = ]       0    .debug_rnglists
  -0.0%     -16  [ = ]       0    .symtab
   -20.0%     -16  [ = ]       0    Loiter::Loiter()
   -66.7%     -32  [ = ]       0    Loiter::reposition()
    +200%     +32  [ = ]       0    Loiter::set_loiter_position()
  -0.3%     -16  [ = ]       0    [Unmapped]
  +0.0%    +136  +0.0%     +16    TOTAL

Updated: 2026-07-03T20:51:59

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

Labels

kind:bug Something is broken or behaving incorrectly. scope:control Rate, attitude, position, allocation, or actuator control. scope:navigation Missions, RTL, geofence, takeoff, landing, or navigator behavior. vehicle:fixed-wing Fixed-wing-specific behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant