diff --git a/docs/en/config_vtol/vtol_weathervane.md b/docs/en/config_vtol/vtol_weathervane.md index 7b23bb1ef1c..ba173f68f68 100644 --- a/docs/en/config_vtol/vtol_weathervane.md +++ b/docs/en/config_vtol/vtol_weathervane.md @@ -18,8 +18,8 @@ The target yaw rate is the sum of weather vane yaw rate and user commanded yaw r ## Mission Mode Behaviour -In [Mission mode](../flight_modes_vtol/mission.md) the weather vane feature will always be active when the parameter is enabled. -Any yaw angle commanded in a mission will be ignored. +In [Mission mode](../flight_modes_vtol/mission.md) the weather vane feature is active (when enabled) for any mission item that does not command a yaw angle. +If a mission item commands a yaw angle, the weather vane feature is disabled for that item and the commanded yaw is used instead. diff --git a/src/modules/navigator/mission.cpp b/src/modules/navigator/mission.cpp index b6560bbe08c..42b6545f5f7 100644 --- a/src/modules/navigator/mission.cpp +++ b/src/modules/navigator/mission.cpp @@ -238,7 +238,8 @@ void Mission::setActiveMissionItems() _mission_item.nav_cmd == NAV_CMD_WAYPOINT; const bool mc_landing_after_transition = _vehicle_status_sub.get().vehicle_type == vehicle_status_s::VEHICLE_TYPE_ROTARY_WING && _vehicle_status_sub.get().is_vtol && - new_work_item_type == WorkItemType::WORK_ITEM_TYPE_MOVE_TO_LAND; + (new_work_item_type == WorkItemType::WORK_ITEM_TYPE_MOVE_TO_LAND || + new_work_item_type == WorkItemType::WORK_ITEM_TYPE_ALIGN_TO_LAND); if (fw_on_mission_landing || mc_landing_after_transition) { pos_sp_triplet->current.alt_acceptance_radius = FLT_MAX; @@ -295,6 +296,7 @@ void Mission::setActiveMissionItems() // Only set the previous position item if the current one really changed if ((_work_item_type != WorkItemType::WORK_ITEM_TYPE_MOVE_TO_LAND) && + (_work_item_type != WorkItemType::WORK_ITEM_TYPE_ALIGN_TO_LAND) && !position_setpoint_equal(&pos_sp_triplet->current, ¤t_setpoint_copy)) { pos_sp_triplet->previous = current_setpoint_copy; } diff --git a/src/modules/navigator/mission_base.cpp b/src/modules/navigator/mission_base.cpp index a8fb1c69fa7..6c819c25cee 100644 --- a/src/modules/navigator/mission_base.cpp +++ b/src/modules/navigator/mission_base.cpp @@ -341,6 +341,7 @@ MissionBase::on_active() || _mission_item.nav_cmd == NAV_CMD_DO_VTOL_TRANSITION || _mission_item.nav_cmd == NAV_CMD_LAND || _mission_item.nav_cmd == NAV_CMD_VTOL_LAND + || _work_item_type == WorkItemType::WORK_ITEM_TYPE_ALIGN_TO_LAND || _work_item_type == WorkItemType::WORK_ITEM_TYPE_ALIGN_HEADING)) { // Mount control is disabled If the vehicle is in ROI-mode, the vehicle // needs to rotate such that ROI is in the field of view. @@ -624,13 +625,6 @@ void MissionBase::handleLanding(WorkItemType &new_work_item_type, mission_item_s (_mission_item.nav_cmd == NAV_CMD_VTOL_LAND) && !_land_detected_sub.get().landed; - /* ignore yaw for landing items */ - /* XXX: if specified heading for landing is desired we could add another step before the descent - * that aligns the vehicle first */ - if (_mission_item.nav_cmd == NAV_CMD_LAND || _mission_item.nav_cmd == NAV_CMD_VTOL_LAND) { - _mission_item.yaw = NAN; - } - /* move to land wp as fixed wing */ if (needs_vtol_landing) { if (_work_item_type == WorkItemType::WORK_ITEM_TYPE_DEFAULT) { @@ -653,6 +647,7 @@ void MissionBase::handleLanding(WorkItemType &new_work_item_type, mission_item_s _mission_item.autocontinue = true; _mission_item.time_inside = 0.0f; _mission_item.vtol_back_transition = true; + _mission_item.yaw = NAN; _navigator->reset_position_setpoint(pos_sp_triplet->previous); } @@ -676,7 +671,7 @@ void MissionBase::handleLanding(WorkItemType &new_work_item_type, mission_item_s /* use current mission item as next position item */ num_found_items = 1u; - next_mission_items[0u] = _mission_item; + next_mission_items[0u] = _mission_item; // contains NAV_CMD_LAND /* * Ignoring waypoint altitude: @@ -692,6 +687,41 @@ void MissionBase::handleLanding(WorkItemType &new_work_item_type, mission_item_s altitude = pos_sp_triplet->current.alt; } + _mission_item.altitude = altitude; + _mission_item.altitude_is_relative = false; + _mission_item.nav_cmd = NAV_CMD_WAYPOINT; + _mission_item.autocontinue = true; + _mission_item.yaw = NAN; + + // have to reset here because these field were used in set_vtol_transition_item + _mission_item.time_inside = 0.f; + _mission_item.acceptance_radius = _navigator->get_acceptance_radius(); + + // make previous setpoint invalid, such that there will be no prev-current line following. + // if the vehicle drifted off the path during back-transition it should just go straight to the landing point + _navigator->reset_position_setpoint(pos_sp_triplet->previous); + + _navigator->activate_set_gimbal_neutral_timer(hrt_absolute_time()); + + } else if ((_vehicle_status_sub.get().vehicle_type == vehicle_status_s::VEHICLE_TYPE_ROTARY_WING) && + !do_need_move_to_item() && + PX4_ISFINITE(_mission_item.yaw) && (_mission_item.land_precision == 0) && + (_work_item_type == WorkItemType::WORK_ITEM_TYPE_DEFAULT || + _work_item_type == WorkItemType::WORK_ITEM_TYPE_MOVE_TO_LAND || + _work_item_type == WorkItemType::WORK_ITEM_TYPE_MOVE_TO_LAND_AFTER_TRANSITION)) { + + float altitude = _global_pos_sub.get().alt; + + if (pos_sp_triplet->current.valid + && pos_sp_triplet->current.type == position_setpoint_s::SETPOINT_TYPE_POSITION) { + altitude = pos_sp_triplet->current.alt; + } + + new_work_item_type = WorkItemType::WORK_ITEM_TYPE_ALIGN_TO_LAND; + + num_found_items = 1u; + next_mission_items[0u] = _mission_item; // contains NAV_CMD_LAND + _mission_item.altitude = altitude; _mission_item.altitude_is_relative = false; _mission_item.nav_cmd = NAV_CMD_WAYPOINT; diff --git a/src/modules/navigator/mission_base.h b/src/modules/navigator/mission_base.h index aabf2f9232f..b7a100a27a6 100644 --- a/src/modules/navigator/mission_base.h +++ b/src/modules/navigator/mission_base.h @@ -88,6 +88,7 @@ protected: WORK_ITEM_TYPE_DEFAULT, /**< default mission item */ WORK_ITEM_TYPE_CLIMB, /**< takeoff before moving to waypoint */ WORK_ITEM_TYPE_MOVE_TO_LAND, /**< move to land waypoint before descent */ + WORK_ITEM_TYPE_ALIGN_TO_LAND, WORK_ITEM_TYPE_ALIGN_HEADING, /**< align for next waypoint */ WORK_ITEM_TYPE_TRANSITION_AFTER_TAKEOFF, WORK_ITEM_TYPE_MOVE_TO_LAND_AFTER_TRANSITION, diff --git a/src/modules/navigator/rtl_direct_mission_land.cpp b/src/modules/navigator/rtl_direct_mission_land.cpp index 03af21689f9..b72b8835e76 100644 --- a/src/modules/navigator/rtl_direct_mission_land.cpp +++ b/src/modules/navigator/rtl_direct_mission_land.cpp @@ -292,6 +292,7 @@ void RtlDirectMissionLand::setActiveMissionItems() // Only set the previous position item if the current one really changed if ((_work_item_type != WorkItemType::WORK_ITEM_TYPE_MOVE_TO_LAND) && + (_work_item_type != WorkItemType::WORK_ITEM_TYPE_ALIGN_TO_LAND) && !position_setpoint_equal(&pos_sp_triplet->current, ¤t_setpoint_copy)) { pos_sp_triplet->previous = current_setpoint_copy; } @@ -303,7 +304,8 @@ void RtlDirectMissionLand::setActiveMissionItems() _mission_item.nav_cmd == NAV_CMD_WAYPOINT; const bool mc_landing_after_transition = _vehicle_status_sub.get().vehicle_type == vehicle_status_s::VEHICLE_TYPE_ROTARY_WING && _vehicle_status_sub.get().is_vtol && - new_work_item_type == WorkItemType::WORK_ITEM_TYPE_MOVE_TO_LAND; + (new_work_item_type == WorkItemType::WORK_ITEM_TYPE_MOVE_TO_LAND || + new_work_item_type == WorkItemType::WORK_ITEM_TYPE_ALIGN_TO_LAND); if (fw_on_mission_landing || mc_landing_after_transition) { pos_sp_triplet->current.alt_acceptance_radius = FLT_MAX; diff --git a/src/modules/navigator/rtl_mission_fast.cpp b/src/modules/navigator/rtl_mission_fast.cpp index 628b0bc6ab7..487d548e193 100644 --- a/src/modules/navigator/rtl_mission_fast.cpp +++ b/src/modules/navigator/rtl_mission_fast.cpp @@ -181,6 +181,7 @@ void RtlMissionFast::setActiveMissionItems() // Only set the previous position item if the current one really changed if ((_work_item_type != WorkItemType::WORK_ITEM_TYPE_MOVE_TO_LAND) && + (_work_item_type != WorkItemType::WORK_ITEM_TYPE_ALIGN_TO_LAND) && !position_setpoint_equal(&pos_sp_triplet->current, ¤t_setpoint_copy)) { pos_sp_triplet->previous = current_setpoint_copy; } @@ -190,7 +191,8 @@ void RtlMissionFast::setActiveMissionItems() _mission_item.nav_cmd == NAV_CMD_WAYPOINT; const bool mc_landing_after_transition = _vehicle_status_sub.get().vehicle_type == vehicle_status_s::VEHICLE_TYPE_ROTARY_WING && _vehicle_status_sub.get().is_vtol && - new_work_item_type == WorkItemType::WORK_ITEM_TYPE_MOVE_TO_LAND; + (new_work_item_type == WorkItemType::WORK_ITEM_TYPE_MOVE_TO_LAND || + new_work_item_type == WorkItemType::WORK_ITEM_TYPE_ALIGN_TO_LAND); if (fw_on_mission_landing || mc_landing_after_transition) { pos_sp_triplet->current.alt_acceptance_radius = FLT_MAX; diff --git a/src/modules/navigator/test/test_RTL.cpp b/src/modules/navigator/test/test_RTL.cpp index 066482cedd6..c0bc998a56d 100644 --- a/src/modules/navigator/test/test_RTL.cpp +++ b/src/modules/navigator/test/test_RTL.cpp @@ -248,6 +248,12 @@ public: const mission_item_s &activeItem() const { return this->_mission_item; } bool activeItemValid() const { return this->_is_current_planned_mission_item_valid; } + float activeYaw() const { return this->_mission_item.yaw; } + + using WorkItemType = typename RtlMissionType::WorkItemType; + + WorkItemType activeWorkItemType() const { return this->_work_item_type; } + protected: bool loadMissionItemFromCache(int32_t index, mission_item_s &mission_item) override { @@ -674,6 +680,282 @@ INSTANTIATE_TEST_SUITE_P(VehicleTypes, RTLClimbUpdateTest, ::testing::Values(vehicle_status_s::VEHICLE_TYPE_ROTARY_WING, vehicle_status_s::VEHICLE_TYPE_FIXED_WING))); +// WHY: A VTOL landing with finite yaw, must rotate before proceeding with its landing, however it must +// also widend its acceptance heights for the landing waypoint to account for the back-transition +// WHAT: A VTOL_LAND item with a finite yaw is driven through MOVE_TO_LAND, the back-transition, +// ALIGN_TO_LAND, and back to VTOL_LAND. +TEST_F(RTLTest, DirectMissionLandAlignsToCommandedYawBeforeDescending) +{ + using WorkItemType = RtlDirectMissionLandTestPeer::WorkItemType; + constexpr float kLandYaw = 1.2f; + + mission_s mission{}; + mission.timestamp = hrt_absolute_time(); + mission.current_seq = 0; + mission.count = 1; + mission.land_start_index = 0; + mission.land_index = 0; + mission.mission_dataman_id = DM_KEY_WAYPOINTS_OFFBOARD_1; + + mission_item_s land = makeSafePointItem(kBaseLat, kBaseLon, kAlt, NAV_FRAME_GLOBAL, NAV_CMD_VTOL_LAND); + land.autocontinue = true; + land.yaw = kLandYaw; + + // GIVEN: A VTOL approaching its land point as a fixed wing, with a commanded landing yaw. + // Publish the mission itself too: unlike a single activation check, this test calls + // on_active() repeatedly, and MissionBase::updateMavlinkMission() reads the real `mission` + // topic there. Without this, a fresh Subscription's first update() picks up whatever another + // test last left on that (process-wide) topic and clobbers _mission with unrelated data. + publishMission(mission); + publishVehicleStatus(true, vehicle_status_s::VEHICLE_TYPE_FIXED_WING); + publishGlobalPosition(kBaseLat, kBaseLon, kAlt); + publishLandDetected(false); + _navigator.get_mission_result()->valid = true; + + // is_mission_item_reached_or_completed() reads the navigator's own cached vehicle state + // rather than MissionBase's subscriptions, so both must be kept in sync by the test. + _navigator.get_global_position()->lat = kBaseLat; + _navigator.get_global_position()->lon = kBaseLon; + _navigator.get_global_position()->alt = kAlt; + _navigator.get_global_position()->timestamp = hrt_absolute_time(); + _navigator.get_land_detected()->landed = false; + _navigator.get_vstatus()->vehicle_type = vehicle_status_s::VEHICLE_TYPE_FIXED_WING; + _navigator.get_vstatus()->is_vtol = true; + _navigator.get_vstatus()->in_transition_mode = false; + + RtlDirectMissionLandTestPeer direct_mission_land{&_navigator, mission}; + direct_mission_land.loadTestMission({land}); + direct_mission_land.setRtlAlt(kAlt); + + // WHEN: The mission activates. + direct_mission_land.activateForTest(); + + // THEN: It moves to the land waypoint first as a fixed wing, with yaw ignored. + ASSERT_EQ(direct_mission_land.activeWorkItemType(), WorkItemType::WORK_ITEM_TYPE_MOVE_TO_LAND); + EXPECT_EQ(direct_mission_land.activeNavCommand(), NAV_CMD_WAYPOINT); + EXPECT_TRUE(std::isnan(direct_mission_land.activeYaw())); + + // WHEN: The vehicle reaches the land point and requests the back-transition to multicopter. + direct_mission_land.on_active(); + + ASSERT_EQ(direct_mission_land.activeWorkItemType(), WorkItemType::WORK_ITEM_TYPE_MOVE_TO_LAND_AFTER_TRANSITION); + EXPECT_EQ(direct_mission_land.activeNavCommand(), NAV_CMD_DO_VTOL_TRANSITION); + + // WHEN: The back-transition completes. + publishVehicleStatus(true, vehicle_status_s::VEHICLE_TYPE_ROTARY_WING); + _navigator.get_vstatus()->vehicle_type = vehicle_status_s::VEHICLE_TYPE_ROTARY_WING; + _navigator.get_vstatus()->is_vtol = true; + _navigator.get_vstatus()->in_transition_mode = false; + direct_mission_land.on_active(); + + // THEN: It aligns to the commanded landing yaw before descending, holding the current + // altitude, and widens the altitude acceptance radius the same way MOVE_TO_LAND does. + ASSERT_EQ(direct_mission_land.activeWorkItemType(), WorkItemType::WORK_ITEM_TYPE_ALIGN_TO_LAND); + EXPECT_EQ(direct_mission_land.activeNavCommand(), NAV_CMD_WAYPOINT); + EXPECT_FLOAT_EQ(direct_mission_land.activeYaw(), kLandYaw); + EXPECT_FLOAT_EQ(_navigator.get_position_setpoint_triplet()->current.alt_acceptance_radius, FLT_MAX); + + // WHEN: The vehicle finishes rotating to the commanded landing yaw. + _navigator.get_local_position()->heading = kLandYaw; + _navigator.get_local_position()->heading_good_for_control = true; + direct_mission_land.on_active(); + + // THEN: It falls through to the real landing item with the commanded yaw intact. + EXPECT_EQ(direct_mission_land.activeWorkItemType(), WorkItemType::WORK_ITEM_TYPE_DEFAULT); + EXPECT_EQ(direct_mission_land.activeNavCommand(), NAV_CMD_VTOL_LAND); + EXPECT_FLOAT_EQ(direct_mission_land.activeYaw(), kLandYaw); +} + +// WHY: With no commanded landing yaw there is nothing to align to, so the mission must +// go straight from the back-transition to the real landing item, never stopping to rotate. +// WHAT: A VTOL_LAND item with yaw = NaN skips ALIGN_TO_LAND entirely. +TEST_F(RTLTest, DirectMissionLandSkipsAlignWhenYawNotCommanded) +{ + using WorkItemType = RtlDirectMissionLandTestPeer::WorkItemType; + + mission_s mission{}; + mission.timestamp = hrt_absolute_time(); + mission.current_seq = 0; + mission.count = 1; + mission.land_start_index = 0; + mission.land_index = 0; + mission.mission_dataman_id = DM_KEY_WAYPOINTS_OFFBOARD_1; + + mission_item_s land = makeSafePointItem(kBaseLat, kBaseLon, kAlt, NAV_FRAME_GLOBAL, NAV_CMD_VTOL_LAND); + land.autocontinue = true; + land.yaw = NAN; + + // GIVEN: A VTOL approaching its land point as a fixed wing, with no commanded landing yaw. + publishMission(mission); + publishVehicleStatus(true, vehicle_status_s::VEHICLE_TYPE_FIXED_WING); + publishGlobalPosition(kBaseLat, kBaseLon, kAlt); + publishLandDetected(false); + _navigator.get_mission_result()->valid = true; + + _navigator.get_global_position()->lat = kBaseLat; + _navigator.get_global_position()->lon = kBaseLon; + _navigator.get_global_position()->alt = kAlt; + _navigator.get_global_position()->timestamp = hrt_absolute_time(); + _navigator.get_land_detected()->landed = false; + _navigator.get_vstatus()->vehicle_type = vehicle_status_s::VEHICLE_TYPE_FIXED_WING; + _navigator.get_vstatus()->is_vtol = true; + _navigator.get_vstatus()->in_transition_mode = false; + + RtlDirectMissionLandTestPeer direct_mission_land{&_navigator, mission}; + direct_mission_land.loadTestMission({land}); + direct_mission_land.setRtlAlt(kAlt); + + // WHEN: The mission activates and the vehicle reaches the land point to request the + // back-transition, exactly as in the commanded-yaw case. + direct_mission_land.activateForTest(); + ASSERT_EQ(direct_mission_land.activeWorkItemType(), WorkItemType::WORK_ITEM_TYPE_MOVE_TO_LAND); + + direct_mission_land.on_active(); + ASSERT_EQ(direct_mission_land.activeWorkItemType(), WorkItemType::WORK_ITEM_TYPE_MOVE_TO_LAND_AFTER_TRANSITION); + EXPECT_EQ(direct_mission_land.activeNavCommand(), NAV_CMD_DO_VTOL_TRANSITION); + + // WHEN: The back-transition completes. + publishVehicleStatus(true, vehicle_status_s::VEHICLE_TYPE_ROTARY_WING); + _navigator.get_vstatus()->vehicle_type = vehicle_status_s::VEHICLE_TYPE_ROTARY_WING; + _navigator.get_vstatus()->is_vtol = true; + _navigator.get_vstatus()->in_transition_mode = false; + direct_mission_land.on_active(); + + // THEN: With no yaw to align to, it lands directly -- no ALIGN_TO_LAND stop in between. + EXPECT_EQ(direct_mission_land.activeWorkItemType(), WorkItemType::WORK_ITEM_TYPE_DEFAULT); + EXPECT_EQ(direct_mission_land.activeNavCommand(), NAV_CMD_VTOL_LAND); + EXPECT_TRUE(std::isnan(direct_mission_land.activeYaw())); +} + +// WHY: for a pure multicopter, if a mission item defines the yaw setpoint, the multicopter should +// rotate to the commanded yaw, before descending +// WHAT: A LAND item with a finite yaw is driven through MOVE_TO_LAND and ALIGN_TO_LAND to LAND +// for a pure multicopter, with no back-transition step in between. +TEST_F(RTLTest, DirectMissionLandMcOnlyAlignsToCommandedYawBeforeDescending) +{ + using WorkItemType = RtlDirectMissionLandTestPeer::WorkItemType; + constexpr float kLandYaw = -0.7f; + + mission_s mission{}; + mission.timestamp = hrt_absolute_time(); + mission.current_seq = 0; + mission.count = 1; + mission.land_start_index = 0; + mission.land_index = 0; + mission.mission_dataman_id = DM_KEY_WAYPOINTS_OFFBOARD_1; + + mission_item_s land = makeSafePointItem(kBaseLat, kBaseLon, kAlt, NAV_FRAME_GLOBAL, NAV_CMD_LAND); + land.autocontinue = true; + land.yaw = kLandYaw; + + // GIVEN: A pure multicopter (never VTOL) starting 100 m from the land point. + const PositionYawSetpoint far_position = makePositionYawSetpointFromOffset(kBaseLat, kBaseLon, 100.f, 0.f, kAlt); + + publishMission(mission); + publishVehicleStatus(false, vehicle_status_s::VEHICLE_TYPE_ROTARY_WING); + publishGlobalPosition(far_position.lat, far_position.lon, kAlt); + publishLandDetected(false); + _navigator.get_mission_result()->valid = true; + + _navigator.get_global_position()->lat = far_position.lat; + _navigator.get_global_position()->lon = far_position.lon; + _navigator.get_global_position()->alt = kAlt; + _navigator.get_global_position()->timestamp = hrt_absolute_time(); + _navigator.get_land_detected()->landed = false; + _navigator.get_vstatus()->vehicle_type = vehicle_status_s::VEHICLE_TYPE_ROTARY_WING; + _navigator.get_vstatus()->is_vtol = false; + + RtlDirectMissionLandTestPeer direct_mission_land{&_navigator, mission}; + direct_mission_land.loadTestMission({land}); + direct_mission_land.setRtlAlt(kAlt); + + // WHEN: The mission activates while the vehicle is still far from the land point. + direct_mission_land.activateForTest(); + + // THEN: It moves to the land waypoint first (too far away), with yaw ignored. + ASSERT_EQ(direct_mission_land.activeWorkItemType(), WorkItemType::WORK_ITEM_TYPE_MOVE_TO_LAND); + EXPECT_EQ(direct_mission_land.activeNavCommand(), NAV_CMD_WAYPOINT); + EXPECT_TRUE(std::isnan(direct_mission_land.activeYaw())); + + // WHEN: The vehicle arrives at the land point. + publishGlobalPosition(kBaseLat, kBaseLon, kAlt); + _navigator.get_global_position()->lat = kBaseLat; + _navigator.get_global_position()->lon = kBaseLon; + direct_mission_land.on_active(); + + // THEN: With no VTOL back-transition to wait for, it goes straight from MOVE_TO_LAND to + // aligning on the commanded landing yaw while holding the current altitude. + ASSERT_EQ(direct_mission_land.activeWorkItemType(), WorkItemType::WORK_ITEM_TYPE_ALIGN_TO_LAND); + EXPECT_EQ(direct_mission_land.activeNavCommand(), NAV_CMD_WAYPOINT); + EXPECT_FLOAT_EQ(direct_mission_land.activeYaw(), kLandYaw); + + // WHEN: The vehicle finishes rotating to the commanded landing yaw. + _navigator.get_local_position()->heading = kLandYaw; + _navigator.get_local_position()->heading_good_for_control = true; + direct_mission_land.on_active(); + + // THEN: It falls through to the real landing item with the commanded yaw intact. + EXPECT_EQ(direct_mission_land.activeWorkItemType(), WorkItemType::WORK_ITEM_TYPE_DEFAULT); + EXPECT_EQ(direct_mission_land.activeNavCommand(), NAV_CMD_LAND); + EXPECT_FLOAT_EQ(direct_mission_land.activeYaw(), kLandYaw); +} + +// WHY: for a pure multicopter: no commanded yaw means no ALIGN_TO_LAND stop. +// WHAT: A LAND item with yaw = NaN skips ALIGN_TO_LAND and lands directly after MOVE_TO_LAND. +TEST_F(RTLTest, DirectMissionLandMcOnlySkipsAlignWhenYawNotCommanded) +{ + using WorkItemType = RtlDirectMissionLandTestPeer::WorkItemType; + + mission_s mission{}; + mission.timestamp = hrt_absolute_time(); + mission.current_seq = 0; + mission.count = 1; + mission.land_start_index = 0; + mission.land_index = 0; + mission.mission_dataman_id = DM_KEY_WAYPOINTS_OFFBOARD_1; + + mission_item_s land = makeSafePointItem(kBaseLat, kBaseLon, kAlt, NAV_FRAME_GLOBAL, NAV_CMD_LAND); + land.autocontinue = true; + land.yaw = NAN; + + // GIVEN: A pure multicopter (never VTOL) starting 100 m from the land point, with no + // commanded landing yaw. + const PositionYawSetpoint far_position = makePositionYawSetpointFromOffset(kBaseLat, kBaseLon, 100.f, 0.f, kAlt); + + publishMission(mission); + publishVehicleStatus(false, vehicle_status_s::VEHICLE_TYPE_ROTARY_WING); + publishGlobalPosition(far_position.lat, far_position.lon, kAlt); + publishLandDetected(false); + _navigator.get_mission_result()->valid = true; + + _navigator.get_global_position()->lat = far_position.lat; + _navigator.get_global_position()->lon = far_position.lon; + _navigator.get_global_position()->alt = kAlt; + _navigator.get_global_position()->timestamp = hrt_absolute_time(); + _navigator.get_land_detected()->landed = false; + _navigator.get_vstatus()->vehicle_type = vehicle_status_s::VEHICLE_TYPE_ROTARY_WING; + _navigator.get_vstatus()->is_vtol = false; + + RtlDirectMissionLandTestPeer direct_mission_land{&_navigator, mission}; + direct_mission_land.loadTestMission({land}); + direct_mission_land.setRtlAlt(kAlt); + + // WHEN: The mission activates while still far from the land point. + direct_mission_land.activateForTest(); + ASSERT_EQ(direct_mission_land.activeWorkItemType(), WorkItemType::WORK_ITEM_TYPE_MOVE_TO_LAND); + + // WHEN: The vehicle arrives at the land point. + publishGlobalPosition(kBaseLat, kBaseLon, kAlt); + _navigator.get_global_position()->lat = kBaseLat; + _navigator.get_global_position()->lon = kBaseLon; + direct_mission_land.on_active(); + + // THEN: With no yaw to align to, it lands directly -- no ALIGN_TO_LAND stop in between. + EXPECT_EQ(direct_mission_land.activeWorkItemType(), WorkItemType::WORK_ITEM_TYPE_DEFAULT); + EXPECT_EQ(direct_mission_land.activeNavCommand(), NAV_CMD_LAND); + EXPECT_TRUE(std::isnan(direct_mission_land.activeYaw())); +} + // WHY: No land point means no usable approach bearing. // WHAT: The chooser should return an invalid loiter. TEST_F(RTLTest, MissionFastKeepsVtolInMulticopterMode)