diff --git a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.cpp b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.cpp index 02cb3894a..19ed4bcfe 100644 --- a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.cpp @@ -285,6 +285,61 @@ void ConfigCcpmWidget::resetActuators(GUIConfigDataUnion *configData) configData->heli.ServoIndexZ = 0; } +void ConfigCcpmWidget::refreshWidgetsValues(QString frameType) +{ + Q_UNUSED(frameType); + + setupUI(frameType); + + GUIConfigDataUnion config = GetConfigData(); + + //swashplate config + setComboCurrentIndex( m_aircraft->ccpmType, m_aircraft->ccpmType->count() - (config.heli.SwashplateType +1)); + setComboCurrentIndex(m_aircraft->ccpmSingleServo, config.heli.FirstServoIndex); + + //ccpm mixing options + m_aircraft->ccpmCollectivePassthrough->setChecked(config.heli.ccpmCollectivePassthroughState); + m_aircraft->ccpmLinkCyclic->setChecked(config.heli.ccpmLinkCyclicState); + m_aircraft->ccpmLinkRoll->setChecked(config.heli.ccpmLinkRollState); + + //correction angle + m_aircraft->ccpmCorrectionAngle->setValue(config.heli.CorrectionAngle); + + //update sliders + m_aircraft->ccpmCollectiveScale->setValue(config.heli.SliderValue0); + m_aircraft->ccpmCollectiveScaleBox->setValue(config.heli.SliderValue0); + m_aircraft->ccpmCyclicScale->setValue(config.heli.SliderValue1); + m_aircraft->ccpmCyclicScaleBox->setValue(config.heli.SliderValue1); + m_aircraft->ccpmPitchScale->setValue(config.heli.SliderValue1); + m_aircraft->ccpmPitchScaleBox->setValue(config.heli.SliderValue1); + m_aircraft->ccpmRollScale->setValue(config.heli.SliderValue2); + m_aircraft->ccpmRollScaleBox->setValue(config.heli.SliderValue2); + m_aircraft->ccpmCollectiveSlider->setValue(config.heli.SliderValue0); + m_aircraft->ccpmCollectivespinBox->setValue(config.heli.SliderValue0); + + //servo assignments + setComboCurrentIndex(m_aircraft->ccpmServoWChannel, config.heli.ServoIndexW); + setComboCurrentIndex( m_aircraft->ccpmServoXChannel,config.heli.ServoIndexX); + setComboCurrentIndex( m_aircraft->ccpmServoYChannel,config.heli.ServoIndexY); + setComboCurrentIndex( m_aircraft->ccpmServoZChannel,config.heli.ServoIndexZ); + + //throttle + setComboCurrentIndex( m_aircraft->ccpmEngineChannel, config.heli.Throttle); + //tail + setComboCurrentIndex( m_aircraft->ccpmTailChannel, config.heli.Tail); + + getMixer(); +} + +QString ConfigCcpmWidget::updateConfigObjectsFromWidgets() +{ + QString airframeType = updateConfigObjects(); + + setMixer(); + + return airframeType; +} + void ConfigCcpmWidget::UpdateType() { int TypeInt, SingleServoIndex, NumServosDefined; @@ -756,59 +811,6 @@ QString ConfigCcpmWidget::updateConfigObjects() return airframeType; } -QString ConfigCcpmWidget::updateConfigObjectsFromWidgets() -{ - QString airframeType = updateConfigObjects(); - - setMixer(); - - return airframeType; -} - -void ConfigCcpmWidget::refreshWidgetsValues(QString frameType) -{ - Q_UNUSED(frameType); - - GUIConfigDataUnion config = GetConfigData(); - - //swashplate config - setComboCurrentIndex( m_aircraft->ccpmType, m_aircraft->ccpmType->count() - (config.heli.SwashplateType +1)); - setComboCurrentIndex(m_aircraft->ccpmSingleServo, config.heli.FirstServoIndex); - - //ccpm mixing options - m_aircraft->ccpmCollectivePassthrough->setChecked(config.heli.ccpmCollectivePassthroughState); - m_aircraft->ccpmLinkCyclic->setChecked(config.heli.ccpmLinkCyclicState); - m_aircraft->ccpmLinkRoll->setChecked(config.heli.ccpmLinkRollState); - - //correction angle - m_aircraft->ccpmCorrectionAngle->setValue(config.heli.CorrectionAngle); - - //update sliders - m_aircraft->ccpmCollectiveScale->setValue(config.heli.SliderValue0); - m_aircraft->ccpmCollectiveScaleBox->setValue(config.heli.SliderValue0); - m_aircraft->ccpmCyclicScale->setValue(config.heli.SliderValue1); - m_aircraft->ccpmCyclicScaleBox->setValue(config.heli.SliderValue1); - m_aircraft->ccpmPitchScale->setValue(config.heli.SliderValue1); - m_aircraft->ccpmPitchScaleBox->setValue(config.heli.SliderValue1); - m_aircraft->ccpmRollScale->setValue(config.heli.SliderValue2); - m_aircraft->ccpmRollScaleBox->setValue(config.heli.SliderValue2); - m_aircraft->ccpmCollectiveSlider->setValue(config.heli.SliderValue0); - m_aircraft->ccpmCollectivespinBox->setValue(config.heli.SliderValue0); - - //servo assignments - setComboCurrentIndex(m_aircraft->ccpmServoWChannel, config.heli.ServoIndexW); - setComboCurrentIndex( m_aircraft->ccpmServoXChannel,config.heli.ServoIndexX); - setComboCurrentIndex( m_aircraft->ccpmServoYChannel,config.heli.ServoIndexY); - setComboCurrentIndex( m_aircraft->ccpmServoZChannel,config.heli.ServoIndexZ); - - //throttle - setComboCurrentIndex( m_aircraft->ccpmEngineChannel, config.heli.Throttle); - //tail - setComboCurrentIndex( m_aircraft->ccpmTailChannel, config.heli.Tail); - - getMixer(); -} - void ConfigCcpmWidget::SetUIComponentVisibilities() { m_aircraft->ccpmRevoMixingBox->setVisible(0); diff --git a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.h b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.h index f2548789b..e2f0e8c08 100644 --- a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.h +++ b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configccpmwidget.h @@ -57,7 +57,6 @@ class ConfigCcpmWidget: public VehicleConfig Q_OBJECT public: - static QStringList getChannelDescriptions(); ConfigCcpmWidget(QWidget *parent = 0); @@ -67,7 +66,6 @@ public: virtual QString updateConfigObjectsFromWidgets(); public slots: - virtual void setupUI(QString airframeType); void getMixer(); void setMixer(); void saveccpmUpdate(); @@ -77,8 +75,6 @@ protected: void resizeEvent(QResizeEvent *event); private: - virtual void resetActuators(GUIConfigDataUnion *configData); - Ui_CcpmConfigWidget *m_aircraft; QGraphicsSvgItem *SwashplateImg; @@ -100,17 +96,19 @@ private: SwashplateServoSettingsStruct newSwashLvlConfiguration; int MixerChannelData[6]; + + virtual void resetActuators(GUIConfigDataUnion *configData); + int ShowDisclaimer(int messageID); virtual void enableControls(bool enable) { Q_UNUSED(enable) }; // Not used by this widget bool updatingFromHardware; bool updatingToHardware; - // TODO ? QString updateConfigObjects(); private slots: - // TODO ? + virtual void setupUI(QString airframeType); virtual bool throwConfigError(QString airframeType); void ccpmSwashplateUpdate(); @@ -131,7 +129,6 @@ private slots: void enableSwashplateLevellingControl(bool state); void setSwashplateLevel(int percent); void SwashLvlSpinBoxChanged(int value); - // TODO ? virtual void refreshValues() {}; // Not used }; diff --git a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configcustomwidget.cpp b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configcustomwidget.cpp index 838baa619..2a62bc5df 100644 --- a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configcustomwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configcustomwidget.cpp @@ -26,9 +26,6 @@ */ #include "configcustomwidget.h" #include "mixersettings.h" -//#include "systemsettings.h" -//#include "actuatorsettings.h" -//#include "actuatorcommand.h" #include #include @@ -41,7 +38,14 @@ #include #include -//const QString ConfigCustomWidget::CHANNELBOXNAME = QString("multiMotorChannelBox"); +QStringList ConfigCustomWidget::getChannelDescriptions() +{ + QStringList channelDesc; + for (int i = 0; i < (int) (VehicleConfig::CHANNEL_NUMELEM); i++) { + channelDesc.append(QString("-")); + } + return channelDesc; +} ConfigCustomWidget::ConfigCustomWidget(QWidget *parent) : VehicleConfig(parent), m_aircraft(new Ui_CustomConfigWidget()) @@ -74,83 +78,10 @@ ConfigCustomWidget::~ConfigCustomWidget() void ConfigCustomWidget::setupUI(QString frameType) { Q_ASSERT(m_aircraft); - - m_aircraft->customMixerTable->resizeColumnsToContents(); - - for (int i = 0; i < (int) (VehicleConfig::CHANNEL_NUMELEM); i++) { - m_aircraft->customMixerTable->setColumnWidth(i, - (m_aircraft->customMixerTable->width() - m_aircraft->customMixerTable->verticalHeader()->width()) / 10); - } -} - -QStringList ConfigCustomWidget::getChannelDescriptions() -{ - QStringList channelDesc; - - for (int i = 0; i < (int) (VehicleConfig::CHANNEL_NUMELEM); i++) { - channelDesc.append(QString("-")); - } - - return channelDesc; } void ConfigCustomWidget::resetActuators(GUIConfigDataUnion *configData) { - -} - -/** - Helper function to update the UI widget objects - */ -QString ConfigCustomWidget::updateConfigObjectsFromWidgets() -{ - UAVDataObject *mixer = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); - Q_ASSERT(mixer); - - setThrottleCurve(mixer, VehicleConfig::MIXER_THROTTLECURVE1, m_aircraft->customThrottle1Curve->getCurve()); - setThrottleCurve(mixer, VehicleConfig::MIXER_THROTTLECURVE2, m_aircraft->customThrottle2Curve->getCurve()); - - // Update the table: - for (int channel = 0; channel < (int) (VehicleConfig::CHANNEL_NUMELEM); channel++) { - QComboBox* q = (QComboBox*) m_aircraft->customMixerTable->cellWidget(0, channel); - if (q->currentText() == "Disabled") { - setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_DISABLED); - } else if (q->currentText() == "Motor") { - setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_MOTOR); - } else if (q->currentText() == "Servo") { - setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_SERVO); - } else if (q->currentText() == "CameraRoll") { - setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_CAMERAROLL); - } else if (q->currentText() == "CameraPitch") { - setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_CAMERAPITCH); - } else if (q->currentText() == "CameraYaw") { - setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_CAMERAYAW); - } else if (q->currentText() == "Accessory0") { - setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_ACCESSORY0); - } else if (q->currentText() == "Accessory1") { - setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_ACCESSORY1); - } else if (q->currentText() == "Accessory2") { - setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_ACCESSORY2); - } else if (q->currentText() == "Accessory3") { - setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_ACCESSORY3); - } else if (q->currentText() == "Accessory4") { - setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_ACCESSORY4); - } else if (q->currentText() == "Accessory5") { - setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_ACCESSORY5); - } - setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_THROTTLECURVE1, - m_aircraft->customMixerTable->item(1, channel)->text().toDouble()); - setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_THROTTLECURVE2, - m_aircraft->customMixerTable->item(2, channel)->text().toDouble()); - setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL, - m_aircraft->customMixerTable->item(3, channel)->text().toDouble()); - setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH, - m_aircraft->customMixerTable->item(4, channel)->text().toDouble()); - setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW, - m_aircraft->customMixerTable->item(5, channel)->text().toDouble()); - } - - return "Custom"; } /** @@ -160,6 +91,8 @@ void ConfigCustomWidget::refreshWidgetsValues(QString frameType) { Q_ASSERT(m_aircraft); + setupUI(frameType); + UAVDataObject *mixer = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); Q_ASSERT(mixer); @@ -219,6 +152,60 @@ void ConfigCustomWidget::refreshWidgetsValues(QString frameType) } } +/** + Helper function to + */ +QString ConfigCustomWidget::updateConfigObjectsFromWidgets() +{ + UAVDataObject *mixer = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); + Q_ASSERT(mixer); + + setThrottleCurve(mixer, VehicleConfig::MIXER_THROTTLECURVE1, m_aircraft->customThrottle1Curve->getCurve()); + setThrottleCurve(mixer, VehicleConfig::MIXER_THROTTLECURVE2, m_aircraft->customThrottle2Curve->getCurve()); + + // Update the table: + for (int channel = 0; channel < (int) (VehicleConfig::CHANNEL_NUMELEM); channel++) { + QComboBox* q = (QComboBox*) m_aircraft->customMixerTable->cellWidget(0, channel); + if (q->currentText() == "Disabled") { + setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_DISABLED); + } else if (q->currentText() == "Motor") { + setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_MOTOR); + } else if (q->currentText() == "Servo") { + setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_SERVO); + } else if (q->currentText() == "CameraRoll") { + setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_CAMERAROLL); + } else if (q->currentText() == "CameraPitch") { + setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_CAMERAPITCH); + } else if (q->currentText() == "CameraYaw") { + setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_CAMERAYAW); + } else if (q->currentText() == "Accessory0") { + setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_ACCESSORY0); + } else if (q->currentText() == "Accessory1") { + setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_ACCESSORY1); + } else if (q->currentText() == "Accessory2") { + setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_ACCESSORY2); + } else if (q->currentText() == "Accessory3") { + setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_ACCESSORY3); + } else if (q->currentText() == "Accessory4") { + setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_ACCESSORY4); + } else if (q->currentText() == "Accessory5") { + setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_ACCESSORY5); + } + setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_THROTTLECURVE1, + m_aircraft->customMixerTable->item(1, channel)->text().toDouble()); + setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_THROTTLECURVE2, + m_aircraft->customMixerTable->item(2, channel)->text().toDouble()); + setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL, + m_aircraft->customMixerTable->item(3, channel)->text().toDouble()); + setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH, + m_aircraft->customMixerTable->item(4, channel)->text().toDouble()); + setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW, + m_aircraft->customMixerTable->item(5, channel)->text().toDouble()); + } + + return "Custom"; +} + /** This function displays text and color formatting in order to help the user understand what channels have not yet been configured. */ @@ -238,7 +225,8 @@ void ConfigCustomWidget::showEvent(QShowEvent *event) int channelCount = (int) VehicleConfig::CHANNEL_NUMELEM; for (int i = 0; i < channelCount; i++) { m_aircraft->customMixerTable->setColumnWidth(i, - (m_aircraft->customMixerTable->width() - m_aircraft->customMixerTable->verticalHeader()->width()) / channelCount); + (m_aircraft->customMixerTable->width() - m_aircraft->customMixerTable->verticalHeader()->width()) + / channelCount); } } @@ -253,7 +241,8 @@ void ConfigCustomWidget::resizeEvent(QResizeEvent *event) int channelCount = (int) VehicleConfig::CHANNEL_NUMELEM; for (int i = 0; i < channelCount; i++) { m_aircraft->customMixerTable->setColumnWidth(i, - (m_aircraft->customMixerTable->width() - m_aircraft->customMixerTable->verticalHeader()->width()) / channelCount); + (m_aircraft->customMixerTable->width() - m_aircraft->customMixerTable->verticalHeader()->width()) + / channelCount); } } diff --git a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configcustomwidget.h b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configcustomwidget.h index 791667895..1debb9a41 100644 --- a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configcustomwidget.h +++ b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configcustomwidget.h @@ -46,7 +46,6 @@ class ConfigCustomWidget: public VehicleConfig Q_OBJECT public: - static QStringList getChannelDescriptions(); ConfigCustomWidget(QWidget *parent = 0); @@ -55,23 +54,18 @@ public: virtual void refreshWidgetsValues(QString frameType); virtual QString updateConfigObjectsFromWidgets(); -public slots: - virtual void setupUI(QString airframeType); - protected: void showEvent(QShowEvent *event); void resizeEvent(QResizeEvent *event); private: - virtual void resetActuators(GUIConfigDataUnion *configData); - Ui_CustomConfigWidget *m_aircraft; -private slots: - virtual bool throwConfigError(int numMotors); + virtual void resetActuators(GUIConfigDataUnion *configData); -//signals: -// void configurationChanged(); +private slots: + virtual void setupUI(QString airframeType); + virtual bool throwConfigError(int numMotors); }; diff --git a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configfixedwingwidget.cpp b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configfixedwingwidget.cpp index c464b56ec..cd0ea1598 100644 --- a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configfixedwingwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configfixedwingwidget.cpp @@ -25,7 +25,6 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "configfixedwingwidget.h" -//#include "configvehicletypewidget.h" #include "mixersettings.h" #include "systemsettings.h" #include "actuatorsettings.h" @@ -41,6 +40,41 @@ #include #include +QStringList ConfigFixedWingWidget::getChannelDescriptions() +{ + // init a channel_numelem list of channel desc defaults + QStringList channelDesc; + for (int i = 0; i < (int) (ConfigFixedWingWidget::CHANNEL_NUMELEM); i++) { + channelDesc.append(QString("-")); + } + + // get the gui config data + GUIConfigDataUnion configData = GetConfigData(); + + if (configData.fixedwing.FixedWingPitch1 > 0) { + channelDesc[configData.fixedwing.FixedWingPitch1 - 1] = QString("FixedWingPitch1"); + } + if (configData.fixedwing.FixedWingPitch2 > 0) { + channelDesc[configData.fixedwing.FixedWingPitch2 - 1] = QString("FixedWingPitch2"); + } + if (configData.fixedwing.FixedWingRoll1 > 0) { + channelDesc[configData.fixedwing.FixedWingRoll1 - 1] = QString("FixedWingRoll1"); + } + if (configData.fixedwing.FixedWingRoll2 > 0) { + channelDesc[configData.fixedwing.FixedWingRoll2 - 1] = QString("FixedWingRoll2"); + } + if (configData.fixedwing.FixedWingYaw1 > 0) { + channelDesc[configData.fixedwing.FixedWingYaw1 - 1] = QString("FixedWingYaw1"); + } + if (configData.fixedwing.FixedWingYaw2 > 0) { + channelDesc[configData.fixedwing.FixedWingYaw2 - 1] = QString("FixedWingYaw2"); + } + if (configData.fixedwing.FixedWingThrottle > 0) { + channelDesc[configData.fixedwing.FixedWingThrottle - 1] = QString("FixedWingThrottle"); + } + return channelDesc; +} + ConfigFixedWingWidget::ConfigFixedWingWidget(QWidget *parent) : VehicleConfig(parent), m_aircraft(new Ui_FixedWingConfigWidget()) { @@ -51,7 +85,9 @@ ConfigFixedWingWidget::ConfigFixedWingWidget(QWidget *parent) : m_aircraft->fixedWingType->addItems(fixedWingTypes); // Set default model to "Elevator aileron rudder" - m_aircraft->fixedWingType->setCurrentIndex(0); + m_aircraft->fixedWingType->setCurrentIndex(m_aircraft->fixedWingType->findText("Elevator aileron rudder")); + + setupUI(m_aircraft->fixedWingType->currentText()); connect(m_aircraft->fixedWingType, SIGNAL(currentIndexChanged(QString)), this, SLOT(setupUI(QString))); } @@ -141,38 +177,6 @@ void ConfigFixedWingWidget::resetActuators(GUIConfigDataUnion *configData) configData->fixedwing.FixedWingThrottle = 0; } -QStringList ConfigFixedWingWidget::getChannelDescriptions() -{ - int i; - QStringList channelDesc; - - // init a channel_numelem list of channel desc defaults - for (i=0; i < (int)(ConfigFixedWingWidget::CHANNEL_NUMELEM); i++) - { - channelDesc.append(QString("-")); - } - - // get the gui config data - GUIConfigDataUnion configData = GetConfigData(); - - if (configData.fixedwing.FixedWingPitch1 > 0) - channelDesc[configData.fixedwing.FixedWingPitch1-1] = QString("FixedWingPitch1"); - if (configData.fixedwing.FixedWingPitch2 > 0) - channelDesc[configData.fixedwing.FixedWingPitch2-1] = QString("FixedWingPitch2"); - if (configData.fixedwing.FixedWingRoll1 > 0) - channelDesc[configData.fixedwing.FixedWingRoll1-1] = QString("FixedWingRoll1"); - if (configData.fixedwing.FixedWingRoll2 > 0) - channelDesc[configData.fixedwing.FixedWingRoll2-1] = QString("FixedWingRoll2"); - if (configData.fixedwing.FixedWingYaw1 > 0) - channelDesc[configData.fixedwing.FixedWingYaw1-1] = QString("FixedWingYaw1"); - if (configData.fixedwing.FixedWingYaw2 > 0) - channelDesc[configData.fixedwing.FixedWingYaw2-1] = QString("FixedWingYaw2"); - if (configData.fixedwing.FixedWingThrottle > 0) - channelDesc[configData.fixedwing.FixedWingThrottle-1] = QString("FixedWingThrottle"); - - return channelDesc; -} - /** Virtual function to update the UI widget objects */ @@ -205,7 +209,6 @@ QString ConfigFixedWingWidget::updateConfigObjectsFromWidgets() return airframeType; } - /** Virtual function to refresh the UI widget values */ @@ -213,6 +216,8 @@ void ConfigFixedWingWidget::refreshWidgetsValues(QString frameType) { Q_ASSERT(m_aircraft); + setupUI(frameType); + UAVDataObject *mixer = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); Q_ASSERT(mixer); diff --git a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configfixedwingwidget.h b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configfixedwingwidget.h index 37df2470c..26f5c282e 100644 --- a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configfixedwingwidget.h +++ b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configfixedwingwidget.h @@ -46,7 +46,6 @@ class ConfigFixedWingWidget: public VehicleConfig Q_OBJECT public: - static QStringList getChannelDescriptions(); ConfigFixedWingWidget(QWidget *parent = 0); @@ -55,23 +54,19 @@ public: virtual void refreshWidgetsValues(QString frameType); virtual QString updateConfigObjectsFromWidgets(); -public slots: - virtual void setupUI(QString airframeType); - private: - virtual void resetActuators(GUIConfigDataUnion *configData); - Ui_FixedWingConfigWidget *m_aircraft; + virtual void resetActuators(GUIConfigDataUnion *configData); + bool setupFrameFixedWing(QString airframeType); bool setupFrameElevon(QString airframeType); bool setupFrameVtail(QString airframeType); private slots: + virtual void setupUI(QString airframeType); virtual bool throwConfigError(QString airframeType); -protected: - }; #endif // CONFIGFIXEDWINGWIDGET_H diff --git a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configgroundvehiclewidget.cpp b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configgroundvehiclewidget.cpp index 2b04a3c63..9704cce75 100644 --- a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configgroundvehiclewidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configgroundvehiclewidget.cpp @@ -41,6 +41,32 @@ #include #include +QStringList ConfigGroundVehicleWidget::getChannelDescriptions() +{ + // init a channel_numelem list of channel desc defaults + QStringList channelDesc; + for (int i = 0; i < (int) (ConfigGroundVehicleWidget::CHANNEL_NUMELEM); i++) { + channelDesc.append(QString("-")); + } + + // get the gui config data + GUIConfigDataUnion configData = GetConfigData(); + + 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; +} + ConfigGroundVehicleWidget::ConfigGroundVehicleWidget(QWidget *parent) : VehicleConfig(parent), m_aircraft(new Ui_GroundConfigWidget()) { @@ -51,7 +77,7 @@ ConfigGroundVehicleWidget::ConfigGroundVehicleWidget(QWidget *parent) : m_aircraft->groundVehicleType->addItems(groundVehicleTypes); // Set default model to "Turnable (car)" - m_aircraft->groundVehicleType->setCurrentIndex(0); + m_aircraft->groundVehicleType->setCurrentIndex(m_aircraft->groundVehicleType->findText("Turnable (car)")); setupUI(m_aircraft->groundVehicleType->currentText()); @@ -169,66 +195,6 @@ void ConfigGroundVehicleWidget::resetActuators(GUIConfigDataUnion *configData) configData->ground.GroundVehicleThrottle2 = 0; } -QStringList ConfigGroundVehicleWidget::getChannelDescriptions() -{ - int i; - QStringList channelDesc; - - // init a channel_numelem list of channel desc defaults - for (i = 0; i < (int) (ConfigGroundVehicleWidget::CHANNEL_NUMELEM); i++) { - channelDesc.append(QString("-")); - } - - // get the gui config data - GUIConfigDataUnion configData = GetConfigData(); - - 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; -} - -/** - Virtual function to update the UI widget objects - */ -QString ConfigGroundVehicleWidget::updateConfigObjectsFromWidgets() -{ - QString airframeType = "GroundVehicleCar"; - - // Save the curve (common to all ground vehicle frames) - UAVDataObject *mixer = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); - - // Remove Feed Forward, it is pointless on a ground vehicle: - setMixerValue(mixer, "FeedForward", 0.0); - - // set the throttle curves - setThrottleCurve(mixer, VehicleConfig::MIXER_THROTTLECURVE1, m_aircraft->groundVehicleThrottle1->getCurve()); - setThrottleCurve(mixer, VehicleConfig::MIXER_THROTTLECURVE2, m_aircraft->groundVehicleThrottle2->getCurve()); - - // All airframe types must start with "GroundVehicle" - if (m_aircraft->groundVehicleType->currentText() == "Turnable (car)") { - airframeType = "GroundVehicleCar"; - setupGroundVehicleCar(airframeType); - } else if (m_aircraft->groundVehicleType->currentText() == "Differential (tank)") { - airframeType = "GroundVehicleDifferential"; - setupGroundVehicleDifferential(airframeType); - } else { // "Motorcycle" - airframeType = "GroundVehicleMotorcycle"; - setupGroundVehicleMotorcycle(airframeType); - } - - return airframeType; -} - /** Virtual function to refresh the UI widget values */ @@ -236,6 +202,8 @@ void ConfigGroundVehicleWidget::refreshWidgetsValues(QString frameType) { qDebug() << "ConfigGroundVehicleWidget::refreshWidgetsValues - frame type:" << frameType; + setupUI(frameType); + UAVDataObject *mixer = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); Q_ASSERT(mixer); @@ -271,25 +239,25 @@ void ConfigGroundVehicleWidget::refreshWidgetsValues(QString frameType) - //UAVDataObject *obj; + //UAVDataObject *obj; //UAVObjectField *field; - + GUIConfigDataUnion config = 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 + //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 setComboCurrentIndex(m_aircraft->gvMotor1ChannelBox, config.ground.GroundVehicleThrottle1); setComboCurrentIndex(m_aircraft->gvMotor2ChannelBox, config.ground.GroundVehicleThrottle2); setComboCurrentIndex(m_aircraft->gvSteering1ChannelBox, config.ground.GroundVehicleSteering1); setComboCurrentIndex(m_aircraft->gvSteering2ChannelBox, config.ground.GroundVehicleSteering2); - if (frameType == "GroundVehicleDifferential") { - //CURRENTLY BROKEN UNTIL WE DECIDE HOW DIFFERENTIAL SHOULD BEHAVE - // If the vehicle type is "differential", restore the slider setting - - // Find the channel number for Motor1 - //obj = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); - //Q_ASSERT(obj); + if (frameType == "GroundVehicleDifferential") { + //CURRENTLY BROKEN UNTIL WE DECIDE HOW DIFFERENTIAL SHOULD BEHAVE + // If the vehicle type is "differential", restore the slider setting + + // Find the channel number for Motor1 + //obj = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); + //Q_ASSERT(obj); int channel = m_aircraft->gvMotor1ChannelBox->currentIndex() - 1; if (channel > -1) { // If for some reason the actuators were incoherent, we might fail here, hence the check. @@ -298,23 +266,54 @@ void ConfigGroundVehicleWidget::refreshWidgetsValues(QString frameType) m_aircraft->differentialSteeringSlider2->setValue( getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH) * 100); } - } - else if (frameType == "GroundVehicleMotorcycle") { - //CURRENTLY BROKEN UNTIL WE DECIDE HOW MOTORCYCLE SHOULD BEHAVE -// obj = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); -// Q_ASSERT(obj); -// int chMixerNumber = m_aircraft->gvMotor1ChannelBox->currentIndex()-1; -// if (chMixerNumber >=0) { -// field = obj->getField(mixerVectors.at(chMixerNumber)); -// int ti = field->getElementNames().indexOf("Yaw"); -// m_aircraft->differentialSteeringSlider1->setValue(field->getDouble(ti)*100); -// -// ti = field->getElementNames().indexOf("Pitch"); -// m_aircraft->differentialSteeringSlider2->setValue(field->getDouble(ti)*100); -// } - } + } + else if (frameType == "GroundVehicleMotorcycle") { + //CURRENTLY BROKEN UNTIL WE DECIDE HOW MOTORCYCLE SHOULD BEHAVE +// obj = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); +// Q_ASSERT(obj); +// int chMixerNumber = m_aircraft->gvMotor1ChannelBox->currentIndex()-1; +// if (chMixerNumber >=0) { +// field = obj->getField(mixerVectors.at(chMixerNumber)); +// int ti = field->getElementNames().indexOf("Yaw"); +// m_aircraft->differentialSteeringSlider1->setValue(field->getDouble(ti)*100); +// +// ti = field->getElementNames().indexOf("Pitch"); +// m_aircraft->differentialSteeringSlider2->setValue(field->getDouble(ti)*100); +// } + } } +/** + Virtual function to update the UI widget objects + */ +QString ConfigGroundVehicleWidget::updateConfigObjectsFromWidgets() +{ + QString airframeType = "GroundVehicleCar"; + + // Save the curve (common to all ground vehicle frames) + UAVDataObject *mixer = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); + + // Remove Feed Forward, it is pointless on a ground vehicle: + setMixerValue(mixer, "FeedForward", 0.0); + + // set the throttle curves + setThrottleCurve(mixer, VehicleConfig::MIXER_THROTTLECURVE1, m_aircraft->groundVehicleThrottle1->getCurve()); + setThrottleCurve(mixer, VehicleConfig::MIXER_THROTTLECURVE2, m_aircraft->groundVehicleThrottle2->getCurve()); + + // All airframe types must start with "GroundVehicle" + if (m_aircraft->groundVehicleType->currentText() == "Turnable (car)") { + airframeType = "GroundVehicleCar"; + setupGroundVehicleCar(airframeType); + } else if (m_aircraft->groundVehicleType->currentText() == "Differential (tank)") { + airframeType = "GroundVehicleDifferential"; + setupGroundVehicleDifferential(airframeType); + } else { // "Motorcycle" + airframeType = "GroundVehicleMotorcycle"; + setupGroundVehicleMotorcycle(airframeType); + } + + return airframeType; +} /** Setup balancing ground vehicle. diff --git a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configgroundvehiclewidget.h b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configgroundvehiclewidget.h index 73f97cc6e..3f8abea37 100644 --- a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configgroundvehiclewidget.h +++ b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configgroundvehiclewidget.h @@ -54,19 +54,17 @@ public: virtual void refreshWidgetsValues(QString frameType); virtual QString updateConfigObjectsFromWidgets(); -public slots: - virtual void setupUI(QString airframeType); - private: - virtual void resetActuators(GUIConfigDataUnion *configData); - Ui_GroundConfigWidget *m_aircraft; + virtual void resetActuators(GUIConfigDataUnion *configData); + bool setupGroundVehicleCar(QString airframeType); bool setupGroundVehicleDifferential(QString airframeType); bool setupGroundVehicleMotorcycle(QString airframeType); private slots: + virtual void setupUI(QString airframeType); virtual bool throwConfigError(QString airframeType); }; diff --git a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configmultirotorwidget.cpp b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configmultirotorwidget.cpp index 4e4180dcf..bef60e9a2 100644 --- a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configmultirotorwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configmultirotorwidget.cpp @@ -43,6 +43,50 @@ const QString ConfigMultiRotorWidget::CHANNELBOXNAME = QString("multiMotorChannelBox"); + +QStringList ConfigMultiRotorWidget::getChannelDescriptions() +{ + // init a channel_numelem list of channel desc defaults + QStringList channelDesc; + for (int i = 0; i < (int) (ConfigMultiRotorWidget::CHANNEL_NUMELEM); i++) { + channelDesc.append(QString("-")); + } + + // get the gui config data + GUIConfigDataUnion configData = GetConfigData(); + multiGUISettingsStruct multi = configData.multi; + + if (multi.VTOLMotorN > 0 && multi.VTOLMotorN <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) { + channelDesc[multi.VTOLMotorN - 1] = QString("VTOLMotorN"); + } + if (multi.VTOLMotorNE > 0 && multi.VTOLMotorNE <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) { + channelDesc[multi.VTOLMotorNE - 1] = QString("VTOLMotorNE"); + } + if (multi.VTOLMotorNW > 0 && multi.VTOLMotorNW <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) { + channelDesc[multi.VTOLMotorNW - 1] = QString("VTOLMotorNW"); + } + if (multi.VTOLMotorS > 0 && multi.VTOLMotorS <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) { + channelDesc[multi.VTOLMotorS - 1] = QString("VTOLMotorS"); + } + if (multi.VTOLMotorSE > 0 && multi.VTOLMotorSE <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) { + channelDesc[multi.VTOLMotorSE - 1] = QString("VTOLMotorSE"); + } + if (multi.VTOLMotorSW > 0 && multi.VTOLMotorSW <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) { + channelDesc[multi.VTOLMotorSW - 1] = QString("VTOLMotorSW"); + } + if (multi.VTOLMotorW > 0 && multi.VTOLMotorW <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) { + channelDesc[multi.VTOLMotorW - 1] = QString("VTOLMotorW"); + } + if (multi.VTOLMotorE > 0 && multi.VTOLMotorE <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) { + channelDesc[multi.VTOLMotorE - 1] = QString("VTOLMotorE"); + } + if (multi.TRIYaw > 0 && multi.TRIYaw <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) { + channelDesc[multi.TRIYaw - 1] = QString("Tri-Yaw"); + } + return channelDesc; +} + + ConfigMultiRotorWidget::ConfigMultiRotorWidget(QWidget *parent) : VehicleConfig(parent), m_aircraft(new Ui_MultiRotorConfigWidget()), invertMotors(1) { @@ -58,30 +102,30 @@ ConfigMultiRotorWidget::ConfigMultiRotorWidget(QWidget *parent) : quad->setSharedRenderer(renderer); quad->setElementId("quad-x"); - QGraphicsScene *scene = new QGraphicsScene(this); + QGraphicsScene *scene = new QGraphicsScene(); scene->addItem(quad); scene->setSceneRect(quad->boundingRect()); m_aircraft->quadShape->setScene(scene); //m_multirotor = new ConfigMultiRotorWidget(m_aircraft); //m_multirotor->quad = quad; - uiowner = this; - setupUI(m_aircraft->multirotorFrameType->currentText()); + //setupUI(m_aircraft->multirotorFrameType->currentText()); QStringList multiRotorTypes; multiRotorTypes << "Tricopter Y" << "Quad +" << "Quad X" << "Hexacopter" << "Hexacopter X" << "Hexacopter Y6" << "Octocopter" << "Octocopter V" << "Octo Coax +" << "Octo Coax X" ; m_aircraft->multirotorFrameType->addItems(multiRotorTypes); + // Set default model to "Quad X" - m_aircraft->multirotorFrameType->setCurrentIndex(2); + m_aircraft->multirotorFrameType->setCurrentIndex(m_aircraft->multirotorFrameType->findText("Quad X")); + + setupUI(m_aircraft->multirotorFrameType->currentText()); connect(m_aircraft->multirotorFrameType, SIGNAL(currentIndexChanged(QString)), this, SLOT(setupUI(QString))); // Connect the multirotor motor reverse checkbox connect(m_aircraft->MultirotorRevMixerCheckBox, SIGNAL(clicked(bool)), this, SLOT(reverseMultirotorMotor())); - - //m_aircraft->quadShape->fitInView(quad, Qt::KeepAspectRatio); } ConfigMultiRotorWidget::~ConfigMultiRotorWidget() @@ -92,7 +136,6 @@ ConfigMultiRotorWidget::~ConfigMultiRotorWidget() void ConfigMultiRotorWidget::setupUI(QString frameType) { Q_ASSERT(m_aircraft); - Q_ASSERT(uiowner); Q_ASSERT(quad); qDebug() << "ConfigMultiRotorWidget::setupUI - frame type" << frameType; @@ -106,7 +149,7 @@ void ConfigMultiRotorWidget::setupUI(QString frameType) // disable all motor channel boxes for (int i = 1; i <= 8; i++) { // do it manually so we can turn off any error decorations - QComboBox *combobox = qFindChild(uiowner, "multiMotorChannelBox" + QString::number(i)); + QComboBox *combobox = qFindChild(this, "multiMotorChannelBox" + QString::number(i)); if (combobox) { combobox->setEnabled(false); combobox->setItemData(0, 0, Qt::DecorationRole); @@ -117,7 +160,7 @@ void ConfigMultiRotorWidget::setupUI(QString frameType) setComboCurrentIndex(m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findText("Tricopter Y")); // Enable all necessary motor channel boxes... - enableComboBoxes(uiowner, CHANNELBOXNAME, 3, true); + enableComboBoxes(this, CHANNELBOXNAME, 3, true); m_aircraft->mrRollMixLevel->setValue(100); m_aircraft->mrPitchMixLevel->setValue(100); @@ -129,7 +172,7 @@ void ConfigMultiRotorWidget::setupUI(QString frameType) setComboCurrentIndex(m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findText("Quad X")); // Enable all necessary motor channel boxes... - enableComboBoxes(uiowner, CHANNELBOXNAME, 4, true); + enableComboBoxes(this, CHANNELBOXNAME, 4, true); // init mixer levels m_aircraft->mrRollMixLevel->setValue(50); @@ -140,7 +183,7 @@ void ConfigMultiRotorWidget::setupUI(QString frameType) setComboCurrentIndex(m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findText("Quad +")); // Enable all necessary motor channel boxes... - enableComboBoxes(uiowner, CHANNELBOXNAME, 4, true); + enableComboBoxes(this, CHANNELBOXNAME, 4, true); m_aircraft->mrRollMixLevel->setValue(100); m_aircraft->mrPitchMixLevel->setValue(100); @@ -150,7 +193,7 @@ void ConfigMultiRotorWidget::setupUI(QString frameType) setComboCurrentIndex(m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findText("Hexacopter")); // Enable all necessary motor channel boxes... - enableComboBoxes(uiowner, CHANNELBOXNAME, 6, true); + enableComboBoxes(this, CHANNELBOXNAME, 6, true); m_aircraft->mrRollMixLevel->setValue(50); m_aircraft->mrPitchMixLevel->setValue(33); @@ -161,7 +204,7 @@ void ConfigMultiRotorWidget::setupUI(QString frameType) m_aircraft->multirotorFrameType->findText("Hexacopter X")); // Enable all necessary motor channel boxes... - enableComboBoxes(uiowner, CHANNELBOXNAME, 6, true); + enableComboBoxes(this, CHANNELBOXNAME, 6, true); m_aircraft->mrRollMixLevel->setValue(33); m_aircraft->mrPitchMixLevel->setValue(50); @@ -172,7 +215,7 @@ void ConfigMultiRotorWidget::setupUI(QString frameType) m_aircraft->multirotorFrameType->findText("Hexacopter Y6")); // Enable all necessary motor channel boxes... - enableComboBoxes(uiowner, CHANNELBOXNAME, 6, true); + enableComboBoxes(this, CHANNELBOXNAME, 6, true); m_aircraft->mrRollMixLevel->setValue(100); m_aircraft->mrPitchMixLevel->setValue(50); @@ -182,7 +225,7 @@ void ConfigMultiRotorWidget::setupUI(QString frameType) setComboCurrentIndex(m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findText("Octocopter")); // Enable all necessary motor channel boxes - enableComboBoxes(uiowner, CHANNELBOXNAME, 8, true); + enableComboBoxes(this, CHANNELBOXNAME, 8, true); m_aircraft->mrRollMixLevel->setValue(33); m_aircraft->mrPitchMixLevel->setValue(33); @@ -193,7 +236,7 @@ void ConfigMultiRotorWidget::setupUI(QString frameType) m_aircraft->multirotorFrameType->findText("Octocopter V")); // Enable all necessary motor channel boxes - enableComboBoxes(uiowner, CHANNELBOXNAME, 8, true); + enableComboBoxes(this, CHANNELBOXNAME, 8, true); m_aircraft->mrRollMixLevel->setValue(25); m_aircraft->mrPitchMixLevel->setValue(25); @@ -203,7 +246,7 @@ void ConfigMultiRotorWidget::setupUI(QString frameType) setComboCurrentIndex(m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findText("Octo Coax +")); // Enable all necessary motor channel boxes - enableComboBoxes(uiowner, CHANNELBOXNAME, 8, true); + enableComboBoxes(this, CHANNELBOXNAME, 8, true); m_aircraft->mrRollMixLevel->setValue(100); m_aircraft->mrPitchMixLevel->setValue(100); @@ -213,7 +256,7 @@ void ConfigMultiRotorWidget::setupUI(QString frameType) setComboCurrentIndex(m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findText("Octo Coax X")); // Enable all necessary motor channel boxes - enableComboBoxes(uiowner, CHANNELBOXNAME, 8, true); + enableComboBoxes(this, CHANNELBOXNAME, 8, true); m_aircraft->mrRollMixLevel->setValue(50); m_aircraft->mrPitchMixLevel->setValue(50); @@ -221,79 +264,7 @@ void ConfigMultiRotorWidget::setupUI(QString frameType) } // Draw the appropriate airframe - drawAirframe(frameType); -} - -void ConfigMultiRotorWidget::drawAirframe(QString frameType) -{ - qDebug() << "ConfigMultiRotorWidget::drawAirframe - frame type" << frameType; - - invertMotors = m_aircraft->MultirotorRevMixerCheckBox->isChecked() ? -1 : 1; - qDebug() << "ConfigMultiRotorWidget::drawAirframe - invert motors" << invertMotors; - - if (frameType == "Tri" || frameType == "Tricopter Y") { - if (invertMotors > 0) { - quad->setElementId("tri"); - } else { - quad->setElementId("tri_reverse"); - } - } else if (frameType == "QuadX" || frameType == "Quad X") { - if (invertMotors > 0) { - quad->setElementId("quad-x"); - } else { - quad->setElementId("quad-x_reverse"); - } - } else if (frameType == "QuadP" || frameType == "Quad +") { - if (invertMotors > 0) { - quad->setElementId("quad-plus"); - } else { - quad->setElementId("quad-plus_reverse"); - } - } else if (frameType == "Hexa" || frameType == "Hexacopter") { - if (invertMotors > 0) { - quad->setElementId("quad-hexa"); - } else { - quad->setElementId("quad-hexa_reverse"); - } - } else if (frameType == "HexaX" || frameType == "Hexacopter X") { - if (invertMotors > 0) { - quad->setElementId("quad-hexa-H"); - } else { - quad->setElementId("quad-hexa-H_reverse"); - } - } else if (frameType == "HexaCoax" || frameType == "Hexacopter Y6") { - if (invertMotors > 0) { - quad->setElementId("hexa-coax"); - } else { - quad->setElementId("hexa-coax_reverse"); - } - } else if (frameType == "Octo" || frameType == "Octocopter") { - if (invertMotors > 0) { - quad->setElementId("quad-octo"); - } else { - quad->setElementId("quad-octo_reverse"); - } - } else if (frameType == "OctoV" || frameType == "Octocopter V") { - if (invertMotors > 0) { - quad->setElementId("quad-octo-v"); - } else { - quad->setElementId("quad-octo-v_reverse"); - } - } else if (frameType == "OctoCoaxP" || frameType == "Octo Coax +") { - if (invertMotors > 0) { - quad->setElementId("octo-coax-P"); - } else { - quad->setElementId("octo-coax-P_reverse"); - } - } else if (frameType == "OctoCoaxX" || frameType == "Octo Coax X") { - if (invertMotors > 0) { - quad->setElementId("octo-coax-X"); - } else { - quad->setElementId("octo-coax-X_reverse"); - } - } - m_aircraft->quadShape->setSceneRect(quad->boundingRect()); - m_aircraft->quadShape->fitInView(quad, Qt::KeepAspectRatio); + // drawAirframe(frameType); } void ConfigMultiRotorWidget::resetActuators(GUIConfigDataUnion *configData) @@ -309,60 +280,298 @@ void ConfigMultiRotorWidget::resetActuators(GUIConfigDataUnion *configData) configData->multi.TRIYaw = 0; } -QStringList ConfigMultiRotorWidget::getChannelDescriptions() +/** + Helper function to refresh the UI widget values + */ +void ConfigMultiRotorWidget::refreshWidgetsValues(QString frameType) { - QStringList channelDesc; + Q_ASSERT(m_aircraft); - // init a channel_numelem list of channel desc defaults - for (int i=0; i < (int)(ConfigMultiRotorWidget::CHANNEL_NUMELEM); i++) - { - channelDesc.append(QString("-")); + setupUI(frameType); + + UAVDataObject *mixer = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); + Q_ASSERT(mixer); + + QList curveValues; + getThrottleCurve(mixer, VehicleConfig::MIXER_THROTTLECURVE1, &curveValues); + + // is at least one of the curve values != 0? + if (isValidThrottleCurve(&curveValues)) { + // yes, use the curve we just read from mixersettings + m_aircraft->multiThrottleCurve->initCurve(&curveValues); + } + else { + // no, init a straight curve + m_aircraft->multiThrottleCurve->initLinearCurve(curveValues.count(), 0.9); } - // get the gui config data - GUIConfigDataUnion configData = GetConfigData(); - multiGUISettingsStruct multi = configData.multi; - if (multi.VTOLMotorN > 0 && multi.VTOLMotorN <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) - channelDesc[multi.VTOLMotorN-1] = QString("VTOLMotorN"); - if (multi.VTOLMotorNE > 0 && multi.VTOLMotorNE <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) - channelDesc[multi.VTOLMotorNE-1] = QString("VTOLMotorNE"); - if (multi.VTOLMotorNW > 0 && multi.VTOLMotorNW <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) - channelDesc[multi.VTOLMotorNW-1] = QString("VTOLMotorNW"); - if (multi.VTOLMotorS > 0 && multi.VTOLMotorS <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) - channelDesc[multi.VTOLMotorS-1] = QString("VTOLMotorS"); - if (multi.VTOLMotorSE > 0 && multi.VTOLMotorSE <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) - channelDesc[multi.VTOLMotorSE-1] = QString("VTOLMotorSE"); - if (multi.VTOLMotorSW > 0 && multi.VTOLMotorSW <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) - channelDesc[multi.VTOLMotorSW-1] = QString("VTOLMotorSW"); - if (multi.VTOLMotorW > 0 && multi.VTOLMotorW <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) - channelDesc[multi.VTOLMotorW-1] = QString("VTOLMotorW"); - if (multi.VTOLMotorE > 0 && multi.VTOLMotorE <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) - channelDesc[multi.VTOLMotorE-1] = QString("VTOLMotorE"); - if (multi.TRIYaw > 0 && multi.TRIYaw <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) - channelDesc[multi.TRIYaw-1] = QString("Tri-Yaw"); - return channelDesc; + + int channel; + double value; + + GUIConfigDataUnion config = GetConfigData(); + multiGUISettingsStruct multi = config.multi; + +// UAVDataObject* mixer = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); +// Q_ASSERT(mixer); + + if (frameType == "QuadP") + { + // 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. + + channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1; + if (channel > -1) + { + value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH); + m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) ); + + value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW); + setYawMixLevel( -qRound(value/1.27) ); + + channel = m_aircraft->multiMotorChannelBox2->currentIndex() - 1; + value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL); + m_aircraft->mrRollMixLevel->setValue( -qRound(value/1.27)); + + } + } + else if (frameType == "QuadX") + { + // 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. + channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1; + if (channel > -1) + { + value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH); + m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) ); + + value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW); + setYawMixLevel( -qRound(value/1.27) ); + + value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL); + m_aircraft->mrRollMixLevel->setValue( qRound(value/1.27)); + + } + + } + else if (frameType == "Hexa") + { + // Motors 1/2/3 4/5/6 are: N / NE / SE / S / SW / NW + + 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. + + channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1; + if (channel > -1) + { + value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH); + m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) ); + + value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW); + setYawMixLevel( -qRound(value/1.27) ); + + //change channels + channel = m_aircraft->multiMotorChannelBox2->currentIndex() - 1; + value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL); + m_aircraft->mrRollMixLevel->setValue( -qRound(value/1.27) ); + + } + + + } + else if (frameType == "HexaX") + { + // 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 + // "custom" setting. + + channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1; + if (channel > -1) + { + value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH); + m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) ); + + value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW); + setYawMixLevel( -qRound(value/1.27) ); + + channel = m_aircraft->multiMotorChannelBox2->currentIndex() - 1; + value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL); + m_aircraft->mrRollMixLevel->setValue( -qRound(value/1.27) ); + } + } + else if (frameType == "HexaCoax") + { + // 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. + channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1; + if (channel > -1) + { + value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH); + m_aircraft->mrPitchMixLevel->setValue( qRound(2*value/1.27) ); + + channel = m_aircraft->multiMotorChannelBox2->currentIndex() - 1; + value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW); + setYawMixLevel( qRound(value/1.27) ); + + value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL); + m_aircraft->mrRollMixLevel->setValue( qRound(value/1.27) ); + } + } + else if (frameType == "Octo" || frameType == "OctoV" || frameType == "OctoCoaxP") + { + // 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. + channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1; + if (channel > -1) + { + if (frameType == "Octo") { + value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH); + m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) ); + + value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW); + setYawMixLevel( -qRound(value/1.27) ); + + //change channels + channel = m_aircraft->multiMotorChannelBox2->currentIndex() - 1; + value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL); + m_aircraft->mrRollMixLevel->setValue( -qRound(value/1.27) ); + } + else if (frameType == "OctoV") { + value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH); + m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) ); + + value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW); + setYawMixLevel( -qRound(value/1.27) ); + + //change channels + channel = m_aircraft->multiMotorChannelBox2->currentIndex() - 1; + value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL); + m_aircraft->mrRollMixLevel->setValue( -qRound(value/1.27) ); + } + else if (frameType == "OctoCoaxP") { + value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH); + m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) ); + + value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW); + setYawMixLevel( -qRound(value/1.27) ); + + //change channels + channel = m_aircraft->multiMotorChannelBox3->currentIndex() - 1; + value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL); + m_aircraft->mrRollMixLevel->setValue( -qRound(value/1.27) ); + } + + } + } + else if (frameType == "OctoCoaxX") + { + // 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. + channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1; + if (channel > -1) + { + value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH); + m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) ); + + value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW); + setYawMixLevel( -qRound(value/1.27) ); + + value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL); + m_aircraft->mrRollMixLevel->setValue( qRound(value/1.27) ); + } + } + else if (frameType == "Tri") + { + // 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); + + channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1; + if (channel > -1) + { + value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH); + m_aircraft->mrPitchMixLevel->setValue( qRound(2*value/1.27) ); + + value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL); + m_aircraft->mrRollMixLevel->setValue( qRound(value/1.27) ); + + } + } + + drawAirframe(frameType); } -void ConfigMultiRotorWidget::setYawMixLevel(int value) -{ - if(value<0) - { - m_aircraft->mrYawMixLevel->setValue((-1)*value); - m_aircraft->MultirotorRevMixerCheckBox->setChecked(true); - } - else - { - m_aircraft->mrYawMixLevel->setValue(value); - m_aircraft->MultirotorRevMixerCheckBox->setChecked(false); - } - -} - - - - /** Helper function to update the UI widget objects */ @@ -566,303 +775,62 @@ QString ConfigMultiRotorWidget::updateConfigObjectsFromWidgets() return airframeType; } +void ConfigMultiRotorWidget::setYawMixLevel(int value) +{ + if (value < 0) { + m_aircraft->mrYawMixLevel->setValue(-value); + m_aircraft->MultirotorRevMixerCheckBox->setChecked(true); + } else { + m_aircraft->mrYawMixLevel->setValue(value); + m_aircraft->MultirotorRevMixerCheckBox->setChecked(false); + } + +} + void ConfigMultiRotorWidget::reverseMultirotorMotor(){ QString frameType = m_aircraft->multirotorFrameType->currentText(); drawAirframe(frameType); } -/** - Helper function to refresh the UI widget values - */ -void ConfigMultiRotorWidget::refreshWidgetsValues(QString frameType) +void ConfigMultiRotorWidget::drawAirframe(QString frameType) { - Q_ASSERT(m_aircraft); + qDebug() << "ConfigMultiRotorWidget::drawAirframe - frame type" << frameType; - UAVDataObject *mixer = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); - Q_ASSERT(mixer); - - QList curveValues; - getThrottleCurve(mixer, VehicleConfig::MIXER_THROTTLECURVE1, &curveValues); - - // is at least one of the curve values != 0? - if (isValidThrottleCurve(&curveValues)) { - // yes, use the curve we just read from mixersettings - m_aircraft->multiThrottleCurve->initCurve(&curveValues); - } - else { - // no, init a straight curve - m_aircraft->multiThrottleCurve->initLinearCurve(curveValues.count(), 0.9); + QString elementId; + if (frameType == "Tri" || frameType == "Tricopter Y") { + elementId = "tri"; + } else if (frameType == "QuadX" || frameType == "Quad X") { + elementId = "quad-x"; + } else if (frameType == "QuadP" || frameType == "Quad +") { + elementId = "quad-plus"; + } else if (frameType == "Hexa" || frameType == "Hexacopter") { + elementId = "quad-hexa"; + } else if (frameType == "HexaX" || frameType == "Hexacopter X") { + elementId = "quad-hexa-H"; + } else if (frameType == "HexaCoax" || frameType == "Hexacopter Y6") { + elementId = "hexa-coax"; + } else if (frameType == "Octo" || frameType == "Octocopter") { + elementId = "quad-octo"; + } else if (frameType == "OctoV" || frameType == "Octocopter V") { + elementId = "quad-octo-v"; + } else if (frameType == "OctoCoaxP" || frameType == "Octo Coax +") { + elementId = "octo-coax-P"; + } else if (frameType == "OctoCoaxX" || frameType == "Octo Coax X") { + elementId = "octo-coax-X"; } - - - - int channel; - double value; - - GUIConfigDataUnion config = GetConfigData(); - multiGUISettingsStruct multi = config.multi; - -// UAVDataObject* mixer = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); -// Q_ASSERT(mixer); - - if (frameType == "QuadP") - { - // 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. - - channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1; - if (channel > -1) - { - value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH); - m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) ); - - value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW); - setYawMixLevel( -qRound(value/1.27) ); - - channel = m_aircraft->multiMotorChannelBox2->currentIndex() - 1; - value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL); - m_aircraft->mrRollMixLevel->setValue( -qRound(value/1.27)); - - } - } - else if (frameType == "QuadX") - { - // 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. - channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1; - if (channel > -1) - { - value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH); - m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) ); - - value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW); - setYawMixLevel( -qRound(value/1.27) ); - - value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL); - m_aircraft->mrRollMixLevel->setValue( qRound(value/1.27)); - - } - - } - else if (frameType == "Hexa") - { - // Motors 1/2/3 4/5/6 are: N / NE / SE / S / SW / NW - - 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. - - channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1; - if (channel > -1) - { - value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH); - m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) ); - - value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW); - setYawMixLevel( -qRound(value/1.27) ); - - //change channels - channel = m_aircraft->multiMotorChannelBox2->currentIndex() - 1; - value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL); - m_aircraft->mrRollMixLevel->setValue( -qRound(value/1.27) ); - - } - - - } - else if (frameType == "HexaX") - { - // 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 - // "custom" setting. - - channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1; - if (channel > -1) - { - value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH); - m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) ); - - value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW); - setYawMixLevel( -qRound(value/1.27) ); - - channel = m_aircraft->multiMotorChannelBox2->currentIndex() - 1; - value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL); - m_aircraft->mrRollMixLevel->setValue( -qRound(value/1.27) ); - } - } - else if (frameType == "HexaCoax") - { - // 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. - channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1; - if (channel > -1) - { - value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH); - m_aircraft->mrPitchMixLevel->setValue( qRound(2*value/1.27) ); - - channel = m_aircraft->multiMotorChannelBox2->currentIndex() - 1; - value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW); - setYawMixLevel( qRound(value/1.27) ); - - value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL); - m_aircraft->mrRollMixLevel->setValue( qRound(value/1.27) ); - } - } - else if (frameType == "Octo" || frameType == "OctoV" || frameType == "OctoCoaxP") - { - // 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. - channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1; - if (channel > -1) - { - if (frameType == "Octo") { - value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH); - m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) ); - - value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW); - setYawMixLevel( -qRound(value/1.27) ); - - //change channels - channel = m_aircraft->multiMotorChannelBox2->currentIndex() - 1; - value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL); - m_aircraft->mrRollMixLevel->setValue( -qRound(value/1.27) ); - } - else if (frameType == "OctoV") { - value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH); - m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) ); - - value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW); - setYawMixLevel( -qRound(value/1.27) ); - - //change channels - channel = m_aircraft->multiMotorChannelBox2->currentIndex() - 1; - value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL); - m_aircraft->mrRollMixLevel->setValue( -qRound(value/1.27) ); - } - else if (frameType == "OctoCoaxP") { - value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH); - m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) ); - - value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW); - setYawMixLevel( -qRound(value/1.27) ); - - //change channels - channel = m_aircraft->multiMotorChannelBox3->currentIndex() - 1; - value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL); - m_aircraft->mrRollMixLevel->setValue( -qRound(value/1.27) ); - } - - } - } - else if (frameType == "OctoCoaxX") - { - // 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. - channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1; - if (channel > -1) - { - value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH); - m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) ); - - value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW); - setYawMixLevel( -qRound(value/1.27) ); - - value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL); - m_aircraft->mrRollMixLevel->setValue( qRound(value/1.27) ); - } - } - else if (frameType == "Tri") - { - // 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); - - channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1; - if (channel > -1) - { - value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH); - m_aircraft->mrPitchMixLevel->setValue( qRound(2*value/1.27) ); - - value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL); - m_aircraft->mrRollMixLevel->setValue( qRound(value/1.27) ); - - } + invertMotors = m_aircraft->MultirotorRevMixerCheckBox->isChecked() ? -1 : 1; + if (invertMotors <= 0) { + elementId += "_reverse"; } - drawAirframe(frameType); + if (elementId != "" && elementId != quad->elementId()) { + quad->setElementId(elementId); + m_aircraft->quadShape->setSceneRect(quad->boundingRect()); + m_aircraft->quadShape->fitInView(quad, Qt::KeepAspectRatio); + } } - - /** Helper function: setupQuadMotor */ @@ -1106,7 +1074,7 @@ bool ConfigMultiRotorWidget::throwConfigError(int numMotors) //Iterate through all instances of multiMotorChannelBox for (int i=0; i(uiowner, "multiMotorChannelBox" + QString::number(i+1)); + QComboBox *combobox = qFindChild(this, "multiMotorChannelBox" + QString::number(i+1)); if (combobox){ if (combobox->currentText() == "None") { int size = combobox->style()->pixelMetric(QStyle::PM_SmallIconSize); diff --git a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configmultirotorwidget.h b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configmultirotorwidget.h index e1d7c0a00..2b2844fad 100644 --- a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configmultirotorwidget.h +++ b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configmultirotorwidget.h @@ -46,9 +46,8 @@ class ConfigMultiRotorWidget: public VehicleConfig Q_OBJECT public: - - static QStringList getChannelDescriptions(); static const QString CHANNELBOXNAME; + static QStringList getChannelDescriptions(); ConfigMultiRotorWidget(QWidget *parent = 0); ~ConfigMultiRotorWidget(); @@ -56,20 +55,16 @@ public: virtual void refreshWidgetsValues(QString frameType); virtual QString updateConfigObjectsFromWidgets(); -public slots: - virtual void setupUI(QString airframeType); - protected: void showEvent(QShowEvent *event); void resizeEvent(QResizeEvent *event); private: - virtual void resetActuators(GUIConfigDataUnion *configData); - Ui_MultiRotorConfigWidget *m_aircraft; - - QWidget *uiowner; QGraphicsSvgItem *quad; + float invertMotors; + + virtual void resetActuators(GUIConfigDataUnion *configData); bool setupQuad(bool pLayout); bool setupHexa(bool pLayout); @@ -78,13 +73,12 @@ private: void setupMotors(QList motorList); void setupQuadMotor(int channel, double roll, double pitch, double yaw); - float invertMotors; - void setYawMixLevel(int); void drawAirframe(QString multiRotorType); private slots: + virtual void setupUI(QString airframeType); virtual bool throwConfigError(int numMotors); void reverseMultirotorMotor(); diff --git a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/vehicleconfig.cpp b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/vehicleconfig.cpp index d9e5cbf00..543de1cba 100644 --- a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/vehicleconfig.cpp +++ b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/vehicleconfig.cpp @@ -138,7 +138,7 @@ void VehicleConfig::setComboCurrentIndex(QComboBox *box, int index) /** Helper function: - enables/disables the named comboboxes within supplied uiowner + enables/disables the named comboboxes within supplied owner */ void VehicleConfig::enableComboBoxes(QWidget *owner, QString boxName, int boxCount, bool enable) { diff --git a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/vehicleconfig.h b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/vehicleconfig.h index 774aea259..ba28d8977 100644 --- a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/vehicleconfig.h +++ b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/vehicleconfig.h @@ -41,11 +41,11 @@ typedef struct { uint VTOLMotorNW:4; uint VTOLMotorNE:4; uint VTOLMotorSW:4; - uint VTOLMotorSE:4; //32bits + uint VTOLMotorSE:4; // 32 bits uint TRIYaw:4; - quint32 padding:28; //64bits + quint32 padding:28; // 64 bits quint32 padding1; - quint32 padding2; //128bits + quint32 padding2; // 128 bits } __attribute__((packed)) multiGUISettingsStruct; typedef struct { @@ -57,15 +57,15 @@ typedef struct { uint ccpmLinkRollState:1; uint SliderValue0:7; uint SliderValue1:7; - uint SliderValue2:7;//41bits + uint SliderValue2:7; // 41 bits uint ServoIndexW:4; uint ServoIndexX:4; uint ServoIndexY:4; - uint ServoIndexZ:4;//57bits + uint ServoIndexZ:4; // 57 bits uint Throttle:4; - uint Tail:4; //65bits - quint32 padding:31; //96bits - quint32 padding1; //128bits + uint Tail:4; // 65bits + quint32 padding:31; // 96 bits + quint32 padding1; // 128 bits } __attribute__((packed)) heliGUISettingsStruct; typedef struct { @@ -76,10 +76,10 @@ typedef struct { uint FixedWingPitch2:4; uint FixedWingYaw1:4; uint FixedWingYaw2:4; - uint padding:4; //32bits + uint padding:4; // 32 bits quint32 padding1; quint32 padding2; - quint32 padding3; //128bits + quint32 padding3; // 128 bits } __attribute__((packed)) fixedGUISettingsStruct; typedef struct { @@ -87,16 +87,16 @@ typedef struct { uint GroundVehicleThrottle2:4; uint GroundVehicleSteering1:4; uint GroundVehicleSteering2:4; - uint padding:16; //32bits + uint padding:16; // 32 bits quint32 padding1; quint32 padding2; - quint32 padding3; //128bits + quint32 padding3; // 128 bits } __attribute__((packed)) groundGUISettingsStruct; typedef union { - uint UAVObject[4]; //32bits * 4 - heliGUISettingsStruct heli; //128bits + uint UAVObject[4]; // 32 bits * 4 + heliGUISettingsStruct heli; // 128 bits fixedGUISettingsStruct fixedwing; multiGUISettingsStruct multi; groundGUISettingsStruct ground; @@ -145,6 +145,7 @@ public: static void SetConfigData(GUIConfigDataUnion configData); static void resetField(UAVObjectField *field); + static void setComboCurrentIndex(QComboBox *box, int index); static void enableComboBoxes(QWidget *owner, QString boxName, int boxCount, bool enable); @@ -170,9 +171,6 @@ public: double getCurveMin(QList *curve); double getCurveMax(QList *curve); -public slots: - virtual void setupUI(QString airframeType); - protected: QStringList channelNames; QStringList mixerTypes; @@ -184,6 +182,9 @@ private: virtual void resetActuators(GUIConfigDataUnion *configData); +private slots: + virtual void setupUI(QString airframeType); + }; #endif // GUIVEHICLECONFIG_H diff --git a/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.cpp b/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.cpp index d590df28a..283ae16a3 100644 --- a/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.cpp @@ -44,6 +44,62 @@ #include #include +/** + Static function to get currently assigned channelDescriptions + for all known vehicle types; instantiates the appropriate object + then asks it to supply channel descs + */ +QStringList ConfigVehicleTypeWidget::getChannelDescriptions() +{ + ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); + UAVObjectManager *objMngr = pm->getObject(); + Q_ASSERT(objMngr); + + // get an instance of systemsettings + SystemSettings *systemSettings = SystemSettings::GetInstance(objMngr); + Q_ASSERT(systemSettings); + SystemSettings::DataFields systemSettingsData = systemSettings->getData(); + + QStringList channelDesc; + switch (systemSettingsData.AirframeType) { + case SystemSettings::AIRFRAMETYPE_FIXEDWING: + case SystemSettings::AIRFRAMETYPE_FIXEDWINGELEVON: + case SystemSettings::AIRFRAMETYPE_FIXEDWINGVTAIL: + // fixed wing + channelDesc = ConfigFixedWingWidget::getChannelDescriptions(); + break; + case SystemSettings::AIRFRAMETYPE_HELICP: + // helicp + channelDesc = ConfigCcpmWidget::getChannelDescriptions(); + break; + 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: + // multirotor + channelDesc = ConfigMultiRotorWidget::getChannelDescriptions(); + break; + case SystemSettings::AIRFRAMETYPE_GROUNDVEHICLECAR: + case SystemSettings::AIRFRAMETYPE_GROUNDVEHICLEDIFFERENTIAL: + case SystemSettings::AIRFRAMETYPE_GROUNDVEHICLEMOTORCYCLE: + // ground + channelDesc = ConfigGroundVehicleWidget::getChannelDescriptions(); + break; + default: + channelDesc = ConfigCustomWidget::getChannelDescriptions(); + break; + } + + return channelDesc; +} + ConfigVehicleTypeWidget::ConfigVehicleTypeWidget(QWidget *parent) : ConfigTaskWidget(parent) { m_aircraft = new Ui_AircraftWidget(); @@ -115,7 +171,7 @@ ConfigVehicleTypeWidget::ConfigVehicleTypeWidget(QWidget *parent) : ConfigTaskWi } // Connect aircraft type selection dropbox to callback function - connect(m_aircraft->aircraftType, SIGNAL(currentIndexChanged(int)), this, SLOT(switchAirframeType(int))); + connect(m_aircraft->aircraftType, SIGNAL(currentIndexChanged(int)), m_aircraft->airframesWidget, SLOT(setCurrentIndex(int))); // Connect the three feed forward test checkboxes connect(m_aircraft->ffTestBox1, SIGNAL(clicked(bool)), this, SLOT(enableFFTest())); @@ -132,7 +188,6 @@ ConfigVehicleTypeWidget::ConfigVehicleTypeWidget(QWidget *parent) : ConfigTaskWi disableMouseWheelEvents(); } - /** Destructor */ @@ -141,76 +196,207 @@ ConfigVehicleTypeWidget::~ConfigVehicleTypeWidget() // Do nothing } -/** - Static function to get currently assigned channelDescriptions - for all known vehicle types; instantiates the appropriate object - then asks it to supply channel descs - */ -QStringList ConfigVehicleTypeWidget::getChannelDescriptions() -{ - ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); - UAVObjectManager *objMngr = pm->getObject(); - Q_ASSERT(objMngr); - - // get an instance of systemsettings - SystemSettings *systemSettings = SystemSettings::GetInstance(objMngr); - Q_ASSERT(systemSettings); - SystemSettings::DataFields systemSettingsData = systemSettings->getData(); - - QStringList channelDesc; - switch (systemSettingsData.AirframeType) { - case SystemSettings::AIRFRAMETYPE_FIXEDWING: - case SystemSettings::AIRFRAMETYPE_FIXEDWINGELEVON: - case SystemSettings::AIRFRAMETYPE_FIXEDWINGVTAIL: - // fixed wing - channelDesc = ConfigFixedWingWidget::getChannelDescriptions(); - break; - case SystemSettings::AIRFRAMETYPE_HELICP: - // helicp - channelDesc = ConfigCcpmWidget::getChannelDescriptions(); - break; - 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: - // multirotor - channelDesc = ConfigMultiRotorWidget::getChannelDescriptions(); - break; - case SystemSettings::AIRFRAMETYPE_GROUNDVEHICLECAR: - case SystemSettings::AIRFRAMETYPE_GROUNDVEHICLEDIFFERENTIAL: - case SystemSettings::AIRFRAMETYPE_GROUNDVEHICLEMOTORCYCLE: - // ground - channelDesc = ConfigGroundVehicleWidget::getChannelDescriptions(); - break; - default: - channelDesc = ConfigCustomWidget::getChannelDescriptions(); - break; - } - - return channelDesc; -} - - /** Slot for switching the airframe type. We do it explicitely 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); +//} + +/** + \brief Sets up the mixer depending on Airframe type. Accepts either system settings or + combo box entry from airframe type, as those do not overlap. + */ +//void ConfigVehicleTypeWidget::setupAirframeUI(QString frameType) +//{ +// qDebug() << "ConfigVehicleTypeWidget::setupAirframeUI - begin"; +// qDebug() << "ConfigVehicleTypeWidget::setupAirframeUI - frame type" << frameType; +// +// bool dirty = isDirty(); +// +// QString category = frameCategory2(frameType); +// if (category == "FixedWing") { +// m_fixedwing->setupUI(frameType); +// } else if (category == "Multirotor") { +// m_multirotor->setupUI(frameType); +// } else if (category == "Helicopter") { +// m_heli->setupUI(frameType); +// } else if (category == "Ground") { +// m_groundvehicle->setupUI(frameType); +// } else if (category == "Custom") { +// m_custom->setupUI(frameType); +// } +// +// setDirty(dirty); +// +// qDebug() << "ConfigVehicleTypeWidget::setupAirframeUI - end"; +//} + +/** + Refreshes the current value of the SystemSettings which holds the aircraft type + */ +void ConfigVehicleTypeWidget::refreshWidgetsValues(UAVObject *o) { - m_aircraft->airframesWidget->setCurrentIndex(index); + Q_UNUSED(o); + + qDebug() << "ConfigVehicleTypeWidget::refreshWidgetsValues - begin"; + + if (!allObjectsUpdated()) { + return; + } + + bool dirty = isDirty(); + qDebug() << "ConfigVehicleTypeWidget::refreshWidgetsValues - isDirty:" << dirty; + + // Get the Airframe type from the system settings: + UAVDataObject *system = dynamic_cast(getObjectManager()->getObject(QString("SystemSettings"))); + Q_ASSERT(system); + + UAVObjectField *field = system->getField(QString("AirframeType")); + Q_ASSERT(field); + + // At this stage, we will need to have some hardcoded settings in this code, this + // is not ideal, but there you go. + QString frameType = field->getValue().toString(); + qDebug() << "ConfigVehicleTypeWidget::refreshWidgetsValues - frame type:" << frameType; + //setupAirframeUI(frameType); + + QString category = "FixedWing";//frameCategory(frameType); + if (category == "FixedWing") { + // Retrieve fixed wing settings + setComboCurrentIndex(m_aircraft->aircraftType, m_aircraft->aircraftType->findText("Fixed Wing")); + m_fixedwing->refreshWidgetsValues(frameType); + } else if (category == "Multirotor") { + // Retrieve multirotor settings + setComboCurrentIndex(m_aircraft->aircraftType, m_aircraft->aircraftType->findText("Multirotor")); + m_multirotor->refreshWidgetsValues(frameType); + } else if (category == "Helicopter") { + setComboCurrentIndex(m_aircraft->aircraftType, m_aircraft->aircraftType->findText("Helicopter")); + m_heli->refreshWidgetsValues(frameType); + } else if (category == "Ground") { + // Retrieve ground vehicle settings + setComboCurrentIndex(m_aircraft->aircraftType, m_aircraft->aircraftType->findText("Ground")); + m_groundvehicle->refreshWidgetsValues(frameType); + } else if (category == "Custom") { + // Retrieve custom settings + setComboCurrentIndex(m_aircraft->aircraftType, m_aircraft->aircraftType->findText("Custom")); + m_custom->refreshWidgetsValues(frameType); + } + + updateFeedForwardUI(); + + setDirty(dirty); + + qDebug() << "ConfigVehicleTypeWidget::refreshWidgetsValues - end"; } -///////////////////////////////////////////////////////// -/// Feed Forward Testing -///////////////////////////////////////////////////////// +//QString ConfigVehicleTypeWidget::frameCategory1(QString frameType) +//{ +// QString category; +// if (frameType.startsWith("FixedWing")) { +// category = "FixedWing"; +// } else if (frameType == "Tri" || frameType == "QuadX" || frameType == "QuadP" || frameType == "Hexa" +// || frameType == "HexaCoax" || frameType == "HexaX" || frameType == "Octo" || frameType == "OctoV" +// || frameType == "OctoCoaxP" || frameType == "OctoCoaxX") { +// category = "Multirotor"; +// } else if (frameType == "HeliCP") { +// category = "Helicopter"; +// } else if (frameType.startsWith("GroundVehicle")) { +// category = "Ground"; +// } else { +// category = "Custom"; +// } +// return category; +//} + + +QString ConfigVehicleTypeWidget::frameCategory(QString frameType) +{ + QString category; + if (frameType == "FixedWing" || frameType == "Elevator aileron rudder" || frameType == "FixedWingElevon" + || frameType == "Elevon" || frameType == "FixedWingVtail" || frameType == "Vtail") { + category = "FixedWing"; + } else if (frameType == "Tri" || frameType == "Tricopter Y" || frameType == "QuadX" || frameType == "Quad X" + || frameType == "QuadP" || frameType == "Quad +" || frameType == "Hexa" || frameType == "Hexacopter" + || frameType == "HexaX" || frameType == "Hexacopter X" || frameType == "HexaCoax" + || frameType == "Hexacopter Y6" || frameType == "Octo" || frameType == "Octocopter" || frameType == "OctoV" + || frameType == "Octocopter V" || frameType == "OctoCoaxP" || frameType == "Octo Coax +" + || frameType == "OctoCoaxX" || frameType == "Octo Coax X") { + category = "Multirotor"; + } else if (frameType == "HeliCP") { + category = "Helicopter"; + } else if (frameType == "GroundVehicleCar" || frameType == "Turnable (car)" + || frameType == "GroundVehicleDifferential" || frameType == "Differential (tank)" + || frameType == "GroundVehicleMotorcyle" || frameType == "Motorcycle") { + category = "Ground"; + } else { + category = "Custom"; + } + return category; +} + +/** + Sends the config to the board (airframe type) + + We do all the tasks common to all airframes, or family of airframes, and + we call additional methods for specific frames, so that we do not have a code + that is too heavy. +*/ +void ConfigVehicleTypeWidget::updateObjectsFromWidgets() +{ + UAVDataObject *mixer = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); + Q_ASSERT(mixer); + + QPointer vconfig = new VehicleConfig(); + + // Update feed forward settings + vconfig->setMixerValue(mixer, "FeedForward", m_aircraft->feedForwardSlider->value() / 100.0); + vconfig->setMixerValue(mixer, "AccelTime", m_aircraft->accelTime->value()); + vconfig->setMixerValue(mixer, "DecelTime", m_aircraft->decelTime->value()); + vconfig->setMixerValue(mixer, "MaxAccel", m_aircraft->maxAccelSlider->value()); + + // Sets airframe type default to "Custom" + QString airframeType = "Custom"; + if (m_aircraft->aircraftType->currentText() == "Fixed Wing") { + airframeType = m_fixedwing->updateConfigObjectsFromWidgets(); + } + else if (m_aircraft->aircraftType->currentText() == "Multirotor") { + airframeType = m_multirotor->updateConfigObjectsFromWidgets(); + } + else if (m_aircraft->aircraftType->currentText() == "Helicopter") { + airframeType = m_heli->updateConfigObjectsFromWidgets(); + } + else if (m_aircraft->aircraftType->currentText() == "Ground") { + airframeType = m_groundvehicle->updateConfigObjectsFromWidgets(); + } + else { + airframeType = m_custom->updateConfigObjectsFromWidgets(); + } + + // set the airframe type + UAVDataObject *system = dynamic_cast(getObjectManager()->getObject(QString("SystemSettings"))); + Q_ASSERT(system); + + QPointer field = system->getField(QString("AirframeType")); + if (field) { + field->setValue(airframeType); + } + + updateFeedForwardUI(); +} + +/** + Reset the contents of a field + */ +//void ConfigVehicleTypeWidget::resetField(UAVObjectField *field) +//{ +// for (unsigned int i = 0; i < field->getNumElements(); i++) { +// field->setValue(0, i); +// } +//} /** Enables and runs feed forward testing @@ -271,150 +457,6 @@ void ConfigVehicleTypeWidget::enableFFTest() } } -/************************** - * Aircraft settings - **************************/ - -/** - Refreshes the current value of the SystemSettings which holds the aircraft type - */ -void ConfigVehicleTypeWidget::refreshWidgetsValues(UAVObject *o) -{ - Q_UNUSED(o); - - qDebug() << "ConfigVehicleTypeWidget::refreshWidgetsValues - begin"; - - if (!allObjectsUpdated()) { - return; - } - - bool dirty = isDirty(); - qDebug() << "ConfigVehicleTypeWidget::refreshWidgetsValues - isDirty:" << dirty; - - // Get the Airframe type from the system settings: - UAVDataObject *system = dynamic_cast(getObjectManager()->getObject(QString("SystemSettings"))); - Q_ASSERT(system); - - UAVObjectField *field = system->getField(QString("AirframeType")); - Q_ASSERT(field); - - // At this stage, we will need to have some hardcoded settings in this code, this - // is not ideal, but there you go. - QString frameType = field->getValue().toString(); - qDebug() << "ConfigVehicleTypeWidget::refreshWidgetsValues - frame type:" << frameType; - setupAirframeUI(frameType); - - QString category = frameCategory1(frameType); - if (category == "FixedWing") { - // Retrieve fixed wing settings - setComboCurrentIndex(m_aircraft->aircraftType, m_aircraft->aircraftType->findText("Fixed Wing")); - m_fixedwing->refreshWidgetsValues(frameType); - } else if (category == "Multirotor") { - // Retrieve multirotor settings - setComboCurrentIndex(m_aircraft->aircraftType, m_aircraft->aircraftType->findText("Multirotor")); - m_multirotor->refreshWidgetsValues(frameType); - } else if (category == "Helicopter") { - setComboCurrentIndex(m_aircraft->aircraftType, m_aircraft->aircraftType->findText("Helicopter")); - m_heli->refreshWidgetsValues(frameType); - } else if (category == "Ground") { - // Retrieve ground vehicle settings - setComboCurrentIndex(m_aircraft->aircraftType, m_aircraft->aircraftType->findText("Ground")); - m_groundvehicle->refreshWidgetsValues(frameType); - } else if (category == "Custom") { - // Retrieve custom settings - setComboCurrentIndex(m_aircraft->aircraftType, m_aircraft->aircraftType->findText("Custom")); - m_custom->refreshWidgetsValues(frameType); - } - - updateFeedForwardUI(); - setDirty(dirty); - - qDebug() << "ConfigVehicleTypeWidget::refreshWidgetsValues - end"; -} - -/** - \brief Sets up the mixer depending on Airframe type. Accepts either system settings or - combo box entry from airframe type, as those do not overlap. - */ -void ConfigVehicleTypeWidget::setupAirframeUI(QString frameType) -{ - qDebug() << "ConfigVehicleTypeWidget::setupAirframeUI - begin"; - qDebug() << "ConfigVehicleTypeWidget::setupAirframeUI - frame type" << frameType; - bool dirty = isDirty(); - - QString category = frameCategory2(frameType); - if (category == "FixedWing") { - m_fixedwing->setupUI(frameType); - } else if (category == "Multirotor") { - m_multirotor->setupUI(frameType); - } else if (category == "Helicopter") { - m_heli->setupUI(frameType); - } else if (category == "Ground") { - m_groundvehicle->setupUI(frameType); - } else if (category == "Custom") { - m_custom->setupUI(frameType); - } - - setDirty(dirty); - qDebug() << "ConfigVehicleTypeWidget::setupAirframeUI - end"; -} - -QString ConfigVehicleTypeWidget::frameCategory1(QString frameType) -{ - QString category; - if (frameType.startsWith("FixedWing")) { - category = "FixedWing"; - } else if (frameType == "Tri" || frameType == "QuadX" || frameType == "QuadP" || frameType == "Hexa" - || frameType == "HexaCoax" || frameType == "HexaX" || frameType == "Octo" || frameType == "OctoV" - || frameType == "OctoCoaxP" || frameType == "OctoCoaxX") { - category = "Multirotor"; - } else if (frameType == "HeliCP") { - category = "Helicopter"; - } else if (frameType.startsWith("GroundVehicle")) { - category = "Ground"; - } else { - category = "Custom"; - } - return category; -} - - -QString ConfigVehicleTypeWidget::frameCategory2(QString frameType) -{ - QString category; - if (frameType == "FixedWing" || frameType == "Elevator aileron rudder" || frameType == "FixedWingElevon" - || frameType == "Elevon" || frameType == "FixedWingVtail" || frameType == "Vtail") { - category = "FixedWing"; - } else if (frameType == "Tri" || frameType == "Tricopter Y" || frameType == "QuadX" || frameType == "Quad X" - || frameType == "QuadP" || frameType == "Quad +" || frameType == "Hexa" || frameType == "Hexacopter" - || frameType == "HexaX" || frameType == "Hexacopter X" || frameType == "HexaCoax" - || frameType == "Hexacopter Y6" || frameType == "Octo" || frameType == "Octocopter" || frameType == "OctoV" - || frameType == "Octocopter V" || frameType == "OctoCoaxP" || frameType == "Octo Coax +" - || frameType == "OctoCoaxX" || frameType == "Octo Coax X") { - category = "Multirotor"; - } else if (frameType == "HeliCP") { - category = "Helicopter"; - } else if (frameType == "GroundVehicleCar" || frameType == "Turnable (car)" - || frameType == "GroundVehicleDifferential" || frameType == "Differential (tank)" - || frameType == "GroundVehicleMotorcyle" || frameType == "Motorcycle") { - category = "Ground"; - } else { - category = "Custom"; - } - return category; -} - - -/** - Reset the contents of a field - */ -void ConfigVehicleTypeWidget::resetField(UAVObjectField * field) -{ - for (unsigned int i = 0; i < field->getNumElements(); i++) { - field->setValue(0, i); - } -} - /** Updates the custom airframe settings based on the current airframe. @@ -422,7 +464,7 @@ void ConfigVehicleTypeWidget::resetField(UAVObjectField * field) */ // TODO rename to FF void ConfigVehicleTypeWidget::updateFeedForwardUI() -{ +{ UAVDataObject* mixer = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); Q_ASSERT(mixer); @@ -435,56 +477,6 @@ void ConfigVehicleTypeWidget::updateFeedForwardUI() m_aircraft->maxAccelSlider->setValue(vconfig->getMixerValue(mixer,"MaxAccel")); } -/** - Sends the config to the board (airframe type) - - We do all the tasks common to all airframes, or family of airframes, and - we call additional methods for specific frames, so that we do not have a code - that is too heavy. -*/ -void ConfigVehicleTypeWidget::updateObjectsFromWidgets() -{ - UAVDataObject *mixer = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); - Q_ASSERT(mixer); - - QPointer vconfig = new VehicleConfig(); - - // Update feed forward settings - vconfig->setMixerValue(mixer, "FeedForward", m_aircraft->feedForwardSlider->value() / 100.0); - vconfig->setMixerValue(mixer, "AccelTime", m_aircraft->accelTime->value()); - vconfig->setMixerValue(mixer, "DecelTime", m_aircraft->decelTime->value()); - vconfig->setMixerValue(mixer, "MaxAccel", m_aircraft->maxAccelSlider->value()); - - // Sets airframe type default to "Custom" - QString airframeType = "Custom"; - if (m_aircraft->aircraftType->currentText() == "Fixed Wing") { - airframeType = m_fixedwing->updateConfigObjectsFromWidgets(); - } - else if (m_aircraft->aircraftType->currentText() == "Multirotor") { - airframeType = m_multirotor->updateConfigObjectsFromWidgets(); - } - else if (m_aircraft->aircraftType->currentText() == "Helicopter") { - airframeType = m_heli->updateConfigObjectsFromWidgets(); - } - else if (m_aircraft->aircraftType->currentText() == "Ground") { - airframeType = m_groundvehicle->updateConfigObjectsFromWidgets(); - } - else { - airframeType = m_custom->updateConfigObjectsFromWidgets(); - } - - // set the airframe type - UAVDataObject *system = dynamic_cast(getObjectManager()->getObject(QString("SystemSettings"))); - Q_ASSERT(system); - - QPointer field = system->getField(QString("AirframeType")); - if (field) { - field->setValue(airframeType); - } - - updateFeedForwardUI(); -} - /** Opens the wiki from the user's default browser */ diff --git a/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.h b/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.h index cdc64fed3..880a10650 100644 --- a/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.h +++ b/ground/openpilotgcs/src/plugins/config/configvehicletypewidget.h @@ -43,10 +43,15 @@ class ConfigVehicleTypeWidget: public ConfigTaskWidget public: static QStringList getChannelDescriptions(); + static void setComboCurrentIndex(QComboBox *box, int index); ConfigVehicleTypeWidget(QWidget *parent = 0); ~ConfigVehicleTypeWidget(); +public slots: + virtual void refreshWidgetsValues(UAVObject *o = NULL); + virtual void updateObjectsFromWidgets(); + private: Ui_AircraftWidget *m_aircraft; @@ -57,10 +62,8 @@ private: VehicleConfig *m_custom; void updateFeedForwardUI(); - void resetField(UAVObjectField *field); - QString frameCategory1(QString frameType); - QString frameCategory2(QString frameType); + QString frameCategory(QString frameType); QStringList channelNames; QStringList mixerTypes; @@ -71,16 +74,6 @@ private: UAVObject::Metadata accInitialData; private slots: - - virtual void refreshWidgetsValues(UAVObject *o = NULL); - virtual void updateObjectsFromWidgets(); - - void setComboCurrentIndex(QComboBox *box, int index); - - void setupAirframeUI(QString type); - // TODO ? - void switchAirframeType(int index); - void enableFFTest(); void openHelp();