From caf75ad3c13c0346dc5a315c7eef1f034ee19960 Mon Sep 17 00:00:00 2001 From: Jonas Perolini Date: Sun, 8 Nov 2026 16:18:35 +0100 Subject: [PATCH] fix(mavlink): report missing Return time estimates as unknown (#29685) Assisted-by: Claude:claude-opus-5-5 --- docs/en/config/safety.md | 1 + docs/en/releases/main.md | 2 ++ src/modules/mavlink/streams/TIME_ESTIMATE_TO_TARGET.hpp | 3 ++- src/modules/navigator/rtl.cpp | 1 + src/modules/navigator/rtl_mission_fast.cpp | 2 +- src/modules/navigator/rtl_mission_fast_reverse.cpp | 2 +- 6 files changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/en/config/safety.md b/docs/en/config/safety.md index 2be4f5298c4..8fafbc96f2d 100644 --- a/docs/en/config/safety.md +++ b/docs/en/config/safety.md @@ -139,6 +139,7 @@ The remaining flight time comes from the battery: Without a remaining flight time estimate, the distance-aware return failsafe never triggers, and there is no warning either. This is the case if `BATn_CAPACITY` is not set (the default is `-1`), if a DroneCAN battery sends only `BatteryInfo`, or if a MAVLink battery does not fill in `time_remaining`. This also applies when there is no valid home position or global position estimate. +It also never triggers with [RTL_TYPE](../advanced_config/parameter_reference.md#RTL_TYPE) = 2 or 4 while a valid mission is loaded: these Return types do not estimate the time to follow the mission. The vehicle is then only protected by the [battery level failsafe](#battery-level-failsafe). ::: diff --git a/docs/en/releases/main.md b/docs/en/releases/main.md index 4b8a438378e..321d3437dac 100644 --- a/docs/en/releases/main.md +++ b/docs/en/releases/main.md @@ -173,6 +173,8 @@ Please continue reading for [upgrade instructions](#upgrade-guide). - ESC/motor health is now reported in [SYS_STATUS](https://mavlink.io/en/messages/common.html#SYS_STATUS) using the [MAV_SYS_STATUS_SENSOR_PROPULSION](https://mavlink.io/en/messages/common.html#MAV_SYS_STATUS_SENSOR_PROPULSION) bit instead of [MAV_SYS_STATUS_SENSOR_MOTOR_OUTPUTS](https://mavlink.io/en/messages/common.html#MAV_SYS_STATUS_SENSOR_MOTOR_OUTPUTS). ([PX4-Autopilot#29192](https://github.com/PX4/PX4-Autopilot/pull/29192)). - [SYS_STATUS](https://mavlink.io/en/messages/common.html#SYS_STATUS) now sets the [MAV_SYS_STATUS_EXTENSION_USED](https://mavlink.io/en/messages/common.html#MAV_SYS_STATUS_EXTENSION_USED) flag in `onboard_control_sensors_present` when extended sensor fields are used. +- [TIME_ESTIMATE_TO_TARGET](https://mavlink.io/en/messages/common.html#TIME_ESTIMATE_TO_TARGET) reports `safe_return` as `-1` (landed or no estimate) when Return has no time estimate: before Home is set, on the ground unless Return would follow a mission landing, and with [RTL_TYPE](../advanced_config/parameter_reference.md#RTL_TYPE) = 2 or 4 and a valid mission. + It used to send `0`, or an undefined value with `RTL_TYPE` 2 and 4. ### RC diff --git a/src/modules/mavlink/streams/TIME_ESTIMATE_TO_TARGET.hpp b/src/modules/mavlink/streams/TIME_ESTIMATE_TO_TARGET.hpp index b28a8bd4dd0..b7b5e805fe0 100644 --- a/src/modules/mavlink/streams/TIME_ESTIMATE_TO_TARGET.hpp +++ b/src/modules/mavlink/streams/TIME_ESTIMATE_TO_TARGET.hpp @@ -64,7 +64,8 @@ private: _rtl_estimate_sub.copy(&rtl_estimate); mavlink_time_estimate_to_target_t msg{}; - msg.safe_return = static_cast(rtl_estimate.safe_time_estimate); + // MAVLink uses -1 when there is no estimate + msg.safe_return = rtl_estimate.valid ? static_cast(rtl_estimate.safe_time_estimate) : -1; // Set to -1 explicitly because not supported (yet) msg.land = -1; diff --git a/src/modules/navigator/rtl.cpp b/src/modules/navigator/rtl.cpp index f922fa518a6..57be2dedd4f 100644 --- a/src/modules/navigator/rtl.cpp +++ b/src/modules/navigator/rtl.cpp @@ -130,6 +130,7 @@ void RTL::publishRemainingTimeEstimate() } } + estimated_time.timestamp = hrt_absolute_time(); _rtl_time_estimate_pub.publish(estimated_time); } diff --git a/src/modules/navigator/rtl_mission_fast.cpp b/src/modules/navigator/rtl_mission_fast.cpp index 79d6bf4afb7..b277c93e7d7 100644 --- a/src/modules/navigator/rtl_mission_fast.cpp +++ b/src/modules/navigator/rtl_mission_fast.cpp @@ -212,7 +212,7 @@ void RtlMissionFast::setActiveMissionItems() rtl_time_estimate_s RtlMissionFast::calc_rtl_time_estimate() { - rtl_time_estimate_s time_estimate; + rtl_time_estimate_s time_estimate{}; time_estimate.valid = false; time_estimate.timestamp = hrt_absolute_time(); diff --git a/src/modules/navigator/rtl_mission_fast_reverse.cpp b/src/modules/navigator/rtl_mission_fast_reverse.cpp index 025ea7d8ec3..092db73a7a8 100644 --- a/src/modules/navigator/rtl_mission_fast_reverse.cpp +++ b/src/modules/navigator/rtl_mission_fast_reverse.cpp @@ -296,7 +296,7 @@ void RtlMissionFastReverse::handleLanding(WorkItemType &new_work_item_type) rtl_time_estimate_s RtlMissionFastReverse::calc_rtl_time_estimate() { - rtl_time_estimate_s time_estimate; + rtl_time_estimate_s time_estimate{}; time_estimate.valid = false; time_estimate.timestamp = hrt_absolute_time();