Skip to content

fix(navigator): compare the battery with the lowest RTL type 6 estimate - #29997

Open
anilkir wants to merge 3 commits into
mainfrom
fix/rtl-type6-failsafe-race
Open

anilkir wants to merge 3 commits into
mainfrom
fix/rtl-type6-failsafe-race

Conversation

@anilkir

@anilkir anilkir commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Solved Problem

With RTL_TYPE=6 the distance-aware return failsafe no longer triggers Return when Home drops out of battery reach while a rally point is still within reach. rtl_time_estimate gets a new field min_safe_time_estimate which commander compares with the remaining flight time.

Type 6 selects Home or a rally point based on energy budget so the estimate it publishes for the selected destination drops when Home goes out of reach. Navigator re-selects every 2s but commander compares that estimate with battery's remaining time estimate every 100ms. At the Home crossing commander sees the Home estimate above the remaining flight time and triggers Return before navigator has switched to the rally point.

Solution

With RTL_TYPE=6,Return only has to start once neither Home nor the rally point is within reach. Navigator now publishes the lower of those two time estimates as min_safe_time_estimate and commander compares the remaining flight time with that value instead of safe_time_estimate. Unlike the estimate to the selected destination, it does not change when Home drops out of reach, so the failsafe no longer triggers at that moment. safe_time_estimate describes the Return that would start now.

Not part of this PR, implemented by #29998:

  • The fallback rally point is still the closest by distance. The follow-up picks the one with the lowest time estimate, so min_safe_time_estimate becomes the lowest over Home and all rally points.
  • With a geofence detour, the estimate of the destination that is not selected still follows the avoidance path of the selected one, but the follow-up estimates each destination on its own path.

Changelog Entry

For release notes:

Bugfix: with RTL_TYPE=6, the distance-aware return failsafe no longer triggers Return when Home drops out of battery reach while a rally point is still within reach
New parameter: none
New uORB field: rtl_time_estimate.min_safe_time_estimate
Documentation: done, see docs.px4.io/main/en/config/safety.html#distance-aware-return-failsafe and docs.px4.io/main/en/flight_modes/return.html#rtl_type_6

Alternatives

Test coverage

Context

Related links, screenshot before/after, video

@anilkir anilkir self-assigned this Nov 24, 2026
@github-actions github-actions Bot added kind:bug Something is broken or behaving incorrectly. kind:test Adds or improves tests. scope:navigation Missions, RTL, geofence, takeoff, landing, or navigator behavior. labels Nov 24, 2026
@anilkir
anilkir added this pull request to stack #29999 November 24, 2026 15:21
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

🔎 Flash and RAM Analysis

Target Flash Δ Flash Total Static RAM Δ Static RAM Total
px4_fmu-v2 (F4) 🟡 +192 B (+0.02%) 97.75% +0 B (+0.00%) 10.29%
px4_fmu-v5x (F7) 🟡 +200 B (+0.01%) 96.14% +0 B (+0.00%) 21.95%
px4_fmu-v6x (H7) 🟡 +216 B (+0.01%) 97.62% +0 B (+0.00%) 10.63%
px4_io-v2 (F1) +0 B (+0.00%) 70.78% +0 B (+0.00%) 54.39%

px4_io-v2 firmware image, which an FMU flashes to its IO at boot: unchanged.

px4_fmu-v2 — Bloaty section/symbol breakdown
     VM SIZE    
 -------------- 
  +0.0%    +192    .text
     +69%    +100    RTL::selectHomeIfReachable()
    [NEW]     +88    RTL::estimateDirectReturn()
     +44%     +64    RTL::publishRemainingTimeEstimate()
     +12%     +12    RtlDirect::calc_rtl_time_estimate()
    +6.9%      +8    RTL::on_active()
    +6.2%      +8    RTL::selectReturn()
    +0.0%      +8    [section .text]
    +0.0%      +8    uORB::compressed_fields
    +2.6%      +4    RTL::on_inactive()
   -22.2%      -4    RtlDirectMissionLand::setNextMissionItem()
    [DEL]    -104    RTL::estimateTimeToHome()
  +0.0%    +192    TOTAL

px4_fmu-v5x — Bloaty section/symbol breakdown
     VM SIZE    
 -------------- 
  +0.0%    +200    .text
     +69%    +116    RTL::selectHomeIfReachable()
    [NEW]     +92    RTL::estimateDirectReturn()
     +44%     +64    RTL::publishRemainingTimeEstimate()
     +12%     +12    RtlDirect::calc_rtl_time_estimate()
    +6.9%      +8    RTL::on_active()
    +6.2%      +8    RTL::selectReturn()
    +1.3%      +8    RtlDirect::estimateReturnFromState()
    +2.6%      +4    RTL::on_inactive()
     +13%      +4    RtlDirect::landDelay()
    +0.0%      +4    uORB::compressed_fields
    +2.9%      +2    up_saveusercontext
    -0.9%      -2    exec_builtin
    -1.2%      -2    netlib_obtain_ipv4addr
   -20.0%      -2    nsh_system_ctty
   -33.3%      -4    Zero
    -0.0%      -4    [section .text]
    -1.0%      -4    matrix::Matrix<>::Matrix()
    [DEL]    -104    RTL::estimateTimeToHome()
  +0.0%    +200    TOTAL

px4_fmu-v6x — Bloaty section/symbol breakdown
     VM SIZE    
 -------------- 
  +0.0%    +216    .text
     +69%    +116    RTL::selectHomeIfReachable()
    [NEW]     +92    RTL::estimateDirectReturn()
     +44%     +64    RTL::publishRemainingTimeEstimate()
     +12%     +12    RtlDirect::calc_rtl_time_estimate()
    +6.9%      +8    RTL::on_active()
    +6.2%      +8    RTL::selectReturn()
    +1.3%      +8    RtlDirect::estimateReturnFromState()
    +2.6%      +4    RTL::on_inactive()
     +13%      +4    RtlDirect::landDelay()
     +50%      +4    Zero
    +0.0%      +4    [section .text]
    +0.0%      +4    uORB::compressed_fields
    -1.2%      -2    netlib_obtain_ipv4addr
   -20.0%      -2    nsh_system_ctty
    -1.0%      -4    matrix::Matrix<>::Matrix()
    [DEL]    -104    RTL::estimateTimeToHome()
  +0.0%    +216    TOTAL

px4_io-v2 — Bloaty section/symbol breakdown
     VM SIZE    
 -------------- 
  [ = ]       0    TOTAL

Updated: 2026-11-26T06:15:55

@github-actions

Copy link
Copy Markdown
Contributor

No broken links found in changed files.

@JonasPerolini JonasPerolini left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @anilkir, this indeed fixes the race. I reproduced it in SIH:

  • on main the failsafe triggers at the Home crossing, 0.3 s before Navigator switches to the rally point.
  • With this PR it triggers 110 s later, when the rally point drops out of reach.

My concern is how much change a second time estimate needs and the fact that it uses RTLDirect to do it. That comes from how RTL is structured today, not from your PR:

  1. The estimate is a method of the executor and reads its configuration (_destination, _land_approach, _rtl_alt). To estimate a destination, estimateDirectReturn() has to configure RtlDirect for it, and applyReturn() has to configure it again right after.
  2. The avoidance path belongs to the one destination the planner holds, and the estimate always adds it. So the rally point is estimated along Home's path.
  3. 3 different asks:
    • The selection wants "what if" estimates
    • the GCS wants the Return that will be flown
    • the failsafe wants the lowest. The third has no natural place, so it became the _alternative_safe_time_estimate member.

If that's ok with you, I'd open a small refactor PR first:

  • RtlDirect::estimateReturnTo(target) estimates any destination without configuring RtlDirect.
  • on_inactive() writes out select, apply and publish, so the second estimate can stay a local passed to the publisher.

Your PR would then only add the field, fill it in selectHomeIfReachable(), and use it in the publisher and in commander.

Comment thread src/modules/navigator/rtl.h Resolved
Comment thread src/modules/navigator/rtl.h Resolved
Comment thread src/modules/navigator/rtl.cpp Resolved
@JonasPerolini

Copy link
Copy Markdown
Contributor

Created #30006 as a first step to simplify this PR.

@JonasPerolini

Copy link
Copy Markdown
Contributor

Hey @anilkir just a heads up that both small PRs have been merged. Thanks for the feedback in each!

@anilkir
anilkir force-pushed the fix/rtl-type6-failsafe-race branch from 94c65de to eac17f5 Compare November 25, 2026 15:23
@anilkir

anilkir commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@JonasPerolini updates are captured in eac17f5 after rebasing on main with your changes

@JonasPerolini JonasPerolini left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @anilkir,

One functional point is left: with a geofence between the vehicle and Home, the rally point fallback estimation follows Home's detour and gets dropped, so the race this PR fixes comes back.

Feel free to discard the Nit comments.

Comment thread docs/en/config/safety.md Resolved
Comment thread docs/en/flight_modes/return.md Resolved
Comment thread src/modules/navigator/rtl.cpp Resolved
Comment thread src/modules/navigator/rtl.cpp Resolved
Comment thread src/modules/navigator/rtl.h Resolved
Comment thread msg/RtlTimeEstimate.msg Resolved
Comment thread msg/RtlTimeEstimate.msg Resolved
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. kind:test Adds or improves tests. scope:navigation Missions, RTL, geofence, takeoff, landing, or navigator behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants