Commit 8bc154ae authored by Gregory Dymarek's avatar Gregory Dymarek

Making deadbands stupid-proof; general cleanup

parent da0b9168
...@@ -96,7 +96,7 @@ void Joystick::_loadSettings(void) ...@@ -96,7 +96,7 @@ void Joystick::_loadSettings(void)
_throttleMode = (ThrottleMode_t)settings.value(_throttleModeSettingsKey, ThrottleModeCenterZero).toInt(&convertOk); _throttleMode = (ThrottleMode_t)settings.value(_throttleModeSettingsKey, ThrottleModeCenterZero).toInt(&convertOk);
badSettings |= !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 minTpl ("Axis%1Min");
QString maxTpl ("Axis%1Max"); QString maxTpl ("Axis%1Max");
...@@ -122,7 +122,7 @@ void Joystick::_loadSettings(void) ...@@ -122,7 +122,7 @@ void Joystick::_loadSettings(void)
calibration->reversed = settings.value(revTpl.arg(axis), false).toBool(); 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; function<maxFunction; function++) { for (int function=0; function<maxFunction; function++) {
...@@ -160,7 +160,7 @@ void Joystick::_saveSettings(void) ...@@ -160,7 +160,7 @@ void Joystick::_saveSettings(void)
settings.setValue(_deadbandSettingsKey, _deadband); settings.setValue(_deadbandSettingsKey, _deadband);
settings.setValue(_throttleModeSettingsKey, _throttleMode); settings.setValue(_throttleModeSettingsKey, _throttleMode);
qCDebug(JoystickLog) << "_saveSettings calibrated:throttlemode" << _calibrated << _throttleMode; qCDebug(JoystickLog) << "_saveSettings calibrated:throttlemode:deadband" << _calibrated << _throttleMode << _deadband;
QString minTpl ("Axis%1Min"); QString minTpl ("Axis%1Min");
QString maxTpl ("Axis%1Max"); QString maxTpl ("Axis%1Max");
...@@ -177,7 +177,7 @@ void Joystick::_saveSettings(void) ...@@ -177,7 +177,7 @@ void Joystick::_saveSettings(void)
settings.setValue(revTpl.arg(axis), calibration->reversed); settings.setValue(revTpl.arg(axis), calibration->reversed);
settings.setValue(deadbndTpl.arg(axis), calibration->deadband); 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 << _name
<< axis << axis
<< calibration->min << calibration->min
...@@ -232,12 +232,13 @@ float Joystick::_adjustRange(int value, Calibration_t calibration) ...@@ -232,12 +232,13 @@ float Joystick::_adjustRange(int value, Calibration_t calibration)
} }
#if 0 #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 << correctedValue
<< value << value
<< calibration.min << calibration.min
<< calibration.max << calibration.max
<< calibration.center << calibration.center
<< calibration.reversed
<< calibration.deadband << calibration.deadband
<< axisBasis << axisBasis
<< valueNormalized << valueNormalized
...@@ -585,7 +586,6 @@ void Joystick::setDeadband(bool deadband) ...@@ -585,7 +586,6 @@ void Joystick::setDeadband(bool deadband)
_deadband = deadband; _deadband = deadband;
_saveSettings(); _saveSettings();
emit deadbandChanged(_deadband);
} }
void Joystick::startCalibrationMode(CalibrationMode_t mode) void Joystick::startCalibrationMode(CalibrationMode_t mode)
......
...@@ -66,9 +66,8 @@ public: ...@@ -66,9 +66,8 @@ 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(int exponential READ exponential WRITE setExponential NOTIFY exponentialChanged) Q_PROPERTY(bool exponential READ exponential WRITE setExponential NOTIFY exponentialChanged)
Q_PROPERTY(int accumulator READ accumulator WRITE setAccumulator NOTIFY accumulatorChanged) Q_PROPERTY(bool accumulator READ accumulator WRITE setAccumulator NOTIFY accumulatorChanged)
Q_PROPERTY(int deadband READ deadband WRITE setDeadband NOTIFY deadbandChanged)
// Property accessors // Property accessors
...@@ -129,8 +128,6 @@ signals: ...@@ -129,8 +128,6 @@ signals:
void accumulatorChanged(bool accumulator); void accumulatorChanged(bool accumulator);
void deadbandChanged(bool deadband);
void enabledChanged(bool enabled); void enabledChanged(bool enabled);
/// Signal containing new joystick information /// Signal containing new joystick information
......
...@@ -430,10 +430,10 @@ SetupPage { ...@@ -430,10 +430,10 @@ SetupPage {
QGCCheckBox { QGCCheckBox {
id: deadband id: deadband
checked: _activeJoystick.deadband checked: controller.deadbandToggle
text: qsTr("Deadband (requires re-calibration)") text: qsTr("Deadbands")
onClicked: _activeJoystick.deadband = checked onClicked: controller.deadbandToggle = checked
} }
} }
......
...@@ -210,6 +210,18 @@ void JoystickConfigController::cancelButtonClicked(void) ...@@ -210,6 +210,18 @@ void JoystickConfigController::cancelButtonClicked(void)
_stopCalibration(); _stopCalibration();
} }
bool JoystickConfigController::getDeadbandToggle() {
return _activeJoystick->deadband();
}
void JoystickConfigController::setDeadbandToggle(bool deadband) {
_activeJoystick->setDeadband(deadband);
_signalAllAttiudeValueChanges();
emit deadbandToggled(deadband);
}
void JoystickConfigController::_saveAllTrims(void) void JoystickConfigController::_saveAllTrims(void)
{ {
// We save all trims as the first step. At this point no axes are mapped but it should still // 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) ...@@ -228,27 +240,9 @@ void JoystickConfigController::_axisDeadbandChanged(int axis, int value)
{ {
value = abs(value)<_calValidMaxValue?abs(value):_calValidMaxValue; value = abs(value)<_calValidMaxValue?abs(value):_calValidMaxValue;
if (value>_rgAxisInfo[axis].deadband) {
_rgAxisInfo[axis].deadband = value; _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; qCDebug(JoystickConfigControllerLog) << "Axis:" << axis << "Deadband:" << _rgAxisInfo[axis].deadband;
}
} }
/// @brief Waits for the sticks to be centered, enabling Next when done. /// @brief Waits for the sticks to be centered, enabling Next when done.
...@@ -257,16 +251,13 @@ void JoystickConfigController::_inputCenterWaitBegin(Joystick::AxisFunction_t fu ...@@ -257,16 +251,13 @@ void JoystickConfigController::_inputCenterWaitBegin(Joystick::AxisFunction_t fu
Q_UNUSED(function); Q_UNUSED(function);
//sensing deadband //sensing deadband
if (_activeJoystick->deadband()) { if (abs(value)*1.1f>_rgAxisInfo[axis].deadband) { //add 10% on top of existing deadband
if (abs(value)*1.5>_rgAxisInfo[axis].deadband) { _axisDeadbandChanged(axis,abs(value)*1.1f);
_axisDeadbandChanged(axis,abs(value)*1.5);
}
} }
_nextButton->setEnabled(true); _nextButton->setEnabled(true);
// FIXME: Doesn't wait for center // FIXME: Doesn't wait for center
// FIXME: Ideally the deadband should be probed only around the center
} }
bool JoystickConfigController::_stickSettleComplete(int axis, int value) bool JoystickConfigController::_stickSettleComplete(int axis, int value)
...@@ -703,7 +694,7 @@ int JoystickConfigController::throttleAxisValue(void) ...@@ -703,7 +694,7 @@ int JoystickConfigController::throttleAxisValue(void)
int JoystickConfigController::rollAxisDeadband(void) int JoystickConfigController::rollAxisDeadband(void)
{ {
if (_rgFunctionAxisMapping[Joystick::rollFunction] != _axisNoAxis) { if ((_rgFunctionAxisMapping[Joystick::rollFunction] != _axisNoAxis) && (_activeJoystick->deadband())) {
return _rgAxisInfo[_rgFunctionAxisMapping[Joystick::rollFunction]].deadband; return _rgAxisInfo[_rgFunctionAxisMapping[Joystick::rollFunction]].deadband;
} else { } else {
return 0; return 0;
...@@ -712,7 +703,7 @@ int JoystickConfigController::rollAxisDeadband(void) ...@@ -712,7 +703,7 @@ int JoystickConfigController::rollAxisDeadband(void)
int JoystickConfigController::pitchAxisDeadband(void) int JoystickConfigController::pitchAxisDeadband(void)
{ {
if (_rgFunctionAxisMapping[Joystick::pitchFunction] != _axisNoAxis) { if ((_rgFunctionAxisMapping[Joystick::pitchFunction] != _axisNoAxis) && (_activeJoystick->deadband())) {
return _rgAxisInfo[_rgFunctionAxisMapping[Joystick::pitchFunction]].deadband; return _rgAxisInfo[_rgFunctionAxisMapping[Joystick::pitchFunction]].deadband;
} else { } else {
return 0; return 0;
...@@ -721,7 +712,7 @@ int JoystickConfigController::pitchAxisDeadband(void) ...@@ -721,7 +712,7 @@ int JoystickConfigController::pitchAxisDeadband(void)
int JoystickConfigController::yawAxisDeadband(void) int JoystickConfigController::yawAxisDeadband(void)
{ {
if (_rgFunctionAxisMapping[Joystick::yawFunction] != _axisNoAxis) { if ((_rgFunctionAxisMapping[Joystick::yawFunction] != _axisNoAxis) && (_activeJoystick->deadband())) {
return _rgAxisInfo[_rgFunctionAxisMapping[Joystick::yawFunction]].deadband; return _rgAxisInfo[_rgFunctionAxisMapping[Joystick::yawFunction]].deadband;
} else { } else {
return 0; return 0;
...@@ -730,7 +721,7 @@ int JoystickConfigController::yawAxisDeadband(void) ...@@ -730,7 +721,7 @@ int JoystickConfigController::yawAxisDeadband(void)
int JoystickConfigController::throttleAxisDeadband(void) int JoystickConfigController::throttleAxisDeadband(void)
{ {
if (_rgFunctionAxisMapping[Joystick::throttleFunction] != _axisNoAxis) { if ((_rgFunctionAxisMapping[Joystick::throttleFunction] != _axisNoAxis) && (_activeJoystick->deadband())) {
return _rgAxisInfo[_rgFunctionAxisMapping[Joystick::throttleFunction]].deadband; return _rgAxisInfo[_rgFunctionAxisMapping[Joystick::throttleFunction]].deadband;
} else { } else {
return 0; return 0;
......
...@@ -67,6 +67,8 @@ public: ...@@ -67,6 +67,8 @@ public:
Q_PROPERTY(int yawAxisReversed READ yawAxisReversed NOTIFY yawAxisReversedChanged) Q_PROPERTY(int yawAxisReversed READ yawAxisReversed NOTIFY yawAxisReversedChanged)
Q_PROPERTY(int throttleAxisReversed READ throttleAxisReversed NOTIFY throttleAxisReversedChanged) 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_PROPERTY(QString imageHelp MEMBER _imageHelp NOTIFY imageHelpChanged)
Q_INVOKABLE void cancelButtonClicked(void); Q_INVOKABLE void cancelButtonClicked(void);
...@@ -94,6 +96,9 @@ public: ...@@ -94,6 +96,9 @@ public:
bool yawAxisReversed(void); bool yawAxisReversed(void);
bool throttleAxisReversed(void); bool throttleAxisReversed(void);
bool getDeadbandToggle(void);
void setDeadbandToggle(bool);
int axisCount(void); int axisCount(void);
signals: signals:
...@@ -119,6 +124,8 @@ signals: ...@@ -119,6 +124,8 @@ signals:
void yawAxisReversedChanged(bool reversed); void yawAxisReversedChanged(bool reversed);
void throttleAxisReversedChanged(bool reversed); void throttleAxisReversedChanged(bool reversed);
void deadbandToggled(bool value);
void imageHelpChanged(QString source); void imageHelpChanged(QString source);
// @brief Signalled when in unit test mode and a message box should be displayed by the next button // @brief Signalled when in unit test mode and a message box should be displayed by the next button
......
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