From 3b82d52dfa565ba90bbc5d4ea90b1540c2b95473 Mon Sep 17 00:00:00 2001 From: Rustom Jehangir Date: Mon, 1 Aug 2016 09:09:47 -0700 Subject: [PATCH] Make supportsThrottleModeCenterZero a plugin option --- src/FirmwarePlugin/APM/ArduSubFirmwarePlugin.cc | 5 +++++ src/FirmwarePlugin/APM/ArduSubFirmwarePlugin.h | 2 ++ src/FirmwarePlugin/FirmwarePlugin.cc | 6 ++++++ src/FirmwarePlugin/FirmwarePlugin.h | 5 +++++ src/Joystick/Joystick.cc | 2 +- src/Vehicle/Vehicle.cc | 5 +++++ src/Vehicle/Vehicle.h | 2 ++ 7 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/FirmwarePlugin/APM/ArduSubFirmwarePlugin.cc b/src/FirmwarePlugin/APM/ArduSubFirmwarePlugin.cc index ea1538a9e..8adf5ca3d 100644 --- a/src/FirmwarePlugin/APM/ArduSubFirmwarePlugin.cc +++ b/src/FirmwarePlugin/APM/ArduSubFirmwarePlugin.cc @@ -52,3 +52,8 @@ int ArduSubFirmwarePlugin::manualControlReservedButtonCount(void) { return 0; } + +bool ArduSubFirmwarePlugin::supportsThrottleModeCenterZero(void) +{ + return false; +} diff --git a/src/FirmwarePlugin/APM/ArduSubFirmwarePlugin.h b/src/FirmwarePlugin/APM/ArduSubFirmwarePlugin.h index a927a44d9..e5d01b2ad 100644 --- a/src/FirmwarePlugin/APM/ArduSubFirmwarePlugin.h +++ b/src/FirmwarePlugin/APM/ArduSubFirmwarePlugin.h @@ -69,6 +69,8 @@ public: // Overrides from FirmwarePlugin int manualControlReservedButtonCount(void); + bool supportsThrottleModeCenterZero(void); + }; #endif diff --git a/src/FirmwarePlugin/FirmwarePlugin.cc b/src/FirmwarePlugin/FirmwarePlugin.cc index 60e988928..f615f73f2 100644 --- a/src/FirmwarePlugin/FirmwarePlugin.cc +++ b/src/FirmwarePlugin/FirmwarePlugin.cc @@ -83,6 +83,12 @@ int FirmwarePlugin::manualControlReservedButtonCount(void) return -1; } +bool FirmwarePlugin::supportsThrottleModeCenterZero(void) +{ + // By default, this is supported + return true; +} + bool FirmwarePlugin::adjustIncomingMavlinkMessage(Vehicle* vehicle, mavlink_message_t* message) { Q_UNUSED(vehicle); diff --git a/src/FirmwarePlugin/FirmwarePlugin.h b/src/FirmwarePlugin/FirmwarePlugin.h index bf3539e72..59fe8d9ff 100644 --- a/src/FirmwarePlugin/FirmwarePlugin.h +++ b/src/FirmwarePlugin/FirmwarePlugin.h @@ -128,6 +128,11 @@ public: /// @return -1: reserver all buttons, >0 number of buttons to reserve virtual int manualControlReservedButtonCount(void); + /// Returns true if the vehicle and firmware supports the use of a throttle joystick that + /// is zero when centered. Typically not supported on vehicles that have bidirectional + /// throttle. + virtual bool supportsThrottleModeCenterZero(void); + /// Called before any mavlink message is processed by Vehicle such that the firmwre plugin /// can adjust any message characteristics. This is handy to adjust or differences in mavlink /// spec implementations such that the base code can remain mavlink generic. diff --git a/src/Joystick/Joystick.cc b/src/Joystick/Joystick.cc index 93dc847da..3becad6bc 100644 --- a/src/Joystick/Joystick.cc +++ b/src/Joystick/Joystick.cc @@ -284,7 +284,7 @@ void Joystick::run(void) throttle = std::max(-1.0f, std::min(tanf(asinf(throttle_limited)), 1.0f)); // Adjust throttle to 0:1 range - if (_throttleMode == ThrottleModeCenterZero && !_activeVehicle->sub()) { + if (_throttleMode == ThrottleModeCenterZero && _activeVehicle->supportsThrottleModeCenterZero()) { throttle = std::max(0.0f, throttle); } else { throttle = (throttle + 1.0f) / 2.0f; diff --git a/src/Vehicle/Vehicle.cc b/src/Vehicle/Vehicle.cc index 942303dba..00963e03e 100644 --- a/src/Vehicle/Vehicle.cc +++ b/src/Vehicle/Vehicle.cc @@ -1528,6 +1528,11 @@ bool Vehicle::supportsManualControl(void) const return false; } +bool Vehicle::supportsThrottleModeCenterZero(void) const +{ + return _firmwarePlugin->supportsThrottleModeCenterZero(); +} + void Vehicle::_setCoordinateValid(bool coordinateValid) { if (coordinateValid != _coordinateValid) { diff --git a/src/Vehicle/Vehicle.h b/src/Vehicle/Vehicle.h index be54c3630..7896adf06 100644 --- a/src/Vehicle/Vehicle.h +++ b/src/Vehicle/Vehicle.h @@ -276,6 +276,7 @@ public: Q_PROPERTY(bool vtol READ vtol CONSTANT) Q_PROPERTY(bool rover READ rover CONSTANT) Q_PROPERTY(bool supportsManualControl READ supportsManualControl CONSTANT) + Q_PROPERTY(bool supportsThrottleModeCenterZero READ supportsThrottleModeCenterZero CONSTANT) Q_PROPERTY(bool sub READ sub CONSTANT) Q_PROPERTY(bool autoDisconnect MEMBER _autoDisconnect NOTIFY autoDisconnectChanged) Q_PROPERTY(QString prearmError READ prearmError WRITE setPrearmError NOTIFY prearmErrorChanged) @@ -473,6 +474,7 @@ public: bool sub(void) const; bool supportsManualControl(void) const; + bool supportsThrottleModeCenterZero(void) const; void setFlying(bool flying); void setGuidedMode(bool guidedMode); -- 2.22.0