mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-25 00:30:50 +08:00
fix(navigator)!: require earlier DO_JUMP targets (#29073)
Co-authored-by: jonas <jonas.perolini@rigi.tech>
This commit is contained in:
1 parent
ed02c02239
commit
32d8646181
6 files changed
+98
-3
No files matched your search
@@ -149,6 +149,8 @@ Mission Items:
|
||||
- [MAV_CMD_NAV_TAKEOFF](https://mavlink.io/en/messages/common.html#MAV_CMD_NAV_TAKEOFF)
|
||||
- [MAV_CMD_NAV_LOITER_TO_ALT](https://mavlink.io/en/messages/common.html#MAV_CMD_NAV_LOITER_TO_ALT)
|
||||
- [MAV_CMD_DO_JUMP](https://mavlink.io/en/messages/common.html#MAV_CMD_DO_JUMP)
|
||||
- _Param1_ (sequence number) must refer to an earlier mission item.
|
||||
A mission is rejected if a jump targets itself or a later item, even if its repeat count is 0.
|
||||
- [MAV_CMD_NAV_ROI](https://mavlink.io/en/messages/common.html#MAV_CMD_NAV_ROI)
|
||||
- [MAV_CMD_DO_SET_ROI](https://mavlink.io/en/messages/common.html#MAV_CMD_DO_SET_ROI)
|
||||
- [MAV_CMD_DO_SET_ROI_LOCATION](https://mavlink.io/en/messages/common.html#MAV_CMD_DO_SET_ROI_LOCATION)
|
||||
|
||||
@@ -151,6 +151,8 @@ Mission Items:
|
||||
- [MAV_CMD_NAV_TAKEOFF](https://mavlink.io/en/messages/common.html#MAV_CMD_NAV_TAKEOFF)
|
||||
- [MAV_CMD_NAV_LOITER_TO_ALT](https://mavlink.io/en/messages/common.html#MAV_CMD_NAV_LOITER_TO_ALT)
|
||||
- [MAV_CMD_DO_JUMP](https://mavlink.io/en/messages/common.html#MAV_CMD_DO_JUMP)
|
||||
- _Param1_ (sequence number) must refer to an earlier mission item.
|
||||
A mission is rejected if a jump targets itself or a later item, even if its repeat count is 0.
|
||||
- [MAV_CMD_NAV_ROI](https://mavlink.io/en/messages/common.html#MAV_CMD_NAV_ROI)
|
||||
- [MAV_CMD_DO_SET_ROI](https://mavlink.io/en/messages/common.html#MAV_CMD_DO_SET_ROI)
|
||||
- [MAV_CMD_DO_SET_ROI_LOCATION](https://mavlink.io/en/messages/common.html#MAV_CMD_DO_SET_ROI_LOCATION)
|
||||
|
||||
@@ -47,6 +47,9 @@ Please continue reading for [upgrade instructions](#upgrade-guide).
|
||||
Saved parameters are migrated automatically, but loading a QGC parameter file with the old names does not restore them.
|
||||
The log analysis scripts in the tree read both the old and the new names.
|
||||
The uORB-over-Cyphal registers are renamed from `uorb.sensor_gps` to `uorb.sensor_gnss` (`uavcan.sub.uorb.sensor_gnss.0.id`, `uavcan.pub.uorb.sensor_gnss.0.id`); `UCAN1_UORB_GPS` and `UCAN1_UORB_GPS_P` are unchanged. ([PX4-Autopilot#24399](https://github.com/PX4/PX4-Autopilot/pull/24399))
|
||||
- **`DO_JUMP` can only loop back.**
|
||||
A mission is now rejected if a `DO_JUMP` targets itself or a later mission item, even if its repeat count is 0.
|
||||
Missions stored on the vehicle with such jumps must be edited and uploaded again.
|
||||
|
||||
## Other changes
|
||||
|
||||
|
||||
@@ -1197,9 +1197,17 @@ MavlinkMissionManager::handle_mission_item_both(const mavlink_message_t *msg)
|
||||
if (ret != PX4_OK) {
|
||||
PX4_DEBUG("WPM: MISSION_ITEM ERROR: seq %u invalid item", wp.seq);
|
||||
|
||||
_mavlink.send_statustext_critical("IGN MISSION_ITEM: Invalid item\t");
|
||||
events::send(events::ID("mavlink_mission_mis_item_invalid"), events::Log::Error,
|
||||
"Ignoring mission item, invalid item");
|
||||
// INVALID_PARAM1 on a DO_JUMP can only mean its target is not an earlier item.
|
||||
if (wp.command == MAV_CMD_DO_JUMP && ret == MAV_MISSION_INVALID_PARAM1) {
|
||||
_mavlink.send_statustext_critical("Mission rejected: DO_JUMP must target an earlier item\t");
|
||||
events::send<uint16_t>(events::ID("mavlink_mission_jump_not_backward"), events::Log::Error,
|
||||
"Mission rejected: DO_JUMP {1} must target an earlier item", wp.seq + 1);
|
||||
|
||||
} else {
|
||||
_mavlink.send_statustext_critical("IGN MISSION_ITEM: Invalid item\t");
|
||||
events::send(events::ID("mavlink_mission_mis_item_invalid"), events::Log::Error,
|
||||
"Ignoring mission item, invalid item");
|
||||
}
|
||||
|
||||
send_mission_ack(_transfer_partner_sysid, _transfer_partner_compid, ret);
|
||||
switch_to_idle_state();
|
||||
@@ -1719,6 +1727,12 @@ MavlinkMissionManager::parse_mavlink_mission_item(const mavlink_mission_item_t *
|
||||
|
||||
switch (mavlink_mission_item->command) {
|
||||
case MAV_CMD_DO_JUMP:
|
||||
|
||||
// Only jumps to an earlier item are supported. Also rejects a NaN target.
|
||||
if (!(mavlink_mission_item->param1 >= 0.f && mavlink_mission_item->param1 < mavlink_mission_item->seq)) {
|
||||
return MAV_MISSION_INVALID_PARAM1;
|
||||
}
|
||||
|
||||
mission_item->nav_cmd = NAV_CMD_DO_JUMP;
|
||||
mission_item->do_jump_mission_index = mavlink_mission_item->param1;
|
||||
mission_item->do_jump_current_count = 0;
|
||||
|
||||
@@ -294,6 +294,16 @@ bool FeasibilityChecker::checkMissionItemValidity(mission_item_s &mission_item,
|
||||
return false;
|
||||
}
|
||||
|
||||
// DO_JUMP is supported only for repeating mission items that precede the jump.
|
||||
if (mission_item.nav_cmd == NAV_CMD_DO_JUMP
|
||||
&& (mission_item.do_jump_mission_index < 0 || mission_item.do_jump_mission_index >= current_index)) {
|
||||
mavlink_log_critical(_mavlink_log_pub, "Mission rejected: DO_JUMP %i must target an earlier item\t",
|
||||
current_index + 1);
|
||||
events::send<uint16_t>(events::ID("navigator_mis_jump_not_backward"), {events::Log::Error, events::LogInternal::Info},
|
||||
"Mission rejected: DO_JUMP {1} must target an earlier item", current_index + 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if the mission starts with a land command while the vehicle is landed
|
||||
if ((current_index == 0) && mission_item.nav_cmd == NAV_CMD_LAND && _is_landed) {
|
||||
|
||||
|
||||
@@ -143,6 +143,70 @@ TEST_F(FeasibilityCheckerTest, mission_item_validity)
|
||||
ASSERT_EQ(ret, false);
|
||||
}
|
||||
|
||||
TEST_F(FeasibilityCheckerTest, do_jump_requires_earlier_target)
|
||||
{
|
||||
struct JumpTargetCase {
|
||||
int current_index;
|
||||
int16_t target_index;
|
||||
bool accepted;
|
||||
};
|
||||
|
||||
static constexpr int mission_count = 4;
|
||||
const JumpTargetCase cases[] = {
|
||||
{0, 0, false}, // A first-item jump cannot point to an earlier item.
|
||||
{0, 1, false},
|
||||
{2, -1, false},
|
||||
{2, 0, true}, // Both the first and immediately preceding item are valid targets.
|
||||
{2, 1, true},
|
||||
{2, 2, false}, // Self-jump.
|
||||
{2, 3, false}, // Even the immediately following item is not a backward target.
|
||||
{2, mission_count, false}, // Out-of-range target.
|
||||
};
|
||||
|
||||
struct JumpRepeatCase {
|
||||
uint16_t repeat_count;
|
||||
uint16_t current_count;
|
||||
};
|
||||
|
||||
const JumpRepeatCase repeat_cases[] = {
|
||||
{3, 0}, // Active jump.
|
||||
{0, 0}, // Disabled jump.
|
||||
{3, 3}, // Exhausted jump: validity must not depend on execution history.
|
||||
};
|
||||
|
||||
for (const auto &test_case : cases) {
|
||||
SCOPED_TRACE(::testing::Message() << "index=" << test_case.current_index << " target=" << test_case.target_index);
|
||||
|
||||
for (const auto &repeat_case : repeat_cases) {
|
||||
SCOPED_TRACE(::testing::Message() << "repeats=" << repeat_case.repeat_count << " count=" << repeat_case.current_count);
|
||||
TestFeasibilityChecker checker;
|
||||
checker.publishVehicleType(vehicle_status_s::VEHICLE_TYPE_ROTARY_WING);
|
||||
checker.publishHomePosition(0., 0., 0.f);
|
||||
|
||||
mission_item_s waypoint{};
|
||||
waypoint.nav_cmd = NAV_CMD_WAYPOINT;
|
||||
|
||||
for (int index = 0; index < test_case.current_index; ++index) {
|
||||
ASSERT_TRUE(checker.processNextItem(waypoint, index, mission_count));
|
||||
ASSERT_FALSE(checker.someCheckFailed());
|
||||
}
|
||||
|
||||
mission_item_s jump{};
|
||||
jump.nav_cmd = NAV_CMD_DO_JUMP;
|
||||
jump.do_jump_mission_index = test_case.target_index;
|
||||
jump.do_jump_repeat_count = repeat_case.repeat_count;
|
||||
jump.do_jump_current_count = repeat_case.current_count;
|
||||
|
||||
EXPECT_EQ(checker.processNextItem(jump, test_case.current_index, mission_count), test_case.accepted);
|
||||
EXPECT_EQ(checker.someCheckFailed(), !test_case.accepted);
|
||||
|
||||
// A later valid item must not clear a rejected mission's failure.
|
||||
EXPECT_EQ(checker.processNextItem(waypoint, test_case.current_index + 1, mission_count), test_case.accepted);
|
||||
EXPECT_EQ(checker.someCheckFailed(), !test_case.accepted);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(FeasibilityCheckerTest, check_dist_first_waypoint)
|
||||
{
|
||||
// GIVEN: MIS_DIST_1WP set to 500m
|
||||
|
||||
Reference in new issue
Block a user