diff --git a/src/FirmwarePlugin/APM/ArduSubFirmwarePlugin.cc b/src/FirmwarePlugin/APM/ArduSubFirmwarePlugin.cc index ea1538a9e473525da69ae6ff0e82c4c9e750bcc9..8adf5ca3ddb2c7b7f92df6959edc9ed30460f860 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 a927a44d9edd004754206324bb5544fa334d2a6d..e5d01b2ad512601fb1e19f7b4fef4a654990552b 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 60e988928df2e2225fd7414461c6c242e7975d91..f615f73f2fa145bd53ab8431befbc6b320a0670b 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 bf3539e727e9c96c9c760c9c1af968907f4619e4..59fe8d9fffd156347b9fc2eeb76771ffe3238236 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 93dc847dabe5105dbb52dd2f055a7c10cff812e6..3becad6bc575b566746e06fd938a302c6bfc8431 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 942303dba059fff8fae5344cf0c604a6e1c6f519..00963e03e45e595fa553b6f6837ca182b01253e5 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 be54c36309f6159eb7400d6b91daee7289e26274..7896adf06494175bdcecc0df644f43f2bb1433eb 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);