From f2f06304134ef1fa5885c8d1615aea8c604933e8 Mon Sep 17 00:00:00 2001 From: jnomikos Date: Sun, 24 May 2026 14:39:06 -0400 Subject: [PATCH] Add 'Restart Mission' capbility to 'Set current waypoint' action When vehicle firmware supports restarting mission, set current waypoint action now has a checkbox for "Restart Mission" --- src/FlyView/GuidedActionsController.qml | 6 +++++- src/Vehicle/Vehicle.cc | 5 +++-- src/Vehicle/Vehicle.h | 12 ++++++++---- src/Vehicle/VehicleSupports.cc | 8 ++++++++ src/Vehicle/VehicleSupports.h | 2 ++ 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/FlyView/GuidedActionsController.qml b/src/FlyView/GuidedActionsController.qml index deac9137e8c9..4d578d8791f2 100644 --- a/src/FlyView/GuidedActionsController.qml +++ b/src/FlyView/GuidedActionsController.qml @@ -488,6 +488,10 @@ Item { case actionSetWaypoint: confirmDialog.title = setWaypointTitle confirmDialog.message = setWaypointMessage + if (_activeVehicle.supports.restartMission) { + confirmDialog.optionText = qsTr("Restart Mission") + confirmDialog.optionChecked = false + } break; case actionOrbit: confirmDialog.title = orbitTitle @@ -632,7 +636,7 @@ Item { } break case actionSetWaypoint: - _activeVehicle.setCurrentMissionSequence(actionData) + _activeVehicle.setCurrentMissionSequence(actionData, optionChecked /* restartMission */) break case actionOrbit: var valueInMeters = _unitsConversion.appSettingsVerticalDistanceUnitsToMeters(sliderOutputValue) diff --git a/src/Vehicle/Vehicle.cc b/src/Vehicle/Vehicle.cc index 9786919992ab..f90cd10ee8ef 100644 --- a/src/Vehicle/Vehicle.cc +++ b/src/Vehicle/Vehicle.cc @@ -2106,7 +2106,7 @@ void Vehicle::landingGearRetract() 1.0f); // up } -void Vehicle::setCurrentMissionSequence(int seq) +void Vehicle::setCurrentMissionSequence(int seq, bool restartMission) { if (!_firmwarePlugin->sendHomePositionToVehicle()) { seq--; @@ -2137,7 +2137,8 @@ void Vehicle::setCurrentMissionSequence(int seq) static_cast(defaultComponentId()), MAV_CMD_DO_SET_MISSION_CURRENT, true, // showError - static_cast(seq) + static_cast(seq), + restartMission ? 1.0f : 0.0f ); } diff --git a/src/Vehicle/Vehicle.h b/src/Vehicle/Vehicle.h index b20bb35c377c..f590415dc2fd 100644 --- a/src/Vehicle/Vehicle.h +++ b/src/Vehicle/Vehicle.h @@ -338,18 +338,22 @@ class Vehicle : public VehicleFactGroup, public VehicleTypes /// Command vehicle to abort landing Q_INVOKABLE void abortLanding(double climbOutAltitude); - /// Command vichecle to deploy landing gear + /// Command vehicle to deploy landing gear Q_INVOKABLE void landingGearDeploy(); - /// Command vichecle to retract landing gear + /// Command vehicle to retract landing gear Q_INVOKABLE void landingGearRetract(); Q_INVOKABLE void startTakeoff(); Q_INVOKABLE void startMission(); - /// Alter the current mission item on the vehicle - Q_INVOKABLE void setCurrentMissionSequence(int seq); + /// Set the current mission item on the vehicle. + /// @param seq Mission sequence number to make current. + /// @param restartMission Passed as param2 of MAV_CMD_DO_SET_MISSION_CURRENT when the + /// firmware supports that command (e.g. ArduPilot). Has no effect on firmware + /// that falls back to the deprecated MISSION_SET_CURRENT message (e.g. PX4). + Q_INVOKABLE void setCurrentMissionSequence(int seq, bool restartMission = false); /// Reboot vehicle Q_INVOKABLE void rebootVehicle(); diff --git a/src/Vehicle/VehicleSupports.cc b/src/Vehicle/VehicleSupports.cc index 7529ee262185..34b0b9fa7a47 100644 --- a/src/Vehicle/VehicleSupports.cc +++ b/src/Vehicle/VehicleSupports.cc @@ -86,3 +86,11 @@ bool VehicleSupports::changeHeading() const { return _vehicle->firmwarePlugin()->isCapable(_vehicle, FirmwarePlugin::ChangeHeadingCapability); } + +bool VehicleSupports::restartMission() const +{ + auto* instanceData = _vehicle->firmwarePluginInstanceData(); + if (!instanceData) return false; + return instanceData->anyVersionSupportsCommand(MAV_CMD_DO_SET_MISSION_CURRENT) + == FirmwarePluginInstanceData::CommandSupportedResult::SUPPORTED; +} diff --git a/src/Vehicle/VehicleSupports.h b/src/Vehicle/VehicleSupports.h index dc7c45b4e687..1b04358e7d55 100644 --- a/src/Vehicle/VehicleSupports.h +++ b/src/Vehicle/VehicleSupports.h @@ -30,6 +30,7 @@ class VehicleSupports : public QObject Q_PROPERTY(bool guidedTakeoffWithAltitude READ guidedTakeoffWithAltitude CONSTANT) Q_PROPERTY(bool guidedTakeoffWithoutAltitude READ guidedTakeoffWithoutAltitude CONSTANT) Q_PROPERTY(bool changeHeading READ changeHeading CONSTANT) + Q_PROPERTY(bool restartMission READ restartMission CONSTANT) bool throttleModeCenterZero() const; bool negativeThrust() const; @@ -46,6 +47,7 @@ class VehicleSupports : public QObject bool guidedTakeoffWithAltitude() const; bool guidedTakeoffWithoutAltitude() const; bool changeHeading() const; + bool restartMission() const; signals: void terrainFrameChanged();