Skip to content

Commit

Permalink
Merge fly view and joystick custom actions in a single backend
Browse files Browse the repository at this point in the history
The custom actions files are now hardwired to be loaded from the CustomActions save path location. The files uses can be set from Fly View Settings.
  • Loading branch information
DonLakeFlyer committed Mar 7, 2024
1 parent 9075aec commit d799372
Show file tree
Hide file tree
Showing 25 changed files with 332 additions and 280 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Note: This file only contains high level features or important fixes.

* New combined compass and attitude instrument
* You can select between multiple instruments by clicking on the instrument conntrol on a desktop build or press and hold on mobile builds
* Support for Fly View and Joystick custom mavlink actions has changed. Both the name and formation of the command file is different now. Go to QGC docs to understand how it works now.

## 4.1

Expand Down
1 change: 1 addition & 0 deletions docs/en/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +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_action.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
46 changes: 46 additions & 0 deletions docs/en/qgc-user-guide/custom_actions/custom_actions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Custom Mavlink Action

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

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

'''
{
"version": 1,
"fileType": "CustomActions",
"actions":
[
{
"label": "First Command",
"description": "This is the first command",
"mavCmd": 10,
"compId": 100,
"param1": 1,
"param2": 2,
...
},
{
"label": "Second Command",
"description": "This is the second command",
"mavCmd": 20,
...
}
]
}
'''

Fields:
* actions (required) - An array of json objects, one for each command
* label (required) - The user visible short description for the command. This is used as the button text for the Fly View - Actions command list. For Joysticks, this is the command you select from the dropdown. For Joysticks, make sure your name doesn't conflict with the built in names.
* description (required) - This is a longer description of the command used in the Fly View - Action list. This is not used by joysticks.
* mavCmd (required) - The command id of the mavlink command you want to send.
* 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

When you start up QGC it will load these files if they exist and make the commands available for use.
4 changes: 2 additions & 2 deletions qgroundcontrol.pro
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ HEADERS += \
src/FollowMe/FollowMe.h \
src/Joystick/Joystick.h \
src/Joystick/JoystickManager.h \
src/Joystick/JoystickMavCommand.h \
src/Utilities/JsonHelper.h \
src/MissionManager/KMLDomDocument.h \
src/MissionManager/KMLHelper.h \
Expand Down Expand Up @@ -531,6 +530,7 @@ HEADERS += \
src/Settings/AutoConnectSettings.h \
src/Settings/BatteryIndicatorSettings.h \
src/Settings/BrandImageSettings.h \
src/Settings/CustomMavlinkActionsSettings.h \
src/Settings/RemoteIDSettings.h \
src/Settings/FirmwareUpgradeSettings.h \
src/Settings/FlightMapSettings.h \
Expand Down Expand Up @@ -702,7 +702,6 @@ SOURCES += \
src/FollowMe/FollowMe.cc \
src/Joystick/Joystick.cc \
src/Joystick/JoystickManager.cc \
src/Joystick/JoystickMavCommand.cc \
src/Utilities/JsonHelper.cc \
src/MissionManager/KMLDomDocument.cc \
src/MissionManager/KMLHelper.cc \
Expand Down Expand Up @@ -790,6 +789,7 @@ SOURCES += \
src/Settings/AutoConnectSettings.cc \
src/Settings/BatteryIndicatorSettings.cc \
src/Settings/BrandImageSettings.cc \
src/Settings/CustomMavlinkActionsSettings.cc \
src/Settings/RemoteIDSettings.cc \
src/Settings/FirmwareUpgradeSettings.cc \
src/Settings/FlightMapSettings.cc \
Expand Down
1 change: 1 addition & 0 deletions qgroundcontrol.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,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="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
9 changes: 5 additions & 4 deletions src/FlightDisplay/GuidedActionList.qml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Rectangle {
property real _margins: Math.round(ScreenTools.defaultFontPixelHeight * 0.66)
property real _actionWidth: ScreenTools.defaultFontPixelWidth * 25
property real _actionHorizSpacing: ScreenTools.defaultFontPixelHeight * 2
property var _flyViewSettings: QGroundControl.settingsManager.flyViewSettings

property var _model: [
{
Expand Down Expand Up @@ -79,9 +80,10 @@ Rectangle {
]

property var _customManager: CustomActionManager {
id: customManager
id: customManager
actionFileNameFact: QGroundControl.settingsManager.customMavlinkActionsSettings.flyViewActionsFile
}
readonly property bool hasCustomActions: QGroundControl.settingsManager.flyViewSettings.enableCustomActions.rawValue && customManager.hasActions
readonly property bool hasCustomActions: customManager.actions.count > 0

QGCPalette { id: qgcPal }

Expand Down Expand Up @@ -154,12 +156,11 @@ Rectangle {

ColumnLayout {
spacing: ScreenTools.defaultFontPixelHeight / 2
visible: _root.hasCustomActions
Layout.fillHeight: true

QGCLabel {
id: customMessage
text: "Custom Action #" + (index + 1)
text: object.description
horizontalAlignment: Text.AlignHCenter
wrapMode: Text.WordWrap
Layout.minimumWidth: _actionWidth
Expand Down
2 changes: 0 additions & 2 deletions src/Joystick/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ qt_add_library(Joystick STATIC
Joystick.h
JoystickManager.cc
JoystickManager.h
JoystickMavCommand.cc
JoystickMavCommand.h
)

if(ANDROID)
Expand Down
33 changes: 18 additions & 15 deletions src/Joystick/Joystick.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#include "VideoManager.h"
#include "QGCCameraManager.h"
#include "VehicleCameraControl.h"
#include "CustomAction.h"
#include "SettingsManager.h"
#include "CustomMavlinkActionsSettings.h"

#include <QSettings>

Expand Down Expand Up @@ -101,13 +104,14 @@ AssignableButtonAction::AssignableButtonAction(QObject* parent, QString action_,
}

Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int hatCount, MultiVehicleManager* multiVehicleManager)
: _name(name)
, _axisCount(axisCount)
, _buttonCount(buttonCount)
, _hatCount(hatCount)
, _hatButtonCount(4 * hatCount)
, _totalButtonCount(_buttonCount+_hatButtonCount)
, _multiVehicleManager(multiVehicleManager)
: _name (name)
, _axisCount (axisCount)
, _buttonCount (buttonCount)
, _hatCount (hatCount)
, _hatButtonCount (4 * hatCount)
, _totalButtonCount (_buttonCount+_hatButtonCount)
, _multiVehicleManager (multiVehicleManager)
, _customActionManager (qgcApp()->toolbox()->settingsManager()->customMavlinkActionsSettings()->joystickActionsFile())
{
qRegisterMetaType<GRIPPER_ACTIONS>();

Expand All @@ -126,8 +130,6 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int hatC
_loadSettings();
connect(_multiVehicleManager, &MultiVehicleManager::activeVehicleChanged, this, &Joystick::_activeVehicleChanged);
connect(qgcApp()->toolbox()->multiVehicleManager()->vehicles(), &QmlObjectListModel::countChanged, this, &Joystick::_vehicleCountChanged);

_customMavCommands = JoystickMavCommand::load("JoystickMavCommands.json");
}

void Joystick::stop()
Expand Down Expand Up @@ -491,7 +493,6 @@ float Joystick::_adjustRange(int value, Calibration_t calibration, bool withDead
return std::max(-1.0f, std::min(correctedValue, 1.0f));
}


void Joystick::run()
{
//-- Joystick thread
Expand Down Expand Up @@ -1077,9 +1078,10 @@ void Joystick::_executeButtonAction(const QString& action, bool buttonDown)
if (buttonDown) emit landingGearRetract();
} else {
if (buttonDown && _activeVehicle) {
for (auto& item : _customMavCommands) {
if (action == item.name()) {
item.send(_activeVehicle);
for (int i=0; i<_customActionManager.actions()->count(); i++) {
auto customAction = _customActionManager.actions()->value<CustomAction*>(i);
if (action == customAction->label()) {
customAction->sendTo(_activeVehicle);
return;
}
}
Expand Down Expand Up @@ -1172,8 +1174,9 @@ void Joystick::_buildActionList(Vehicle* activeVehicle)
_assignableButtonActions.append(new AssignableButtonAction(this, _buttonActionLandingGearDeploy));
_assignableButtonActions.append(new AssignableButtonAction(this, _buttonActionLandingGearRetract));

for (auto& item : _customMavCommands) {
_assignableButtonActions.append(new AssignableButtonAction(this, item.name()));
for (int i=0; i<_customActionManager.actions()->count(); i++) {
auto customAction = _customActionManager.actions()->value<CustomAction*>(i);
_assignableButtonActions.append(new AssignableButtonAction(this, customAction->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 @@
#include "QGCLoggingCategory.h"
#include "Vehicle.h"
#include "MultiVehicleManager.h"
#include "JoystickMavCommand.h"
#include "CustomActionManager.h"

// JoystickLog Category declaration moved to QGCLoggingCategory.cc to allow access in Vehicle
Q_DECLARE_LOGGING_CATEGORY(JoystickValuesLog)
Expand Down Expand Up @@ -303,7 +303,7 @@ class Joystick : public QThread
QStringList _availableActionTitles;
MultiVehicleManager* _multiVehicleManager = nullptr;

QList<JoystickMavCommand> _customMavCommands;
CustomActionManager _customActionManager;

static const float _minAxisFrequencyHz;
static const float _maxAxisFrequencyHz;
Expand Down
101 changes: 0 additions & 101 deletions src/Joystick/JoystickMavCommand.cc

This file was deleted.

40 changes: 0 additions & 40 deletions src/Joystick/JoystickMavCommand.h

This file was deleted.

Loading

0 comments on commit d799372

Please sign in to comment.