From c3fba6e8a5191f9f7f354536720f435a73417932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Thu, 25 Apr 2019 00:15:52 -0300 Subject: [PATCH 1/7] JoystickThumbPad: Add center variable to control Y throttle behaviour MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- src/QmlControls/JoystickThumbPad.qml | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/QmlControls/JoystickThumbPad.qml b/src/QmlControls/JoystickThumbPad.qml index de7b54e..6050f00 100644 --- a/src/QmlControls/JoystickThumbPad.qml +++ b/src/QmlControls/JoystickThumbPad.qml @@ -11,15 +11,14 @@ Item { property real xAxis: 0 ///< Value range [-1,1], negative values left stick, positive values right stick property real yAxis: 0 ///< Value range [-1,1], negative values up stick, positive values down stick property bool yAxisThrottle: false ///< true: yAxis used for throttle, range [1,0], positive value are stick up + property bool yAxisThrottleCentered: false ///< false: center yAxis in throttle for reverser and forward property real xPositionDelta: 0 ///< Amount to move the control on x axis property real yPositionDelta: 0 ///< Amount to move the control on y axis - property bool throttle: false property real _centerXY: width / 2 property bool _processTouchPoints: false - property bool _stickCenteredOnce: false property real stickPositionX: _centerXY - property real stickPositionY: yAxisThrottle ? height : _centerXY + property real stickPositionY: yAxisThrottleCentered ? _centerXY : height QGCMapPalette { id: mapPal } @@ -50,7 +49,7 @@ Item { // Center sticks stickPositionX = _centerXY - if (!yAxisThrottle) { + if (yAxisThrottleCentered) { stickPositionY = _centerXY } } @@ -86,7 +85,7 @@ Item { QGCColoredImage { color: lightColors ? "white" : "black" - visible: throttle + visible: yAxisThrottle height: ScreenTools.defaultFontPixelHeight width: height sourceSize.height: height @@ -100,7 +99,7 @@ Item { QGCColoredImage { color: lightColors ? "white" : "black" - visible: throttle + visible: yAxisThrottle height: ScreenTools.defaultFontPixelHeight width: height sourceSize.height: height @@ -114,7 +113,7 @@ Item { QGCColoredImage { color: lightColors ? "white" : "black" - visible: throttle + visible: yAxisThrottle height: ScreenTools.defaultFontPixelHeight width: height sourceSize.height: height @@ -128,7 +127,7 @@ Item { QGCColoredImage { color: lightColors ? "white" : "black" - visible: throttle + visible: yAxisThrottle height: ScreenTools.defaultFontPixelHeight width: height sourceSize.height: height From 59a5d0a643a49d26d582e2dfd3239e9d2b6fc99c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Thu, 25 Apr 2019 00:16:41 -0300 Subject: [PATCH 2/7] VirtualJoystick: Add centralizeThrottle variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- src/FlightDisplay/VirtualJoystick.qml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/FlightDisplay/VirtualJoystick.qml b/src/FlightDisplay/VirtualJoystick.qml index 777f0ca..c73869c 100644 --- a/src/FlightDisplay/VirtualJoystick.qml +++ b/src/FlightDisplay/VirtualJoystick.qml @@ -18,7 +18,7 @@ import QGroundControl.Vehicle 1.0 Item { //property bool useLightColors - Must be passed in from loaded - + //property bool centralizeThrottle - Must be passed in from loaded Timer { interval: 40 // 25Hz, same as real joystick rate running: QGroundControl.settingsManager.appSettings.virtualJoystick.value && _activeVehicle @@ -39,8 +39,8 @@ Item { width: parent.height height: parent.height yAxisThrottle: true + yAxisThrottleCentered: centralizeThrottle lightColors: useLightColors - throttle: true } JoystickThumbPad { From 831d2f8650d39ec192ee54bead5a10eece9b289a Mon Sep 17 00:00:00 2001 From: Willian Galvani Date: Fri, 8 Feb 2019 15:48:08 -0200 Subject: [PATCH 3/7] JoystickConfig.qml: Change deadband adjustment to dragging horizontally --- src/VehicleSetup/JoystickConfig.qml | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/VehicleSetup/JoystickConfig.qml b/src/VehicleSetup/JoystickConfig.qml index db6c1a4..44e6f84 100644 --- a/src/VehicleSetup/JoystickConfig.qml +++ b/src/VehicleSetup/JoystickConfig.qml @@ -849,20 +849,24 @@ SetupPage { MouseArea { - id: deadbandMouseArea - anchors.fill: parent.item - enabled: controller.deadbandToggle + id: deadbandMouseArea + anchors.fill: parent.item + enabled: controller.deadbandToggle + preventStealing: true - property real startY + property real startX + property real direction onPressed: { - startY = mouseY + startX = mouseX + direction = startX > width/2 ? 1 : -1 parent.item.deadbandColor = "#3C6315" } onPositionChanged: { - var newValue = parent.item.deadbandValue + (startY - mouseY)*15 + var mouseToDeadband = 32768/(width/2) // Factor to have deadband follow the mouse movement + var newValue = parent.item.deadbandValue + direction*(mouseX - startX)*mouseToDeadband if ((newValue > 0) && (newValue <32768)){parent.item.deadbandValue=newValue;} - startY = mouseY + startX = mouseX } onReleased: { controller.setDeadbandValue(modelData,parent.item.deadbandValue) From c72abd336f4bd94a4d584228becd282bb5e6c6a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Thu, 25 Apr 2019 00:17:33 -0300 Subject: [PATCH 4/7] Add virtualJoystickCentralized setting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- src/FlightDisplay/FlightDisplayViewWidgets.qml | 4 ++++ src/Settings/App.SettingsGroup.json | 7 +++++++ src/Settings/AppSettings.cc | 1 + src/Settings/AppSettings.h | 1 + src/ui/preferences/GeneralSettings.qml | 11 +++++++++++ 5 files changed, 24 insertions(+) diff --git a/src/FlightDisplay/FlightDisplayViewWidgets.qml b/src/FlightDisplay/FlightDisplayViewWidgets.qml index 6d8458d..a60c925 100644 --- a/src/FlightDisplay/FlightDisplayViewWidgets.qml +++ b/src/FlightDisplay/FlightDisplayViewWidgets.qml @@ -86,6 +86,10 @@ Item { target: QGroundControl.settingsManager.appSettings.virtualJoystick onValueChanged: _setInstrumentWidget() } + Connections { + target: QGroundControl.settingsManager.appSettings.virtualJoystickCentralized + onValueChanged: _setInstrumentWidget() + } Connections { target: QGroundControl.settingsManager.appSettings.showLargeCompass diff --git a/src/Settings/App.SettingsGroup.json b/src/Settings/App.SettingsGroup.json index 4e42382..37058d7 100644 --- a/src/Settings/App.SettingsGroup.json +++ b/src/Settings/App.SettingsGroup.json @@ -104,6 +104,13 @@ "defaultValue": false }, { + "name": "virtualJoystickCentralized", + "shortDescription": "Set virtual joystick to be centralize throttle (spring-loaded).", + "longDescription": "If this option is enabled the virtual joystick throttle stick will be centralized.", + "type": "bool", + "defaultValue": false +}, +{ "name": "gstDebugLevel", "shortDescription": "Video streaming debug", "longDescription": "Sets the environment variable GST_DEBUG for all pipeline elements on boot.", diff --git a/src/Settings/AppSettings.cc b/src/Settings/AppSettings.cc index b9512f6..c8774f2 100644 --- a/src/Settings/AppSettings.cc +++ b/src/Settings/AppSettings.cc @@ -78,6 +78,7 @@ DECLARE_SETTINGSFACT(AppSettings, telemetrySave) DECLARE_SETTINGSFACT(AppSettings, telemetrySaveNotArmed) DECLARE_SETTINGSFACT(AppSettings, audioMuted) DECLARE_SETTINGSFACT(AppSettings, virtualJoystick) +DECLARE_SETTINGSFACT(AppSettings, virtualJoystickCentralized) DECLARE_SETTINGSFACT(AppSettings, appFontPointSize) DECLARE_SETTINGSFACT(AppSettings, showLargeCompass) DECLARE_SETTINGSFACT(AppSettings, savePath) diff --git a/src/Settings/AppSettings.h b/src/Settings/AppSettings.h index 17cb0ec..afa5496 100644 --- a/src/Settings/AppSettings.h +++ b/src/Settings/AppSettings.h @@ -33,6 +33,7 @@ public: DEFINE_SETTINGFACT(telemetrySaveNotArmed) DEFINE_SETTINGFACT(audioMuted) DEFINE_SETTINGFACT(virtualJoystick) + DEFINE_SETTINGFACT(virtualJoystickCentralized) DEFINE_SETTINGFACT(appFontPointSize) DEFINE_SETTINGFACT(indoorPalette) DEFINE_SETTINGFACT(showLargeCompass) diff --git a/src/ui/preferences/GeneralSettings.qml b/src/ui/preferences/GeneralSettings.qml index ad4a90a..66983e1 100644 --- a/src/ui/preferences/GeneralSettings.qml +++ b/src/ui/preferences/GeneralSettings.qml @@ -455,6 +455,17 @@ QGCView { property Fact _virtualJoystick: QGroundControl.settingsManager.appSettings.virtualJoystick } + FactCheckBox { + text: qsTr("Auto-Center throttle") + visible: _virtualJoystickCentralized.visible && ( + QGroundControl.multiVehicleManager.activeVehicle.sub || QGroundControl.multiVehicleManager.activeVehicle.rover + ) + fact: _virtualJoystickCentralized + Layout.leftMargin: _margins + + property Fact _virtualJoystickCentralized: QGroundControl.settingsManager.appSettings.virtualJoystickCentralized + } + GridLayout { columns: 2 From 3c9a246f99a6c6720b3c1352a654f23df0567ece Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Thu, 9 May 2019 11:22:52 -0300 Subject: [PATCH 5/7] FlightDisplayView: Use virtualJoystickCentralized setting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- src/FlightDisplay/FlightDisplayView.qml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/FlightDisplay/FlightDisplayView.qml b/src/FlightDisplay/FlightDisplayView.qml index 6c60bb2..f56e139 100644 --- a/src/FlightDisplay/FlightDisplayView.qml +++ b/src/FlightDisplay/FlightDisplayView.qml @@ -550,8 +550,11 @@ QGCView { active: (_virtualJoystick ? _virtualJoystick.value : false) && !(_activeVehicle ? _activeVehicle.highLatencyLink : false) property bool useLightColors: isBackgroundDark + // The default behaviour is not centralized throttle + property bool centralizeThrottle: _virtualJoystickCentralized ? _virtualJoystickCentralized.value : false property Fact _virtualJoystick: QGroundControl.settingsManager.appSettings.virtualJoystick + property Fact _virtualJoystickCentralized: QGroundControl.settingsManager.appSettings.virtualJoystickCentralized } ToolStrip { From e89d23b99b5803132dffd62b27fc0175160b48e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Thu, 25 Apr 2019 00:31:16 -0300 Subject: [PATCH 6/7] JoystickThumbPad: Fix invalid axis value calculation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the item is not visible, the width and height are not valid, resulting in wrong output values Signed-off-by: Patrick José Pereira --- src/QmlControls/JoystickThumbPad.qml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/QmlControls/JoystickThumbPad.qml b/src/QmlControls/JoystickThumbPad.qml index 6050f00..6889ab3 100644 --- a/src/QmlControls/JoystickThumbPad.qml +++ b/src/QmlControls/JoystickThumbPad.qml @@ -22,14 +22,27 @@ Item { QGCMapPalette { id: mapPal } - onStickPositionXChanged: { + onWidthChanged: calculateXAxis() + onStickPositionXChanged: calculateXAxis() + onHeightChanged: calculateYAxis() + onStickPositionYChanged: calculateYAxis() + + function calculateXAxis() + { + if(!visible()) { + return; + } var xAxisTemp = stickPositionX / width xAxisTemp *= 2.0 xAxisTemp -= 1.0 xAxis = xAxisTemp } - onStickPositionYChanged: { + function calculateYAxis() + { + if(!visible()) { + return; + } var yAxisTemp = stickPositionY / height yAxisTemp *= 2.0 yAxisTemp -= 1.0 From 83b500d0b126a8296301ba8ca46fafb537b64d28 Mon Sep 17 00:00:00 2001 From: DonLakeFlyer Date: Tue, 14 May 2019 15:16:06 -0700 Subject: [PATCH 7/7] Handle ArduPilot strangeness with respect to components and mavlink spec for parameter messages --- src/FirmwarePlugin/APM/APMFirmwarePlugin.cc | 81 ++++++++++++++++------------- src/FirmwarePlugin/APM/APMFirmwarePlugin.h | 1 + 2 files changed, 45 insertions(+), 37 deletions(-) diff --git a/src/FirmwarePlugin/APM/APMFirmwarePlugin.cc b/src/FirmwarePlugin/APM/APMFirmwarePlugin.cc index b4ce2e4..d67a530 100644 --- a/src/FirmwarePlugin/APM/APMFirmwarePlugin.cc +++ b/src/FirmwarePlugin/APM/APMFirmwarePlugin.cc @@ -446,46 +446,55 @@ void APMFirmwarePlugin::_handleIncomingHeartbeat(Vehicle* vehicle, mavlink_messa { bool flying = false; - // We pull Vehicle::flying state from HEARTBEAT on ArduPilot. This is a firmware specific test. + mavlink_heartbeat_t heartbeat; + mavlink_msg_heartbeat_decode(message, &heartbeat); - if (vehicle->armed()) { - mavlink_heartbeat_t heartbeat; - mavlink_msg_heartbeat_decode(message, &heartbeat); + if (message->compid == MAV_COMP_ID_AUTOPILOT1) { + // We pull Vehicle::flying state from HEARTBEAT on ArduPilot. This is a firmware specific test. + if (vehicle->armed()) { - flying = heartbeat.system_status == MAV_STATE_ACTIVE; - if (!flying && vehicle->flying()) { - // If we were previously flying, and we go into critical or emergency assume we are still flying - flying = heartbeat.system_status == MAV_STATE_CRITICAL || heartbeat.system_status == MAV_STATE_EMERGENCY; + flying = heartbeat.system_status == MAV_STATE_ACTIVE; + if (!flying && vehicle->flying()) { + // If we were previously flying, and we go into critical or emergency assume we are still flying + flying = heartbeat.system_status == MAV_STATE_CRITICAL || heartbeat.system_status == MAV_STATE_EMERGENCY; + } } + vehicle->_setFlying(flying); } - vehicle->_setFlying(flying); + // We need to know whether this component is part of the ArduPilot stack code or not so we can adjust mavlink quirks appropriately. + // If the component sends a heartbeat we can know that. If it's doesn't there is pretty much no way to know. + _ardupilotComponentMap[message->sysid][message->compid] = heartbeat.autopilot == MAV_AUTOPILOT_ARDUPILOTMEGA; + + // Force the ESP8266 to be non-ArduPilot code (it doesn't send heartbeats) + _ardupilotComponentMap[message->sysid][MAV_COMP_ID_UDP_BRIDGE] = false; } bool APMFirmwarePlugin::adjustIncomingMavlinkMessage(Vehicle* vehicle, mavlink_message_t* message) { - // Only translate messages which come from the autopilot. All other components are expected to follow current mavlink spec. - if (message->compid != MAV_COMP_ID_AUTOPILOT1) { + if (message->msgid == MAVLINK_MSG_ID_HEARTBEAT) { + // We need to look at all heartbeats that go by from any component + _handleIncomingHeartbeat(vehicle, message); return true; } - switch (message->msgid) { - case MAVLINK_MSG_ID_PARAM_VALUE: - _handleIncomingParamValue(vehicle, message); - break; - case MAVLINK_MSG_ID_STATUSTEXT: - return _handleIncomingStatusText(vehicle, message, false /* longVersion */); - case MAVLINK_MSG_ID_STATUSTEXT_LONG: - return _handleIncomingStatusText(vehicle, message, true /* longVersion */); - case MAVLINK_MSG_ID_HEARTBEAT: - _handleIncomingHeartbeat(vehicle, message); - break; - case MAVLINK_MSG_ID_RC_CHANNELS: - _handleRCChannels(vehicle, message); - break; - case MAVLINK_MSG_ID_RC_CHANNELS_RAW: - _handleRCChannelsRaw(vehicle, message); - break; + // Only translate messages which come from ArduPilot code. All other components are expected to follow current mavlink spec. + if (_ardupilotComponentMap[vehicle->id()][message->compid]) { + switch (message->msgid) { + case MAVLINK_MSG_ID_PARAM_VALUE: + _handleIncomingParamValue(vehicle, message); + break; + case MAVLINK_MSG_ID_STATUSTEXT: + return _handleIncomingStatusText(vehicle, message, false /* longVersion */); + case MAVLINK_MSG_ID_STATUSTEXT_LONG: + return _handleIncomingStatusText(vehicle, message, true /* longVersion */); + case MAVLINK_MSG_ID_RC_CHANNELS: + _handleRCChannels(vehicle, message); + break; + case MAVLINK_MSG_ID_RC_CHANNELS_RAW: + _handleRCChannelsRaw(vehicle, message); + break; + } } return true; @@ -493,15 +502,13 @@ bool APMFirmwarePlugin::adjustIncomingMavlinkMessage(Vehicle* vehicle, mavlink_m void APMFirmwarePlugin::adjustOutgoingMavlinkMessage(Vehicle* vehicle, LinkInterface* outgoingLink, mavlink_message_t* message) { - //-- Don't process messages to/from UDP Bridge. It doesn't suffer from these issues - if (message->compid == MAV_COMP_ID_UDP_BRIDGE) { - return; - } - - switch (message->msgid) { - case MAVLINK_MSG_ID_PARAM_SET: - _handleOutgoingParamSet(vehicle, outgoingLink, message); - break; + // Only translate messages which come from ArduPilot code. All other components are expected to follow current mavlink spec. + if (_ardupilotComponentMap[vehicle->id()][message->compid]) { + switch (message->msgid) { + case MAVLINK_MSG_ID_PARAM_SET: + _handleOutgoingParamSet(vehicle, outgoingLink, message); + break; + } } } diff --git a/src/FirmwarePlugin/APM/APMFirmwarePlugin.h b/src/FirmwarePlugin/APM/APMFirmwarePlugin.h index b7cbfbb..c5867d0 100644 --- a/src/FirmwarePlugin/APM/APMFirmwarePlugin.h +++ b/src/FirmwarePlugin/APM/APMFirmwarePlugin.h @@ -137,6 +137,7 @@ private: // Vehicle specific data should go into APMFirmwarePluginInstanceData QList _supportedModes; + QMap> _ardupilotComponentMap; static const char* _artooIP; static const int _artooVideoHandshakePort;