diff --git a/docs/en/flight_modes_mc/hold.md b/docs/en/flight_modes_mc/hold.md
index e65de49b332..3894de6d080 100644
--- a/docs/en/flight_modes_mc/hold.md
+++ b/docs/en/flight_modes_mc/hold.md
@@ -31,6 +31,12 @@ The vehicle will first ascend to [NAV_MIN_LTR_ALT](#NAV_MIN_LTR_ALT) if the mode
Stick movement will change the vehicle to [Position mode](../flight_modes_mc/position.md) (by [default](#MAN_OVERRIDE_SPD)).
+If a region of interest (ROI) location is set, for example with [MAV_CMD_DO_SET_ROI_LOCATION](https://mavlink.io/en/messages/common.html#MAV_CMD_DO_SET_ROI_LOCATION), the vehicle yaws so that its nose points towards it.
+The heading keeps tracking the ROI while the vehicle holds or repositions, and stops updating when the vehicle is within the acceptance radius of the ROI.
+Clearing the ROI with [MAV_CMD_DO_SET_ROI_NONE](https://mavlink.io/en/messages/common.html#MAV_CMD_DO_SET_ROI_NONE) leaves the vehicle at its last heading.
+A [MAV_CMD_DO_REPOSITION](https://mavlink.io/en/messages/common.html#MAV_CMD_DO_REPOSITION) with an explicit yaw sent after the ROI overrides ROI tracking until the next ROI command.
+Set [MIS_MNT_YAW_CTL](#MIS_MNT_YAW_CTL) to yaw a gimbal towards the ROI instead of the vehicle.
+
### Mode Requirements
@@ -55,6 +61,7 @@ Hold mode behaviour can be configured using the parameters below.
| [NAV_MIN_LTR_ALT](../advanced_config/parameter_reference.md#NAV_MIN_LTR_ALT) | This is the minimum altitude above Home the system will always obey in Hold mode if switched into this mode without specifying an altitude (e.g. through switch on RC). |
| [MAN_OVERRIDE_SPD](../advanced_config/parameter_reference.md#MAN_OVERRIDE_SPD) | Speed (normalized stick travel per second) above which moving the sticks controlling a multicopter (or VTOL in hover) gives control back to the pilot by switching to [Position mode](../flight_modes_mc/position.md) (or Altitude mode if position is unavailable). At the default value of 1 a half-stick movement in ~0.5 s triggers it; lower is more sensitive. A stick held statically has zero speed and will not trigger. Set to -1 to disable. |
| [MPC_AUTO_NUDGING](../advanced_config/parameter_reference.md#MPC_AUTO_NUDGING) | Bitmask enabling stick nudging in Auto modes (multicopter). Bit 0 (yaw nudging) lets the yaw stick nudge heading in Hold, held when the stick is released; switching flight mode clears the held heading. Requires stick override to be disabled ([MAN_OVERRIDE_SPD](#MAN_OVERRIDE_SPD) = -1). |
+| [MIS_MNT_YAW_CTL](../advanced_config/parameter_reference.md#MIS_MNT_YAW_CTL) | If disabled (default), the vehicle yaws towards an active ROI location. If enabled, the gimbal yaws towards the ROI and the vehicle keeps its heading. |
diff --git a/src/modules/navigator/loiter.cpp b/src/modules/navigator/loiter.cpp
index 3e66b604bc2..38070d08b50 100644
--- a/src/modules/navigator/loiter.cpp
+++ b/src/modules/navigator/loiter.cpp
@@ -57,6 +57,7 @@ Loiter::on_activation()
// an already-established loiter (used by set_loiter_position()).
const position_setpoint_s previous_setpoint = _navigator->get_position_setpoint_triplet()->current;
_navigator->reset_triplets();
+ _reposition_yaw_timestamp = 0;
if (_navigator->get_reposition_triplet()->current.valid
&& hrt_elapsed_time(&_navigator->get_reposition_triplet()->current.timestamp) < 500_ms) {
@@ -89,6 +90,8 @@ Loiter::on_active()
} else {
_loiter_at_last_link_position_executed = false;
}
+
+ updateHeadingToRoi();
}
void
@@ -97,6 +100,42 @@ Loiter::on_inactive()
_loiter_at_last_link_position_executed = false;
}
+void
+Loiter::updateHeadingToRoi()
+{
+ // With mount yaw control enabled the gimbal yaws towards the ROI instead of the vehicle
+ if (_param_mis_mnt_yaw_ctl.get()
+ || _navigator->get_vstatus()->vehicle_type != vehicle_status_s::VEHICLE_TYPE_ROTARY_WING
+ || _navigator->get_land_detected()->landed
+ || _navigator->get_vroi().mode != vehicle_roi_s::ROI_LOCATION) {
+ return;
+ }
+
+ position_setpoint_triplet_s *pos_sp_triplet = _navigator->get_position_setpoint_triplet();
+
+ if (!pos_sp_triplet->current.valid || pos_sp_triplet->current.type == position_setpoint_s::SETPOINT_TYPE_IDLE) {
+ return;
+ }
+
+ // A reposition with an explicit yaw sent after the ROI takes precedence
+ if (_reposition_yaw_timestamp > _navigator->get_vroi().timestamp) {
+ return;
+ }
+
+ const double lat = _navigator->get_global_position()->lat;
+ const double lon = _navigator->get_global_position()->lon;
+ const double roi_lat = _navigator->get_vroi().lat;
+ const double roi_lon = _navigator->get_vroi().lon;
+
+ // Keep the last heading when close to the ROI to prevent excessive yawing
+ if (get_distance_to_next_waypoint(lat, lon, roi_lat, roi_lon) <= _navigator->get_acceptance_radius()) {
+ return;
+ }
+
+ pos_sp_triplet->current.yaw = get_bearing_to_next_waypoint(lat, lon, roi_lat, roi_lon);
+ _navigator->set_position_setpoint_triplet_updated();
+}
+
void
Loiter::set_loiter_position(const position_setpoint_s &reference_setpoint)
{
@@ -162,6 +201,7 @@ Loiter::reposition()
if (rep->current.valid) {
// set loiter position based on reposition command
+ _reposition_yaw_timestamp = PX4_ISFINITE(rep->current.yaw) ? rep->current.timestamp : 0;
// convert mission item to current setpoint
struct position_setpoint_triplet_s *pos_sp_triplet = _navigator->get_position_setpoint_triplet();
diff --git a/src/modules/navigator/loiter.h b/src/modules/navigator/loiter.h
index 36df5390ef1..255e8902863 100644
--- a/src/modules/navigator/loiter.h
+++ b/src/modules/navigator/loiter.h
@@ -67,9 +67,17 @@ private:
*/
void set_loiter_position(const position_setpoint_s &reference_setpoint);
+ /**
+ * Point the vehicle heading towards the ROI location (multicopter only).
+ */
+ void updateHeadingToRoi();
+
bool _loiter_at_last_link_position_executed{false};
+ hrt_abstime _reposition_yaw_timestamp{0}; ///< time of the last reposition with an explicit yaw, 0 if none
+
DEFINE_PARAMETERS(
- (ParamInt) _param_nav_ltr_last_dl
+ (ParamInt) _param_nav_ltr_last_dl,
+ (ParamInt) _param_mis_mnt_yaw_ctl
)
};
diff --git a/src/modules/navigator/mission_params.yaml b/src/modules/navigator/mission_params.yaml
index 68d5cfd4339..b0790c685fb 100644
--- a/src/modules/navigator/mission_params.yaml
+++ b/src/modules/navigator/mission_params.yaml
@@ -46,12 +46,12 @@ parameters:
increment: 100
MIS_MNT_YAW_CTL:
description:
- short: Enable gimbal yaw control in missions
+ short: Enable gimbal yaw control in missions and Hold
long: |-
- Enable yaw control of the mount. (Only affects multicopters and ROI mission items)
+ Enable yaw control of the mount. (Only affects multicopters with an active ROI)
If enabled, yaw commands will be sent to the mount and the vehicle will follow its heading towards the flight direction.
- If disabled, the vehicle will yaw towards the ROI.
+ If disabled, the vehicle will yaw towards the ROI in Mission and Hold mode.
type: enum
values:
0: Disable