From 76d2d8678e5ee18c84804de65d59a6d45b537c64 Mon Sep 17 00:00:00 2001 From: khancyr Date: Mon, 21 Aug 2017 12:19:10 +0200 Subject: [PATCH] Joystick: make negativethrust visible by firmwarePlugin --- src/FirmwarePlugin/FirmwarePlugin.cc | 6 ++++++ src/FirmwarePlugin/FirmwarePlugin.h | 4 ++++ src/Joystick/Joystick.cc | 2 +- src/Vehicle/Vehicle.cc | 5 +++++ src/Vehicle/Vehicle.h | 2 ++ src/VehicleSetup/JoystickConfig.qml | 1 + 6 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/FirmwarePlugin/FirmwarePlugin.cc b/src/FirmwarePlugin/FirmwarePlugin.cc index 489274b..612314f 100644 --- a/src/FirmwarePlugin/FirmwarePlugin.cc +++ b/src/FirmwarePlugin/FirmwarePlugin.cc @@ -129,6 +129,12 @@ bool FirmwarePlugin::supportsThrottleModeCenterZero(void) return true; } +bool FirmwarePlugin::supportsNegativeThrust(void) +{ + // By default, this is not supported + return false; +} + bool FirmwarePlugin::supportsManualControl(void) { return false; diff --git a/src/FirmwarePlugin/FirmwarePlugin.h b/src/FirmwarePlugin/FirmwarePlugin.h index 1df9f74..65b981e 100644 --- a/src/FirmwarePlugin/FirmwarePlugin.h +++ b/src/FirmwarePlugin/FirmwarePlugin.h @@ -158,6 +158,10 @@ public: /// throttle. virtual bool supportsThrottleModeCenterZero(void); + /// Returns true if the vehicle and firmware supports the use of negative thrust + /// Typically supported rover. + virtual bool supportsNegativeThrust(void); + /// Returns true if the firmware supports the use of the MAVlink "MANUAL_CONTROL" message. /// By default, this returns false unless overridden in the firmware plugin. virtual bool supportsManualControl(void); diff --git a/src/Joystick/Joystick.cc b/src/Joystick/Joystick.cc index 356ed2f..b2093d4 100644 --- a/src/Joystick/Joystick.cc +++ b/src/Joystick/Joystick.cc @@ -463,7 +463,7 @@ void Joystick::run(void) // Adjust throttle to 0:1 range if (_throttleMode == ThrottleModeCenterZero && _activeVehicle->supportsThrottleModeCenterZero()) { - if (!_negativeThrust) { + if (!_activeVehicle->supportsNegativeThrust() || !_negativeThrust) { throttle = std::max(0.0f, throttle); } } else { diff --git a/src/Vehicle/Vehicle.cc b/src/Vehicle/Vehicle.cc index 01030f8..39c49a8 100644 --- a/src/Vehicle/Vehicle.cc +++ b/src/Vehicle/Vehicle.cc @@ -2118,6 +2118,11 @@ bool Vehicle::supportsThrottleModeCenterZero(void) const return _firmwarePlugin->supportsThrottleModeCenterZero(); } +bool Vehicle::supportsNegativeThrust(void) const +{ + return _firmwarePlugin->supportsNegativeThrust(); +} + bool Vehicle::supportsRadio(void) const { return _firmwarePlugin->supportsRadio(); diff --git a/src/Vehicle/Vehicle.h b/src/Vehicle/Vehicle.h index 96c60f1..21ac005 100644 --- a/src/Vehicle/Vehicle.h +++ b/src/Vehicle/Vehicle.h @@ -284,6 +284,7 @@ public: Q_PROPERTY(bool sub READ sub NOTIFY vehicleTypeChanged) Q_PROPERTY(bool supportsManualControl READ supportsManualControl CONSTANT) Q_PROPERTY(bool supportsThrottleModeCenterZero READ supportsThrottleModeCenterZero CONSTANT) + Q_PROPERTY(bool supportsNegativeThrust READ supportsNegativeThrust CONSTANT) Q_PROPERTY(bool supportsJSButton READ supportsJSButton CONSTANT) Q_PROPERTY(bool supportsRadio READ supportsRadio CONSTANT) Q_PROPERTY(bool supportsMotorInterference READ supportsMotorInterference CONSTANT) @@ -522,6 +523,7 @@ public: bool supportsManualControl(void) const; bool supportsThrottleModeCenterZero(void) const; + bool supportsNegativeThrust(void) const; bool supportsRadio(void) const; bool supportsJSButton(void) const; bool supportsMotorInterference(void) const; diff --git a/src/VehicleSetup/JoystickConfig.qml b/src/VehicleSetup/JoystickConfig.qml index ca9d029..f2d044b 100644 --- a/src/VehicleSetup/JoystickConfig.qml +++ b/src/VehicleSetup/JoystickConfig.qml @@ -455,6 +455,7 @@ SetupPage { } QGCCheckBox { + visible: _activeVehicle.supportsNegativeThrust id: negativeThrust text: qsTr("Allow negative Thrust") checked: _activeJoystick ? _activeJoystick.negativeThrust : false