From ed54716436ecb7e5f0703a6ab31d1fd44b36be4c Mon Sep 17 00:00:00 2001 From: Mike LaBranche Date: Mon, 14 May 2012 10:05:40 -0700 Subject: [PATCH] add gui config data bit storage to fixedwing,multirotor,ground vehicles --- .../cfg_vehicletypes/configccpmwidget.cpp | 54 ++-- .../cfg_vehicletypes/configccpmwidget.h | 48 +-- .../configfixedwingwidget.cpp | 177 ++++------- .../configgroundvehiclewidget.cpp | 138 +++------ .../configmultirotorwidget.cpp | 276 ++++++++---------- .../config/cfg_vehicletypes/guiconfigdata.cpp | 131 ++++++++- .../config/cfg_vehicletypes/guiconfigdata.h | 17 +- .../config/configvehicletypewidget.cpp | 12 +- .../plugins/config/configvehicletypewidget.h | 6 +- shared/uavobjectdefinition/systemsettings.xml | 2 +- 10 files changed, 428 insertions(+), 433 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.cpp b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.cpp index 6d7a974c2..00da51f44 100644 --- a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.cpp @@ -25,7 +25,7 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "configccpmwidget.h" -#include "mixersettings.h" +//#include "mixersettings.h" #include #include @@ -892,7 +892,7 @@ void ConfigccpmWidget::UpdateMixer() } } - if (GUIConfigData.heli.SwasplateType>0) + if (GUIConfigData.heli.SwashplateType>0) {//not advanced settings //get the channel data from the ui MixerChannelData[0] = m_ccpm->ccpmEngineChannel->currentIndex(); @@ -999,7 +999,7 @@ void ConfigccpmWidget::UpdateCCPMOptionsFromUI() if (updatingFromHardware) return; //get the user options //swashplate config - GUIConfigData.heli.SwasplateType = m_ccpm->ccpmType->count() - m_ccpm->ccpmType->currentIndex()-1; + GUIConfigData.heli.SwashplateType = m_ccpm->ccpmType->count() - m_ccpm->ccpmType->currentIndex()-1; GUIConfigData.heli.FirstServoIndex = m_ccpm->ccpmSingleServo->currentIndex(); //ccpm mixing options @@ -1036,12 +1036,17 @@ void ConfigccpmWidget::UpdateCCPMOptionsFromUI() GUIConfigData.heli.ServoIndexX = m_ccpm->ccpmServoXChannel->currentIndex(); GUIConfigData.heli.ServoIndexY = m_ccpm->ccpmServoYChannel->currentIndex(); GUIConfigData.heli.ServoIndexZ = m_ccpm->ccpmServoZChannel->currentIndex(); + + //throttle + GUIConfigData.heli.Throttle = m_ccpm->ccpmEngineChannel->currentIndex(); + //tail + GUIConfigData.heli.Tail = m_ccpm->ccpmTailChannel->currentIndex(); } void ConfigccpmWidget::UpdateCCPMUIFromOptions() { //swashplate config - m_ccpm->ccpmType->setCurrentIndex(m_ccpm->ccpmType->count() - (GUIConfigData.heli.SwasplateType +1)); + m_ccpm->ccpmType->setCurrentIndex(m_ccpm->ccpmType->count() - (GUIConfigData.heli.SwashplateType +1)); m_ccpm->ccpmSingleServo->setCurrentIndex(GUIConfigData.heli.FirstServoIndex); //ccpm mixing options @@ -1070,6 +1075,10 @@ void ConfigccpmWidget::UpdateCCPMUIFromOptions() m_ccpm->ccpmServoYChannel->setCurrentIndex(GUIConfigData.heli.ServoIndexY); m_ccpm->ccpmServoZChannel->setCurrentIndex(GUIConfigData.heli.ServoIndexZ); + //throttle + m_ccpm->ccpmEngineChannel->setCurrentIndex(GUIConfigData.heli.Throttle); + //tail + m_ccpm->ccpmTailChannel->setCurrentIndex((GUIConfigData.heli.Tail)); } @@ -1117,15 +1126,17 @@ void ConfigccpmWidget::requestccpmUpdate() unsigned int i,j; - SystemSettings * systemSettings = SystemSettings::GetInstance(getObjectManager()); - Q_ASSERT(systemSettings); - SystemSettings::DataFields systemSettingsData = systemSettings->getData(); +// SystemSettings * systemSettings = SystemSettings::GetInstance(getObjectManager()); +// Q_ASSERT(systemSettings); +// SystemSettings::DataFields systemSettingsData = systemSettings->getData(); - Q_ASSERT(SystemSettings::GUICONFIGDATA_NUMELEM == - (sizeof(GUIConfigData.UAVObject) / sizeof(GUIConfigData.UAVObject[0]))); +// Q_ASSERT(SystemSettings::GUICONFIGDATA_NUMELEM == +// (sizeof(GUIConfigData.UAVObject) / sizeof(GUIConfigData.UAVObject[0]))); - for(i = 0; i < SystemSettings::GUICONFIGDATA_NUMELEM; i++) - GUIConfigData.UAVObject[i]=systemSettingsData.GUIConfigData[i]; +// for(i = 0; i < SystemSettings::GUICONFIGDATA_NUMELEM; i++) +// GUIConfigData.UAVObject[i]=systemSettingsData.GUIConfigData[i]; + + GUIConfigData = GUIManager.GetConfigData(); UpdateCCPMUIFromOptions(); @@ -1178,7 +1189,7 @@ void ConfigccpmWidget::requestccpmUpdate() (MixerDataFromHeli[i][4]==0))//Yaw { EngineChannel = i; - m_ccpm->ccpmEngineChannel->setCurrentIndex(i); + //m_ccpm->ccpmEngineChannel->setCurrentIndex(i); } //check if this is the tail rotor... REVO and YAW @@ -1190,7 +1201,7 @@ void ConfigccpmWidget::requestccpmUpdate() (MixerDataFromHeli[i][4]!=0))//Yaw { TailRotorChannel = i; - m_ccpm->ccpmTailChannel->setCurrentIndex(i); + //m_ccpm->ccpmTailChannel->setCurrentIndex(i); m_ccpm->ccpmRevoSlider->setValue((MixerDataFromHeli[i][0]*100)/127); m_ccpm->ccpmREVOspinBox->setValue((MixerDataFromHeli[i][0]*100)/127); } @@ -1239,14 +1250,17 @@ void ConfigccpmWidget::sendccpmUpdate() UpdateCCPMOptionsFromUI(); + GUIManager.SetConfigData(GUIConfigData); + // Store the data required to reconstruct - SystemSettings * systemSettings = SystemSettings::GetInstance(getObjectManager()); - Q_ASSERT(systemSettings); - SystemSettings::DataFields systemSettingsData = systemSettings->getData(); - systemSettingsData.GUIConfigData[0] = GUIConfigData.UAVObject[0]; - systemSettingsData.GUIConfigData[1] = GUIConfigData.UAVObject[1]; - systemSettings->setData(systemSettingsData); - systemSettings->updated(); +// SystemSettings * systemSettings = SystemSettings::GetInstance(getObjectManager()); +// Q_ASSERT(systemSettings); +// SystemSettings::DataFields systemSettingsData = systemSettings->getData(); +// for (i=0; isetData(systemSettingsData); +// systemSettings->updated(); MixerSettings * mixerSettings = MixerSettings::GetInstance(getObjectManager()); Q_ASSERT(mixerSettings); diff --git a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.h b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.h index 31a5e227d..75652c01b 100644 --- a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.h +++ b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.h @@ -29,6 +29,7 @@ #include "ui_ccpm.h" #include "../uavobjectwidgetutils/configtaskwidget.h" +#include "guiconfigdata.h" #include "extensionsystem/pluginmanager.h" #include "uavobjectmanager.h" #include "uavobject.h" @@ -49,29 +50,31 @@ typedef struct { int Neutral[CCPM_MAX_SWASH_SERVOS]; int Min[CCPM_MAX_SWASH_SERVOS]; } SwashplateServoSettingsStruct; +//typedef struct { +// uint SwasplateType:3; +// uint FirstServoIndex:2; +// uint CorrectionAngle:9; +// uint ccpmCollectivePassthroughState:1; +// uint ccpmLinkCyclicState:1; +// uint ccpmLinkRollState:1; +// uint SliderValue0:7; +// uint SliderValue1:7; +// uint SliderValue2:7;//41bits +// uint ServoIndexW:4; +// uint ServoIndexX:4; +// uint ServoIndexY:4; +// uint ServoIndexZ:4;//57bits +// uint Throttle:4; +// uint Tail:4; //65bits +// quint32 padding1:31; //96bits +// quint32 padding2; //128bits +//} __attribute__((packed)) heliGUISettingsStruct; -typedef struct { - uint SwasplateType:3; - uint FirstServoIndex:2; - uint CorrectionAngle:9; - uint ccpmCollectivePassthroughState:1; - uint ccpmLinkCyclicState:1; - uint ccpmLinkRollState:1; - uint SliderValue0:7; - uint SliderValue1:7; - uint SliderValue2:7;//41bits - uint ServoIndexW:4; - uint ServoIndexX:4; - uint ServoIndexY:4; - uint ServoIndexZ:4;//57bits - uint padding:7; -} __attribute__((packed)) heliGUISettingsStruct; - -typedef union -{ - uint UAVObject[2];//32bits * 2 - heliGUISettingsStruct heli;//64bits -} GUIConfigDataUnion; +//typedef union +//{ +// uint UAVObject[4];//32bits * 4 +// heliGUISettingsStruct heli;//128bits +//} GUIConfigDataUnion; class ConfigccpmWidget: public ConfigTaskWidget { @@ -109,6 +112,7 @@ private: SwashplateServoSettingsStruct oldSwashLvlConfiguration; SwashplateServoSettingsStruct newSwashLvlConfiguration; + GUIConfigDataManager GUIManager; GUIConfigDataUnion GUIConfigData; int MixerChannelData[6]; diff --git a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configfixedwingwidget.cpp b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configfixedwingwidget.cpp index 7c641acfa..32ec686e2 100644 --- a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configfixedwingwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configfixedwingwidget.cpp @@ -136,7 +136,7 @@ QString ConfigVehicleTypeWidget::updateFixedWingObjectsFromWidgets() //All airframe types must start with "FixedWing" if (m_aircraft->fixedWingType->currentText() == "Elevator aileron rudder" ) { airframeType = "FixedWing"; - setupFrameFixedWing( airframeType ); + setupFrameFixedWing( airframeType ); } else if (m_aircraft->fixedWingType->currentText() == "Elevon") { airframeType = "FixedWingElevon"; setupFrameElevon( airframeType ); @@ -156,42 +156,22 @@ QString ConfigVehicleTypeWidget::updateFixedWingObjectsFromWidgets() Helper function to refresh the UI widget values */ void ConfigVehicleTypeWidget::refreshFixedWingWidgetsValues(QString frameType) -{ - - UAVDataObject* obj; - UAVObjectField *field; - - // Then retrieve how channels are setup - obj = dynamic_cast(getObjectManager()->getObject(QString("ActuatorSettings"))); - Q_ASSERT(obj); - field = obj->getField(QString("FixedWingThrottle")); - Q_ASSERT(field); - m_aircraft->fwEngineChannelBox->setCurrentIndex(m_aircraft->fwEngineChannelBox->findText(field->getValue().toString())); +{ + GUIConfigData = GUIManager.GetConfigData(); + fixedGUISettingsStruct fixed = GUIConfigData.fixed; + + // Then retrieve how channels are setup + setComboCurrentIndex(m_aircraft->fwEngineChannelBox, fixed.FixedWingThrottle); + setComboCurrentIndex(m_aircraft->fwAileron1ChannelBox, fixed.FixedWingRoll1); + setComboCurrentIndex(m_aircraft->fwAileron2ChannelBox, fixed.FixedWingRoll2); + setComboCurrentIndex(m_aircraft->fwElevator1ChannelBox, fixed.FixedWingPitch1); + setComboCurrentIndex(m_aircraft->fwElevator2ChannelBox, fixed.FixedWingPitch2); + setComboCurrentIndex(m_aircraft->fwRudder1ChannelBox, fixed.FixedWingYaw1); + setComboCurrentIndex(m_aircraft->fwRudder2ChannelBox, fixed.FixedWingYaw2); + + UAVDataObject* obj; + UAVObjectField *field; - field = obj->getField(QString("FixedWingRoll1")); - Q_ASSERT(field); - m_aircraft->fwAileron1ChannelBox->setCurrentIndex(m_aircraft->fwAileron1ChannelBox->findText(field->getValue().toString())); - - field = obj->getField(QString("FixedWingRoll2")); - Q_ASSERT(field); - m_aircraft->fwAileron2ChannelBox->setCurrentIndex(m_aircraft->fwAileron2ChannelBox->findText(field->getValue().toString())); - - field = obj->getField(QString("FixedWingPitch1")); - Q_ASSERT(field); - m_aircraft->fwElevator1ChannelBox->setCurrentIndex(m_aircraft->fwElevator1ChannelBox->findText(field->getValue().toString())); - - field = obj->getField(QString("FixedWingPitch2")); - Q_ASSERT(field); - m_aircraft->fwElevator2ChannelBox->setCurrentIndex(m_aircraft->fwElevator2ChannelBox->findText(field->getValue().toString())); - - field = obj->getField(QString("FixedWingYaw1")); - Q_ASSERT(field); - m_aircraft->fwRudder1ChannelBox->setCurrentIndex(m_aircraft->fwRudder1ChannelBox->findText(field->getValue().toString())); - - field = obj->getField(QString("FixedWingYaw2")); - Q_ASSERT(field); - m_aircraft->fwRudder2ChannelBox->setCurrentIndex(m_aircraft->fwRudder2ChannelBox->findText(field->getValue().toString())); - if (frameType == "FixedWingElevon") { // If the airframe is elevon, restore the slider setting // Find the channel number for Elevon1 (FixedWingRoll1) @@ -245,40 +225,24 @@ bool ConfigVehicleTypeWidget::setupFrameFixedWing(QString airframeType) // m_aircraft->fwStatusLabel->setText("ERROR: check channel assignment"); return false; } - // Now setup the channels: - resetActuators(); - - UAVDataObject* obj = dynamic_cast(getObjectManager()->getObject(QString("ActuatorSettings"))); - Q_ASSERT(obj); - - // Elevator - UAVObjectField *field = obj->getField("FixedWingPitch1"); - Q_ASSERT(field); - field->setValue(m_aircraft->fwElevator1ChannelBox->currentText()); - field = obj->getField("FixedWingPitch2"); - Q_ASSERT(field); - field->setValue(m_aircraft->fwElevator2ChannelBox->currentText()); - // Aileron - field = obj->getField("FixedWingRoll1"); - Q_ASSERT(field); - field->setValue(m_aircraft->fwAileron1ChannelBox->currentText()); - field = obj->getField("FixedWingRoll2"); - Q_ASSERT(field); - field->setValue(m_aircraft->fwAileron2ChannelBox->currentText()); - - // Rudder - field = obj->getField("FixedWingYaw1"); - Q_ASSERT(field); - field->setValue(m_aircraft->fwRudder1ChannelBox->currentText()); - - // Throttle - field = obj->getField("FixedWingThrottle"); - Q_ASSERT(field); - field->setValue(m_aircraft->fwEngineChannelBox->currentText()); + // Now setup the channels: - obj->updated(); + GUIConfigData = GUIManager.GetConfigData(); + GUIManager.ResetActuators(&GUIConfigData); + + GUIConfigData.fixed.FixedWingPitch1 = m_aircraft->fwElevator1ChannelBox->currentIndex(); + GUIConfigData.fixed.FixedWingPitch2 = m_aircraft->fwElevator2ChannelBox->currentIndex(); + GUIConfigData.fixed.FixedWingRoll1 = m_aircraft->fwAileron1ChannelBox->currentIndex(); + GUIConfigData.fixed.FixedWingRoll2 = m_aircraft->fwAileron2ChannelBox->currentIndex(); + GUIConfigData.fixed.FixedWingYaw1 = m_aircraft->fwRudder1ChannelBox->currentIndex(); + GUIConfigData.fixed.FixedWingThrottle = m_aircraft->fwEngineChannelBox->currentIndex(); + + GUIManager.SetConfigData(GUIConfigData); + UAVDataObject* obj; + UAVObjectField* field; + obj = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); Q_ASSERT(obj); // ... and compute the matrix: @@ -382,32 +346,20 @@ bool ConfigVehicleTypeWidget::setupFrameElevon(QString airframeType) return false; } - resetActuators(); - UAVDataObject* obj = dynamic_cast(getObjectManager()->getObject(QString("ActuatorSettings"))); - Q_ASSERT(obj); - - // Elevons - UAVObjectField *field = obj->getField("FixedWingRoll1"); - Q_ASSERT(field); - field->setValue(m_aircraft->fwAileron1ChannelBox->currentText()); - field = obj->getField("FixedWingRoll2"); - Q_ASSERT(field); - field->setValue(m_aircraft->fwAileron2ChannelBox->currentText()); - // Rudder 1 (can be None) - field = obj->getField("FixedWingYaw1"); - Q_ASSERT(field); - field->setValue(m_aircraft->fwRudder1ChannelBox->currentText()); - // Rudder 2 (can be None) - field = obj->getField("FixedWingYaw2"); - Q_ASSERT(field); - field->setValue(m_aircraft->fwRudder2ChannelBox->currentText()); - // Throttle - field = obj->getField("FixedWingThrottle"); - Q_ASSERT(field); - field->setValue(m_aircraft->fwEngineChannelBox->currentText()); - - obj->updated(); - + GUIConfigData = GUIManager.GetConfigData(); + GUIManager.ResetActuators(&GUIConfigData); + + GUIConfigData.fixed.FixedWingRoll1 = m_aircraft->fwAileron1ChannelBox->currentIndex(); + GUIConfigData.fixed.FixedWingRoll2 = m_aircraft->fwAileron2ChannelBox->currentIndex(); + GUIConfigData.fixed.FixedWingYaw1 = m_aircraft->fwRudder1ChannelBox->currentIndex(); + GUIConfigData.fixed.FixedWingYaw2 = m_aircraft->fwRudder2ChannelBox->currentIndex(); + GUIConfigData.fixed.FixedWingThrottle = m_aircraft->fwEngineChannelBox->currentIndex(); + + GUIManager.SetConfigData(GUIConfigData); + + UAVDataObject* obj; + UAVObjectField* field; + // Save the curve: obj = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); Q_ASSERT(obj); @@ -506,31 +458,20 @@ bool ConfigVehicleTypeWidget::setupFrameVtail(QString airframeType) return false; } - resetActuators(); - UAVDataObject* obj = dynamic_cast(getObjectManager()->getObject(QString("ActuatorSettings"))); - Q_ASSERT(obj); - - // Elevons - UAVObjectField *field = obj->getField("FixedWingPitch1"); - Q_ASSERT(field); - field->setValue(m_aircraft->fwElevator1ChannelBox->currentText()); - field = obj->getField("FixedWingPitch2"); - Q_ASSERT(field); - field->setValue(m_aircraft->fwElevator2ChannelBox->currentText()); - field = obj->getField("FixedWingRoll1"); - Q_ASSERT(field); - field->setValue(m_aircraft->fwAileron1ChannelBox->currentText()); - field = obj->getField("FixedWingRoll2"); - Q_ASSERT(field); - field->setValue(m_aircraft->fwAileron2ChannelBox->currentText()); - - // Throttle - field = obj->getField("FixedWingThrottle"); - Q_ASSERT(field); - field->setValue(m_aircraft->fwEngineChannelBox->currentText()); - - obj->updated(); - + GUIConfigData = GUIManager.GetConfigData(); + GUIManager.ResetActuators(&GUIConfigData); + + GUIConfigData.fixed.FixedWingPitch1 = m_aircraft->fwElevator1ChannelBox->currentIndex(); + GUIConfigData.fixed.FixedWingPitch2 = m_aircraft->fwElevator2ChannelBox->currentIndex(); + GUIConfigData.fixed.FixedWingRoll1 = m_aircraft->fwAileron1ChannelBox->currentIndex(); + GUIConfigData.fixed.FixedWingRoll2 = m_aircraft->fwAileron2ChannelBox->currentIndex(); + GUIConfigData.fixed.FixedWingThrottle = m_aircraft->fwEngineChannelBox->currentIndex(); + + GUIManager.SetConfigData(GUIConfigData); + + UAVDataObject* obj; + UAVObjectField* field; + obj = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); Q_ASSERT(obj); // ... and compute the matrix: diff --git a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configgroundvehiclewidget.cpp b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configgroundvehiclewidget.cpp index 67035ae39..b7b31b0f6 100644 --- a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configgroundvehiclewidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configgroundvehiclewidget.cpp @@ -194,38 +194,15 @@ void ConfigVehicleTypeWidget::refreshGroundVehicleWidgetsValues(QString frameTyp UAVDataObject* obj; UAVObjectField *field; + GUIConfigData = GUIManager.GetConfigData(); + //THIS SECTION STILL NEEDS WORK. FOR THE MOMENT, USE THE FIXED-WING ONBOARD SETTING IN ORDER TO MINIMIZE CHANCES OF BOLLOXING REAL CODE // Retrieve channel setup values - obj = dynamic_cast(getObjectManager()->getObject(QString("ActuatorSettings"))); - Q_ASSERT(obj); - field = obj->getField(QString("FixedWingThrottle")); - Q_ASSERT(field); - m_aircraft->gvEngineChannelBox->setCurrentIndex(m_aircraft->gvEngineChannelBox->findText(field->getValue().toString())); - - field = obj->getField(QString("FixedWingRoll1")); - Q_ASSERT(field); - m_aircraft->gvAileron1ChannelBox->setCurrentIndex(m_aircraft->gvAileron1ChannelBox->findText(field->getValue().toString())); - - field = obj->getField(QString("FixedWingRoll2")); - Q_ASSERT(field); - m_aircraft->gvAileron2ChannelBox->setCurrentIndex(m_aircraft->gvAileron2ChannelBox->findText(field->getValue().toString())); - - field = obj->getField(QString("GroundVehicleThrottle1")); - Q_ASSERT(field); - m_aircraft->gvMotor1ChannelBox->setCurrentIndex(m_aircraft->gvMotor1ChannelBox->findText(field->getValue().toString())); - - field = obj->getField(QString("GroundVehicleThrottle2")); - Q_ASSERT(field); - m_aircraft->gvMotor2ChannelBox->setCurrentIndex(m_aircraft->gvMotor2ChannelBox->findText(field->getValue().toString())); - - field = obj->getField(QString("GroundVehicleSteering1")); - Q_ASSERT(field); - m_aircraft->gvSteering1ChannelBox->setCurrentIndex(m_aircraft->gvSteering1ChannelBox->findText(field->getValue().toString())); - - field = obj->getField(QString("GroundVehicleSteering2")); - Q_ASSERT(field); - m_aircraft->gvSteering2ChannelBox->setCurrentIndex(m_aircraft->gvSteering2ChannelBox->findText(field->getValue().toString())); - + setComboCurrentIndex(m_aircraft->gvMotor1ChannelBox, GUIConfigData.ground.GroundVehicleThrottle1); + setComboCurrentIndex(m_aircraft->gvMotor2ChannelBox, GUIConfigData.ground.GroundVehicleThrottle2); + setComboCurrentIndex(m_aircraft->gvSteering1ChannelBox, GUIConfigData.ground.GroundVehicleSteering1); + setComboCurrentIndex(m_aircraft->gvSteering2ChannelBox, GUIConfigData.ground.GroundVehicleSteering2); + if (frameType == "GroundVehicleDifferential") { //CURRENTLY BROKEN UNTIL WE DECIDE HOW DIFFERENTIAL SHOULD BEHAVE // If the vehicle type is "differential", restore the slider setting @@ -280,25 +257,19 @@ bool ConfigVehicleTypeWidget::setupGroundVehicleMotorcycle(QString airframeType) return false; } - + // Now setup the channels: - resetActuators(); - - UAVDataObject* obj = dynamic_cast(getObjectManager()->getObject(QString("ActuatorSettings"))); - Q_ASSERT(obj); - - // Left motor - UAVObjectField *field = obj->getField("GroundVehicleThrottle1"); - Q_ASSERT(field); - field->setValue(m_aircraft->gvMotor1ChannelBox->currentText()); - - // Right motor - field = obj->getField("GroundVehicleThrottle2"); - Q_ASSERT(field); - field->setValue(m_aircraft->gvMotor2ChannelBox->currentText()); - - obj->updated(); + GUIConfigData = GUIManager.GetConfigData(); + + GUIManager.ResetActuators(&GUIConfigData); + GUIConfigData.ground.GroundVehicleThrottle1 = m_aircraft->gvMotor1ChannelBox->currentIndex(); + GUIConfigData.ground.GroundVehicleThrottle2 = m_aircraft->gvMotor2ChannelBox->currentIndex(); + + GUIManager.SetConfigData(GUIConfigData); + UAVObject* obj; + UAVObjectField* field; + obj = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); Q_ASSERT(obj); // ... and compute the matrix: @@ -397,25 +368,19 @@ bool ConfigVehicleTypeWidget::setupGroundVehicleDifferential(QString airframeTyp return false; } + + // Now setup the channels: + GUIConfigData = GUIManager.GetConfigData(); + GUIManager.ResetActuators(&GUIConfigData); - // Now setup the channels: - resetActuators(); - - UAVDataObject* obj = dynamic_cast(getObjectManager()->getObject(QString("ActuatorSettings"))); - Q_ASSERT(obj); - - // Left motor - UAVObjectField *field = obj->getField("GroundVehicleThrottle1"); - Q_ASSERT(field); - field->setValue(m_aircraft->gvMotor1ChannelBox->currentText()); - - // Right motor - field = obj->getField("GroundVehicleThrottle2"); - Q_ASSERT(field); - field->setValue(m_aircraft->gvMotor2ChannelBox->currentText()); - - obj->updated(); + GUIConfigData.ground.GroundVehicleThrottle1 = m_aircraft->gvMotor1ChannelBox->currentIndex(); + GUIConfigData.ground.GroundVehicleThrottle2 = m_aircraft->gvMotor2ChannelBox->currentIndex(); + + GUIManager.SetConfigData((GUIConfigData)); + UAVObject* obj; + UAVObjectField* field; + obj = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); Q_ASSERT(obj); // ... and compute the matrix: @@ -524,43 +489,20 @@ bool ConfigVehicleTypeWidget::setupGroundVehicleCar(QString airframeType) // m_aircraft->gvMotor2Label->setText(htmlText->toPlainText()); // } - // Now setup the channels: - resetActuators(); + // Now setup the channels: + GUIConfigData = GUIManager.GetConfigData(); + GUIManager.ResetActuators(&GUIConfigData); - UAVDataObject* obj = dynamic_cast(getObjectManager()->getObject(QString("ActuatorSettings"))); - Q_ASSERT(obj); - - // Front motor - UAVObjectField *field = obj->getField("GroundVehicleThrottle1"); - Q_ASSERT(field); - field->setValue(m_aircraft->gvMotor1ChannelBox->currentText()); - - // Rear motor - field = obj->getField("GroundVehicleThrottle2"); - Q_ASSERT(field); - field->setValue(m_aircraft->gvMotor2ChannelBox->currentText()); + GUIConfigData.ground.GroundVehicleThrottle1 = m_aircraft->gvMotor1ChannelBox->currentIndex(); + GUIConfigData.ground.GroundVehicleThrottle2 = m_aircraft->gvMotor2ChannelBox->currentIndex(); + GUIConfigData.ground.GroundVehicleSteering1 = m_aircraft->gvSteering1ChannelBox->currentIndex(); + GUIConfigData.ground.GroundVehicleSteering2 = m_aircraft->gvSteering2ChannelBox->currentIndex(); -// // Aileron -// field = obj->getField("FixedWingRoll1"); -// Q_ASSERT(field); -// field->setValue(m_aircraft->fwAileron1ChannelBox->currentText()); -// -// field = obj->getField("FixedWingRoll2"); -// Q_ASSERT(field); -// field->setValue(m_aircraft->fwAileron2ChannelBox->currentText()); - - // Front steering - field = obj->getField("GroundVehicleSteering1"); - Q_ASSERT(field); - field->setValue(m_aircraft->gvSteering1ChannelBox->currentText()); - - // Rear steering - field = obj->getField("GroundVehicleSteering2"); - Q_ASSERT(field); - field->setValue(m_aircraft->gvSteering2ChannelBox->currentText()); - - obj->updated(); + GUIManager.SetConfigData(GUIConfigData); + UAVDataObject* obj; + UAVObjectField* field; + obj = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); Q_ASSERT(obj); // ... and compute the matrix: diff --git a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configmultirotorwidget.cpp b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configmultirotorwidget.cpp index c0d4972f0..e6701f002 100644 --- a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configmultirotorwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configmultirotorwidget.cpp @@ -41,6 +41,7 @@ #include "mixersettings.h" #include "systemsettings.h" #include "actuatorcommand.h" +#include "guiconfigdata.h" //#define Pi 3.14159265358979323846 @@ -63,7 +64,7 @@ void ConfigVehicleTypeWidget::setupMultiRotorUI(QString frameType) //and grey out all unused motor channel boxes for (int i=4; i <=8; i++) { QComboBox *combobox = qFindChild(this, "multiMotorChannelBox" + QString::number(i)); - combobox->setEnabled(false); + combobox->setEnabled(false); } m_aircraft->triYawChannelBox->setEnabled(true); @@ -80,7 +81,7 @@ void ConfigVehicleTypeWidget::setupMultiRotorUI(QString frameType) //and grey out all unused motor channel boxes for (int i=5; i <=8; i++) { QComboBox *combobox = qFindChild(this, "multiMotorChannelBox" + QString::number(i)); - combobox->setEnabled(false); + combobox->setEnabled(false); } m_aircraft->triYawChannelBox->setEnabled(false); @@ -100,7 +101,7 @@ void ConfigVehicleTypeWidget::setupMultiRotorUI(QString frameType) //and grey out all unused motor channel boxes for (int i=5; i <=8; i++) { QComboBox *combobox = qFindChild(this, "multiMotorChannelBox" + QString::number(i)); - combobox->setEnabled(false); + combobox->setEnabled(false); } m_aircraft->triYawChannelBox->setEnabled(false); @@ -120,7 +121,7 @@ void ConfigVehicleTypeWidget::setupMultiRotorUI(QString frameType) //and grey out all unused motor channel boxes for (int i=7; i <=8; i++) { QComboBox *combobox = qFindChild(this, "multiMotorChannelBox" + QString::number(i)); - combobox->setEnabled(false); + combobox->setEnabled(false); } m_aircraft->triYawChannelBox->setEnabled(false); @@ -140,7 +141,7 @@ void ConfigVehicleTypeWidget::setupMultiRotorUI(QString frameType) //and grey out all unused motor channel boxes for (int i=7; i <=8; i++) { QComboBox *combobox = qFindChild(this, "multiMotorChannelBox" + QString::number(i)); - combobox->setEnabled(false); + combobox->setEnabled(false); } m_aircraft->triYawChannelBox->setEnabled(false); @@ -161,7 +162,7 @@ void ConfigVehicleTypeWidget::setupMultiRotorUI(QString frameType) //and grey out all unused motor channel boxes for (int i=7; i <=8; i++) { QComboBox *combobox = qFindChild(this, "multiMotorChannelBox" + QString::number(i)); - combobox->setEnabled(false); + combobox->setEnabled(false); } m_aircraft->triYawChannelBox->setEnabled(false); @@ -467,10 +468,11 @@ QString ConfigVehicleTypeWidget::updateMultiRotorObjectsFromWidgets() } motorList << "VTOLMotorNW" << "VTOLMotorNE" << "VTOLMotorS"; setupMotors(motorList); - obj = dynamic_cast(getObjectManager()->getObject(QString("ActuatorSettings"))); - Q_ASSERT(obj); - field = obj->getField("FixedWingYaw1"); - field->setValue(m_aircraft->triYawChannelBox->currentText()); + + GUIConfigData = GUIManager.GetConfigData(); + GUIConfigData.multi.TRIYaw = m_aircraft->triYawChannelBox->currentIndex(); + GUIManager.SetConfigData(GUIConfigData); + // Motor 1 to 6, Y6 Layout: // pitch roll yaw @@ -514,26 +516,20 @@ void ConfigVehicleTypeWidget::refreshMultiRotorWidgetsValues(QString frameType) ////////////////////////////////////////////////////////////////// // Retrieve settings ////////////////////////////////////////////////////////////////// - - UAVDataObject* obj = dynamic_cast(getObjectManager()->getObject(QString("ActuatorSettings"))); - Q_ASSERT(obj); - UAVObjectField *field; + + GUIConfigData = GUIManager.GetConfigData(); + multiGUISettingsStruct multi = GUIConfigData.multi; + + UAVDataObject* obj; + UAVObjectField *field; if (frameType == "QuadP") { - // Motors 1/2/3/4 are: N / E / S / W - field = obj->getField(QString("VTOLMotorN")); - Q_ASSERT(field); - m_aircraft->multiMotorChannelBox1->setCurrentIndex(m_aircraft->multiMotorChannelBox1->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorE")); - Q_ASSERT(field); - m_aircraft->multiMotorChannelBox2->setCurrentIndex(m_aircraft->multiMotorChannelBox2->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorS")); - Q_ASSERT(field); - m_aircraft->multiMotorChannelBox3->setCurrentIndex(m_aircraft->multiMotorChannelBox3->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorW")); - Q_ASSERT(field); - m_aircraft->multiMotorChannelBox4->setCurrentIndex(m_aircraft->multiMotorChannelBox4->findText(field->getValue().toString())); - + // Motors 1/2/3/4 are: N / E / S / W + setComboCurrentIndex(m_aircraft->multiMotorChannelBox1,multi.VTOLMotorN); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox2,multi.VTOLMotorE); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox3,multi.VTOLMotorS); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox4,multi.VTOLMotorW); + // Now, read the 1st mixer R/P/Y levels and initialize the mix sliders. // This assumes that all vectors are identical - if not, the user should use the // "custom" setting. @@ -556,20 +552,12 @@ void ConfigVehicleTypeWidget::refreshMultiRotorWidgetsValues(QString frameType) m_aircraft->mrRollMixLevel->setValue(val); } } else if (frameType == "QuadX") { - // Motors 1/2/3/4 are: NW / NE / SE / SW - field = obj->getField(QString("VTOLMotorNW")); - Q_ASSERT(field); - m_aircraft->multiMotorChannelBox1->setCurrentIndex(m_aircraft->multiMotorChannelBox1->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorNE")); - Q_ASSERT(field); - m_aircraft->multiMotorChannelBox2->setCurrentIndex(m_aircraft->multiMotorChannelBox2->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorSE")); - Q_ASSERT(field); - m_aircraft->multiMotorChannelBox3->setCurrentIndex(m_aircraft->multiMotorChannelBox3->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorSW")); - Q_ASSERT(field); - m_aircraft->multiMotorChannelBox4->setCurrentIndex(m_aircraft->multiMotorChannelBox4->findText(field->getValue().toString())); - + // Motors 1/2/3/4 are: NW / NE / SE / SW + setComboCurrentIndex(m_aircraft->multiMotorChannelBox1,multi.VTOLMotorNW); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox2,multi.VTOLMotorNE); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox3,multi.VTOLMotorSE); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox4,multi.VTOLMotorSW); + // Now, read the 1st mixer R/P/Y levels and initialize the mix sliders. // This assumes that all vectors are identical - if not, the user should use the // "custom" setting. @@ -591,23 +579,18 @@ void ConfigVehicleTypeWidget::refreshMultiRotorWidgetsValues(QString frameType) } } else if (frameType == "Hexa") { // Motors 1/2/3 4/5/6 are: N / NE / SE / S / SW / NW - field = obj->getField(QString("VTOLMotorN")); - m_aircraft->multiMotorChannelBox1->setCurrentIndex(m_aircraft->multiMotorChannelBox1->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorNE")); - m_aircraft->multiMotorChannelBox2->setCurrentIndex(m_aircraft->multiMotorChannelBox2->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorSE")); - m_aircraft->multiMotorChannelBox3->setCurrentIndex(m_aircraft->multiMotorChannelBox3->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorS")); - m_aircraft->multiMotorChannelBox4->setCurrentIndex(m_aircraft->multiMotorChannelBox4->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorSW")); - m_aircraft->multiMotorChannelBox5->setCurrentIndex(m_aircraft->multiMotorChannelBox4->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorNW")); - m_aircraft->multiMotorChannelBox6->setCurrentIndex(m_aircraft->multiMotorChannelBox4->findText(field->getValue().toString())); - + + setComboCurrentIndex(m_aircraft->multiMotorChannelBox1,multi.VTOLMotorN); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox2,multi.VTOLMotorNE); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox3,multi.VTOLMotorSE); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox4,multi.VTOLMotorS); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox5,multi.VTOLMotorSW); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox6,multi.VTOLMotorNW); + // Now, read the 1st mixer R/P/Y levels and initialize the mix sliders. // This assumes that all vectors are identical - if not, the user should use the // "custom" setting. - obj = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); + obj = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); int tmpVal= m_aircraft->multiMotorChannelBox1->currentIndex()-1; // tmpVal will be -1 if value is set to "None" if (tmpVal > -1) { @@ -628,19 +611,15 @@ void ConfigVehicleTypeWidget::refreshMultiRotorWidgetsValues(QString frameType) } } } else if (frameType == "HexaX") { - // Motors 1/2/3 4/5/6 are: NE / E / SE / SW / W / NW - field = obj->getField(QString("VTOLMotorNE")); - m_aircraft->multiMotorChannelBox1->setCurrentIndex(m_aircraft->multiMotorChannelBox1->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorE")); - m_aircraft->multiMotorChannelBox2->setCurrentIndex(m_aircraft->multiMotorChannelBox2->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorSE")); - m_aircraft->multiMotorChannelBox3->setCurrentIndex(m_aircraft->multiMotorChannelBox3->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorSW")); - m_aircraft->multiMotorChannelBox4->setCurrentIndex(m_aircraft->multiMotorChannelBox4->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorW")); - m_aircraft->multiMotorChannelBox5->setCurrentIndex(m_aircraft->multiMotorChannelBox4->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorNW")); - m_aircraft->multiMotorChannelBox6->setCurrentIndex(m_aircraft->multiMotorChannelBox4->findText(field->getValue().toString())); + // Motors 1/2/3 4/5/6 are: NE / E / SE / SW / W / NW + + setComboCurrentIndex(m_aircraft->multiMotorChannelBox1,multi.VTOLMotorNE); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox2,multi.VTOLMotorE); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox3,multi.VTOLMotorSE); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox4,multi.VTOLMotorSW); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox5,multi.VTOLMotorW); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox6,multi.VTOLMotorNW); + // Now, read the 1st mixer R/P/Y levels and initialize the mix sliders. // This assumes that all vectors are identical - if not, the user should use the @@ -663,20 +642,16 @@ void ConfigVehicleTypeWidget::refreshMultiRotorWidgetsValues(QString frameType) m_aircraft->mrRollMixLevel->setValue(val); } } else if (frameType == "HexaCoax") { - // Motors 1/2/3 4/5/6 are: NW/W NE/E S/SE - field = obj->getField(QString("VTOLMotorNW")); - m_aircraft->multiMotorChannelBox1->setCurrentIndex(m_aircraft->multiMotorChannelBox1->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorW")); - m_aircraft->multiMotorChannelBox2->setCurrentIndex(m_aircraft->multiMotorChannelBox2->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorNE")); - m_aircraft->multiMotorChannelBox3->setCurrentIndex(m_aircraft->multiMotorChannelBox3->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorE")); - m_aircraft->multiMotorChannelBox4->setCurrentIndex(m_aircraft->multiMotorChannelBox4->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorS")); - m_aircraft->multiMotorChannelBox5->setCurrentIndex(m_aircraft->multiMotorChannelBox4->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorSE")); - m_aircraft->multiMotorChannelBox6->setCurrentIndex(m_aircraft->multiMotorChannelBox4->findText(field->getValue().toString())); - + // Motors 1/2/3 4/5/6 are: NW/W NE/E S/SE + + setComboCurrentIndex(m_aircraft->multiMotorChannelBox1,multi.VTOLMotorNW); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox2,multi.VTOLMotorW); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox3,multi.VTOLMotorNE); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox4,multi.VTOLMotorE); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox5,multi.VTOLMotorS); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox6,multi.VTOLMotorSE); + + // Now, read the 1st mixer R/P/Y levels and initialize the mix sliders. // This assumes that all vectors are identical - if not, the user should use the // "custom" setting. @@ -697,32 +672,18 @@ void ConfigVehicleTypeWidget::refreshMultiRotorWidgetsValues(QString frameType) } } else if (frameType == "Octo" || frameType == "OctoV" || frameType == "OctoCoaxP") { - // Motors 1 to 8 are N / NE / E / etc - field = obj->getField(QString("VTOLMotorN")); - Q_ASSERT(field); - m_aircraft->multiMotorChannelBox1->setCurrentIndex(m_aircraft->multiMotorChannelBox1->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorNE")); - Q_ASSERT(field); - m_aircraft->multiMotorChannelBox2->setCurrentIndex(m_aircraft->multiMotorChannelBox2->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorE")); - Q_ASSERT(field); - m_aircraft->multiMotorChannelBox3->setCurrentIndex(m_aircraft->multiMotorChannelBox3->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorSE")); - Q_ASSERT(field); - m_aircraft->multiMotorChannelBox4->setCurrentIndex(m_aircraft->multiMotorChannelBox4->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorS")); - Q_ASSERT(field); - m_aircraft->multiMotorChannelBox5->setCurrentIndex(m_aircraft->multiMotorChannelBox4->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorSW")); - Q_ASSERT(field); - m_aircraft->multiMotorChannelBox6->setCurrentIndex(m_aircraft->multiMotorChannelBox4->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorW")); - Q_ASSERT(field); - m_aircraft->multiMotorChannelBox7->setCurrentIndex(m_aircraft->multiMotorChannelBox4->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorNW")); - Q_ASSERT(field); - m_aircraft->multiMotorChannelBox8->setCurrentIndex(m_aircraft->multiMotorChannelBox4->findText(field->getValue().toString())); - + // Motors 1 to 8 are N / NE / E / etc + + setComboCurrentIndex(m_aircraft->multiMotorChannelBox1,multi.VTOLMotorN); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox2,multi.VTOLMotorNE); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox3,multi.VTOLMotorE); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox4,multi.VTOLMotorSE); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox5,multi.VTOLMotorS); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox6,multi.VTOLMotorSW); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox7,multi.VTOLMotorW); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox8,multi.VTOLMotorNW); + + // Now, read the 1st mixer R/P/Y levels and initialize the mix sliders. // This assumes that all vectors are identical - if not, the user should use the // "custom" setting. @@ -774,32 +735,18 @@ void ConfigVehicleTypeWidget::refreshMultiRotorWidgetsValues(QString frameType) } } } else if (frameType == "OctoCoaxX") { - // Motors 1 to 8 are N / NE / E / etc - field = obj->getField(QString("VTOLMotorNW")); - Q_ASSERT(field); - m_aircraft->multiMotorChannelBox1->setCurrentIndex(m_aircraft->multiMotorChannelBox1->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorN")); - Q_ASSERT(field); - m_aircraft->multiMotorChannelBox2->setCurrentIndex(m_aircraft->multiMotorChannelBox2->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorNE")); - Q_ASSERT(field); - m_aircraft->multiMotorChannelBox3->setCurrentIndex(m_aircraft->multiMotorChannelBox3->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorE")); - Q_ASSERT(field); - m_aircraft->multiMotorChannelBox4->setCurrentIndex(m_aircraft->multiMotorChannelBox4->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorSE")); - Q_ASSERT(field); - m_aircraft->multiMotorChannelBox5->setCurrentIndex(m_aircraft->multiMotorChannelBox4->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorS")); - Q_ASSERT(field); - m_aircraft->multiMotorChannelBox6->setCurrentIndex(m_aircraft->multiMotorChannelBox4->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorSW")); - Q_ASSERT(field); - m_aircraft->multiMotorChannelBox7->setCurrentIndex(m_aircraft->multiMotorChannelBox4->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorW")); - Q_ASSERT(field); - m_aircraft->multiMotorChannelBox8->setCurrentIndex(m_aircraft->multiMotorChannelBox4->findText(field->getValue().toString())); - + // Motors 1 to 8 are N / NE / E / etc + + setComboCurrentIndex(m_aircraft->multiMotorChannelBox1,multi.VTOLMotorNW); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox2,multi.VTOLMotorN); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox3,multi.VTOLMotorNE); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox4,multi.VTOLMotorE); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox5,multi.VTOLMotorSE); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox6,multi.VTOLMotorS); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox7,multi.VTOLMotorSW); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox8,multi.VTOLMotorW); + + // Now, read the 1st mixer R/P/Y levels and initialize the mix sliders. // This assumes that all vectors are identical - if not, the user should use the // "custom" setting. @@ -819,20 +766,14 @@ void ConfigVehicleTypeWidget::refreshMultiRotorWidgetsValues(QString frameType) m_aircraft->mrRollMixLevel->setValue(val); } } else if (frameType == "Tri") { - // Motors 1 to 8 are N / NE / E / etc - field = obj->getField(QString("VTOLMotorNW")); - Q_ASSERT(field); - m_aircraft->multiMotorChannelBox1->setCurrentIndex(m_aircraft->multiMotorChannelBox1->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorNE")); - Q_ASSERT(field); - m_aircraft->multiMotorChannelBox2->setCurrentIndex(m_aircraft->multiMotorChannelBox2->findText(field->getValue().toString())); - field = obj->getField(QString("VTOLMotorS")); - Q_ASSERT(field); - m_aircraft->multiMotorChannelBox3->setCurrentIndex(m_aircraft->multiMotorChannelBox3->findText(field->getValue().toString())); - field = obj->getField(QString("FixedWingYaw1")); - Q_ASSERT(field); - m_aircraft->triYawChannelBox->setCurrentIndex(m_aircraft->multiMotorChannelBox3->findText(field->getValue().toString())); - + // Motors 1 to 8 are N / NE / E / etc + + setComboCurrentIndex(m_aircraft->multiMotorChannelBox1,multi.VTOLMotorNW); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox2,multi.VTOLMotorNE); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox3,multi.VTOLMotorS); + setComboCurrentIndex(m_aircraft->multiMotorChannelBox4,multi.VTOLMotorS); + setComboCurrentIndex(m_aircraft->triYawChannelBox,multi.TRIYaw); + obj = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); int tmpVal= m_aircraft->multiMotorChannelBox1->currentIndex()-1; // tmpVal will be -1 if value is set to "None" @@ -883,19 +824,40 @@ void ConfigVehicleTypeWidget::setupQuadMotor(int channel, double pitch, double r */ void ConfigVehicleTypeWidget::setupMotors(QList motorList) { - resetActuators(); - UAVDataObject* obj = dynamic_cast(getObjectManager()->getObject(QString("ActuatorSettings"))); - Q_ASSERT(obj); - UAVObjectField *field; QList mmList; mmList << m_aircraft->multiMotorChannelBox1 << m_aircraft->multiMotorChannelBox2 << m_aircraft->multiMotorChannelBox3 << m_aircraft->multiMotorChannelBox4 << m_aircraft->multiMotorChannelBox5 << m_aircraft->multiMotorChannelBox6 << m_aircraft->multiMotorChannelBox7 << m_aircraft->multiMotorChannelBox8; + + GUIConfigData = GUIManager.GetConfigData(); + GUIManager.ResetActuators(&GUIConfigData); + + int index; foreach (QString motor, motorList) { - field = obj->getField(motor); - field->setValue(mmList.takeFirst()->currentText()); + + index = mmList.takeFirst()->currentIndex(); + + //qDebug()<updated(); // Save... + GUIManager.SetConfigData(GUIConfigData); + } @@ -1143,4 +1105,4 @@ void ConfigVehicleTypeWidget::throwMultiRotorChannelConfigError(int numMotors) if (error){ m_aircraft->mrStatusLabel->setText(QString("ERROR: Assign all %1 motor channels").arg(numMotors)); } -} \ No newline at end of file +} diff --git a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/guiconfigdata.cpp b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/guiconfigdata.cpp index 43630d4ae..5e8d1c7ee 100644 --- a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/guiconfigdata.cpp +++ b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/guiconfigdata.cpp @@ -85,6 +85,95 @@ void GUIConfigDataManager::SetConfigData(GUIConfigDataUnion configData) { systemSettings->updated(); } +void GUIConfigDataManager::ResetActuators() +{ + // get the gui config data + GUIConfigDataUnion configData = GetConfigData(); + + // reset the actuators by airframe type + ResetActuators(&configData); + + // set the gui config data + SetConfigData(configData); + +} + +void GUIConfigDataManager::ResetActuators(GUIConfigDataUnion* configData) +{ + // get systemsettings for airframe type + SystemSettings * systemSettings = SystemSettings::GetInstance(getObjectManager()); + Q_ASSERT(systemSettings); + SystemSettings::DataFields systemSettingsData = systemSettings->getData(); + + switch (systemSettingsData.AirframeType) + { + // fixed wing + case SystemSettings::AIRFRAMETYPE_FIXEDWING: + case SystemSettings::AIRFRAMETYPE_FIXEDWINGELEVON: + case SystemSettings::AIRFRAMETYPE_FIXEDWINGVTAIL: + { + configData->fixed.FixedWingPitch1 = 0; + configData->fixed.FixedWingPitch2 = 0; + configData->fixed.FixedWingRoll1 = 0; + configData->fixed.FixedWingRoll2 = 0; + configData->fixed.FixedWingYaw1 = 0; + configData->fixed.FixedWingYaw2 = 0; + configData->fixed.FixedWingThrottle = 0; + } + break; + + // helicp + case SystemSettings::AIRFRAMETYPE_HELICP: + { + configData->heli.Throttle = 0; + configData->heli.Tail = 0; + configData->heli.ServoIndexW = 0; + configData->heli.ServoIndexX = 0; + configData->heli.ServoIndexY = 0; + configData->heli.ServoIndexZ = 0; + } + break; + + //multirotor + case SystemSettings::AIRFRAMETYPE_VTOL: + case SystemSettings::AIRFRAMETYPE_TRI: + case SystemSettings::AIRFRAMETYPE_QUADX: + case SystemSettings::AIRFRAMETYPE_QUADP: + case SystemSettings::AIRFRAMETYPE_OCTOV: + case SystemSettings::AIRFRAMETYPE_OCTOCOAXX: + case SystemSettings::AIRFRAMETYPE_OCTOCOAXP: + case SystemSettings::AIRFRAMETYPE_OCTO: + case SystemSettings::AIRFRAMETYPE_HEXAX: + case SystemSettings::AIRFRAMETYPE_HEXACOAX: + case SystemSettings::AIRFRAMETYPE_HEXA: + { + configData->multi.VTOLMotorN = 0; + configData->multi.VTOLMotorNE = 0; + configData->multi.VTOLMotorE = 0; + configData->multi.VTOLMotorSE = 0; + configData->multi.VTOLMotorS = 0; + configData->multi.VTOLMotorSW = 0; + configData->multi.VTOLMotorW = 0; + configData->multi.VTOLMotorNW = 0; + configData->multi.TRIYaw = 0; + } + break; + + // ground + case SystemSettings::AIRFRAMETYPE_GROUNDVEHICLECAR: + case SystemSettings::AIRFRAMETYPE_GROUNDVEHICLEDIFFERENTIAL: + case SystemSettings::AIRFRAMETYPE_GROUNDVEHICLEMOTORCYCLE: + { + configData->ground.GroundVehicleSteering1 = 0; + configData->ground.GroundVehicleSteering2 = 0; + configData->ground.GroundVehicleThrottle1 = 0; + configData->ground.GroundVehicleThrottle2 = 0; + } + break; + + } +} + QStringList GUIConfigDataManager::getChannelDescriptions() { int i; @@ -183,20 +272,46 @@ QStringList GUIConfigDataManager::getChannelDescriptions() case SystemSettings::AIRFRAMETYPE_HEXACOAX: case SystemSettings::AIRFRAMETYPE_HEXA: { - channelDesc[configData.multi.VTOLMotorN] = QString("VTOLMotorN"); - channelDesc[configData.multi.VTOLMotorNE] = QString("VTOLMotorNE"); - channelDesc[configData.multi.VTOLMotorNW] = QString("VTOLMotorNW"); - channelDesc[configData.multi.VTOLMotorS] = QString("VTOLMotorS"); - channelDesc[configData.multi.VTOLMotorSE] = QString("VTOLMotorSE"); - channelDesc[configData.multi.VTOLMotorSW] = QString("VTOLMotorSW"); - channelDesc[configData.multi.VTOLMotorW] = QString("VTOLMotorW"); - channelDesc[configData.multi.VTOLMotorE] = QString("VTOLMotorE"); + multiGUISettingsStruct multi = configData.multi; + + if (multi.VTOLMotorN > 0 && multi.VTOLMotorN < GUIConfigDataManager::CHANNEL_NUMELEM) + channelDesc[multi.VTOLMotorN-1] = QString("VTOLMotorN"); + if (multi.VTOLMotorNE > 0 && multi.VTOLMotorNE < GUIConfigDataManager::CHANNEL_NUMELEM) + channelDesc[multi.VTOLMotorNE-1] = QString("VTOLMotorNE"); + if (multi.VTOLMotorNW > 0 && multi.VTOLMotorNW < GUIConfigDataManager::CHANNEL_NUMELEM) + channelDesc[multi.VTOLMotorNW-1] = QString("VTOLMotorNW"); + if (multi.VTOLMotorS > 0 && multi.VTOLMotorS < GUIConfigDataManager::CHANNEL_NUMELEM) + channelDesc[multi.VTOLMotorS-1] = QString("VTOLMotorS"); + if (multi.VTOLMotorSE > 0 && multi.VTOLMotorSE < GUIConfigDataManager::CHANNEL_NUMELEM) + channelDesc[multi.VTOLMotorSE-1] = QString("VTOLMotorSE"); + if (multi.VTOLMotorSW > 0 && multi.VTOLMotorSW < GUIConfigDataManager::CHANNEL_NUMELEM) + channelDesc[multi.VTOLMotorSW-1] = QString("VTOLMotorSW"); + if (multi.VTOLMotorW > 0 && multi.VTOLMotorW < GUIConfigDataManager::CHANNEL_NUMELEM) + channelDesc[multi.VTOLMotorW-1] = QString("VTOLMotorW"); + if (multi.VTOLMotorE > 0 && multi.VTOLMotorE < GUIConfigDataManager::CHANNEL_NUMELEM) + channelDesc[multi.VTOLMotorE-1] = QString("VTOLMotorE"); + return channelDesc; } break; // ground + case SystemSettings::AIRFRAMETYPE_GROUNDVEHICLECAR: + case SystemSettings::AIRFRAMETYPE_GROUNDVEHICLEDIFFERENTIAL: + case SystemSettings::AIRFRAMETYPE_GROUNDVEHICLEMOTORCYCLE: + { + if (configData.ground.GroundVehicleSteering1 > 0) + channelDesc[configData.ground.GroundVehicleSteering1-1] = QString("GroundSteering1"); + if (configData.ground.GroundVehicleSteering2 > 0) + channelDesc[configData.ground.GroundVehicleSteering2-1] = QString("GroundSteering2"); + if (configData.ground.GroundVehicleThrottle1 > 0) + channelDesc[configData.ground.GroundVehicleThrottle1-1] = QString("GroundThrottle1"); + if (configData.ground.GroundVehicleThrottle2 > 0) + channelDesc[configData.ground.GroundVehicleThrottle2-1] = QString("GroundThrottle2"); + return channelDesc; + } + break; } return channelDesc; diff --git a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/guiconfigdata.h b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/guiconfigdata.h index 287bfcb67..9c92faa0e 100644 --- a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/guiconfigdata.h +++ b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/guiconfigdata.h @@ -48,7 +48,7 @@ typedef struct { } __attribute__((packed)) multiGUISettingsStruct; typedef struct { - uint SwasplateType:3; + uint SwashplateType:3; uint FirstServoIndex:2; uint CorrectionAngle:9; uint ccpmCollectivePassthroughState:1; @@ -109,20 +109,23 @@ class GUIConfigDataManager: public QObject GUIConfigDataManager(); ~GUIConfigDataManager(); + GUIConfigDataUnion GetConfigData(); + void SetConfigData(GUIConfigDataUnion configData); + QStringList getChannelDescriptions(); + void ResetActuators(); + void ResetActuators(GUIConfigDataUnion* configData); + static const quint32 CHANNEL_NUMELEM = 10; friend class ConfigTaskWidget; private: - - - private slots: UAVObjectManager* getObjectManager(); + private slots: + public slots: - GUIConfigDataUnion GetConfigData(); - void SetConfigData(GUIConfigDataUnion configData); - QStringList getChannelDescriptions(); + protected: diff --git a/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.cpp b/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.cpp index 943aaf6d4..1fec3f05c 100644 --- a/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.cpp @@ -250,7 +250,7 @@ ConfigVehicleTypeWidget::~ConfigVehicleTypeWidget() rather than a signal in the UI, because we want to force a fitInView of the quad shapes. This is because this method (fitinview) only works when the widget is shown. */ -void ConfigVehicleTypeWidget::switchAirframeType(int index){ +void ConfigVehicleTypeWidget::switchAirframeType(int index){ m_aircraft->airframesWidget->setCurrentIndex(index); m_aircraft->quadShape->setSceneRect(quad->boundingRect()); m_aircraft->quadShape->fitInView(quad, Qt::KeepAspectRatio); @@ -844,6 +844,16 @@ void ConfigVehicleTypeWidget::openHelp() QDesktopServices::openUrl( QUrl("http://wiki.openpilot.org/display/Doc/Airframe+configuration", QUrl::StrictMode) ); } +/** + Helper function: + Sets the current index on supplied combobox to index + if it is within bounds 0 <= index < combobox.count() + */ +void ConfigVehicleTypeWidget::setComboCurrentIndex(QComboBox* box, int index) +{ + if (index >= 0 && index < box->count()) + box->setCurrentIndex(index); +} /** WHAT DOES THIS DO??? diff --git a/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.h b/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.h index 9c6daf16e..59a97277c 100644 --- a/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.h +++ b/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.h @@ -33,6 +33,7 @@ #include "uavobjectmanager.h" #include "uavobject.h" #include "uavtalk/telemetrymanager.h" +#include "cfg_vehicletypes/guiconfigdata.h" #include #include #include @@ -67,7 +68,7 @@ private: void resetActuators(); //void setMixerChannel(int channelNumber, bool channelIsMotor, QList vector); void setupQuadMotor(int channel, double roll, double pitch, double yaw); - + void setComboCurrentIndex(QComboBox* box, int index); QStringList mixerTypes; QStringList mixerVectors; QGraphicsSvgItem *quad; @@ -75,6 +76,9 @@ private: bool ffTuningPhase; UAVObject::Metadata accInitialData; + GUIConfigDataManager GUIManager; + GUIConfigDataUnion GUIConfigData; + private slots: virtual void refreshWidgetsValues(); void refreshFixedWingWidgetsValues(QString frameType); diff --git a/shared/uavobjectdefinition/systemsettings.xml b/shared/uavobjectdefinition/systemsettings.xml index ec092df8e..d1255c858 100644 --- a/shared/uavobjectdefinition/systemsettings.xml +++ b/shared/uavobjectdefinition/systemsettings.xml @@ -2,7 +2,7 @@ Select airframe type. Currently used by @ref ActuatorModule to choose mixing from @ref ActuatorDesired to @ref ActuatorCommand - +