From 8c1cbc6dd6bc94fbb459d2fed45c6146ed7015b2 Mon Sep 17 00:00:00 2001 From: Gregory Dymarek Date: Tue, 11 Oct 2016 21:25:09 +0100 Subject: [PATCH 1/5] Implementing throttle axis accumulator with deadband support --- src/Joystick/Joystick.cc | 49 ++++++++++++++++++++++++++-- src/Joystick/Joystick.h | 9 +++++ src/VehicleSetup/JoystickConfig.qml | 14 ++++++++ src/VehicleSetup/JoystickConfigController.cc | 15 ++++++--- src/VehicleSetup/JoystickConfigController.h | 1 + 5 files changed, 80 insertions(+), 8 deletions(-) diff --git a/src/Joystick/Joystick.cc b/src/Joystick/Joystick.cc index 4c5fc64..b241e22 100644 --- a/src/Joystick/Joystick.cc +++ b/src/Joystick/Joystick.cc @@ -23,6 +23,7 @@ const char* Joystick::_calibratedSettingsKey = "Calibrated1"; // Increment const char* Joystick::_buttonActionSettingsKey = "ButtonActionName%1"; const char* Joystick::_throttleModeSettingsKey = "ThrottleMode"; const char* Joystick::_exponentialSettingsKey = "Exponential"; +const char* Joystick::_accumulatorSettingsKey = "Accumulator"; const char* Joystick::_rgFunctionSettingsKey[Joystick::maxFunction] = { "RollAxis", @@ -46,6 +47,7 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int hatC , _lastButtonBits(0) , _throttleMode(ThrottleModeCenterZero) , _exponential(false) + , _accumulator(false) , _activeVehicle(NULL) , _pollingStartedForCalibration(false) , _multiVehicleManager(multiVehicleManager) @@ -86,6 +88,7 @@ void Joystick::_loadSettings(void) _calibrated = settings.value(_calibratedSettingsKey, false).toBool(); _exponential = settings.value(_exponentialSettingsKey, false).toBool(); + _accumulator = settings.value(_accumulatorSettingsKey, false).toBool(); _throttleMode = (ThrottleMode_t)settings.value(_throttleModeSettingsKey, ThrottleModeCenterZero).toInt(&convertOk); badSettings |= !convertOk; @@ -96,6 +99,7 @@ void Joystick::_loadSettings(void) QString maxTpl ("Axis%1Max"); QString trimTpl ("Axis%1Trim"); QString revTpl ("Axis%1Rev"); + QString deadbndTpl ("Axis%1Deadbnd"); for (int axis=0; axis<_axisCount; axis++) { Calibration_t* calibration = &_rgCalibration[axis]; @@ -109,9 +113,13 @@ void Joystick::_loadSettings(void) calibration->max = settings.value(maxTpl.arg(axis), 32767).toInt(&convertOk); badSettings |= !convertOk; + calibration->deadband = settings.value(deadbndTpl.arg(axis), 0).toInt(&convertOk); + badSettings |= !convertOk; + calibration->reversed = settings.value(revTpl.arg(axis), false).toBool(); - qCDebug(JoystickLog) << "_loadSettings axis:min:max:trim:reversed:badsettings" << axis << calibration->min << calibration->max << calibration->center << calibration->reversed << badSettings; + + qCDebug(JoystickLog) << "_loadSettings axis:min:max:trim:reversed:badsettings" << axis << calibration->min << calibration->max << calibration->center << calibration->reversed << calibration->deadband << badSettings; } for (int function=0; functionmin); settings.setValue(maxTpl.arg(axis), calibration->max); settings.setValue(revTpl.arg(axis), calibration->reversed); + settings.setValue(deadbndTpl.arg(axis), calibration->deadband); qCDebug(JoystickLog) << "_saveSettings name:axis:min:max:trim:reversed" << _name @@ -168,7 +179,8 @@ void Joystick::_saveSettings(void) << calibration->min << calibration->max << calibration->center - << calibration->reversed; + << calibration->reversed + << calibration->deadband; } for (int function=0; function calibration.center) { axisBasis = 1.0f; valueNormalized = value - calibration.center; @@ -199,6 +213,13 @@ float Joystick::_adjustRange(int value, Calibration_t calibration) axisLength = calibration.center - calibration.min; } + if (_accumulator) {//deadband will be applied only in accumulator mode + int deadband = calibration.deadband*1.5; //we are increasing deadband to accommodate slight variations + if (valueNormalized>deadband) valueNormalized-=deadband; + else if (valueNormalized<-deadband) valueNormalized+=deadband; + else valueNormalized = 0.f; + } + float axisPercent = valueNormalized / axisLength; float correctedValue = axisBasis * axisPercent; @@ -214,7 +235,7 @@ float Joystick::_adjustRange(int value, Calibration_t calibration) << calibration.min << calibration.max << calibration.center - << calibration.center + << calibration.deadband << axisBasis << valueNormalized << axisLength; @@ -276,6 +297,15 @@ void Joystick::run(void) axis = _rgFunctionAxis[throttleFunction]; float throttle = _adjustRange(_rgAxisValues[axis], _rgCalibration[axis]); + if ( _accumulator ) { + static float throttle_accu = 0.f; + + throttle_accu += throttle*(40/1000.f); //for throttle to change from min to max it will take 1000ms (40ms is a loop time) + + throttle_accu = std::max(static_cast(-1.f), std::min(throttle_accu, static_cast(1.f))); + throttle = throttle_accu; + } + float roll_limited = std::max(static_cast(-M_PI_4), std::min(roll, static_cast(M_PI_4))); float pitch_limited = std::max(static_cast(-M_PI_4), std::min(pitch, static_cast(M_PI_4))); float yaw_limited = std::max(static_cast(-M_PI_4), std::min(yaw, static_cast(M_PI_4))); @@ -529,6 +559,19 @@ void Joystick::setExponential(bool expo) emit exponentialChanged(_exponential); } +bool Joystick::accumulator(void) +{ + return _accumulator; +} + +void Joystick::setAccumulator(bool accu) +{ + _accumulator = accu; + + _saveSettings(); + emit accumulatorChanged(_accumulator); +} + void Joystick::startCalibrationMode(CalibrationMode_t mode) { if (mode == CalibrationModeOff) { diff --git a/src/Joystick/Joystick.h b/src/Joystick/Joystick.h index bc32bc6..81ff52b 100644 --- a/src/Joystick/Joystick.h +++ b/src/Joystick/Joystick.h @@ -34,6 +34,7 @@ public: int min; int max; int center; + int deadband; bool reversed; } Calibration_t; @@ -66,6 +67,7 @@ public: Q_PROPERTY(int throttleMode READ throttleMode WRITE setThrottleMode NOTIFY throttleModeChanged) Q_PROPERTY(int exponential READ exponential WRITE setExponential NOTIFY exponentialChanged) + Q_PROPERTY(int accumulator READ accumulator WRITE setAccumulator NOTIFY accumulatorChanged) // Property accessors @@ -93,6 +95,9 @@ public: bool exponential(void); void setExponential(bool expo); + bool accumulator(void); + void setAccumulator(bool accu); + typedef enum { CalibrationModeOff, // Not calibrating CalibrationModeMonitor, // Monitors are active, continue to send to vehicle if already polling @@ -118,6 +123,8 @@ signals: void exponentialChanged(bool exponential); + void accumulatorChanged(bool accumulator); + void enabledChanged(bool enabled); /// Signal containing new joystick information @@ -175,6 +182,7 @@ protected: ThrottleMode_t _throttleMode; bool _exponential; + bool _accumulator; Vehicle* _activeVehicle; bool _pollingStartedForCalibration; @@ -189,6 +197,7 @@ private: static const char* _buttonActionSettingsKey; static const char* _throttleModeSettingsKey; static const char* _exponentialSettingsKey; + static const char* _accumulatorSettingsKey; }; #endif diff --git a/src/VehicleSetup/JoystickConfig.qml b/src/VehicleSetup/JoystickConfig.qml index 45128a0..1464152 100644 --- a/src/VehicleSetup/JoystickConfig.qml +++ b/src/VehicleSetup/JoystickConfig.qml @@ -382,6 +382,20 @@ SetupPage { onClicked: _activeJoystick.throttleMode = 0 } + Row { + width: parent.width + spacing: ScreenTools.defaultFontPixelWidth + visible: _activeJoystick.throttleMode == 0 + + QGCCheckBox { + id: accumulator + checked: _activeJoystick.accumulator + text: qsTr("Use accumulator on throttle") + + onClicked: _activeJoystick.accumulator = checked + } + } + QGCRadioButton { exclusiveGroup: throttleModeExclusiveGroup text: qsTr("Full down stick is zero throttle") diff --git a/src/VehicleSetup/JoystickConfigController.cc b/src/VehicleSetup/JoystickConfigController.cc index 81da51b..acfefcc 100644 --- a/src/VehicleSetup/JoystickConfigController.cc +++ b/src/VehicleSetup/JoystickConfigController.cc @@ -228,12 +228,13 @@ void JoystickConfigController::_saveAllTrims(void) void JoystickConfigController::_inputCenterWaitBegin(Joystick::AxisFunction_t function, int axis, int value) { Q_UNUSED(function); - Q_UNUSED(axis); - Q_UNUSED(value); - - // FIXME: Doesn't wait for center - + _rgAxisInfo[axis].deadband = std::max(abs(value),_rgAxisInfo[axis].deadband); _nextButton->setEnabled(true); + + // FIXME: Doesn't wait for center + // FIXME: Ideally the deadband should be probed only around the center + + qCDebug(JoystickConfigControllerLog) << "Axis:" << axis << "Deadband:" << _rgAxisInfo[axis].deadband; } bool JoystickConfigController::_stickSettleComplete(int axis, int value) @@ -420,6 +421,7 @@ void JoystickConfigController::_resetInternalCalibrationValues(void) struct AxisInfo* info = &_rgAxisInfo[i]; info->function = Joystick::maxFunction; info->reversed = false; + info->deadband = 0; info->axisMin = JoystickConfigController::_calCenterPoint; info->axisMax = JoystickConfigController::_calCenterPoint; info->axisTrim = JoystickConfigController::_calCenterPoint; @@ -457,6 +459,7 @@ void JoystickConfigController::_setInternalCalibrationValuesFromSettings(void) info->axisMin = calibration.min; info->axisMax = calibration.max; info->reversed = calibration.reversed; + info->deadband = calibration.deadband; qCDebug(JoystickConfigControllerLog) << "Read settings name:axis:min:max:trim:reversed" << joystick->name() << axis << info->axisMin << info->axisMax << info->axisTrim << info->reversed; } @@ -512,6 +515,7 @@ void JoystickConfigController::_validateCalibration(void) info->axisMin = _calDefaultMinValue; info->axisMax = _calDefaultMaxValue; info->axisTrim = info->axisMin + ((info->axisMax - info->axisMin) / 2); + info->deadband = 0; info->reversed = false; } } @@ -534,6 +538,7 @@ void JoystickConfigController::_writeCalibration(void) calibration.min = info->axisMin; calibration.max = info->axisMax; calibration.reversed = info->reversed; + calibration.deadband = info->deadband; joystick->setCalibration(axis, calibration); } diff --git a/src/VehicleSetup/JoystickConfigController.h b/src/VehicleSetup/JoystickConfigController.h index 231a130..9ae564c 100644 --- a/src/VehicleSetup/JoystickConfigController.h +++ b/src/VehicleSetup/JoystickConfigController.h @@ -144,6 +144,7 @@ private: int axisMin; ///< Minimum axis value int axisMax; ///< Maximum axis value int axisTrim; ///< Trim position + int deadband; ///< Deadband }; Joystick* _activeJoystick; From 6d9fb038ca5cd438096171d556da9aaf6477c753 Mon Sep 17 00:00:00 2001 From: Gregory Dymarek Date: Fri, 14 Oct 2016 10:23:22 +0100 Subject: [PATCH 2/5] Cleanup & Sync --- src/Joystick/Joystick.cc | 24 +++++++-- src/Joystick/Joystick.h | 8 +++ src/VehicleSetup/JoystickConfig.qml | 49 +++++++++++++++-- src/VehicleSetup/JoystickConfigController.cc | 81 ++++++++++++++++++++++++++-- src/VehicleSetup/JoystickConfigController.h | 26 +++++++-- 5 files changed, 172 insertions(+), 16 deletions(-) diff --git a/src/Joystick/Joystick.cc b/src/Joystick/Joystick.cc index b241e22..ddcbf36 100644 --- a/src/Joystick/Joystick.cc +++ b/src/Joystick/Joystick.cc @@ -24,6 +24,7 @@ const char* Joystick::_buttonActionSettingsKey = "ButtonActionName%1"; const char* Joystick::_throttleModeSettingsKey = "ThrottleMode"; const char* Joystick::_exponentialSettingsKey = "Exponential"; const char* Joystick::_accumulatorSettingsKey = "Accumulator"; +const char* Joystick::_deadbandSettingsKey = "Deadband"; const char* Joystick::_rgFunctionSettingsKey[Joystick::maxFunction] = { "RollAxis", @@ -48,6 +49,7 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int hatC , _throttleMode(ThrottleModeCenterZero) , _exponential(false) , _accumulator(false) + , _deadband(false) , _activeVehicle(NULL) , _pollingStartedForCalibration(false) , _multiVehicleManager(multiVehicleManager) @@ -89,6 +91,7 @@ void Joystick::_loadSettings(void) _calibrated = settings.value(_calibratedSettingsKey, false).toBool(); _exponential = settings.value(_exponentialSettingsKey, false).toBool(); _accumulator = settings.value(_accumulatorSettingsKey, false).toBool(); + _deadband = settings.value(_deadbandSettingsKey, false).toBool(); _throttleMode = (ThrottleMode_t)settings.value(_throttleModeSettingsKey, ThrottleModeCenterZero).toInt(&convertOk); badSettings |= !convertOk; @@ -154,6 +157,7 @@ void Joystick::_saveSettings(void) settings.setValue(_calibratedSettingsKey, _calibrated); settings.setValue(_exponentialSettingsKey, _exponential); settings.setValue(_accumulatorSettingsKey, _accumulator); + settings.setValue(_deadbandSettingsKey, _deadband); settings.setValue(_throttleModeSettingsKey, _throttleMode); qCDebug(JoystickLog) << "_saveSettings calibrated:throttlemode" << _calibrated << _throttleMode; @@ -213,10 +217,9 @@ float Joystick::_adjustRange(int value, Calibration_t calibration) axisLength = calibration.center - calibration.min; } - if (_accumulator) {//deadband will be applied only in accumulator mode - int deadband = calibration.deadband*1.5; //we are increasing deadband to accommodate slight variations - if (valueNormalized>deadband) valueNormalized-=deadband; - else if (valueNormalized<-deadband) valueNormalized+=deadband; + if (_deadband) { + if (valueNormalized>calibration.deadband) valueNormalized-=calibration.deadband; + else if (valueNormalized<-calibration.deadband) valueNormalized+=calibration.deadband; else valueNormalized = 0.f; } @@ -572,6 +575,19 @@ void Joystick::setAccumulator(bool accu) emit accumulatorChanged(_accumulator); } +bool Joystick::deadband(void) +{ + return _deadband; +} + +void Joystick::setDeadband(bool deadband) +{ + _deadband = deadband; + + _saveSettings(); + emit deadbandChanged(_deadband); +} + void Joystick::startCalibrationMode(CalibrationMode_t mode) { if (mode == CalibrationModeOff) { diff --git a/src/Joystick/Joystick.h b/src/Joystick/Joystick.h index 81ff52b..89470a4 100644 --- a/src/Joystick/Joystick.h +++ b/src/Joystick/Joystick.h @@ -68,6 +68,7 @@ public: Q_PROPERTY(int throttleMode READ throttleMode WRITE setThrottleMode NOTIFY throttleModeChanged) Q_PROPERTY(int exponential READ exponential WRITE setExponential NOTIFY exponentialChanged) Q_PROPERTY(int accumulator READ accumulator WRITE setAccumulator NOTIFY accumulatorChanged) + Q_PROPERTY(int deadband READ deadband WRITE setDeadband NOTIFY deadbandChanged) // Property accessors @@ -98,6 +99,9 @@ public: bool accumulator(void); void setAccumulator(bool accu); + bool deadband(void); + void setDeadband(bool accu); + typedef enum { CalibrationModeOff, // Not calibrating CalibrationModeMonitor, // Monitors are active, continue to send to vehicle if already polling @@ -125,6 +129,8 @@ signals: void accumulatorChanged(bool accumulator); + void deadbandChanged(bool deadband); + void enabledChanged(bool enabled); /// Signal containing new joystick information @@ -183,6 +189,7 @@ protected: bool _exponential; bool _accumulator; + bool _deadband; Vehicle* _activeVehicle; bool _pollingStartedForCalibration; @@ -198,6 +205,7 @@ private: static const char* _throttleModeSettingsKey; static const char* _exponentialSettingsKey; static const char* _accumulatorSettingsKey; + static const char* _deadbandSettingsKey; }; #endif diff --git a/src/VehicleSetup/JoystickConfig.qml b/src/VehicleSetup/JoystickConfig.qml index 1464152..9c5ea13 100644 --- a/src/VehicleSetup/JoystickConfig.qml +++ b/src/VehicleSetup/JoystickConfig.qml @@ -72,7 +72,7 @@ SetupPage { Item { property int axisValue: 0 - + property int deadbandValue: 0 property int __lastAxisValue: 0 readonly property int __axisValueMaxJitter: 100 @@ -87,6 +87,20 @@ SetupPage { color: __barColor } + // Deadband + Rectangle { + id: deadbandBar + anchors.verticalCenter: parent.verticalCenter + x: _deadbandPosition + width: _deadbandWidth + height: parent.height / 2 + color: "#8c161a" + + property real _percentDeadband: ((2 * deadbandValue) / (32768.0 * 2)) + property real _deadbandWidth: parent.width * _percentDeadband + property real _deadbandPosition: (parent.width - _deadbandWidth) / 2 + } + // Center point Rectangle { anchors.horizontalCenter: parent.horizontalCenter @@ -126,13 +140,15 @@ SetupPage { duration: 1500 } - /* + // Axis value debugger + /* QGCLabel { anchors.fill: parent text: axisValue } */ + } } // Component - axisMonitorDisplayComponent @@ -180,6 +196,8 @@ SetupPage { target: controller onRollAxisValueChanged: rollLoader.item.axisValue = value + + onRollAxisDeadbandChanged: rollLoader.item.deadbandValue = value } } @@ -210,6 +228,9 @@ SetupPage { target: controller onPitchAxisValueChanged: pitchLoader.item.axisValue = value + + onPitchAxisDeadbandChanged: pitchLoader.item.deadbandValue = value + } } @@ -240,6 +261,8 @@ SetupPage { target: controller onYawAxisValueChanged: yawLoader.item.axisValue = value + + onYawAxisDeadbandChanged: yawLoader.item.deadbandValue = value } } @@ -270,6 +293,8 @@ SetupPage { target: controller onThrottleAxisValueChanged: throttleLoader.item.axisValue = value + + onThrottleAxisDeadbandChanged: throttleLoader.item.deadbandValue = value } } } // Column - Attitude Control labels @@ -383,6 +408,7 @@ SetupPage { } Row { + x: 20 width: parent.width spacing: ScreenTools.defaultFontPixelWidth visible: _activeJoystick.throttleMode == 0 @@ -390,12 +416,27 @@ SetupPage { QGCCheckBox { id: accumulator checked: _activeJoystick.accumulator - text: qsTr("Use accumulator on throttle") + text: qsTr("Spring on throttle support") onClicked: _activeJoystick.accumulator = checked } } + Row { + x: 20 + width: parent.width + spacing: ScreenTools.defaultFontPixelWidth + visible: _activeJoystick.throttleMode == 0 + + QGCCheckBox { + id: deadband + checked: _activeJoystick.deadband + text: qsTr("Deadband (requires re-calibration)") + + onClicked: _activeJoystick.deadband = checked + } + } + QGCRadioButton { exclusiveGroup: throttleModeExclusiveGroup text: qsTr("Full down stick is zero throttle") @@ -711,3 +752,5 @@ SetupPage { } // Item } // Component - pageComponent } // SetupPage + + diff --git a/src/VehicleSetup/JoystickConfigController.cc b/src/VehicleSetup/JoystickConfigController.cc index acfefcc..7864c23 100644 --- a/src/VehicleSetup/JoystickConfigController.cc +++ b/src/VehicleSetup/JoystickConfigController.cc @@ -224,17 +224,49 @@ void JoystickConfigController::_saveAllTrims(void) _advanceState(); } +void JoystickConfigController::_axisDeadbandChanged(int axis, int value) +{ + value = abs(value)<_calValidMaxValue?abs(value):_calValidMaxValue; + + if (value>_rgAxisInfo[axis].deadband) { + _rgAxisInfo[axis].deadband = value; + + switch (_rgAxisInfo[axis].function) { + case Joystick::rollFunction: + emit rollAxisDeadbandChanged(_rgAxisInfo[axis].deadband); + break; + case Joystick::pitchFunction: + emit pitchAxisDeadbandChanged(_rgAxisInfo[axis].deadband); + break; + case Joystick::yawFunction: + emit yawAxisDeadbandChanged(_rgAxisInfo[axis].deadband); + break; + case Joystick::throttleFunction: + emit throttleAxisDeadbandChanged(_rgAxisInfo[axis].deadband); + break; + default: + break; + } + qCDebug(JoystickConfigControllerLog) << "Axis:" << axis << "Deadband:" << _rgAxisInfo[axis].deadband; + } +} + /// @brief Waits for the sticks to be centered, enabling Next when done. void JoystickConfigController::_inputCenterWaitBegin(Joystick::AxisFunction_t function, int axis, int value) { Q_UNUSED(function); - _rgAxisInfo[axis].deadband = std::max(abs(value),_rgAxisInfo[axis].deadband); + + //sensing deadband + if (_activeJoystick->deadband()) { + if (abs(value)*1.5>_rgAxisInfo[axis].deadband) { + _axisDeadbandChanged(axis,abs(value)*1.5); + } + } + _nextButton->setEnabled(true); // FIXME: Doesn't wait for center // FIXME: Ideally the deadband should be probed only around the center - - qCDebug(JoystickConfigControllerLog) << "Axis:" << axis << "Deadband:" << _rgAxisInfo[axis].deadband; } bool JoystickConfigController::_stickSettleComplete(int axis, int value) @@ -460,7 +492,7 @@ void JoystickConfigController::_setInternalCalibrationValuesFromSettings(void) info->axisMax = calibration.max; info->reversed = calibration.reversed; info->deadband = calibration.deadband; - + qCDebug(JoystickConfigControllerLog) << "Read settings name:axis:min:max:trim:reversed" << joystick->name() << axis << info->axisMin << info->axisMax << info->axisTrim << info->reversed; } @@ -669,6 +701,42 @@ int JoystickConfigController::throttleAxisValue(void) } } +int JoystickConfigController::rollAxisDeadband(void) +{ + if (_rgFunctionAxisMapping[Joystick::rollFunction] != _axisNoAxis) { + return _rgAxisInfo[_rgFunctionAxisMapping[Joystick::rollFunction]].deadband; + } else { + return 0; + } +} + +int JoystickConfigController::pitchAxisDeadband(void) +{ + if (_rgFunctionAxisMapping[Joystick::pitchFunction] != _axisNoAxis) { + return _rgAxisInfo[_rgFunctionAxisMapping[Joystick::pitchFunction]].deadband; + } else { + return 0; + } +} + +int JoystickConfigController::yawAxisDeadband(void) +{ + if (_rgFunctionAxisMapping[Joystick::yawFunction] != _axisNoAxis) { + return _rgAxisInfo[_rgFunctionAxisMapping[Joystick::yawFunction]].deadband; + } else { + return 0; + } +} + +int JoystickConfigController::throttleAxisDeadband(void) +{ + if (_rgFunctionAxisMapping[Joystick::throttleFunction] != _axisNoAxis) { + return _rgAxisInfo[_rgFunctionAxisMapping[Joystick::throttleFunction]].deadband; + } else { + return 0; + } +} + bool JoystickConfigController::rollAxisMapped(void) { return _rgFunctionAxisMapping[Joystick::rollFunction] != _axisNoAxis; @@ -736,6 +804,11 @@ void JoystickConfigController::_signalAllAttiudeValueChanges(void) emit pitchAxisReversedChanged(pitchAxisReversed()); emit yawAxisReversedChanged(yawAxisReversed()); emit throttleAxisReversedChanged(throttleAxisReversed()); + + emit rollAxisDeadbandChanged(rollAxisDeadband()); + emit pitchAxisDeadbandChanged(pitchAxisDeadband()); + emit yawAxisDeadbandChanged(yawAxisDeadband()); + emit throttleAxisDeadbandChanged(throttleAxisDeadband()); } void JoystickConfigController::_activeJoystickChanged(Joystick* joystick) diff --git a/src/VehicleSetup/JoystickConfigController.h b/src/VehicleSetup/JoystickConfigController.h index 9ae564c..07455e1 100644 --- a/src/VehicleSetup/JoystickConfigController.h +++ b/src/VehicleSetup/JoystickConfigController.h @@ -51,12 +51,17 @@ public: Q_PROPERTY(bool pitchAxisMapped READ pitchAxisMapped NOTIFY pitchAxisMappedChanged) Q_PROPERTY(bool yawAxisMapped READ yawAxisMapped NOTIFY yawAxisMappedChanged) Q_PROPERTY(bool throttleAxisMapped READ throttleAxisMapped NOTIFY throttleAxisMappedChanged) - + Q_PROPERTY(int rollAxisValue READ rollAxisValue NOTIFY rollAxisValueChanged) Q_PROPERTY(int pitchAxisValue READ pitchAxisValue NOTIFY pitchAxisValueChanged) Q_PROPERTY(int yawAxisValue READ yawAxisValue NOTIFY yawAxisValueChanged) Q_PROPERTY(int throttleAxisValue READ throttleAxisValue NOTIFY throttleAxisValueChanged) - + + Q_PROPERTY(int rollAxisDeadband READ rollAxisDeadband NOTIFY rollAxisDeadbandChanged) + Q_PROPERTY(int pitchAxisDeadband READ pitchAxisDeadband NOTIFY pitchAxisDeadbandChanged) + Q_PROPERTY(int yawAxisDeadband READ yawAxisDeadband NOTIFY yawAxisDeadbandChanged) + Q_PROPERTY(int throttleAxisDeadband READ throttleAxisDeadband NOTIFY throttleAxisDeadbandChanged) + Q_PROPERTY(int rollAxisReversed READ rollAxisReversed NOTIFY rollAxisReversedChanged) Q_PROPERTY(int pitchAxisReversed READ pitchAxisReversed NOTIFY pitchAxisReversedChanged) Q_PROPERTY(int yawAxisReversed READ yawAxisReversed NOTIFY yawAxisReversedChanged) @@ -68,12 +73,17 @@ public: Q_INVOKABLE void skipButtonClicked(void); Q_INVOKABLE void nextButtonClicked(void); Q_INVOKABLE void start(void); - + int rollAxisValue(void); int pitchAxisValue(void); int yawAxisValue(void); int throttleAxisValue(void); + int rollAxisDeadband(void); + int pitchAxisDeadband(void); + int yawAxisDeadband(void); + int throttleAxisDeadband(void); + bool rollAxisMapped(void); bool pitchAxisMapped(void); bool yawAxisMapped(void); @@ -88,7 +98,7 @@ public: signals: void axisValueChanged(int axis, int value); - + void rollAxisMappedChanged(bool mapped); void pitchAxisMappedChanged(bool mapped); void yawAxisMappedChanged(bool mapped); @@ -98,7 +108,12 @@ signals: void pitchAxisValueChanged(int value); void yawAxisValueChanged(int value); void throttleAxisValueChanged(int value); - + + void rollAxisDeadbandChanged(int value); + void pitchAxisDeadbandChanged(int value); + void yawAxisDeadbandChanged(int value); + void throttleAxisDeadbandChanged(int value); + void rollAxisReversedChanged(bool reversed); void pitchAxisReversedChanged(bool reversed); void yawAxisReversedChanged(bool reversed); @@ -112,6 +127,7 @@ signals: private slots: void _activeJoystickChanged(Joystick* joystick); void _axisValueChanged(int axis, int value); + void _axisDeadbandChanged(int axis, int value); private: /// @brief The states of the calibration state machine. From 8bc154ae36788dbd726d26e4fe9b9bd9423ba127 Mon Sep 17 00:00:00 2001 From: Gregory Dymarek Date: Sat, 15 Oct 2016 18:22:55 +0100 Subject: [PATCH 3/5] Making deadbands stupid-proof; general cleanup --- src/Joystick/Joystick.cc | 12 +++---- src/Joystick/Joystick.h | 7 ++-- src/VehicleSetup/JoystickConfig.qml | 6 ++-- src/VehicleSetup/JoystickConfigController.cc | 51 ++++++++++++---------------- src/VehicleSetup/JoystickConfigController.h | 9 ++++- 5 files changed, 40 insertions(+), 45 deletions(-) diff --git a/src/Joystick/Joystick.cc b/src/Joystick/Joystick.cc index ddcbf36..295b028 100644 --- a/src/Joystick/Joystick.cc +++ b/src/Joystick/Joystick.cc @@ -96,7 +96,7 @@ void Joystick::_loadSettings(void) _throttleMode = (ThrottleMode_t)settings.value(_throttleModeSettingsKey, ThrottleModeCenterZero).toInt(&convertOk); badSettings |= !convertOk; - qCDebug(JoystickLog) << "_loadSettings calibrated:throttlemode:exponential:badsettings" << _calibrated << _throttleMode << _exponential << badSettings; + qCDebug(JoystickLog) << "_loadSettings calibrated:throttlemode:exponential:deadband:badsettings" << _calibrated << _throttleMode << _exponential << _deadband << badSettings; QString minTpl ("Axis%1Min"); QString maxTpl ("Axis%1Max"); @@ -122,7 +122,7 @@ void Joystick::_loadSettings(void) calibration->reversed = settings.value(revTpl.arg(axis), false).toBool(); - qCDebug(JoystickLog) << "_loadSettings axis:min:max:trim:reversed:badsettings" << axis << calibration->min << calibration->max << calibration->center << calibration->reversed << calibration->deadband << badSettings; + qCDebug(JoystickLog) << "_loadSettings axis:min:max:trim:reversed:deadband:badsettings" << axis << calibration->min << calibration->max << calibration->center << calibration->reversed << calibration->deadband << badSettings; } for (int function=0; functionreversed); settings.setValue(deadbndTpl.arg(axis), calibration->deadband); - qCDebug(JoystickLog) << "_saveSettings name:axis:min:max:trim:reversed" + qCDebug(JoystickLog) << "_saveSettings name:axis:min:max:trim:reversed:deadband" << _name << axis << calibration->min @@ -232,12 +232,13 @@ float Joystick::_adjustRange(int value, Calibration_t calibration) } #if 0 - qCDebug(JoystickLog) << "_adjustRange corrected:value:min:max:center:reversed:basis:normalized:length" + qCDebug(JoystickLog) << "_adjustRange corrected:value:min:max:center:reversed:deadband:basis:normalized:length" << correctedValue << value << calibration.min << calibration.max << calibration.center + << calibration.reversed << calibration.deadband << axisBasis << valueNormalized @@ -585,7 +586,6 @@ void Joystick::setDeadband(bool deadband) _deadband = deadband; _saveSettings(); - emit deadbandChanged(_deadband); } void Joystick::startCalibrationMode(CalibrationMode_t mode) diff --git a/src/Joystick/Joystick.h b/src/Joystick/Joystick.h index 89470a4..10f9782 100644 --- a/src/Joystick/Joystick.h +++ b/src/Joystick/Joystick.h @@ -66,9 +66,8 @@ public: Q_INVOKABLE QString getButtonAction(int button); Q_PROPERTY(int throttleMode READ throttleMode WRITE setThrottleMode NOTIFY throttleModeChanged) - Q_PROPERTY(int exponential READ exponential WRITE setExponential NOTIFY exponentialChanged) - Q_PROPERTY(int accumulator READ accumulator WRITE setAccumulator NOTIFY accumulatorChanged) - Q_PROPERTY(int deadband READ deadband WRITE setDeadband NOTIFY deadbandChanged) + Q_PROPERTY(bool exponential READ exponential WRITE setExponential NOTIFY exponentialChanged) + Q_PROPERTY(bool accumulator READ accumulator WRITE setAccumulator NOTIFY accumulatorChanged) // Property accessors @@ -129,8 +128,6 @@ signals: void accumulatorChanged(bool accumulator); - void deadbandChanged(bool deadband); - void enabledChanged(bool enabled); /// Signal containing new joystick information diff --git a/src/VehicleSetup/JoystickConfig.qml b/src/VehicleSetup/JoystickConfig.qml index 9c5ea13..bb0563c 100644 --- a/src/VehicleSetup/JoystickConfig.qml +++ b/src/VehicleSetup/JoystickConfig.qml @@ -430,10 +430,10 @@ SetupPage { QGCCheckBox { id: deadband - checked: _activeJoystick.deadband - text: qsTr("Deadband (requires re-calibration)") + checked: controller.deadbandToggle + text: qsTr("Deadbands") - onClicked: _activeJoystick.deadband = checked + onClicked: controller.deadbandToggle = checked } } diff --git a/src/VehicleSetup/JoystickConfigController.cc b/src/VehicleSetup/JoystickConfigController.cc index 7864c23..505478b 100644 --- a/src/VehicleSetup/JoystickConfigController.cc +++ b/src/VehicleSetup/JoystickConfigController.cc @@ -210,6 +210,18 @@ void JoystickConfigController::cancelButtonClicked(void) _stopCalibration(); } +bool JoystickConfigController::getDeadbandToggle() { + return _activeJoystick->deadband(); +} + +void JoystickConfigController::setDeadbandToggle(bool deadband) { + _activeJoystick->setDeadband(deadband); + + _signalAllAttiudeValueChanges(); + + emit deadbandToggled(deadband); +} + void JoystickConfigController::_saveAllTrims(void) { // We save all trims as the first step. At this point no axes are mapped but it should still @@ -228,27 +240,9 @@ void JoystickConfigController::_axisDeadbandChanged(int axis, int value) { value = abs(value)<_calValidMaxValue?abs(value):_calValidMaxValue; - if (value>_rgAxisInfo[axis].deadband) { - _rgAxisInfo[axis].deadband = value; - - switch (_rgAxisInfo[axis].function) { - case Joystick::rollFunction: - emit rollAxisDeadbandChanged(_rgAxisInfo[axis].deadband); - break; - case Joystick::pitchFunction: - emit pitchAxisDeadbandChanged(_rgAxisInfo[axis].deadband); - break; - case Joystick::yawFunction: - emit yawAxisDeadbandChanged(_rgAxisInfo[axis].deadband); - break; - case Joystick::throttleFunction: - emit throttleAxisDeadbandChanged(_rgAxisInfo[axis].deadband); - break; - default: - break; - } - qCDebug(JoystickConfigControllerLog) << "Axis:" << axis << "Deadband:" << _rgAxisInfo[axis].deadband; - } + _rgAxisInfo[axis].deadband = value; + + qCDebug(JoystickConfigControllerLog) << "Axis:" << axis << "Deadband:" << _rgAxisInfo[axis].deadband; } /// @brief Waits for the sticks to be centered, enabling Next when done. @@ -257,16 +251,13 @@ void JoystickConfigController::_inputCenterWaitBegin(Joystick::AxisFunction_t fu Q_UNUSED(function); //sensing deadband - if (_activeJoystick->deadband()) { - if (abs(value)*1.5>_rgAxisInfo[axis].deadband) { - _axisDeadbandChanged(axis,abs(value)*1.5); - } + if (abs(value)*1.1f>_rgAxisInfo[axis].deadband) { //add 10% on top of existing deadband + _axisDeadbandChanged(axis,abs(value)*1.1f); } _nextButton->setEnabled(true); // FIXME: Doesn't wait for center - // FIXME: Ideally the deadband should be probed only around the center } bool JoystickConfigController::_stickSettleComplete(int axis, int value) @@ -703,7 +694,7 @@ int JoystickConfigController::throttleAxisValue(void) int JoystickConfigController::rollAxisDeadband(void) { - if (_rgFunctionAxisMapping[Joystick::rollFunction] != _axisNoAxis) { + if ((_rgFunctionAxisMapping[Joystick::rollFunction] != _axisNoAxis) && (_activeJoystick->deadband())) { return _rgAxisInfo[_rgFunctionAxisMapping[Joystick::rollFunction]].deadband; } else { return 0; @@ -712,7 +703,7 @@ int JoystickConfigController::rollAxisDeadband(void) int JoystickConfigController::pitchAxisDeadband(void) { - if (_rgFunctionAxisMapping[Joystick::pitchFunction] != _axisNoAxis) { + if ((_rgFunctionAxisMapping[Joystick::pitchFunction] != _axisNoAxis) && (_activeJoystick->deadband())) { return _rgAxisInfo[_rgFunctionAxisMapping[Joystick::pitchFunction]].deadband; } else { return 0; @@ -721,7 +712,7 @@ int JoystickConfigController::pitchAxisDeadband(void) int JoystickConfigController::yawAxisDeadband(void) { - if (_rgFunctionAxisMapping[Joystick::yawFunction] != _axisNoAxis) { + if ((_rgFunctionAxisMapping[Joystick::yawFunction] != _axisNoAxis) && (_activeJoystick->deadband())) { return _rgAxisInfo[_rgFunctionAxisMapping[Joystick::yawFunction]].deadband; } else { return 0; @@ -730,7 +721,7 @@ int JoystickConfigController::yawAxisDeadband(void) int JoystickConfigController::throttleAxisDeadband(void) { - if (_rgFunctionAxisMapping[Joystick::throttleFunction] != _axisNoAxis) { + if ((_rgFunctionAxisMapping[Joystick::throttleFunction] != _axisNoAxis) && (_activeJoystick->deadband())) { return _rgAxisInfo[_rgFunctionAxisMapping[Joystick::throttleFunction]].deadband; } else { return 0; diff --git a/src/VehicleSetup/JoystickConfigController.h b/src/VehicleSetup/JoystickConfigController.h index 07455e1..9b0a8c8 100644 --- a/src/VehicleSetup/JoystickConfigController.h +++ b/src/VehicleSetup/JoystickConfigController.h @@ -67,6 +67,8 @@ public: Q_PROPERTY(int yawAxisReversed READ yawAxisReversed NOTIFY yawAxisReversedChanged) Q_PROPERTY(int throttleAxisReversed READ throttleAxisReversed NOTIFY throttleAxisReversedChanged) + Q_PROPERTY(bool deadbandToggle READ getDeadbandToggle WRITE setDeadbandToggle NOTIFY deadbandToggled) + Q_PROPERTY(QString imageHelp MEMBER _imageHelp NOTIFY imageHelpChanged) Q_INVOKABLE void cancelButtonClicked(void); @@ -78,7 +80,7 @@ public: int pitchAxisValue(void); int yawAxisValue(void); int throttleAxisValue(void); - + int rollAxisDeadband(void); int pitchAxisDeadband(void); int yawAxisDeadband(void); @@ -94,6 +96,9 @@ public: bool yawAxisReversed(void); bool throttleAxisReversed(void); + bool getDeadbandToggle(void); + void setDeadbandToggle(bool); + int axisCount(void); signals: @@ -118,6 +123,8 @@ signals: void pitchAxisReversedChanged(bool reversed); void yawAxisReversedChanged(bool reversed); void throttleAxisReversedChanged(bool reversed); + + void deadbandToggled(bool value); void imageHelpChanged(QString source); From c8d39176306a6d265f128dd2f2a75feea6f6516e Mon Sep 17 00:00:00 2001 From: Gregory Dymarek Date: Sun, 16 Oct 2016 12:10:56 +0100 Subject: [PATCH 4/5] Changing label --- src/VehicleSetup/JoystickConfig.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VehicleSetup/JoystickConfig.qml b/src/VehicleSetup/JoystickConfig.qml index bb0563c..2a62c11 100644 --- a/src/VehicleSetup/JoystickConfig.qml +++ b/src/VehicleSetup/JoystickConfig.qml @@ -416,7 +416,7 @@ SetupPage { QGCCheckBox { id: accumulator checked: _activeJoystick.accumulator - text: qsTr("Spring on throttle support") + text: qsTr("Spring loaded throttle smoothing") onClicked: _activeJoystick.accumulator = checked } From 7fcae94cb75bebb93d6f453d22228986644aa692 Mon Sep 17 00:00:00 2001 From: Gregory Dymarek Date: Thu, 20 Oct 2016 10:45:24 +0100 Subject: [PATCH 5/5] Don't apply throttle deadband in ThrottleModeDownZero --- src/Joystick/Joystick.cc | 19 +++++++++++-------- src/Joystick/Joystick.h | 2 +- src/VehicleSetup/JoystickConfig.qml | 29 ++++++++++++++--------------- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/Joystick/Joystick.cc b/src/Joystick/Joystick.cc index 295b028..17ce67b 100644 --- a/src/Joystick/Joystick.cc +++ b/src/Joystick/Joystick.cc @@ -199,14 +199,12 @@ void Joystick::_saveSettings(void) } /// Adjust the raw axis value to the -1:1 range given calibration information -float Joystick::_adjustRange(int value, Calibration_t calibration) +float Joystick::_adjustRange(int value, Calibration_t calibration, bool withDeadbands) { float valueNormalized; float axisLength; float axisBasis; - - if (value > calibration.center) { axisBasis = 1.0f; valueNormalized = value - calibration.center; @@ -217,7 +215,7 @@ float Joystick::_adjustRange(int value, Calibration_t calibration) axisLength = calibration.center - calibration.min; } - if (_deadband) { + if (withDeadbands) { if (valueNormalized>calibration.deadband) valueNormalized-=calibration.deadband; else if (valueNormalized<-calibration.deadband) valueNormalized+=calibration.deadband; else valueNormalized = 0.f; @@ -290,16 +288,16 @@ void Joystick::run(void) if (_calibrationMode != CalibrationModeCalibrating) { int axis = _rgFunctionAxis[rollFunction]; - float roll = _adjustRange(_rgAxisValues[axis], _rgCalibration[axis]); + float roll = _adjustRange(_rgAxisValues[axis], _rgCalibration[axis], _deadband); axis = _rgFunctionAxis[pitchFunction]; - float pitch = _adjustRange(_rgAxisValues[axis], _rgCalibration[axis]); + float pitch = _adjustRange(_rgAxisValues[axis], _rgCalibration[axis], _deadband); axis = _rgFunctionAxis[yawFunction]; - float yaw = _adjustRange(_rgAxisValues[axis], _rgCalibration[axis]); + float yaw = _adjustRange(_rgAxisValues[axis], _rgCalibration[axis],_deadband); axis = _rgFunctionAxis[throttleFunction]; - float throttle = _adjustRange(_rgAxisValues[axis], _rgCalibration[axis]); + float throttle = _adjustRange(_rgAxisValues[axis], _rgCalibration[axis], _throttleMode==ThrottleModeDownZero?false:_deadband); if ( _accumulator ) { static float throttle_accu = 0.f; @@ -546,6 +544,11 @@ void Joystick::setThrottleMode(int mode) } _throttleMode = (ThrottleMode_t)mode; + + if (_throttleMode == ThrottleModeDownZero) { + setAccumulator(false); + } + _saveSettings(); emit throttleModeChanged(_throttleMode); } diff --git a/src/Joystick/Joystick.h b/src/Joystick/Joystick.h index 10f9782..c9915ea 100644 --- a/src/Joystick/Joystick.h +++ b/src/Joystick/Joystick.h @@ -143,7 +143,7 @@ signals: protected: void _saveSettings(void); void _loadSettings(void); - float _adjustRange(int value, Calibration_t calibration); + float _adjustRange(int value, Calibration_t calibration, bool withDeadbands); void _buttonAction(const QString& action); bool _validAxis(int axis); bool _validButton(int button); diff --git a/src/VehicleSetup/JoystickConfig.qml b/src/VehicleSetup/JoystickConfig.qml index 2a62c11..503c6be 100644 --- a/src/VehicleSetup/JoystickConfig.qml +++ b/src/VehicleSetup/JoystickConfig.qml @@ -422,21 +422,6 @@ SetupPage { } } - Row { - x: 20 - width: parent.width - spacing: ScreenTools.defaultFontPixelWidth - visible: _activeJoystick.throttleMode == 0 - - QGCCheckBox { - id: deadband - checked: controller.deadbandToggle - text: qsTr("Deadbands") - - onClicked: controller.deadbandToggle = checked - } - } - QGCRadioButton { exclusiveGroup: throttleModeExclusiveGroup text: qsTr("Full down stick is zero throttle") @@ -490,6 +475,20 @@ SetupPage { onActivated: _activeVehicle.joystickMode = index } } + + Row { + width: parent.width + spacing: ScreenTools.defaultFontPixelWidth + visible: advancedSettings.checked + + QGCCheckBox { + id: deadband + checked: controller.deadbandToggle + text: qsTr("Deadbands") + + onClicked: controller.deadbandToggle = checked + } + } } } // Column - left column