Commit d4ec57c8 authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #5185 from khancyr/negativethrust

Joystick: add a button to support negative thrust
parents 53b44635 3bd546a2
...@@ -106,3 +106,13 @@ void ArduRoverFirmwarePlugin::guidedModeChangeAltitude(Vehicle* vehicle, double ...@@ -106,3 +106,13 @@ void ArduRoverFirmwarePlugin::guidedModeChangeAltitude(Vehicle* vehicle, double
qgcApp()->showMessage(QStringLiteral("Change altitude not supported.")); qgcApp()->showMessage(QStringLiteral("Change altitude not supported."));
} }
bool ArduRoverFirmwarePlugin::supportsNegativeThrust(void)
{
return true;
}
bool ArduRoverFirmwarePlugin::supportsManualControl(void)
{
return true;
}
...@@ -55,6 +55,8 @@ public: ...@@ -55,6 +55,8 @@ public:
void guidedModeChangeAltitude (Vehicle* vehicle, double altitudeChange) final; void guidedModeChangeAltitude (Vehicle* vehicle, double altitudeChange) final;
int remapParamNameHigestMinorVersionNumber (int majorVersionNumber) const final; int remapParamNameHigestMinorVersionNumber (int majorVersionNumber) const final;
const FirmwarePlugin::remapParamNameMajorVersionMap_t& paramNameRemapMajorVersionMap(void) const final { return _remapParamName; } const FirmwarePlugin::remapParamNameMajorVersionMap_t& paramNameRemapMajorVersionMap(void) const final { return _remapParamName; }
bool supportsNegativeThrust(void) final;
bool supportsManualControl(void) final;
private: private:
static bool _remapParamNameIntialized; static bool _remapParamNameIntialized;
......
...@@ -129,6 +129,12 @@ bool FirmwarePlugin::supportsThrottleModeCenterZero(void) ...@@ -129,6 +129,12 @@ bool FirmwarePlugin::supportsThrottleModeCenterZero(void)
return true; return true;
} }
bool FirmwarePlugin::supportsNegativeThrust(void)
{
// By default, this is not supported
return false;
}
bool FirmwarePlugin::supportsManualControl(void) bool FirmwarePlugin::supportsManualControl(void)
{ {
return false; return false;
......
...@@ -158,6 +158,10 @@ public: ...@@ -158,6 +158,10 @@ public:
/// throttle. /// throttle.
virtual bool supportsThrottleModeCenterZero(void); 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. /// 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. /// By default, this returns false unless overridden in the firmware plugin.
virtual bool supportsManualControl(void); virtual bool supportsManualControl(void);
......
...@@ -55,6 +55,7 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int hatC ...@@ -55,6 +55,7 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int hatC
, _rgButtonValues(NULL) , _rgButtonValues(NULL)
, _lastButtonBits(0) , _lastButtonBits(0)
, _throttleMode(ThrottleModeCenterZero) , _throttleMode(ThrottleModeCenterZero)
, _negativeThrust(false)
, _exponential(0) , _exponential(0)
, _accumulator(false) , _accumulator(false)
, _deadband(false) , _deadband(false)
...@@ -462,7 +463,9 @@ void Joystick::run(void) ...@@ -462,7 +463,9 @@ void Joystick::run(void)
// Adjust throttle to 0:1 range // Adjust throttle to 0:1 range
if (_throttleMode == ThrottleModeCenterZero && _activeVehicle->supportsThrottleModeCenterZero()) { if (_throttleMode == ThrottleModeCenterZero && _activeVehicle->supportsThrottleModeCenterZero()) {
throttle = std::max(0.0f, throttle); if (!_activeVehicle->supportsNegativeThrust() || !_negativeThrust) {
throttle = std::max(0.0f, throttle);
}
} else { } else {
throttle = (throttle + 1.0f) / 2.0f; throttle = (throttle + 1.0f) / 2.0f;
} }
...@@ -687,6 +690,22 @@ void Joystick::setThrottleMode(int mode) ...@@ -687,6 +690,22 @@ void Joystick::setThrottleMode(int mode)
emit throttleModeChanged(_throttleMode); emit throttleModeChanged(_throttleMode);
} }
bool Joystick::negativeThrust(void)
{
return _negativeThrust;
}
void Joystick::setNegativeThrust(bool allowNegative)
{
if (_negativeThrust == allowNegative) {
return;
}
_negativeThrust = allowNegative;
_saveSettings();
emit negativeThrustChanged(_negativeThrust);
}
float Joystick::exponential(void) float Joystick::exponential(void)
{ {
return _exponential; return _exponential;
......
...@@ -72,6 +72,7 @@ public: ...@@ -72,6 +72,7 @@ public:
Q_INVOKABLE QString getButtonAction(int button); Q_INVOKABLE QString getButtonAction(int button);
Q_PROPERTY(int throttleMode READ throttleMode WRITE setThrottleMode NOTIFY throttleModeChanged) Q_PROPERTY(int throttleMode READ throttleMode WRITE setThrottleMode NOTIFY throttleModeChanged)
Q_PROPERTY(bool negativeThrust READ negativeThrust WRITE setNegativeThrust NOTIFY negativeThrustChanged)
Q_PROPERTY(float exponential READ exponential WRITE setExponential NOTIFY exponentialChanged) Q_PROPERTY(float exponential READ exponential WRITE setExponential NOTIFY exponentialChanged)
Q_PROPERTY(bool accumulator READ accumulator WRITE setAccumulator NOTIFY accumulatorChanged) Q_PROPERTY(bool accumulator READ accumulator WRITE setAccumulator NOTIFY accumulatorChanged)
Q_PROPERTY(bool requiresCalibration READ requiresCalibration CONSTANT) Q_PROPERTY(bool requiresCalibration READ requiresCalibration CONSTANT)
...@@ -106,6 +107,9 @@ public: ...@@ -106,6 +107,9 @@ public:
int throttleMode(void); int throttleMode(void);
void setThrottleMode(int mode); void setThrottleMode(int mode);
bool negativeThrust(void);
void setNegativeThrust(bool allowNegative);
float exponential(void); float exponential(void);
void setExponential(float expo); void setExponential(float expo);
...@@ -141,6 +145,8 @@ signals: ...@@ -141,6 +145,8 @@ signals:
void throttleModeChanged(int mode); void throttleModeChanged(int mode);
void negativeThrustChanged(bool allowNegative);
void exponentialChanged(float exponential); void exponentialChanged(float exponential);
void accumulatorChanged(bool accumulator); void accumulatorChanged(bool accumulator);
...@@ -206,6 +212,8 @@ protected: ...@@ -206,6 +212,8 @@ protected:
ThrottleMode_t _throttleMode; ThrottleMode_t _throttleMode;
bool _negativeThrust;
float _exponential; float _exponential;
bool _accumulator; bool _accumulator;
bool _deadband; bool _deadband;
......
...@@ -2118,6 +2118,11 @@ bool Vehicle::supportsThrottleModeCenterZero(void) const ...@@ -2118,6 +2118,11 @@ bool Vehicle::supportsThrottleModeCenterZero(void) const
return _firmwarePlugin->supportsThrottleModeCenterZero(); return _firmwarePlugin->supportsThrottleModeCenterZero();
} }
bool Vehicle::supportsNegativeThrust(void) const
{
return _firmwarePlugin->supportsNegativeThrust();
}
bool Vehicle::supportsRadio(void) const bool Vehicle::supportsRadio(void) const
{ {
return _firmwarePlugin->supportsRadio(); return _firmwarePlugin->supportsRadio();
......
...@@ -284,6 +284,7 @@ public: ...@@ -284,6 +284,7 @@ public:
Q_PROPERTY(bool sub READ sub NOTIFY vehicleTypeChanged) Q_PROPERTY(bool sub READ sub NOTIFY vehicleTypeChanged)
Q_PROPERTY(bool supportsManualControl READ supportsManualControl CONSTANT) Q_PROPERTY(bool supportsManualControl READ supportsManualControl CONSTANT)
Q_PROPERTY(bool supportsThrottleModeCenterZero READ supportsThrottleModeCenterZero 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 supportsJSButton READ supportsJSButton CONSTANT)
Q_PROPERTY(bool supportsRadio READ supportsRadio CONSTANT) Q_PROPERTY(bool supportsRadio READ supportsRadio CONSTANT)
Q_PROPERTY(bool supportsMotorInterference READ supportsMotorInterference CONSTANT) Q_PROPERTY(bool supportsMotorInterference READ supportsMotorInterference CONSTANT)
...@@ -522,6 +523,7 @@ public: ...@@ -522,6 +523,7 @@ public:
bool supportsManualControl(void) const; bool supportsManualControl(void) const;
bool supportsThrottleModeCenterZero(void) const; bool supportsThrottleModeCenterZero(void) const;
bool supportsNegativeThrust(void) const;
bool supportsRadio(void) const; bool supportsRadio(void) const;
bool supportsJSButton(void) const; bool supportsJSButton(void) const;
bool supportsMotorInterference(void) const; bool supportsMotorInterference(void) const;
......
...@@ -296,7 +296,7 @@ SetupPage { ...@@ -296,7 +296,7 @@ SetupPage {
Connections { Connections {
target: _activeJoystick target: _activeJoystick
onManualControl: throttleLoader.item.axisValue = (-2*throttle+1)*32768.0 onManualControl: throttleLoader.item.axisValue = _activeJoystick.negativeThrust ? -throttle*32768.0 : (-2*throttle+1)*32768.0
} }
} }
} // Column - Attitude Control labels } // Column - Attitude Control labels
...@@ -453,6 +453,15 @@ SetupPage { ...@@ -453,6 +453,15 @@ SetupPage {
onClicked: _activeJoystick.throttleMode = 1 onClicked: _activeJoystick.throttleMode = 1
} }
QGCCheckBox {
visible: _activeVehicle.supportsNegativeThrust
id: negativeThrust
text: qsTr("Allow negative Thrust")
enabled: _activeJoystick.negativeThrust = _activeVehicle.supportsNegativeThrust
checked: _activeJoystick ? _activeJoystick.negativeThrust : false
onClicked: _activeJoystick.negativeThrust = checked
}
} }
Column { Column {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment