From aa72da856b658f798d46027db0b4c12c202c754c Mon Sep 17 00:00:00 2001 From: nanthony21 Date: Sat, 25 Feb 2017 23:21:53 -0600 Subject: [PATCH 1/5] Changed Joystick._exponential from bool to float. It can now be set between 0 and -0.5 by user using a slider. --- src/Joystick/Joystick.cc | 20 ++++++++++---------- src/Joystick/Joystick.h | 10 +++++----- src/VehicleSetup/JoystickConfig.qml | 13 ++++++++++++- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/Joystick/Joystick.cc b/src/Joystick/Joystick.cc index 36d8572..3b95e61 100644 --- a/src/Joystick/Joystick.cc +++ b/src/Joystick/Joystick.cc @@ -55,7 +55,7 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int hatC , _rgButtonValues(NULL) , _lastButtonBits(0) , _throttleMode(ThrottleModeCenterZero) - , _exponential(false) + , _exponential(0) , _accumulator(false) , _deadband(false) , _activeVehicle(NULL) @@ -109,7 +109,7 @@ void Joystick::_setDefaultCalibration(void) { _rgFunctionAxis[yawFunction] = 0; _rgFunctionAxis[throttleFunction] = 1; - _exponential = false; + _exponential = 0; _accumulator = false; _deadband = false; _throttleMode = ThrottleModeCenterZero; @@ -162,7 +162,7 @@ void Joystick::_loadSettings(void) qCDebug(JoystickLog) << "_loadSettings " << _name; _calibrated = settings.value(_calibratedSettingsKey, false).toBool(); - _exponential = settings.value(_exponentialSettingsKey, false).toBool(); + _exponential = settings.value(_exponentialSettingsKey, 0).toFloat(); _accumulator = settings.value(_accumulatorSettingsKey, false).toBool(); _deadband = settings.value(_deadbandSettingsKey, false).toBool(); @@ -443,16 +443,16 @@ void Joystick::run(void) yaw = std::max(-1.0f, std::min(tanf(asinf(yaw_limited)), 1.0f)); throttle = std::max(-1.0f, std::min(tanf(asinf(throttle_limited)), 1.0f)); - if ( _exponential ) { + if ( _exponential != 0 ) { // Exponential (0% to -50% range like most RC radios) // 0 for no exponential // -0.5 for strong exponential - float expo = -0.35f; + //float expo = -0.35f; // Calculate new RPY with exponential applied - roll = -expo*powf(roll,3) + (1+expo)*roll; - pitch = -expo*powf(pitch,3) + (1+expo)*pitch; - yaw = -expo*powf(yaw,3) + (1+expo)*yaw; + roll = -_exponential*powf(roll,3) + (1+_exponential)*roll; + pitch = -_exponential*powf(pitch,3) + (1+_exponential)*pitch; + yaw = -_exponential*powf(yaw,3) + (1+_exponential)*yaw; } // Adjust throttle to 0:1 range @@ -682,12 +682,12 @@ void Joystick::setThrottleMode(int mode) emit throttleModeChanged(_throttleMode); } -bool Joystick::exponential(void) +float Joystick::exponential(void) { return _exponential; } -void Joystick::setExponential(bool expo) +void Joystick::setExponential(float expo) { _exponential = expo; diff --git a/src/Joystick/Joystick.h b/src/Joystick/Joystick.h index 10d65fb..f23b491 100644 --- a/src/Joystick/Joystick.h +++ b/src/Joystick/Joystick.h @@ -72,7 +72,7 @@ public: Q_INVOKABLE QString getButtonAction(int button); Q_PROPERTY(int throttleMode READ throttleMode WRITE setThrottleMode NOTIFY throttleModeChanged) - Q_PROPERTY(bool 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 requiresCalibration READ requiresCalibration CONSTANT) @@ -106,8 +106,8 @@ public: int throttleMode(void); void setThrottleMode(int mode); - bool exponential(void); - void setExponential(bool expo); + float exponential(void); + void setExponential(float expo); bool accumulator(void); void setAccumulator(bool accu); @@ -141,7 +141,7 @@ signals: void throttleModeChanged(int mode); - void exponentialChanged(bool exponential); + void exponentialChanged(float exponential); void accumulatorChanged(bool accumulator); @@ -206,7 +206,7 @@ protected: ThrottleMode_t _throttleMode; - bool _exponential; + float _exponential; bool _accumulator; bool _deadband; diff --git a/src/VehicleSetup/JoystickConfig.qml b/src/VehicleSetup/JoystickConfig.qml index 3ac79d4..a87e865 100644 --- a/src/VehicleSetup/JoystickConfig.qml +++ b/src/VehicleSetup/JoystickConfig.qml @@ -456,12 +456,23 @@ SetupPage { Column { spacing: ScreenTools.defaultFontPixelHeight / 3 - QGCCheckBox { + /*QGCCheckBox { id: exponential checked: _activeJoystick ? _activeJoystick.exponential : false text: qsTr("Use exponential curve on roll, pitch, yaw") onClicked: _activeJoystick.exponential = checked + }*/ + QGCSlider { + id: expoSlider + value: -_activeJoystick.exponential + minimumValue: 0 + maximumValue: 0.5 + Binding { + target: _activeJoystick + property: "exponential" + value:-expoSlider.value + } } } From cb75acef2f24b344f201b2a78057f5b12110d420 Mon Sep 17 00:00:00 2001 From: Nick Anthony Date: Sun, 26 Feb 2017 02:07:22 -0600 Subject: [PATCH 2/5] Added labels to the exponential slider --- src/VehicleSetup/JoystickConfig.qml | 39 ++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/VehicleSetup/JoystickConfig.qml b/src/VehicleSetup/JoystickConfig.qml index a87e865..c926062 100644 --- a/src/VehicleSetup/JoystickConfig.qml +++ b/src/VehicleSetup/JoystickConfig.qml @@ -456,22 +456,29 @@ SetupPage { Column { spacing: ScreenTools.defaultFontPixelHeight / 3 - /*QGCCheckBox { - id: exponential - checked: _activeJoystick ? _activeJoystick.exponential : false - text: qsTr("Use exponential curve on roll, pitch, yaw") - - onClicked: _activeJoystick.exponential = checked - }*/ - QGCSlider { - id: expoSlider - value: -_activeJoystick.exponential - minimumValue: 0 - maximumValue: 0.5 - Binding { - target: _activeJoystick - property: "exponential" - value:-expoSlider.value + QGCLabel { + id: expoSliderLabel + text: qsTr("Exponential:") + } + + Row { + + QGCSlider { + id: expoSlider + value: -_activeJoystick.exponential + minimumValue: 0 + maximumValue: 0.75 + + Binding { + target: _activeJoystick + property: "exponential" + value:-expoSlider.value + } + } + + QGCLabel { + id: expoSliderIndicator + text: expoSlider.value.toFixed(2) } } } From 867596802f1c4ed8e49d6e79aac7bf89647b67d6 Mon Sep 17 00:00:00 2001 From: nanthony21 Date: Mon, 13 Mar 2017 21:31:13 -0500 Subject: [PATCH 3/5] Fixed binding loop --- src/VehicleSetup/JoystickConfig.qml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/VehicleSetup/JoystickConfig.qml b/src/VehicleSetup/JoystickConfig.qml index c926062..467bde2 100644 --- a/src/VehicleSetup/JoystickConfig.qml +++ b/src/VehicleSetup/JoystickConfig.qml @@ -462,18 +462,13 @@ SetupPage { } Row { - QGCSlider { id: expoSlider - value: -_activeJoystick.exponential minimumValue: 0 maximumValue: 0.75 - Binding { - target: _activeJoystick - property: "exponential" - value:-expoSlider.value - } + Component.onCompleted: value=-_activeJoystick.exponential + onValueChanged: _activeJoystick.exponential=-value } QGCLabel { From 08b2f4c4abc05da1e5a5912a040b4722978f5477 Mon Sep 17 00:00:00 2001 From: nanthony21 Date: Mon, 13 Mar 2017 22:00:26 -0500 Subject: [PATCH 4/5] Changed comments --- src/Joystick/Joystick.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Joystick/Joystick.cc b/src/Joystick/Joystick.cc index 3b95e61..0ba928d 100644 --- a/src/Joystick/Joystick.cc +++ b/src/Joystick/Joystick.cc @@ -445,9 +445,7 @@ void Joystick::run(void) if ( _exponential != 0 ) { // Exponential (0% to -50% range like most RC radios) - // 0 for no exponential - // -0.5 for strong exponential - //float expo = -0.35f; + //_exponential is set by a slider in joystickConfig.qml // Calculate new RPY with exponential applied roll = -_exponential*powf(roll,3) + (1+_exponential)*roll; From 1cdfd63640e175eb723a1bee7465f0f466556207 Mon Sep 17 00:00:00 2001 From: Nick Anthony Date: Fri, 24 Mar 2017 21:52:16 -0500 Subject: [PATCH 5/5] Re-added private import to fix QGCSlider --- src/QmlControls/QGCSlider.qml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/QmlControls/QGCSlider.qml b/src/QmlControls/QGCSlider.qml index 1bbd2f1..6d4824b 100644 --- a/src/QmlControls/QGCSlider.qml +++ b/src/QmlControls/QGCSlider.qml @@ -13,6 +13,7 @@ import QtQuick.Controls.Styles 1.4 import QGroundControl.Palette 1.0 import QGroundControl.ScreenTools 1.0 +import QtQuick.Controls.Private 1.0 Slider { property var _qgcPal: QGCPalette { colorGroupEnabled: enabled }