|
|
@ -25,6 +25,7 @@ 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::_circleCorrectionSettingsKey = "Circle_Correction"; |
|
|
|
const char* Joystick::_txModeSettingsKey = NULL; |
|
|
|
const char* Joystick::_txModeSettingsKey = NULL; |
|
|
|
const char* Joystick::_fixedWingTXModeSettingsKey = "TXMode_FixedWing"; |
|
|
|
const char* Joystick::_fixedWingTXModeSettingsKey = "TXMode_FixedWing"; |
|
|
|
const char* Joystick::_multiRotorTXModeSettingsKey = "TXMode_MultiRotor"; |
|
|
|
const char* Joystick::_multiRotorTXModeSettingsKey = "TXMode_MultiRotor"; |
|
|
@ -64,6 +65,7 @@ Joystick::Joystick(const QString& name, int axisCount, int buttonCount, int hatC |
|
|
|
, _exponential(0) |
|
|
|
, _exponential(0) |
|
|
|
, _accumulator(false) |
|
|
|
, _accumulator(false) |
|
|
|
, _deadband(false) |
|
|
|
, _deadband(false) |
|
|
|
|
|
|
|
, _circleCorrection(false) |
|
|
|
, _activeVehicle(NULL) |
|
|
|
, _activeVehicle(NULL) |
|
|
|
, _pollingStartedForCalibration(false) |
|
|
|
, _pollingStartedForCalibration(false) |
|
|
|
, _multiVehicleManager(multiVehicleManager) |
|
|
|
, _multiVehicleManager(multiVehicleManager) |
|
|
@ -124,6 +126,7 @@ void Joystick::_setDefaultCalibration(void) { |
|
|
|
_exponential = 0; |
|
|
|
_exponential = 0; |
|
|
|
_accumulator = false; |
|
|
|
_accumulator = false; |
|
|
|
_deadband = false; |
|
|
|
_deadband = false; |
|
|
|
|
|
|
|
_circleCorrection = false; |
|
|
|
_throttleMode = ThrottleModeCenterZero; |
|
|
|
_throttleMode = ThrottleModeCenterZero; |
|
|
|
_calibrated = true; |
|
|
|
_calibrated = true; |
|
|
|
|
|
|
|
|
|
|
@ -188,6 +191,7 @@ void Joystick::_loadSettings(void) |
|
|
|
_exponential = settings.value(_exponentialSettingsKey, 0).toFloat(); |
|
|
|
_exponential = settings.value(_exponentialSettingsKey, 0).toFloat(); |
|
|
|
_accumulator = settings.value(_accumulatorSettingsKey, false).toBool(); |
|
|
|
_accumulator = settings.value(_accumulatorSettingsKey, false).toBool(); |
|
|
|
_deadband = settings.value(_deadbandSettingsKey, false).toBool(); |
|
|
|
_deadband = settings.value(_deadbandSettingsKey, false).toBool(); |
|
|
|
|
|
|
|
_circleCorrection = settings.value(_circleCorrectionSettingsKey, false).toBool(); |
|
|
|
|
|
|
|
|
|
|
|
_throttleMode = (ThrottleMode_t)settings.value(_throttleModeSettingsKey, ThrottleModeCenterZero).toInt(&convertOk); |
|
|
|
_throttleMode = (ThrottleMode_t)settings.value(_throttleModeSettingsKey, ThrottleModeCenterZero).toInt(&convertOk); |
|
|
|
badSettings |= !convertOk; |
|
|
|
badSettings |= !convertOk; |
|
|
@ -264,9 +268,10 @@ void Joystick::_saveSettings(void) |
|
|
|
settings.setValue(_exponentialSettingsKey, _exponential); |
|
|
|
settings.setValue(_exponentialSettingsKey, _exponential); |
|
|
|
settings.setValue(_accumulatorSettingsKey, _accumulator); |
|
|
|
settings.setValue(_accumulatorSettingsKey, _accumulator); |
|
|
|
settings.setValue(_deadbandSettingsKey, _deadband); |
|
|
|
settings.setValue(_deadbandSettingsKey, _deadband); |
|
|
|
|
|
|
|
settings.setValue(_circleCorrectionSettingsKey, _circleCorrection); |
|
|
|
settings.setValue(_throttleModeSettingsKey, _throttleMode); |
|
|
|
settings.setValue(_throttleModeSettingsKey, _throttleMode); |
|
|
|
|
|
|
|
|
|
|
|
qCDebug(JoystickLog) << "_saveSettings calibrated:throttlemode:deadband:txmode" << _calibrated << _throttleMode << _deadband << _transmitterMode; |
|
|
|
qCDebug(JoystickLog) << "_saveSettings calibrated:throttlemode:deadband:txmode" << _calibrated << _throttleMode << _deadband << _circleCorrection << _transmitterMode; |
|
|
|
|
|
|
|
|
|
|
|
QString minTpl ("Axis%1Min"); |
|
|
|
QString minTpl ("Axis%1Min"); |
|
|
|
QString maxTpl ("Axis%1Max"); |
|
|
|
QString maxTpl ("Axis%1Max"); |
|
|
@ -462,17 +467,19 @@ void Joystick::run(void) |
|
|
|
throttle = throttle_accu; |
|
|
|
throttle = throttle_accu; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
float roll_limited = std::max(static_cast<float>(-M_PI_4), std::min(roll, static_cast<float>(M_PI_4))); |
|
|
|
if ( _circleCorrection ) { |
|
|
|
float pitch_limited = std::max(static_cast<float>(-M_PI_4), std::min(pitch, static_cast<float>(M_PI_4))); |
|
|
|
float roll_limited = std::max(static_cast<float>(-M_PI_4), std::min(roll, static_cast<float>(M_PI_4))); |
|
|
|
float yaw_limited = std::max(static_cast<float>(-M_PI_4), std::min(yaw, static_cast<float>(M_PI_4))); |
|
|
|
float pitch_limited = std::max(static_cast<float>(-M_PI_4), std::min(pitch, static_cast<float>(M_PI_4))); |
|
|
|
float throttle_limited = std::max(static_cast<float>(-M_PI_4), std::min(throttle, static_cast<float>(M_PI_4))); |
|
|
|
float yaw_limited = std::max(static_cast<float>(-M_PI_4), std::min(yaw, static_cast<float>(M_PI_4))); |
|
|
|
|
|
|
|
float throttle_limited = std::max(static_cast<float>(-M_PI_4), std::min(throttle, static_cast<float>(M_PI_4))); |
|
|
|
// Map from unit circle to linear range and limit
|
|
|
|
|
|
|
|
roll = std::max(-1.0f, std::min(tanf(asinf(roll_limited)), 1.0f)); |
|
|
|
// Map from unit circle to linear range and limit
|
|
|
|
pitch = std::max(-1.0f, std::min(tanf(asinf(pitch_limited)), 1.0f)); |
|
|
|
roll = std::max(-1.0f, std::min(tanf(asinf(roll_limited)), 1.0f)); |
|
|
|
yaw = std::max(-1.0f, std::min(tanf(asinf(yaw_limited)), 1.0f)); |
|
|
|
pitch = std::max(-1.0f, std::min(tanf(asinf(pitch_limited)), 1.0f)); |
|
|
|
throttle = std::max(-1.0f, std::min(tanf(asinf(throttle_limited)), 1.0f)); |
|
|
|
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 != 0 ) { |
|
|
|
if ( _exponential != 0 ) { |
|
|
|
// Exponential (0% to -50% range like most RC radios)
|
|
|
|
// Exponential (0% to -50% range like most RC radios)
|
|
|
|
//_exponential is set by a slider in joystickConfig.qml
|
|
|
|
//_exponential is set by a slider in joystickConfig.qml
|
|
|
@ -767,6 +774,19 @@ void Joystick::setDeadband(bool deadband) |
|
|
|
_saveSettings(); |
|
|
|
_saveSettings(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Joystick::circleCorrection(void) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return _circleCorrection; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Joystick::setCircleCorrection(bool circleCorrection) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
_circleCorrection = circleCorrection; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_saveSettings(); |
|
|
|
|
|
|
|
emit circleCorrectionChanged(_circleCorrection); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Joystick::setCalibrationMode(bool calibrating) |
|
|
|
void Joystick::setCalibrationMode(bool calibrating) |
|
|
|
{ |
|
|
|
{ |
|
|
|
_calibrationMode = calibrating; |
|
|
|
_calibrationMode = calibrating; |
|
|
|