fix(navigator): use yaw acceptance timeout by default

MIS_YAW_TMT defaults to 10s, counted from when the heading is commanded, so a multicopter with low yaw authority continues instead of getting stuck.
Forced heading in a mission still fails the mission.
VTOLs only wait for forced headings.
This commit is contained in:
Matthias Grob committed 2026-11-05 16:54:27 +01:00
1 parent 9941e2f769
commit abda07efe4
8 files changed
+300 -18

No files matched your search

@@ -40,7 +40,6 @@ param set-default MC_PITCHRATE_P 0.2
param set-default MC_ROLL_P 6
param set-default MC_ROLLRATE_P 0.3
param set-default MIS_TAKEOFF_ALT 10
param set-default MIS_YAW_TMT 10
param set-default MPC_THR_MIN 0.1
param set-default MPC_XY_P 0.8
@@ -13,7 +13,6 @@ param set-default MAV_TYPE 22
param set-default COM_POS_LOW_EPH 50
param set-default MIS_TAKEOFF_ALT 20
param set-default MIS_YAW_TMT 10
param set-default EKF2_ARSP_THR 10
param set-default EKF2_FUSE_BETA 1
+20 -9
View File
@@ -68,6 +68,11 @@ MissionBlock::is_mission_item_reached_or_completed()
{
const hrt_abstime now = hrt_absolute_time();
// The first check after a reset represents when the item and its heading got commanded
if (_time_item_started == 0) {
_time_item_started = now;
}
// Handle indefinite waypoints and action commands
switch (_mission_item.nav_cmd) {
@@ -397,7 +402,7 @@ MissionBlock::is_mission_item_reached_or_completed()
update_precision_takeoff(now);
#endif // CONFIG_MODULES_VISION_TARGET_ESTIMATOR
// Update the 'waypoint position reached' status (only for rotary wing flight)
// Update the 'waypoint yaw reached' status, only rotary wings wait for the heading
if (_waypoint_position_reached && !_waypoint_yaw_reached) {
if (_navigator->get_vstatus()->vehicle_type == vehicle_status_s::VEHICLE_TYPE_ROTARY_WING
@@ -405,20 +410,25 @@ MissionBlock::is_mission_item_reached_or_completed()
&& _navigator->get_local_position()->heading_good_for_control) {
const float yaw_err = wrap_pi(_mission_item.yaw - _navigator->get_local_position()->heading);
const bool yaw_timed_out = (_navigator->get_yaw_timeout() >= FLT_EPSILON)
&& (now > _time_item_started + (hrt_abstime)(_navigator->get_yaw_timeout() * 1_s));
/* accept yaw if reached or if timeout is set in which case we ignore not forced headings */
// Accept yaw if reached, VTOLs only care about forced headings
if (fabsf(yaw_err) < _navigator->get_yaw_threshold()
|| (_navigator->get_yaw_timeout() >= FLT_EPSILON && !_mission_item.force_heading)) {
|| (_navigator->get_vstatus()->is_vtol && !_mission_item.force_heading)) {
_waypoint_yaw_reached = true;
}
/* if heading needs to be reached, the timeout is enabled and we don't make it, abort mission */
if (!_waypoint_yaw_reached && _mission_item.force_heading &&
(_navigator->get_yaw_timeout() >= FLT_EPSILON) &&
(now - _time_wp_reached >= (hrt_abstime)_navigator->get_yaw_timeout() * 1e6f)) {
} else if (yaw_timed_out) {
if (_mission_item.force_heading
&& _navigator->get_vstatus()->nav_state == vehicle_status_s::NAVIGATION_STATE_AUTO_MISSION) {
// The mission relies on the heading (e.g. VTOL forward transition), abort it
_navigator->set_mission_failure_heading_timeout();
_navigator->set_mission_failure_heading_timeout();
} else {
// Never get stuck, e.g. when yaw authority is lost
_waypoint_yaw_reached = true;
}
}
} else {
@@ -526,6 +536,7 @@ MissionBlock::reset_mission_item_reached()
_waypoint_position_reached = false;
_waypoint_yaw_reached = false;
_time_wp_reached = 0;
_time_item_started = 0;
}
void
+1
View File
@@ -231,6 +231,7 @@ protected:
bool _waypoint_yaw_reached{false};
hrt_abstime _time_wp_reached{0};
hrt_abstime _time_item_started{0}; ///< first reached check of the current item, i.e. when its heading got commanded
// Mission items that have a timeout to allow the payload e.g. gripper, winch, gimbal executing the command see item_has_timeout()
hrt_abstime _timestamp_command_timeout{0}; ///< Timestamp when the current item_has_timeout() command was started
+7 -7
View File
@@ -63,17 +63,17 @@ parameters:
description:
short: Waypoint heading timeout
long: |-
Time in seconds we wait on reaching target heading at a waypoint if it is forced
Time from commanding a waypoint heading until a multicopter continues without reaching it,
to not get stuck with low yaw authority.
If set > 0 it will ignore the target heading for normal waypoint acceptance. If the
waypoint forces the heading the timeout will matter. For example on VTOL forwards transition.
Mainly useful for VTOLs that have less yaw authority and might not reach target
yaw in wind. Disabled by default.
A forced heading in a mission (e.g. before VTOL transition) fails the mission instead.
VTOLs only wait for forced headings.
-1: wait indefinitely
type: float
default: -1.0
default: 10.0
unit: s
min: -1
max: 20
max: 60
decimal: 1
increment: 1
MIS_YAW_ERR:
@@ -36,6 +36,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
px4_add_functional_gtest(SRC test_geofence.cpp LINKLIBS modules__navigator modules__dataman)
px4_add_functional_gtest(SRC test_mission_base.cpp LINKLIBS modules__navigator modules__dataman)
px4_add_functional_gtest(SRC test_RTL.cpp LINKLIBS modules__navigator modules__dataman)
px4_add_functional_gtest(SRC test_mission_block_yaw.cpp LINKLIBS modules__navigator modules__dataman)
px4_add_functional_gtest(SRC test_prec_land.cpp LINKLIBS modules__navigator modules__dataman)
px4_add_functional_gtest(SRC test_geofence_paths.cpp LINKLIBS modules__navigator modules__dataman)
if(CONFIG_NAVIGATOR_GEOFENCE_PATH_CHECKS)
@@ -0,0 +1,248 @@
/****************************************************************************
*
* Copyright (c) 2026 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/**
* @file test_mission_block_yaw.cpp
*
* Heading acceptance of a rotary-wing waypoint: awaited for at most MIS_YAW_TMT counted from when the
* heading got commanded so a vehicle that cannot turn (e.g. lost yaw authority) does not get stuck.
*/
#include <gtest/gtest.h>
#include "mission_block.h"
#include "navigator.h"
#include "support/navigator_dataman_test.h"
#include <drivers/drv_hrt.h>
#include <lib/geo/geo.h>
#include <lib/mathlib/mathlib.h>
#include <px4_platform_common/posix.h>
namespace
{
constexpr double kLat = 47.397742;
constexpr double kLon = 8.545594;
constexpr float kAlt = 500.f;
constexpr float kHeading = 0.1f; // rad, vehicle heading
constexpr float kItemYaw = kHeading + math::radians(90.f); // well outside MIS_YAW_ERR
constexpr float kTimeout = 0.2f; // s, short MIS_YAW_TMT to keep the tests fast
float paramFloat(const char *name)
{
float value = NAN;
param_get(param_find(name), &value);
return value;
}
} // namespace
class MissionBlockYawTestNavigator : public Navigator
{
public:
using Navigator::updateParams;
};
class MissionBlockYawTestPeer : public MissionBlock
{
public:
explicit MissionBlockYawTestPeer(Navigator *navigator)
: MissionBlock(navigator, vehicle_status_s::NAVIGATION_STATE_AUTO_MISSION) {}
mission_item_s &item() { return _mission_item; }
bool reached() { return is_mission_item_reached_or_completed(); }
bool yawReached() const { return _waypoint_yaw_reached; }
void reset() { reset_mission_item_reached(); }
};
class MissionBlockYawTest : public NavigatorDatamanTestBase
{
protected:
MissionBlockYawTestNavigator _navigator{};
MissionBlockYawTestPeer _block{&_navigator};
void SetUp() override
{
param_control_autosave(false);
param_reset_all();
setYawTimeout(kTimeout);
vehicle_status_s *status = _navigator.get_vstatus();
status->timestamp = hrt_absolute_time();
status->vehicle_type = vehicle_status_s::VEHICLE_TYPE_ROTARY_WING;
status->is_vtol = false;
status->nav_state = vehicle_status_s::NAVIGATION_STATE_AUTO_RTL;
vehicle_local_position_s *local = _navigator.get_local_position();
local->timestamp = hrt_absolute_time();
local->heading = kHeading;
local->heading_good_for_control = true;
_navigator.get_land_detected()->landed = false;
_navigator.get_mission_result()->failure = false;
// a waypoint whose heading the vehicle has not reached
mission_item_s &item = _block.item();
item = {};
item.nav_cmd = NAV_CMD_WAYPOINT;
item.lat = kLat;
item.lon = kLon;
item.altitude = kAlt;
item.altitude_is_relative = false;
item.yaw = kItemYaw;
item.acceptance_radius = NAN;
item.time_inside = 0.f;
_block.reset();
setVehicleOnWaypoint(true);
}
void setVehicleOnWaypoint(bool on_waypoint)
{
vehicle_global_position_s *global = _navigator.get_global_position();
global->timestamp = hrt_absolute_time();
global->lat = kLat;
global->lon = kLon;
global->alt = on_waypoint ? kAlt : kAlt + 50.f; // e.g. still descending towards it
}
void setYawTimeout(float seconds)
{
ASSERT_EQ(param_set(param_find("MIS_YAW_TMT"), &seconds), PX4_OK);
_navigator.updateParams();
}
void sleepPastTimeout() { px4_usleep((useconds_t)(kTimeout * 1.25e6f)); }
};
TEST_F(MissionBlockYawTest, HeadingIsAcceptedWhenReached)
{
EXPECT_FALSE(_block.reached()); // on the waypoint, heading not reached
_navigator.get_local_position()->heading = kItemYaw;
EXPECT_TRUE(_block.reached());
EXPECT_FALSE(_navigator.get_mission_result()->failure);
}
TEST_F(MissionBlockYawTest, ContinuesWithoutHeadingAfterTimeout)
{
EXPECT_FALSE(_block.reached());
px4_usleep((useconds_t)(kTimeout * 0.5e6f));
EXPECT_FALSE(_block.reached()); // still inside the timeout
px4_usleep((useconds_t)(kTimeout * 0.75e6f));
EXPECT_TRUE(_block.reached()); // e.g. lost yaw authority: continue without the heading
EXPECT_TRUE(_block.yawReached());
EXPECT_FALSE(_navigator.get_mission_result()->failure);
}
TEST_F(MissionBlockYawTest, TimeoutIsCountedFromWhenHeadingIsCommanded)
{
// the turn happens on the way, e.g. during the descent, which uses up the timeout
setVehicleOnWaypoint(false);
EXPECT_FALSE(_block.reached());
sleepPastTimeout();
EXPECT_FALSE(_block.reached()); // position not reached yet
setVehicleOnWaypoint(true);
EXPECT_TRUE(_block.reached()); // no extra wait once there
}
TEST_F(MissionBlockYawTest, TimeoutAppliesInMissionToo)
{
_navigator.get_vstatus()->nav_state = vehicle_status_s::NAVIGATION_STATE_AUTO_MISSION;
EXPECT_FALSE(_block.reached());
sleepPastTimeout();
EXPECT_TRUE(_block.reached());
EXPECT_FALSE(_navigator.get_mission_result()->failure);
}
TEST_F(MissionBlockYawTest, ForcedHeadingTimeoutFailsMission)
{
_navigator.get_vstatus()->nav_state = vehicle_status_s::NAVIGATION_STATE_AUTO_MISSION;
_block.item().force_heading = true;
EXPECT_FALSE(_block.reached());
sleepPastTimeout();
EXPECT_FALSE(_block.reached()); // the mission relies on the heading, the failsafe takes over
EXPECT_TRUE(_navigator.get_mission_result()->failure);
}
TEST_F(MissionBlockYawTest, ForcedHeadingTimeoutContinuesInReturn)
{
_block.item().force_heading = true;
EXPECT_FALSE(_block.reached());
sleepPastTimeout();
EXPECT_TRUE(_block.reached()); // nothing would react to a mission failure in Return
EXPECT_FALSE(_navigator.get_mission_result()->failure);
}
TEST_F(MissionBlockYawTest, VtolIgnoresHeadingThatIsNotForced)
{
_navigator.get_vstatus()->is_vtol = true;
EXPECT_TRUE(_block.reached());
}
TEST_F(MissionBlockYawTest, VtolAwaitsForcedHeading)
{
_navigator.get_vstatus()->is_vtol = true;
_block.item().force_heading = true;
EXPECT_FALSE(_block.reached());
}
TEST_F(MissionBlockYawTest, DisabledTimeoutWaitsIndefinitely)
{
setYawTimeout(-1.f);
EXPECT_FALSE(_block.reached());
sleepPastTimeout();
EXPECT_FALSE(_block.reached());
}
TEST_F(MissionBlockYawTest, ResetRestartsTimeout)
{
EXPECT_FALSE(_block.reached());
sleepPastTimeout();
_block.reset(); // e.g. heading alignment added to an already reached item
EXPECT_FALSE(_block.reached());
}
TEST_F(MissionBlockYawTest, DefaultTimeoutCoversHalfTurnAtDefaultYawLimits)
{
param_reset_all();
const float rate = paramFloat("MPC_YAWRAUTO_MAX"); // deg/s
const float acc = paramFloat("MPC_YAWRAUTO_ACC"); // deg/s^2
ASSERT_TRUE(PX4_ISFINITE(rate) && PX4_ISFINITE(acc));
// trapezoidal profile: accelerate to the rate, cruise, decelerate
const float half_turn_time = 180.f / rate + rate / acc;
EXPECT_GT(paramFloat("MIS_YAW_TMT"), half_turn_time);
}
@@ -1,5 +1,6 @@
import pytest
from mavsdk.plugins.failure import FailureResult, FailureType, FailureUnit # type: ignore
from mavsdk.plugins.offboard import PositionNedYaw # type: ignore
from autopilot_tester import AutopilotTester
@@ -81,3 +82,25 @@ def test_undetected_motor_failure_stops_only_failed_motor(tester: AutopilotTeste
allocator is not informed and the opposite motor keeps running."""
take_off_and_hover_for_motor_failure(tester)
fail_and_restore_motor(tester, FailureType.WRONG, 1 << (MOTOR_INSTANCE - 1))
@pytest.mark.motor_failure_injection
def test_return_lands_with_failed_motor_and_heading_off(tester: AutopilotTester) -> None:
"""Return with the motor still failed. With CA_FAILURE_MODE = 1 the hexarotor flies on four
motors and has no yaw authority left. The vehicle faces 90 deg away from the home
heading when Return is commanded: navigator must not wait for that heading forever but
continue after MIS_YAW_TMT and land."""
take_off_and_hover_for_motor_failure(tester)
# turn away from the heading Return will command at the destination
tester.offboard_goto(PositionNedYaw(0.0, 0.0, -FLIGHT_ALTITUDE_M, 90.0),
acceptance_radius_m=1.0)
tester.sleep_for(5)
tester.hold()
tester.inject_failure(FailureUnit.SYSTEM_MOTOR, FailureType.OFF, MOTOR_INSTANCE)
tester.sleep_for(5)
tester.ensure_motors_stopped(0b1001, NUM_MOTORS)
tester.execute_rtl()
tester.wait_until_disarmed(180)