Skip to content

Commit

Permalink
Custom Actions are now Mavlink Actions
Browse files Browse the repository at this point in the history
This reduces confusion with custom build functionality
  • Loading branch information
DonLakeFlyer committed Jan 19, 2025
1 parent fcaa13e commit 71bfe1e
Show file tree
Hide file tree
Showing 25 changed files with 108 additions and 129 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Note: This file only contains high level features or important fixes.
* Added functionality for setting individual MAVLink message rates in the MAVLink Inspector.
* Enabled support for MAVLink 2 signing.
* Dynamic battery display that reduces the number of bars based on battery percentage, with configurable states (100%, Config 1, Config 2, Low, Critical) for clearer status indication.
* Custom Actions changed to Mavlink Actions. The location of the actions json files has changes to the "Mavlink Actions" directory. If you were using the previous "Custom Actions" directory, move you json files to the new location.


## 4.1
Expand Down
2 changes: 1 addition & 1 deletion custom-example/qgroundcontrol.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@
<file alias="CameraSection.FactMetaData.json">../src/MissionManager/CameraSection.FactMetaData.json</file>
<file alias="CameraSpec.FactMetaData.json">../src/MissionManager/CameraSpec.FactMetaData.json</file>
<file alias="CorridorScan.SettingsGroup.json">../src/MissionManager/CorridorScan.SettingsGroup.json</file>
<file alias="CustomMavlinkActions.SettingsGroup.json">../src/Settings/CustomMavlinkActions.SettingsGroup.json</file>
<file alias="MavlinkActions.SettingsGroup.json">../src/Settings/MavlinkActions.SettingsGroup.json</file>
<file alias="RemoteID.SettingsGroup.json">../src/Settings/RemoteID.SettingsGroup.json</file>
<file alias="EditPositionDialog.FactMetaData.json">../src/QmlControls/EditPositionDialog.FactMetaData.json</file>
<file alias="FirmwareUpgrade.SettingsGroup.json">../src/Settings/FirmwareUpgrade.SettingsGroup.json</file>
Expand Down
2 changes: 1 addition & 1 deletion docs/en/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- [Fly](qgc-user-guide/fly_view/fly_view.md)
- [Replay Flight Data](qgc-user-guide/fly_view/replay_flight_data.md)
- [Video Overlay](qgc-user-guide/fly_view/video_overlay.md)
- [Custom Mavlink Actions](qgc-user-guide/custom_actions/custom_actions.md)
- [Mavlink Actions](qgc-user-guide/custom_actions/custom_actions.md)
- [3D View](qgc-user-guide/viewer_3d/viewer_3d.md)
- [Plan](qgc-user-guide/plan_view/plan_view.md)
- [GeoFence](qgc-user-guide/plan_view/plan_geofence.md)
Expand Down
10 changes: 4 additions & 6 deletions docs/en/qgc-user-guide/custom_actions/custom_actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

Both the Fly View and Joysticks support the ability execute arbitrary mavlink commands to the active vehicle. In the Fly View these will show up in the Toolstrip Action list. With Joysticks you can assign then to button presses.

## Custom Actions File
## Mavlink Actions File

The custom actions available are defined in a JSON file. The format of that file is as follows:
The actions available are defined in a JSON file. The format of that file is as follows:

```
{
"version": 1,
"fileType": "CustomActions",
"fileType": "MavlinkActions",
"actions":
[
{
Expand Down Expand Up @@ -39,8 +39,6 @@ Fields:
* compId (options) - The component id for where you want to send the command to. If not specified `MAV_COMP_ID_AUTOPILOT1` is used.
* param1 thru param7 (optional) - The parameters for the command. Parameters which are not specified will default to 0.0

Custom action files should be located in the CustomActions directory of the QGC save location. For example on Linux that would be `~/Documents/QGroundControl/CustomActions` or `~/Documents/QGroundControl Daily/CustomActions`. The Fly View and Joysticks each have there own custom actions files:
* Fly View - FlyViewCustomActions.json
* Joystick - JoystickCustomActions.json
Mavlink action files should be located in the MavlinkActions directory of the QGC save location. For example on Linux that would be `~/Documents/QGroundControl/MavlinkActions` or `~/Documents/QGroundControl Daily/MavlinkActions`. The Fly View and Joysticks can each have there own custom actions file.

When you start up QGC it will load these files if they exist and make the commands available for use.
2 changes: 1 addition & 1 deletion qgroundcontrol.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@
<file alias="CameraSection.FactMetaData.json">src/MissionManager/CameraSection.FactMetaData.json</file>
<file alias="CameraSpec.FactMetaData.json">src/MissionManager/CameraSpec.FactMetaData.json</file>
<file alias="CorridorScan.SettingsGroup.json">src/MissionManager/CorridorScan.SettingsGroup.json</file>
<file alias="CustomMavlinkActions.SettingsGroup.json">src/Settings/CustomMavlinkActions.SettingsGroup.json</file>
<file alias="MavlinkActions.SettingsGroup.json">src/Settings/MavlinkActions.SettingsGroup.json</file>
<file alias="RemoteID.SettingsGroup.json">src/Settings/RemoteID.SettingsGroup.json</file>
<file alias="EditPositionDialog.FactMetaData.json">src/QmlControls/EditPositionDialog.FactMetaData.json</file>
<file alias="FirmwareUpgrade.SettingsGroup.json">src/Settings/FirmwareUpgrade.SettingsGroup.json</file>
Expand Down
6 changes: 3 additions & 3 deletions src/FlightDisplay/GuidedActionList.qml
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ Rectangle {
}
]

property var _customManager: CustomActionManager {
MavlinkActionManager {
id: customManager
actionFileNameFact: QGroundControl.settingsManager.customMavlinkActionsSettings.flyViewActionsFile
actionFileNameFact: QGroundControl.settingsManager.mavlinkActionsSettings.flyViewActionsFile
}
readonly property bool hasCustomActions: customManager.actions.count > 0
readonly property bool hasMavlinkActions: customManager.actions.count > 0

QGCPalette { id: qgcPal }

Expand Down
2 changes: 1 addition & 1 deletion src/FlightDisplay/GuidedActionsController.qml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ Item {
property bool showLandAbort: _guidedActionsEnabled && _vehicleFlying && _fixedWingOnApproach
property bool showGotoLocation: _guidedActionsEnabled && _vehicleFlying
property bool showSetHome: _guidedActionsEnabled
property bool showActionList: _guidedActionsEnabled && (showStartMission || showResumeMission || showChangeAlt || showLandAbort || actionList.hasCustomActions)
property bool showActionList: _guidedActionsEnabled && (showStartMission || showResumeMission || showChangeAlt || showLandAbort || actionList.hasMavlinkActions)
property bool showGripper: _initialConnectComplete ? _activeVehicle.hasGripper : false
property bool showSetEstimatorOrigin: _activeVehicle && !(_activeVehicle.sensorsPresentBits & Vehicle.SysStatusSensorGPS)
property bool showChangeHeading: _guidedActionsEnabled && _vehicleFlying
Expand Down
22 changes: 11 additions & 11 deletions src/Joystick/Joystick.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@


#include "Joystick.h"
#include "CustomAction.h"
#include "CustomActionManager.h"
#include "CustomMavlinkActionsSettings.h"
#include "MavlinkAction.h"
#include "MavlinkActionManager.h"
#include "MavlinkActionsSettings.h"
#include "FirmwarePlugin.h"
#include "GimbalController.h"
#include "MultiVehicleManager.h"
Expand Down Expand Up @@ -58,7 +58,7 @@ Joystick::Joystick(const QString &name, int axisCount, int buttonCount, int hatC
, _rgAxisValues(new int[static_cast<size_t>(_axisCount)])
, _rgCalibration(new Calibration_t[static_cast<size_t>(_axisCount)])
, _rgButtonValues(new uint8_t[static_cast<size_t>(_totalButtonCount)])
, _customActionManager(new CustomActionManager(SettingsManager::instance()->customMavlinkActionsSettings()->joystickActionsFile(), this))
, _mavlinkActionManager(new MavlinkActionManager(SettingsManager::instance()->mavlinkActionsSettings()->joystickActionsFile(), this))
, _assignableButtonActions(new QmlObjectListModel(this))
{
// qCDebug(JoystickLog) << Q_FUNC_INFO << this;
Expand Down Expand Up @@ -1101,10 +1101,10 @@ void Joystick::_executeButtonAction(const QString &action, bool buttonDown)
} else {
if (buttonDown && _activeVehicle) {
emit unknownAction(action);
for (int i = 0; i<_customActionManager->actions()->count(); i++) {
CustomAction *const customAction = _customActionManager->actions()->value<CustomAction*>(i);
if (action == customAction->label()) {
customAction->sendTo(_activeVehicle);
for (int i = 0; i<_mavlinkActionManager->actions()->count(); i++) {
MavlinkAction *const mavlinkAction = _mavlinkActionManager->actions()->value<MavlinkAction*>(i);
if (action == mavlinkAction->label()) {
mavlinkAction->sendTo(_activeVehicle);
return;
}
}
Expand Down Expand Up @@ -1194,9 +1194,9 @@ void Joystick::_buildActionList(Vehicle *activeVehicle)
_assignableButtonActions->append(new AssignableButtonAction(action.name, action.canRepeat));
}

for (int i = 0; i < _customActionManager->actions()->count(); i++) {
const CustomAction *const customAction = _customActionManager->actions()->value<const CustomAction*>(i);
_assignableButtonActions->append(new AssignableButtonAction(customAction->label()));
for (int i = 0; i < _mavlinkActionManager->actions()->count(); i++) {
const MavlinkAction *const mavlinkAction = _mavlinkActionManager->actions()->value<const MavlinkAction*>(i);
_assignableButtonActions->append(new AssignableButtonAction(mavlinkAction->label()));
}

for (int i = 0; i < _assignableButtonActions->count(); i++) {
Expand Down
4 changes: 2 additions & 2 deletions src/Joystick/Joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Q_DECLARE_LOGGING_CATEGORY(JoystickLog)
Q_DECLARE_LOGGING_CATEGORY(JoystickValuesLog)

class CustomActionManager;
class MavlinkActionManager;
class QmlObjectListModel;
class Vehicle;

Expand Down Expand Up @@ -274,7 +274,7 @@ private slots:
int *_rgAxisValues = nullptr;
Calibration_t *_rgCalibration = nullptr;
uint8_t *_rgButtonValues = nullptr;
CustomActionManager *_customActionManager = nullptr;
MavlinkActionManager *_mavlinkActionManager = nullptr;
QmlObjectListModel *_assignableButtonActions = nullptr;

bool _accumulator = false;
Expand Down
8 changes: 4 additions & 4 deletions src/QmlControls/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ find_package(Qt6 REQUIRED COMPONENTS Concurrent Core Gui Location Positioning Qm
qt_add_library(QmlControls STATIC
AppMessages.cc
AppMessages.h
CustomAction.cc
CustomAction.h
CustomActionManager.cc
CustomActionManager.h
MavlinkAction.cc
MavlinkAction.h
MavlinkActionManager.cc
MavlinkActionManager.h
EditPositionDialogController.cc
EditPositionDialogController.h
FactValueGrid.cc
Expand Down
22 changes: 0 additions & 22 deletions src/QmlControls/CustomActions.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
*
****************************************************************************/

#include "CustomAction.h"
#include "MavlinkAction.h"
#include "Vehicle.h"
#include "QGCLoggingCategory.h"

QGC_LOGGING_CATEGORY(CustomActionLog, "qgc.qmlcontrols.customaction")
QGC_LOGGING_CATEGORY(MavlinkActionLog, "qgc.qmlcontrols.mavlinkaction")

CustomAction::CustomAction(QObject *parent)
MavlinkAction::MavlinkAction(QObject *parent)
: QObject(parent)
{
// qCDebug(CustomActionLog) << Q_FUNC_INFO << this;
// qCDebug(MavlinkActionLog) << Q_FUNC_INFO << this;
}

CustomAction::CustomAction(
MavlinkAction::MavlinkAction(
const QString &label,
const QString &description,
MAV_CMD mavCmd,
Expand All @@ -39,15 +39,15 @@ CustomAction::CustomAction(
, _compId(compId)
, _params{ param1, param2, param3, param4, param5, param6, param7 }
{
// qCDebug(CustomActionLog) << Q_FUNC_INFO << this;
// qCDebug(MavlinkActionLog) << Q_FUNC_INFO << this;
};

CustomAction::~CustomAction()
MavlinkAction::~MavlinkAction()
{
// qCDebug(CustomActionLog) << Q_FUNC_INFO << this;
// qCDebug(MavlinkActionLog) << Q_FUNC_INFO << this;
}

void CustomAction::sendTo(Vehicle *vehicle)
void MavlinkAction::sendTo(Vehicle *vehicle)
{
if (vehicle) {
const bool showError = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
#include <QtCore/QObject>
#include <QtQmlIntegration/QtQmlIntegration>

Q_DECLARE_LOGGING_CATEGORY(CustomActionLog)
Q_DECLARE_LOGGING_CATEGORY(MavlinkActionLog)

class Vehicle;

class CustomAction: public QObject
class MavlinkAction: public QObject
{
Q_OBJECT
QML_ELEMENT
Expand All @@ -28,8 +28,8 @@ class CustomAction: public QObject
Q_PROPERTY(QString description READ description CONSTANT)

public:
explicit CustomAction(QObject *parent = nullptr);
CustomAction(
explicit MavlinkAction(QObject *parent = nullptr);
MavlinkAction(
const QString &label,
const QString &description,
MAV_CMD mavCmd,
Expand All @@ -43,7 +43,7 @@ class CustomAction: public QObject
float param7,
QObject *parent = nullptr
);
~CustomAction();
~MavlinkAction();

Q_INVOKABLE void sendTo(Vehicle *vehicle);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*
****************************************************************************/

#include "CustomActionManager.h"
#include "CustomAction.h"
#include "MavlinkActionManager.h"
#include "MavlinkAction.h"
#include "Fact.h"
#include "JsonHelper.h"
#include "QGCApplication.h"
Expand All @@ -21,37 +21,37 @@
#include <QtCore/QJsonArray>
#include <QtQml/QQmlEngine>

QGC_LOGGING_CATEGORY(CustomActionManagerLog, "qgc.qmlcontrols.customactionmanager")
QGC_LOGGING_CATEGORY(MavlinkActionManagerLog, "qgc.qmlcontrols.mavlinkactionmanager")

CustomActionManager::CustomActionManager(QObject *parent)
MavlinkActionManager::MavlinkActionManager(QObject *parent)
: QObject(parent)
, _actions(new QmlObjectListModel(this))
{
// qCDebug(CustomActionManagerLog) << Q_FUNC_INFO << this;
// qCDebug(MavlinkActionManagerLog) << Q_FUNC_INFO << this;
}

CustomActionManager::CustomActionManager(Fact *actionFileNameFact, QObject *parent)
MavlinkActionManager::MavlinkActionManager(Fact *actionFileNameFact, QObject *parent)
: QObject(parent)
, _actions(new QmlObjectListModel(this))
{
setActionFileNameFact(actionFileNameFact);
}

CustomActionManager::~CustomActionManager()
MavlinkActionManager::~MavlinkActionManager()
{
// qCDebug(CustomActionManagerLog) << Q_FUNC_INFO << this;
// qCDebug(MavlinkActionManagerLog) << Q_FUNC_INFO << this;
}

void CustomActionManager::setActionFileNameFact(Fact *actionFileNameFact)
void MavlinkActionManager::setActionFileNameFact(Fact *actionFileNameFact)
{
_actionFileNameFact = actionFileNameFact;
emit actionFileNameFactChanged();
(void) connect(_actionFileNameFact, &Fact::rawValueChanged, this, &CustomActionManager::_loadActionsFile);
(void) connect(_actionFileNameFact, &Fact::rawValueChanged, this, &MavlinkActionManager::_loadActionsFile);

_loadActionsFile();
}

void CustomActionManager::_loadActionsFile()
void MavlinkActionManager::_loadActionsFile()
{
_actions->clearAndDeleteContents();
const QString actionFileName = _actionFileNameFact->rawValue().toString();
Expand All @@ -60,7 +60,7 @@ void CustomActionManager::_loadActionsFile()
}

// Custom actions are always loaded from the custom actions save path
const QString savePath = SettingsManager::instance()->appSettings()->customActionsSavePath();
const QString savePath = SettingsManager::instance()->appSettings()->mavlinkActionsSavePath();
const QDir saveDir = QDir(savePath);
const QString fullPath = saveDir.absoluteFilePath(actionFileName);

Expand All @@ -70,7 +70,7 @@ void CustomActionManager::_loadActionsFile()
return;
}

constexpr const char *kQgcFileType = "CustomActions";
constexpr const char *kQgcFileType = "MavlinkActions";
constexpr const char *kActionListKey = "actions";

_actions->clearAndDeleteContents();
Expand Down Expand Up @@ -133,7 +133,7 @@ void CustomActionManager::_loadActionsFile()
const auto param6 = actionObj["param6"].toDouble(0.0);
const auto param7 = actionObj["param7"].toDouble(0.0);

CustomAction *const action = new CustomAction(label, description, mavCmd, compId, param1, param2, param3, param4, param5, param6, param7, this);
MavlinkAction *const action = new MavlinkAction(label, description, mavCmd, compId, param1, param2, param3, param4, param5, param6, param7, this);
QQmlEngine::setObjectOwnership(action, QQmlEngine::CppOwnership);
(void) _actions->append(action);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
#include <QtCore/QObject>
#include <QtQmlIntegration/QtQmlIntegration>

Q_DECLARE_LOGGING_CATEGORY(CustomActionManagerLog)
Q_DECLARE_LOGGING_CATEGORY(MavlinkActionManagerLog)

class Fact;
class QmlObjectListModel;

/// Loads the specified action file and provides access to the actions it contains.
/// Action files are loaded from the default CustomActions directory.
/// Action files are loaded from the default MavlinkActions directory.
/// The actions file name is filename only, no path.
class CustomActionManager : public QObject
class MavlinkActionManager : public QObject
{
Q_OBJECT
QML_ELEMENT
Expand All @@ -31,9 +31,9 @@ class CustomActionManager : public QObject
Q_PROPERTY(QmlObjectListModel* actions READ actions CONSTANT)

public:
explicit CustomActionManager(QObject *parent = nullptr);
explicit CustomActionManager(Fact *actionFileNameFact, QObject *parent = nullptr);
~CustomActionManager();
explicit MavlinkActionManager(QObject *parent = nullptr);
explicit MavlinkActionManager(Fact *actionFileNameFact, QObject *parent = nullptr);
~MavlinkActionManager();

Fact *actionFileNameFact() { return _actionFileNameFact; }
void setActionFileNameFact(Fact *actionFileNameFact);
Expand Down
Loading

0 comments on commit 71bfe1e

Please sign in to comment.