From c7eb0c912ce6842398ca679c94fba85c8d6ff6cb Mon Sep 17 00:00:00 2001 From: andrew Date: Sun, 12 Dec 2010 04:57:43 +0000 Subject: [PATCH] GCS Control - controller now only updates the OP hardware when it is in GCSControl mode. Previously it would update all the time and this could create glitches in control when both a standard Tx and the GCS were connected to the flight H/W. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2221 ebee16cc-31ac-478f-84a7-5cbb03baadba --- .../plugins/gcscontrol/gcscontrolgadget.cpp | 85 +++++++++++-------- 1 file changed, 49 insertions(+), 36 deletions(-) diff --git a/ground/src/plugins/gcscontrol/gcscontrolgadget.cpp b/ground/src/plugins/gcscontrol/gcscontrolgadget.cpp index a465f1b2c..b93e7cbce 100644 --- a/ground/src/plugins/gcscontrol/gcscontrolgadget.cpp +++ b/ground/src/plugins/gcscontrol/gcscontrolgadget.cpp @@ -173,6 +173,9 @@ void GCSControlGadget::sticksChangedLocally(double leftX, double leftY, double r if ((buttonSettings[i].FunctionID==4)&&((buttonSettings[i].ActionID==1)||(buttonSettings[i].ActionID==2)))buttonThrottleControl=1; } + //if we are not in local gcs control mode, ignore the joystick input + if (((GCSControlGadgetWidget *)m_widget)->getGCSControl()==false)return; + if((newThrottle != oldThrottle) || (newPitch != oldPitch) || (newYaw != oldYaw) || (newRoll != oldRoll)) { if (buttonRollControl==0)obj->getField("Roll")->setDouble(newRoll); if (buttonPitchControl==0)obj->getField("Pitch")->setDouble(newPitch); @@ -196,58 +199,68 @@ void GCSControlGadget::buttonState(ButtonNumber number, bool pressed) ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); UAVObjectManager *objManager = pm->getObject(); UAVDataObject* obj = dynamic_cast( objManager->getObject(QString("ManualControlCommand")) ); + bool currentCGSControl = ((GCSControlGadgetWidget *)m_widget)->getGCSControl(); switch (buttonSettings[number].ActionID) { case 1://increase - switch (buttonSettings[number].FunctionID) + if (currentCGSControl) { - case 1://Roll - obj->getField("Roll")->setValue(bound(obj->getField("Roll")->getValue().toDouble()+buttonSettings[number].Amount)); - break; - case 2://Pitch - obj->getField("Pitch")->setValue(bound(obj->getField("Pitch")->getValue().toDouble()+buttonSettings[number].Amount)); - break; - case 3://Yaw - obj->getField("Yaw")->setValue(wrap(obj->getField("Yaw")->getValue().toDouble()+buttonSettings[number].Amount)); - break; - case 4://Throttle - obj->getField("Throttle")->setValue(bound(obj->getField("Throttle")->getValue().toDouble()+buttonSettings[number].Amount)); - break; + switch (buttonSettings[number].FunctionID) + { + case 1://Roll + obj->getField("Roll")->setValue(bound(obj->getField("Roll")->getValue().toDouble()+buttonSettings[number].Amount)); + break; + case 2://Pitch + obj->getField("Pitch")->setValue(bound(obj->getField("Pitch")->getValue().toDouble()+buttonSettings[number].Amount)); + break; + case 3://Yaw + obj->getField("Yaw")->setValue(wrap(obj->getField("Yaw")->getValue().toDouble()+buttonSettings[number].Amount)); + break; + case 4://Throttle + obj->getField("Throttle")->setValue(bound(obj->getField("Throttle")->getValue().toDouble()+buttonSettings[number].Amount)); + break; + } } break; case 2://decrease - switch (buttonSettings[number].FunctionID) + if (currentCGSControl) { - case 1://Roll - obj->getField("Roll")->setValue(bound(obj->getField("Roll")->getValue().toDouble()-buttonSettings[number].Amount)); - break; - case 2://Pitch - obj->getField("Pitch")->setValue(bound(obj->getField("Pitch")->getValue().toDouble()-buttonSettings[number].Amount)); - break; - case 3://Yaw - obj->getField("Yaw")->setValue(wrap(obj->getField("Yaw")->getValue().toDouble()-buttonSettings[number].Amount)); - break; - case 4://Throttle - obj->getField("Throttle")->setValue(bound(obj->getField("Throttle")->getValue().toDouble()-buttonSettings[number].Amount)); - break; + switch (buttonSettings[number].FunctionID) + { + case 1://Roll + obj->getField("Roll")->setValue(bound(obj->getField("Roll")->getValue().toDouble()-buttonSettings[number].Amount)); + break; + case 2://Pitch + obj->getField("Pitch")->setValue(bound(obj->getField("Pitch")->getValue().toDouble()-buttonSettings[number].Amount)); + break; + case 3://Yaw + obj->getField("Yaw")->setValue(wrap(obj->getField("Yaw")->getValue().toDouble()-buttonSettings[number].Amount)); + break; + case 4://Throttle + obj->getField("Throttle")->setValue(bound(obj->getField("Throttle")->getValue().toDouble()-buttonSettings[number].Amount)); + break; + } } break; case 3://toggle - switch (buttonSettings[number].FunctionID) - { - case 1://Armed - if(obj->getField("Armed")->getValue().toString().compare("True")==0) + switch (buttonSettings[number].FunctionID) + { + case 1://Armed + if (currentCGSControl) { - obj->getField("Armed")->setValue("False"); - } - else - { - obj->getField("Armed")->setValue("True"); + if(obj->getField("Armed")->getValue().toString().compare("True")==0) + { + obj->getField("Armed")->setValue("False"); + } + else + { + obj->getField("Armed")->setValue("True"); + } } break; case 2://GCS Control - bool currentCGSControl = ((GCSControlGadgetWidget *)m_widget)->getGCSControl(); + //Toggle the GCS Control checkbox, its built in signalling will handle the update to OP ((GCSControlGadgetWidget *)m_widget)->setGCSControl(!currentCGSControl); break;