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

Merge pull request #4470 from bluerobotics/calibration

Rework joystick calibration (2)
parents 7688c667 cc180856
...@@ -254,17 +254,6 @@ ...@@ -254,17 +254,6 @@
<file alias="radioThrottleDown.png">resources/calibration/mode2/radioThrottleDown.png</file> <file alias="radioThrottleDown.png">resources/calibration/mode2/radioThrottleDown.png</file>
<file alias="radioSwitchMinMax.png">resources/calibration/mode2/radioSwitchMinMax.png</file> <file alias="radioSwitchMinMax.png">resources/calibration/mode2/radioSwitchMinMax.png</file>
</qresource> </qresource>
<qresource prefix="/qml/calibration/joystick">
<file alias="joystickCenter.png">resources/calibration/joystick/joystickCenter.png</file>
<file alias="joystickRollLeft.png">resources/calibration/joystick/joystickRollLeft.png</file>
<file alias="joystickRollRight.png">resources/calibration/joystick/joystickRollRight.png</file>
<file alias="joystickPitchUp.png">resources/calibration/joystick/joystickPitchUp.png</file>
<file alias="joystickPitchDown.png">resources/calibration/joystick/joystickPitchDown.png</file>
<file alias="joystickYawLeft.png">resources/calibration/joystick/joystickYawLeft.png</file>
<file alias="joystickYawRight.png">resources/calibration/joystick/joystickYawRight.png</file>
<file alias="joystickThrottleUp.png">resources/calibration/joystick/joystickThrottleUp.png</file>
<file alias="joystickThrottleDown.png">resources/calibration/joystick/joystickThrottleDown.png</file>
</qresource>
<qresource prefix="/db/mapping/joystick"> <qresource prefix="/db/mapping/joystick">
<file alias="gamecontrollerdb.txt">resources/SDL_GameControllerDB/gamecontrollerdb.txt</file> <file alias="gamecontrollerdb.txt">resources/SDL_GameControllerDB/gamecontrollerdb.txt</file>
</qresource> </qresource>
...@@ -278,4 +267,48 @@ ...@@ -278,4 +267,48 @@
<qresource prefix="/opengl"> <qresource prefix="/opengl">
<file>resources/opengl/buglist.json</file> <file>resources/opengl/buglist.json</file>
</qresource> </qresource>
<qresource prefix="/qml/calibration/joystick/mode1">
<file alias="joystickCenter.png">resources/calibration/joystick/mode1/joystickCenter.png</file>
<file alias="joystickPitchDown.png">resources/calibration/joystick/mode1/joystickPitchDown.png</file>
<file alias="joystickPitchUp.png">resources/calibration/joystick/mode1/joystickPitchUp.png</file>
<file alias="joystickRollLeft.png">resources/calibration/joystick/mode1/joystickRollLeft.png</file>
<file alias="joystickRollRight.png">resources/calibration/joystick/mode1/joystickRollRight.png</file>
<file alias="joystickThrottleDown.png">resources/calibration/joystick/mode1/joystickThrottleDown.png</file>
<file alias="joystickThrottleUp.png">resources/calibration/joystick/mode1/joystickThrottleUp.png</file>
<file alias="joystickYawLeft.png">resources/calibration/joystick/mode1/joystickYawLeft.png</file>
<file alias="joystickYawRight.png">resources/calibration/joystick/mode1/joystickYawRight.png</file>
</qresource>
<qresource prefix="/qml/calibration/joystick/mode2">
<file alias="joystickCenter.png">resources/calibration/joystick/mode2/joystickCenter.png</file>
<file alias="joystickPitchDown.png">resources/calibration/joystick/mode2/joystickPitchDown.png</file>
<file alias="joystickPitchUp.png">resources/calibration/joystick/mode2/joystickPitchUp.png</file>
<file alias="joystickRollLeft.png">resources/calibration/joystick/mode2/joystickRollLeft.png</file>
<file alias="joystickRollRight.png">resources/calibration/joystick/mode2/joystickRollRight.png</file>
<file alias="joystickThrottleDown.png">resources/calibration/joystick/mode2/joystickThrottleDown.png</file>
<file alias="joystickThrottleUp.png">resources/calibration/joystick/mode2/joystickThrottleUp.png</file>
<file alias="joystickYawLeft.png">resources/calibration/joystick/mode2/joystickYawLeft.png</file>
<file alias="joystickYawRight.png">resources/calibration/joystick/mode2/joystickYawRight.png</file>
</qresource>
<qresource prefix="/qml/calibration/joystick/mode3">
<file alias="joystickCenter.png">resources/calibration/joystick/mode3/joystickCenter.png</file>
<file alias="joystickPitchDown.png">resources/calibration/joystick/mode3/joystickPitchDown.png</file>
<file alias="joystickPitchUp.png">resources/calibration/joystick/mode3/joystickPitchUp.png</file>
<file alias="joystickRollLeft.png">resources/calibration/joystick/mode3/joystickRollLeft.png</file>
<file alias="joystickRollRight.png">resources/calibration/joystick/mode3/joystickRollRight.png</file>
<file alias="joystickThrottleDown.png">resources/calibration/joystick/mode3/joystickThrottleDown.png</file>
<file alias="joystickThrottleUp.png">resources/calibration/joystick/mode3/joystickThrottleUp.png</file>
<file alias="joystickYawLeft.png">resources/calibration/joystick/mode3/joystickYawLeft.png</file>
<file alias="joystickYawRight.png">resources/calibration/joystick/mode3/joystickYawRight.png</file>
</qresource>
<qresource prefix="/qml/calibration/joystick/mode4">
<file alias="joystickCenter.png">resources/calibration/joystick/mode4/joystickCenter.png</file>
<file alias="joystickPitchDown.png">resources/calibration/joystick/mode4/joystickPitchDown.png</file>
<file alias="joystickPitchUp.png">resources/calibration/joystick/mode4/joystickPitchUp.png</file>
<file alias="joystickRollLeft.png">resources/calibration/joystick/mode4/joystickRollLeft.png</file>
<file alias="joystickRollRight.png">resources/calibration/joystick/mode4/joystickRollRight.png</file>
<file alias="joystickThrottleDown.png">resources/calibration/joystick/mode4/joystickThrottleDown.png</file>
<file alias="joystickThrottleUp.png">resources/calibration/joystick/mode4/joystickThrottleUp.png</file>
<file alias="joystickYawLeft.png">resources/calibration/joystick/mode4/joystickYawLeft.png</file>
<file alias="joystickYawRight.png">resources/calibration/joystick/mode4/joystickYawRight.png</file>
</qresource>
</RCC> </RCC>
...@@ -69,6 +69,8 @@ public: ...@@ -69,6 +69,8 @@ public:
// Overrides from FirmwarePlugin // Overrides from FirmwarePlugin
int manualControlReservedButtonCount(void); int manualControlReservedButtonCount(void);
int defaultJoystickTXMode(void) final { return 3; }
bool supportsThrottleModeCenterZero(void); bool supportsThrottleModeCenterZero(void);
bool supportsManualControl(void); bool supportsManualControl(void);
......
...@@ -106,6 +106,11 @@ int FirmwarePlugin::manualControlReservedButtonCount(void) ...@@ -106,6 +106,11 @@ int FirmwarePlugin::manualControlReservedButtonCount(void)
return -1; return -1;
} }
int FirmwarePlugin::defaultJoystickTXMode(void)
{
return 2;
}
bool FirmwarePlugin::supportsThrottleModeCenterZero(void) bool FirmwarePlugin::supportsThrottleModeCenterZero(void)
{ {
// By default, this is supported // By default, this is supported
......
...@@ -142,6 +142,10 @@ public: ...@@ -142,6 +142,10 @@ public:
/// @return -1: reserver all buttons, >0 number of buttons to reserve /// @return -1: reserver all buttons, >0 number of buttons to reserve
virtual int manualControlReservedButtonCount(void); virtual int manualControlReservedButtonCount(void);
/// Default tx mode to apply to joystick axes
/// TX modes are as outlined here: http://www.rc-airplane-world.com/rc-transmitter-modes.html
virtual int defaultJoystickTXMode(void);
/// Returns true if the vehicle and firmware supports the use of a throttle joystick that /// 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 /// is zero when centered. Typically not supported on vehicles that have bidirectional
/// throttle. /// throttle.
......
...@@ -19,12 +19,18 @@ QGC_LOGGING_CATEGORY(JoystickLog, "JoystickLog") ...@@ -19,12 +19,18 @@ QGC_LOGGING_CATEGORY(JoystickLog, "JoystickLog")
QGC_LOGGING_CATEGORY(JoystickValuesLog, "JoystickValuesLog") QGC_LOGGING_CATEGORY(JoystickValuesLog, "JoystickValuesLog")
const char* Joystick::_settingsGroup = "Joysticks"; const char* Joystick::_settingsGroup = "Joysticks";
const char* Joystick::_calibratedSettingsKey = "Calibrated1"; // Increment number to force recalibration const char* Joystick::_calibratedSettingsKey = "Calibrated2"; // Increment number to force recalibration
const char* Joystick::_buttonActionSettingsKey = "ButtonActionName%1"; const char* Joystick::_buttonActionSettingsKey = "ButtonActionName%1";
const char* Joystick::_throttleModeSettingsKey = "ThrottleMode"; const char* Joystick::_throttleModeSettingsKey = "ThrottleMode";
const char* Joystick::_exponentialSettingsKey = "Exponential"; const char* Joystick::_exponentialSettingsKey = "Exponential";
const char* Joystick::_accumulatorSettingsKey = "Accumulator"; const char* Joystick::_accumulatorSettingsKey = "Accumulator";
const char* Joystick::_deadbandSettingsKey = "Deadband"; const char* Joystick::_deadbandSettingsKey = "Deadband";
const char* Joystick::_txModeSettingsKey = NULL;
const char* Joystick::_fixedWingTXModeSettingsKey = "TXMode_FixedWing";
const char* Joystick::_multiRotorTXModeSettingsKey = "TXMode_MultiRotor";
const char* Joystick::_roverTXModeSettingsKey = "TXMode_Rover";
const char* Joystick::_vtolTXModeSettingsKey = "TXMode_VTOL";
const char* Joystick::_submarineTXModeSettingsKey = "TXMode_Submarine";
const char* Joystick::_rgFunctionSettingsKey[Joystick::maxFunction] = { const char* Joystick::_rgFunctionSettingsKey[Joystick::maxFunction] = {
"RollAxis", "RollAxis",
...@@ -33,6 +39,8 @@ const char* Joystick::_rgFunctionSettingsKey[Joystick::maxFunction] = { ...@@ -33,6 +39,8 @@ const char* Joystick::_rgFunctionSettingsKey[Joystick::maxFunction] = {
"ThrottleAxis" "ThrottleAxis"
}; };
int Joystick::_transmitterMode = 2;
Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int hatCount, MultiVehicleManager* multiVehicleManager) Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int hatCount, MultiVehicleManager* multiVehicleManager)
: _exitThread(false) : _exitThread(false)
, _name(name) , _name(name)
...@@ -67,6 +75,8 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int hatC ...@@ -67,6 +75,8 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int hatC
} }
_loadSettings(); _loadSettings();
connect(_multiVehicleManager, &MultiVehicleManager::activeVehicleChanged, this, &Joystick::_activeVehicleChanged);
} }
Joystick::~Joystick() Joystick::~Joystick()
...@@ -76,11 +86,74 @@ Joystick::~Joystick() ...@@ -76,11 +86,74 @@ Joystick::~Joystick()
delete _rgButtonValues; delete _rgButtonValues;
} }
void Joystick::_setDefaultCalibration(void) {
QSettings settings;
settings.beginGroup(_settingsGroup);
settings.beginGroup(_name);
_calibrated = settings.value(_calibratedSettingsKey, false).toBool();
// Only set default calibrations if we do not have a calibration for this gamecontroller
if(_calibrated) return;
for(int axis = 0; axis < _axisCount; axis++) {
Joystick::Calibration_t calibration;
_rgCalibration[axis] = calibration;
}
_rgCalibration[1].reversed = true;
_rgCalibration[3].reversed = true;
// Default TX Mode 2 axis assignments for gamecontrollers
_rgFunctionAxis[rollFunction] = 2;
_rgFunctionAxis[pitchFunction] = 3;
_rgFunctionAxis[yawFunction] = 0;
_rgFunctionAxis[throttleFunction] = 1;
_exponential = false;
_accumulator = false;
_deadband = false;
_throttleMode = ThrottleModeCenterZero;
_calibrated = true;
_saveSettings();
}
void Joystick::_activeVehicleChanged(Vehicle *activeVehicle)
{
if(activeVehicle) {
if(activeVehicle->fixedWing()) {
_txModeSettingsKey = _fixedWingTXModeSettingsKey;
} else if(activeVehicle->multiRotor()) {
_txModeSettingsKey = _multiRotorTXModeSettingsKey;
} else if(activeVehicle->rover()) {
_txModeSettingsKey = _roverTXModeSettingsKey;
} else if(activeVehicle->vtol()) {
_txModeSettingsKey = _vtolTXModeSettingsKey;
} else if(activeVehicle->sub()) {
_txModeSettingsKey = _submarineTXModeSettingsKey;
} else {
_txModeSettingsKey = NULL;
qWarning() << "No valid joystick TXmode settings key for selected vehicle";
return;
}
QSettings settings;
settings.beginGroup(_settingsGroup);
int mode = settings.value(_txModeSettingsKey, activeVehicle->firmwarePlugin()->defaultJoystickTXMode()).toInt();
setTXMode(mode);
}
}
void Joystick::_loadSettings(void) void Joystick::_loadSettings(void)
{ {
QSettings settings; QSettings settings;
settings.beginGroup(_settingsGroup); settings.beginGroup(_settingsGroup);
if(_txModeSettingsKey)
_transmitterMode = settings.value(_txModeSettingsKey, 2).toInt();
settings.beginGroup(_name); settings.beginGroup(_name);
bool badSettings = false; bool badSettings = false;
...@@ -96,7 +169,7 @@ void Joystick::_loadSettings(void) ...@@ -96,7 +169,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:deadband:badsettings" << _calibrated << _throttleMode << _exponential << _deadband << badSettings; qCDebug(JoystickLog) << "_loadSettings calibrated:txmode:throttlemode:exponential:deadband:badsettings" << _calibrated << _transmitterMode << _throttleMode << _exponential << _deadband << badSettings;
QString minTpl ("Axis%1Min"); QString minTpl ("Axis%1Min");
QString maxTpl ("Axis%1Max"); QString maxTpl ("Axis%1Max");
...@@ -136,6 +209,10 @@ void Joystick::_loadSettings(void) ...@@ -136,6 +209,10 @@ void Joystick::_loadSettings(void)
qCDebug(JoystickLog) << "_loadSettings function:axis:badsettings" << function << functionAxis << badSettings; qCDebug(JoystickLog) << "_loadSettings function:axis:badsettings" << function << functionAxis << badSettings;
} }
// FunctionAxis mappings are always stored in TX mode 2
// Remap to stored TX mode in settings
_remapAxes(2, _transmitterMode, _rgFunctionAxis);
for (int button=0; button<_totalButtonCount; button++) { for (int button=0; button<_totalButtonCount; button++) {
_rgButtonActions << settings.value(QString(_buttonActionSettingsKey).arg(button), QString()).toString(); _rgButtonActions << settings.value(QString(_buttonActionSettingsKey).arg(button), QString()).toString();
qCDebug(JoystickLog) << "_loadSettings button:action" << button << _rgButtonActions[button]; qCDebug(JoystickLog) << "_loadSettings button:action" << button << _rgButtonActions[button];
...@@ -152,6 +229,12 @@ void Joystick::_saveSettings(void) ...@@ -152,6 +229,12 @@ void Joystick::_saveSettings(void)
QSettings settings; QSettings settings;
settings.beginGroup(_settingsGroup); settings.beginGroup(_settingsGroup);
// Transmitter mode is static
// Save the mode we are using
if(_txModeSettingsKey)
settings.setValue(_txModeSettingsKey, _transmitterMode);
settings.beginGroup(_name); settings.beginGroup(_name);
settings.setValue(_calibratedSettingsKey, _calibrated); settings.setValue(_calibratedSettingsKey, _calibrated);
...@@ -160,7 +243,7 @@ void Joystick::_saveSettings(void) ...@@ -160,7 +243,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:deadband" << _calibrated << _throttleMode << _deadband; qCDebug(JoystickLog) << "_saveSettings calibrated:throttlemode:deadband:txmode" << _calibrated << _throttleMode << _deadband << _transmitterMode;
QString minTpl ("Axis%1Min"); QString minTpl ("Axis%1Min");
QString maxTpl ("Axis%1Max"); QString maxTpl ("Axis%1Max");
...@@ -187,8 +270,13 @@ void Joystick::_saveSettings(void) ...@@ -187,8 +270,13 @@ void Joystick::_saveSettings(void)
<< calibration->deadband; << calibration->deadband;
} }
// Always save function Axis mappings in TX Mode 2
// Write mode 2 mappings without changing mapping currently in use
int temp[maxFunction];
_remapAxes(_transmitterMode, 2, temp);
for (int function=0; function<maxFunction; function++) { for (int function=0; function<maxFunction; function++) {
settings.setValue(_rgFunctionSettingsKey[function], _rgFunctionAxis[function]); settings.setValue(_rgFunctionSettingsKey[function], temp[function]);
qCDebug(JoystickLog) << "_saveSettings name:function:axis" << _name << function << _rgFunctionSettingsKey[function]; qCDebug(JoystickLog) << "_saveSettings name:function:axis" << _name << function << _rgFunctionSettingsKey[function];
} }
...@@ -198,6 +286,42 @@ void Joystick::_saveSettings(void) ...@@ -198,6 +286,42 @@ void Joystick::_saveSettings(void)
} }
} }
// Relative mappings of axis functions between different TX modes
int Joystick::_mapFunctionMode(int mode, int function) {
static const int mapping[][4] = {
{ 2, 1, 0, 3 },
{ 2, 3, 0, 1 },
{ 0, 1, 2, 3 },
{ 0, 3, 2, 1 }};
return mapping[mode-1][function];
}
// Remap current axis functions from current TX mode to new TX mode
void Joystick::_remapAxes(int currentMode, int newMode, int (&newMapping)[maxFunction]) {
int temp[maxFunction];
for(int function = 0; function < maxFunction; function++) {
temp[_mapFunctionMode(newMode, function)] = _rgFunctionAxis[_mapFunctionMode(currentMode, function)];
}
for(int function = 0; function < maxFunction; function++) {
newMapping[function] = temp[function];
}
}
void Joystick::setTXMode(int mode) {
if(mode > 0 && mode <= 4) {
_remapAxes(_transmitterMode, mode, _rgFunctionAxis);
_transmitterMode = mode;
_saveSettings();
} else {
qCWarning(JoystickLog) << "Invalid mode:" << mode;
}
}
/// Adjust the raw axis value to the -1:1 range given calibration information /// Adjust the raw axis value to the -1:1 range given calibration information
float Joystick::_adjustRange(int value, Calibration_t calibration, bool withDeadbands) float Joystick::_adjustRange(int value, Calibration_t calibration, bool withDeadbands)
{ {
...@@ -471,6 +595,7 @@ void Joystick::setFunctionAxis(AxisFunction_t function, int axis) ...@@ -471,6 +595,7 @@ void Joystick::setFunctionAxis(AxisFunction_t function, int axis)
_calibrated = true; _calibrated = true;
_rgFunctionAxis[function] = axis; _rgFunctionAxis[function] = axis;
_saveSettings(); _saveSettings();
emit calibratedChanged(_calibrated); emit calibratedChanged(_calibrated);
} }
......
...@@ -30,12 +30,18 @@ public: ...@@ -30,12 +30,18 @@ public:
~Joystick(); ~Joystick();
typedef struct { typedef struct Calibration_t {
int min; int min;
int max; int max;
int center; int center;
int deadband; int deadband;
bool reversed; bool reversed;
Calibration_t()
: min(-32767)
, max(32767)
, center(0)
, deadband(0)
, reversed(false) {}
} Calibration_t; } Calibration_t;
typedef enum { typedef enum {
...@@ -68,6 +74,7 @@ public: ...@@ -68,6 +74,7 @@ public:
Q_PROPERTY(int throttleMode READ throttleMode WRITE setThrottleMode NOTIFY throttleModeChanged) Q_PROPERTY(int throttleMode READ throttleMode WRITE setThrottleMode NOTIFY throttleModeChanged)
Q_PROPERTY(bool exponential READ exponential WRITE setExponential NOTIFY exponentialChanged) Q_PROPERTY(bool 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)
// Property accessors // Property accessors
...@@ -89,6 +96,8 @@ public: ...@@ -89,6 +96,8 @@ public:
QString name(void) { return _name; } QString name(void) { return _name; }
virtual bool requiresCalibration(void) { return true; }
int throttleMode(void); int throttleMode(void);
void setThrottleMode(int mode); void setThrottleMode(int mode);
...@@ -101,6 +110,9 @@ public: ...@@ -101,6 +110,9 @@ public:
bool deadband(void); bool deadband(void);
void setDeadband(bool accu); void setDeadband(bool accu);
void setTXMode(int mode);
int getTXMode(void) { return _transmitterMode; }
typedef enum { typedef enum {
CalibrationModeOff, // Not calibrating CalibrationModeOff, // Not calibrating
CalibrationModeMonitor, // Monitors are active, continue to send to vehicle if already polling CalibrationModeMonitor, // Monitors are active, continue to send to vehicle if already polling
...@@ -141,6 +153,7 @@ signals: ...@@ -141,6 +153,7 @@ signals:
void buttonActionTriggered(int action); void buttonActionTriggered(int action);
protected: protected:
void _setDefaultCalibration(void);
void _saveSettings(void); void _saveSettings(void);
void _loadSettings(void); void _loadSettings(void);
float _adjustRange(int value, Calibration_t calibration, bool withDeadbands); float _adjustRange(int value, Calibration_t calibration, bool withDeadbands);
...@@ -157,6 +170,9 @@ private: ...@@ -157,6 +170,9 @@ private:
virtual int _getAxis(int i) = 0; virtual int _getAxis(int i) = 0;
virtual uint8_t _getHat(int hat,int i) = 0; virtual uint8_t _getHat(int hat,int i) = 0;
int _mapFunctionMode(int mode, int function);
void _remapAxes(int currentMode, int newMode, int (&newMapping)[maxFunction]);
// Override from QThread // Override from QThread
virtual void run(void); virtual void run(void);
...@@ -172,6 +188,7 @@ protected: ...@@ -172,6 +188,7 @@ protected:
int _hatButtonCount; int _hatButtonCount;
int _totalButtonCount; int _totalButtonCount;
static int _transmitterMode;
CalibrationMode_t _calibrationMode; CalibrationMode_t _calibrationMode;
int* _rgAxisValues; int* _rgAxisValues;
...@@ -203,6 +220,15 @@ private: ...@@ -203,6 +220,15 @@ private:
static const char* _exponentialSettingsKey; static const char* _exponentialSettingsKey;
static const char* _accumulatorSettingsKey; static const char* _accumulatorSettingsKey;
static const char* _deadbandSettingsKey; static const char* _deadbandSettingsKey;
static const char* _txModeSettingsKey;
static const char* _fixedWingTXModeSettingsKey;
static const char* _multiRotorTXModeSettingsKey;
static const char* _roverTXModeSettingsKey;
static const char* _vtolTXModeSettingsKey;
static const char* _submarineTXModeSettingsKey;
private slots:
void _activeVehicleChanged(Vehicle* activeVehicle);
}; };
#endif #endif
...@@ -10,6 +10,7 @@ JoystickSDL::JoystickSDL(const QString& name, int axisCount, int buttonCount, in ...@@ -10,6 +10,7 @@ JoystickSDL::JoystickSDL(const QString& name, int axisCount, int buttonCount, in
, _isGameController(isGameController) , _isGameController(isGameController)
, _index(index) , _index(index)
{ {
if(_isGameController) _setDefaultCalibration();
} }
QMap<QString, Joystick*> JoystickSDL::discover(MultiVehicleManager* _multiVehicleManager) { QMap<QString, Joystick*> JoystickSDL::discover(MultiVehicleManager* _multiVehicleManager) {
......
...@@ -14,6 +14,9 @@ public: ...@@ -14,6 +14,9 @@ public:
static QMap<QString, Joystick*> discover(MultiVehicleManager* _multiVehicleManager); static QMap<QString, Joystick*> discover(MultiVehicleManager* _multiVehicleManager);
// This can be uncommented to hide the calibration buttons for gamecontrollers in the future
// bool requiresCalibration(void) final { return !_isGameController; }
private: private:
static void _loadGameControllerMappings(); static void _loadGameControllerMappings();
......
...@@ -176,7 +176,7 @@ SetupPage { ...@@ -176,7 +176,7 @@ SetupPage {
QGCLabel { QGCLabel {
id: rollLabel id: rollLabel
width: defaultTextWidth * 10 width: defaultTextWidth * 10
text: qsTr("Roll") text: _activeVehicle.sub ? qsTr("Lateral") : qsTr("Roll")
} }
Loader { Loader {
...@@ -208,7 +208,7 @@ SetupPage { ...@@ -208,7 +208,7 @@ SetupPage {
QGCLabel { QGCLabel {
id: pitchLabel id: pitchLabel
width: defaultTextWidth * 10 width: defaultTextWidth * 10
text: qsTr("Pitch") text: _activeVehicle.sub ? qsTr("Forward") : qsTr("Pitch")
} }
Loader { Loader {
...@@ -302,6 +302,7 @@ SetupPage { ...@@ -302,6 +302,7 @@ SetupPage {
// Command Buttons // Command Buttons
Row { Row {
spacing: 10 spacing: 10
visible: _activeJoystick.requiresCalibration
QGCButton { QGCButton {
id: skipButton id: skipButton
...@@ -643,12 +644,57 @@ SetupPage { ...@@ -643,12 +644,57 @@ SetupPage {
id: rightColumn id: rightColumn
anchors.top: parent.top anchors.top: parent.top
anchors.right: parent.right anchors.right: parent.right
width: defaultTextWidth * 35 width: Math.min(joystickPage.defaultTextWidth * 35, availableWidth * 0.4)
spacing: 10 spacing: ScreenTools.defaultFontPixelHeight / 2
Row {
spacing: ScreenTools.defaultFontPixelWidth
ExclusiveGroup { id: modeGroup }
QGCLabel {
text: "TX Mode:"
}
QGCRadioButton {
exclusiveGroup: modeGroup
text: "1"
checked: controller.transmitterMode == 1
enabled: !controller.calibrating
onClicked: controller.transmitterMode = 1
}
QGCRadioButton {
exclusiveGroup: modeGroup
text: "2"
checked: controller.transmitterMode == 2
enabled: !controller.calibrating
onClicked: controller.transmitterMode = 2
}
QGCRadioButton {
exclusiveGroup: modeGroup
text: "3"
checked: controller.transmitterMode == 3
enabled: !controller.calibrating
onClicked: controller.transmitterMode = 3
}
QGCRadioButton {
exclusiveGroup: modeGroup
text: "4"
checked: controller.transmitterMode == 4
enabled: !controller.calibrating
onClicked: controller.transmitterMode = 4
}
}
Image { Image {
//width: parent.width width: parent.width
height: defaultTextHeight * 15
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
smooth: true smooth: true
source: controller.imageHelp source: controller.imageHelp
......
...@@ -29,8 +29,11 @@ const int JoystickConfigController::_calMinDelta = 1000; ///< Amo ...@@ -29,8 +29,11 @@ const int JoystickConfigController::_calMinDelta = 1000; ///< Amo
const int JoystickConfigController::_stickDetectSettleMSecs = 500; const int JoystickConfigController::_stickDetectSettleMSecs = 500;
const char* JoystickConfigController::_imageFilePrefix = "calibration/"; const char* JoystickConfigController::_imageFilePrefix = "calibration/joystick/";
const char* JoystickConfigController::_imageFileMode2Dir = "joystick/"; const char* JoystickConfigController::_imageFileMode1Dir = "mode1/";
const char* JoystickConfigController::_imageFileMode2Dir = "mode2/";
const char* JoystickConfigController::_imageFileMode3Dir = "mode3/";
const char* JoystickConfigController::_imageFileMode4Dir = "mode4/";
const char* JoystickConfigController::_imageCenter = "joystickCenter.png"; const char* JoystickConfigController::_imageCenter = "joystickCenter.png";
const char* JoystickConfigController::_imageThrottleUp = "joystickThrottleUp.png"; const char* JoystickConfigController::_imageThrottleUp = "joystickThrottleUp.png";
const char* JoystickConfigController::_imageThrottleDown = "joystickThrottleDown.png"; const char* JoystickConfigController::_imageThrottleDown = "joystickThrottleDown.png";
...@@ -43,6 +46,7 @@ const char* JoystickConfigController::_imagePitchDown = "joystickPitchDown.p ...@@ -43,6 +46,7 @@ const char* JoystickConfigController::_imagePitchDown = "joystickPitchDown.p
JoystickConfigController::JoystickConfigController(void) JoystickConfigController::JoystickConfigController(void)
: _activeJoystick(NULL) : _activeJoystick(NULL)
, _transmitterMode(2)
, _currentStep(-1) , _currentStep(-1)
, _axisCount(0) , _axisCount(0)
, _rgAxisInfo(NULL) , _rgAxisInfo(NULL)
...@@ -496,6 +500,8 @@ void JoystickConfigController::_setInternalCalibrationValuesFromSettings(void) ...@@ -496,6 +500,8 @@ void JoystickConfigController::_setInternalCalibrationValuesFromSettings(void)
_rgAxisInfo[paramAxis].function = (Joystick::AxisFunction_t)function; _rgAxisInfo[paramAxis].function = (Joystick::AxisFunction_t)function;
} }
_transmitterMode = joystick->getTXMode();
_signalAllAttiudeValueChanges(); _signalAllAttiudeValueChanges();
} }
...@@ -591,6 +597,7 @@ void JoystickConfigController::_startCalibration(void) ...@@ -591,6 +597,7 @@ void JoystickConfigController::_startCalibration(void)
_currentStep = 0; _currentStep = 0;
_setupCurrentState(); _setupCurrentState();
emit calibratingChanged();
} }
/// @brief Cancels the calibration process, setting things back to initial state. /// @brief Cancels the calibration process, setting things back to initial state.
...@@ -609,6 +616,7 @@ void JoystickConfigController::_stopCalibration(void) ...@@ -609,6 +616,7 @@ void JoystickConfigController::_stopCalibration(void)
_skipButton->setEnabled(false); _skipButton->setEnabled(false);
_setHelpImage(_imageCenter); _setHelpImage(_imageCenter);
emit calibratingChanged();
} }
/// @brief Saves the current axis values, so that we can detect when the use moves an input. /// @brief Saves the current axis values, so that we can detect when the use moves an input.
...@@ -642,7 +650,23 @@ void JoystickConfigController::_setHelpImage(const char* imageFile) ...@@ -642,7 +650,23 @@ void JoystickConfigController::_setHelpImage(const char* imageFile)
{ {
QString file = _imageFilePrefix; QString file = _imageFilePrefix;
switch(_transmitterMode) {
case 1:
file += _imageFileMode1Dir;
break;
case 2:
file += _imageFileMode2Dir; file += _imageFileMode2Dir;
break;
case 3:
file += _imageFileMode3Dir;
break;
case 4:
file += _imageFileMode4Dir;
break;
default:
Q_ASSERT(false);
}
file += imageFile; file += imageFile;
qCDebug(JoystickConfigControllerLog) << "_setHelpImage" << file; qCDebug(JoystickConfigControllerLog) << "_setHelpImage" << file;
...@@ -784,6 +808,20 @@ bool JoystickConfigController::throttleAxisReversed(void) ...@@ -784,6 +808,20 @@ bool JoystickConfigController::throttleAxisReversed(void)
} }
} }
void JoystickConfigController::setTransmitterMode(int mode)
{
if (mode > 0 && mode <= 4) {
_transmitterMode = mode;
if (_currentStep != -1) { // This should never be true, mode selection is disabled during calibration
const stateMachineEntry* state = _getStateMachineEntry(_currentStep);
_setHelpImage(state->image);
} else {
_activeJoystick->setTXMode(mode);
_setInternalCalibrationValuesFromSettings();
}
}
}
void JoystickConfigController::_signalAllAttiudeValueChanges(void) void JoystickConfigController::_signalAllAttiudeValueChanges(void)
{ {
emit rollAxisMappedChanged(rollAxisMapped()); emit rollAxisMappedChanged(rollAxisMapped());
...@@ -800,6 +838,8 @@ void JoystickConfigController::_signalAllAttiudeValueChanges(void) ...@@ -800,6 +838,8 @@ void JoystickConfigController::_signalAllAttiudeValueChanges(void)
emit pitchAxisDeadbandChanged(pitchAxisDeadband()); emit pitchAxisDeadbandChanged(pitchAxisDeadband());
emit yawAxisDeadbandChanged(yawAxisDeadband()); emit yawAxisDeadbandChanged(yawAxisDeadband());
emit throttleAxisDeadbandChanged(throttleAxisDeadband()); emit throttleAxisDeadbandChanged(throttleAxisDeadband());
emit transmitterModeChanged(_transmitterMode);
} }
void JoystickConfigController::_activeJoystickChanged(Joystick* joystick) void JoystickConfigController::_activeJoystickChanged(Joystick* joystick)
......
...@@ -69,7 +69,9 @@ public: ...@@ -69,7 +69,9 @@ public:
Q_PROPERTY(bool deadbandToggle READ getDeadbandToggle WRITE setDeadbandToggle NOTIFY deadbandToggled) Q_PROPERTY(bool deadbandToggle READ getDeadbandToggle WRITE setDeadbandToggle NOTIFY deadbandToggled)
Q_PROPERTY(int transmitterMode READ transmitterMode WRITE setTransmitterMode NOTIFY transmitterModeChanged)
Q_PROPERTY(QString imageHelp MEMBER _imageHelp NOTIFY imageHelpChanged) Q_PROPERTY(QString imageHelp MEMBER _imageHelp NOTIFY imageHelpChanged)
Q_PROPERTY(bool calibrating READ calibrating NOTIFY calibratingChanged)
Q_INVOKABLE void cancelButtonClicked(void); Q_INVOKABLE void cancelButtonClicked(void);
Q_INVOKABLE void skipButtonClicked(void); Q_INVOKABLE void skipButtonClicked(void);
...@@ -101,6 +103,11 @@ public: ...@@ -101,6 +103,11 @@ public:
int axisCount(void); int axisCount(void);
int transmitterMode(void) { return _transmitterMode; }
void setTransmitterMode(int mode);
bool calibrating(void) { return _currentStep != -1; }
signals: signals:
void axisValueChanged(int axis, int value); void axisValueChanged(int axis, int value);
...@@ -127,6 +134,8 @@ signals: ...@@ -127,6 +134,8 @@ signals:
void deadbandToggled(bool value); void deadbandToggled(bool value);
void imageHelpChanged(QString source); void imageHelpChanged(QString source);
void transmitterModeChanged(int mode);
void calibratingChanged(void);
// @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
void nextButtonMessageBoxDisplayed(void); void nextButtonMessageBoxDisplayed(void);
...@@ -172,6 +181,7 @@ private: ...@@ -172,6 +181,7 @@ private:
Joystick* _activeJoystick; Joystick* _activeJoystick;
int _transmitterMode;
int _currentStep; ///< Current step of state machine int _currentStep; ///< Current step of state machine
const struct stateMachineEntry* _getStateMachineEntry(int step); const struct stateMachineEntry* _getStateMachineEntry(int step);
...@@ -211,7 +221,10 @@ private: ...@@ -211,7 +221,10 @@ private:
// Member variables // Member variables
static const char* _imageFileMode1Dir;
static const char* _imageFileMode2Dir; static const char* _imageFileMode2Dir;
static const char* _imageFileMode3Dir;
static const char* _imageFileMode4Dir;
static const char* _imageFilePrefix; static const char* _imageFilePrefix;
static const char* _imageCenter; static const char* _imageCenter;
static const char* _imageThrottleUp; static const char* _imageThrottleUp;
......
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