Browse Source

Joystick: Fix calibration and default use: Do not send anything to vehicle until enabled. Enable after calibration by default.

QGC4.4
Lorenz Meier 10 years ago
parent
commit
e93d3d1de4
  1. 54
      src/Joystick/Joystick.cc
  2. 7
      src/VehicleSetup/JoystickConfigController.cc

54
src/Joystick/Joystick.cc

@ -367,27 +367,30 @@ void Joystick::run(void) @@ -367,27 +367,30 @@ void Joystick::run(void)
void Joystick::startPolling(Vehicle* vehicle)
{
if (isRunning()) {
if (vehicle != _activeVehicle) {
// Joystick was previously disabled, but now enabled from config screen
if (_calibrationMode == CalibrationModeOff) {
qWarning() << "Incorrect usage pattern";
return;
}
_activeVehicle = vehicle;
_pollingStartedForCalibration = false;
if (vehicle) {
// If a vehicle is connected, disconnect it
if (_activeVehicle) {
UAS* uas = _activeVehicle->uas();
disconnect(this, &Joystick::manualControl, uas, &UAS::setExternalControlSetpoint);
}
} else {
// Always set up the new vehicle
_activeVehicle = vehicle;
UAS* uas = _activeVehicle->uas();
connect(this, &Joystick::manualControl, uas, &UAS::setExternalControlSetpoint);
// FIXME: ****
//connect(this, &Joystick::buttonActionTriggered, uas, &UAS::triggerAction);
// Only connect the new vehicle if it wants joystick data
if (vehicle->joystickEnabled()) {
_pollingStartedForCalibration = false;
UAS* uas = _activeVehicle->uas();
connect(this, &Joystick::manualControl, uas, &UAS::setExternalControlSetpoint);
// FIXME: ****
//connect(this, &Joystick::buttonActionTriggered, uas, &UAS::triggerAction);
}
}
if (!isRunning()) {
_exitThread = false;
start();
}
@ -396,9 +399,12 @@ void Joystick::startPolling(Vehicle* vehicle) @@ -396,9 +399,12 @@ void Joystick::startPolling(Vehicle* vehicle)
void Joystick::stopPolling(void)
{
if (isRunning()) {
UAS* uas = _activeVehicle->uas();
disconnect(this, &Joystick::manualControl, uas, &UAS::setExternalControlSetpoint);
if (_activeVehicle && _activeVehicle->joystickEnabled()) {
UAS* uas = _activeVehicle->uas();
disconnect(this, &Joystick::manualControl, uas, &UAS::setExternalControlSetpoint);
}
// FIXME: ****
//disconnect(this, &Joystick::buttonActionTriggered, uas, &UAS::triggerAction);
@ -544,6 +550,10 @@ void Joystick::stopCalibrationMode(CalibrationMode_t mode) @@ -544,6 +550,10 @@ void Joystick::stopCalibrationMode(CalibrationMode_t mode)
void Joystick::_buttonAction(const QString& action)
{
if (!_activeVehicle || !_activeVehicle->joystickEnabled()) {
return;
}
if (action == "Arm") {
_activeVehicle->setArmed(true);
} else if (action == "Disarm") {

7
src/VehicleSetup/JoystickConfigController.cc

@ -99,7 +99,7 @@ const JoystickConfigController::stateMachineEntry* JoystickConfigController::_ge @@ -99,7 +99,7 @@ const JoystickConfigController::stateMachineEntry* JoystickConfigController::_ge
static const char* msgPitchDown = "Move the Pitch stick all the way down and hold it there...";
static const char* msgPitchUp = "Move the Pitch stick all the way up and hold it there...";
static const char* msgPitchCenter = "Allow the Pitch stick to move back to center...";
static const char* msgComplete = "All settings have been captured. Click Next to Save.";
static const char* msgComplete = "All settings have been captured. Click Next to enable the joystick.";
static const stateMachineEntry rgStateMachine[] = {
//Function
@ -564,6 +564,11 @@ void JoystickConfigController::_writeCalibration(void) @@ -564,6 +564,11 @@ void JoystickConfigController::_writeCalibration(void)
_stopCalibration();
_setInternalCalibrationValuesFromSettings();
Vehicle* vehicle = qgcApp()->toolbox()->multiVehicleManager()->activeVehicle();
if (vehicle) {
vehicle->setJoystickEnabled(true);
}
}
/// @brief Starts the calibration process

Loading…
Cancel
Save