From 8c0a33cd6fdaada3730394c021d8932250b709e7 Mon Sep 17 00:00:00 2001 From: Laurent Lalanne Date: Sun, 1 Feb 2015 06:22:38 +0100 Subject: [PATCH] OP-1698 First commit : Add Accessory0,1,2 to Output --- .../src/plugins/config/airframe_multirotor.ui | 373 ++++++++++++++---- .../configmultirotorwidget.cpp | 90 ++++- .../cfg_vehicletypes/configmultirotorwidget.h | 3 + .../config/cfg_vehicletypes/vehicleconfig.h | 5 +- 4 files changed, 392 insertions(+), 79 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/config/airframe_multirotor.ui b/ground/openpilotgcs/src/plugins/config/airframe_multirotor.ui index 4d96dce60..7b8bbb11c 100644 --- a/ground/openpilotgcs/src/plugins/config/airframe_multirotor.ui +++ b/ground/openpilotgcs/src/plugins/config/airframe_multirotor.ui @@ -511,7 +511,7 @@ Typical value is 50% for + or X configuration on quads. Motor output channels - + 9 @@ -524,19 +524,31 @@ Typical value is 50% for + or X configuration on quads. 9 - - + + QLayout::SetMaximumSize QFormLayout::AllNonFixedFieldsGrow - - 6 + + 10 - + + + + 0 + 0 + + + + + 90 + 16 + + background-color: qlineargradient(spread:reflect, x1:0.507, y1:0, x2:0.507, y2:0.772, stop:0.208955 rgba(74, 74, 74, 255), stop:0.78607 rgba(36, 36, 36, 255)); color: rgb(255, 255, 255); @@ -545,19 +557,59 @@ font: bold 12px; margin:1px; - 1 + RC Input + + + Qt::AlignCenter - + + + + 0 + 0 + + + + + 80 + 0 + + - Assign your motor output channels using the drawing above as a reference. Respect propeller rotation. + RcOutput channels + + + background-color: qlineargradient(spread:reflect, x1:0.507, y1:0, x2:0.507, y2:0.772, stop:0.208955 rgba(74, 74, 74, 255), stop:0.78607 rgba(36, 36, 36, 255)); +color: rgb(255, 255, 255); +border-radius: 5; +font: bold 12px; +margin:1px; + + + RC Output + + + Qt::AlignCenter - + + + + 0 + 0 + + + + + 90 + 0 + + background-color: qlineargradient(spread:reflect, x1:0.507, y1:0, x2:0.507, y2:0.772, stop:0.208955 rgba(74, 74, 74, 255), stop:0.78607 rgba(36, 36, 36, 255)); color: rgb(255, 255, 255); @@ -566,19 +618,40 @@ font: bold 12px; margin:1px; - 2 + Accessory0 + + + Qt::AlignCenter - + + + + 0 + 0 + + + + + 80 + 0 + + - Assign your motor output channels using the drawing above as a reference. Respect propeller rotation. + Select output channel for Accessory0 RcInput - + + + + 90 + 0 + + background-color: qlineargradient(spread:reflect, x1:0.507, y1:0, x2:0.507, y2:0.772, stop:0.208955 rgba(74, 74, 74, 255), stop:0.78607 rgba(36, 36, 36, 255)); color: rgb(255, 255, 255); @@ -587,19 +660,40 @@ font: bold 12px; margin:1px; - 3 + Accessory1 + + + Qt::AlignCenter - + + + + 0 + 0 + + + + + 80 + 0 + + - Assign your motor output channels using the drawing above as a reference. Respect propeller rotation. + Select output channel for Accessory1 RcInput - + + + + 90 + 0 + + background-color: qlineargradient(spread:reflect, x1:0.507, y1:0, x2:0.507, y2:0.772, stop:0.208955 rgba(74, 74, 74, 255), stop:0.78607 rgba(36, 36, 36, 255)); color: rgb(255, 255, 255); @@ -608,19 +702,63 @@ font: bold 12px; margin:1px; - 4 + Accessory2 + + + Qt::AlignCenter - + + + + 0 + 0 + + + + + 80 + 0 + + - Assign your motor output channels using the drawing above as a reference. Respect propeller rotation. + Select output channel for Accessory2 RcInput + + + + + 0 + 0 + + + + + 0 + 16 + + + + background-color: qlineargradient(spread:reflect, x1:0.507, y1:0, x2:0.507, y2:0.772, stop:0.208955 rgba(74, 74, 74, 255), stop:0.78607 rgba(36, 36, 36, 255)); +color: rgb(255, 255, 255); +border-radius: 5; +font: bold 12px; +margin:1px; + + + Tricopter Yaw Servo channel + + + Qt::AlignCenter + + + @@ -749,7 +887,143 @@ margin:1px; - + + + + true + + + + 0 + 0 + + + + + 40 + 20 + + + + + + + + QLayout::SetMaximumSize + + + QFormLayout::AllNonFixedFieldsGrow + + + 6 + + + + + background-color: qlineargradient(spread:reflect, x1:0.507, y1:0, x2:0.507, y2:0.772, stop:0.208955 rgba(74, 74, 74, 255), stop:0.78607 rgba(36, 36, 36, 255)); +color: rgb(255, 255, 255); +border-radius: 5; +font: bold 12px; +margin:1px; + + + 1 + + + + + + + Assign your motor output channels using the drawing above as a reference. Respect propeller rotation. + + + + + + + background-color: qlineargradient(spread:reflect, x1:0.507, y1:0, x2:0.507, y2:0.772, stop:0.208955 rgba(74, 74, 74, 255), stop:0.78607 rgba(36, 36, 36, 255)); +color: rgb(255, 255, 255); +border-radius: 5; +font: bold 12px; +margin:1px; + + + 2 + + + + + + + Assign your motor output channels using the drawing above as a reference. Respect propeller rotation. + + + + + + + background-color: qlineargradient(spread:reflect, x1:0.507, y1:0, x2:0.507, y2:0.772, stop:0.208955 rgba(74, 74, 74, 255), stop:0.78607 rgba(36, 36, 36, 255)); +color: rgb(255, 255, 255); +border-radius: 5; +font: bold 12px; +margin:1px; + + + 3 + + + + + + + Assign your motor output channels using the drawing above as a reference. Respect propeller rotation. + + + + + + + background-color: qlineargradient(spread:reflect, x1:0.507, y1:0, x2:0.507, y2:0.772, stop:0.208955 rgba(74, 74, 74, 255), stop:0.78607 rgba(36, 36, 36, 255)); +color: rgb(255, 255, 255); +border-radius: 5; +font: bold 12px; +margin:1px; + + + 4 + + + + + + + Assign your motor output channels using the drawing above as a reference. Respect propeller rotation. + + + + + + + + + Qt::Vertical + + + + + + + + 0 + 20 + + + + Reverse all motors + + + + @@ -778,61 +1052,6 @@ margin:1px; - - - - true - - - - 0 - 0 - - - - - 40 - 0 - - - - - - - - - 0 - 0 - - - - - 0 - 16 - - - - background-color: qlineargradient(spread:reflect, x1:0.507, y1:0, x2:0.507, y2:0.772, stop:0.208955 rgba(74, 74, 74, 255), stop:0.78607 rgba(36, 36, 36, 255)); -color: rgb(255, 255, 255); -border-radius: 5; -font: bold 12px; -margin:1px; - - - Tricopter Yaw Servo channel - - - Qt::AlignCenter - - - - - - - Reverse all motors - - - diff --git a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configmultirotorwidget.cpp b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configmultirotorwidget.cpp index e186a5972..ac95e4a30 100644 --- a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configmultirotorwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configmultirotorwidget.cpp @@ -110,6 +110,17 @@ QStringList ConfigMultiRotorWidget::getChannelDescriptions() if (multi.TRIYaw > 0 && multi.TRIYaw <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) { channelDesc[multi.TRIYaw - 1] = QString("Tri-Yaw"); } + + if (multi.Accessory0 > 0 && multi.Accessory0 <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) { + channelDesc[multi.Accessory0 - 1] = QString("Accessory0"); + } + if (multi.Accessory1 > 0 && multi.Accessory1 <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) { + channelDesc[multi.Accessory1 - 1] = QString("Accessory1"); + } + if (multi.Accessory2 > 0 && multi.Accessory2 <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) { + channelDesc[multi.Accessory2 - 1] = QString("Accessory2"); + } + return channelDesc; } @@ -319,6 +330,9 @@ void ConfigMultiRotorWidget::registerWidgets(ConfigTaskWidget &parent) parent.addWidget(m_aircraft->mrYawMixLevel); parent.addWidget(m_aircraft->triYawChannelBox); parent.addWidget(m_aircraft->MultirotorRevMixerCheckBox); + parent.addWidget(m_aircraft->rcOutputChannelBox1); + parent.addWidget(m_aircraft->rcOutputChannelBox2); + parent.addWidget(m_aircraft->rcOutputChannelBox3); } void ConfigMultiRotorWidget::resetActuators(GUIConfigDataUnion *configData) @@ -342,6 +356,29 @@ void ConfigMultiRotorWidget::resetActuators(GUIConfigDataUnion *configData) configData->multi.VTOLMotorNNW = 0; } +void ConfigMultiRotorWidget::resetRcOutputs(GUIConfigDataUnion *configData) +{ + configData->multi.Accessory0 = 0; + configData->multi.Accessory1 = 0; + configData->multi.Accessory2 = 0; +} + +void ConfigMultiRotorWidget::resetMixers() +{ + UAVDataObject *mixer = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); + + Q_ASSERT(mixer); + + for (int channel = 0; channel < (int)ConfigMultiRotorWidget::CHANNEL_NUMELEM; channel++) { + setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_DISABLED); + setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_THROTTLECURVE1, 0); + setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_THROTTLECURVE2, 0); + setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL, 0); + setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH, 0); + setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW, 0); + } +} + /** Helper function to refresh the UI widget values */ @@ -457,6 +494,10 @@ void ConfigMultiRotorWidget::refreshWidgetsValues(QString frameType) setComboCurrentIndex(m_aircraft->triYawChannelBox, multi.TRIYaw); } + setComboCurrentIndex(m_aircraft->rcOutputChannelBox1, multi.Accessory0); + setComboCurrentIndex(m_aircraft->rcOutputChannelBox2, multi.Accessory1); + setComboCurrentIndex(m_aircraft->rcOutputChannelBox3, multi.Accessory2); + // Now, read mixing values stored on board and applies values on sliders. m_aircraft->mrPitchMixLevel->setValue(getMixerValue(mixer, "MixerValuePitch")); m_aircraft->mrRollMixLevel->setValue(getMixerValue(mixer, "MixerValueRoll")); @@ -476,6 +517,13 @@ QString ConfigMultiRotorWidget::updateConfigObjectsFromWidgets() Q_ASSERT(mixer); + // Reset all Mixers + resetMixers(); + + QList rcOutputList; + rcOutputList << "Accessory0" << "Accessory1" << "Accessory2"; + setupRcOutputs(rcOutputList); + // Curve is also common to all quads: setThrottleCurve(mixer, VehicleConfig::MIXER_THROTTLECURVE1, m_aircraft->multiThrottleCurve->getCurve()); @@ -731,7 +779,6 @@ QString ConfigMultiRotorWidget::updateConfigObjectsFromWidgets() m_aircraft->mrStatusLabel->setText(tr("Configuration OK")); } - return airframeType; } @@ -816,6 +863,47 @@ void ConfigMultiRotorWidget::setupQuadMotor(int channel, double pitch, double ro setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW, yaw * 127); } +/** + Helper function: setup rc outputs. Takes a list of channel names in input. + */ +void ConfigMultiRotorWidget::setupRcOutputs(QList rcOutputList) +{ + QList rcList; + rcList << m_aircraft->rcOutputChannelBox1 << m_aircraft->rcOutputChannelBox2 << m_aircraft->rcOutputChannelBox3; + + GUIConfigDataUnion configData = getConfigData(); + resetRcOutputs(&configData); + + UAVDataObject *mixer = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); + Q_ASSERT(mixer); + + foreach(QString rc_output, rcOutputList) { + int index = rcList.takeFirst()->currentIndex(); + + if (rc_output == QString("Accessory0")) { + configData.multi.Accessory0 = index; + if (index) { + setMixerType(mixer, index - 1, VehicleConfig::MIXERTYPE_ACCESSORY0); + setMixerVectorValue(mixer, index - 1, VehicleConfig::MIXERVECTOR_THROTTLECURVE2, 127); + } + } else if (rc_output == QString("Accessory1")) { + configData.multi.Accessory1 = index; + if (index) { + setMixerType(mixer, index - 1, VehicleConfig::MIXERTYPE_ACCESSORY1); + setMixerVectorValue(mixer, index - 1, VehicleConfig::MIXERVECTOR_THROTTLECURVE2, 127); + } + } else if (rc_output == QString("Accessory2")) { + configData.multi.Accessory2 = index; + if (index) { + setMixerType(mixer, index - 1, VehicleConfig::MIXERTYPE_ACCESSORY2); + setMixerVectorValue(mixer, index - 1, VehicleConfig::MIXERVECTOR_THROTTLECURVE2, 127); + } + } + } + setConfigData(configData); +} + + /** Helper function: setup motors. Takes a list of channel names in input. */ diff --git a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configmultirotorwidget.h b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configmultirotorwidget.h index dde2ced06..8140903d8 100644 --- a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configmultirotorwidget.h +++ b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/configmultirotorwidget.h @@ -65,12 +65,15 @@ private: virtual void registerWidgets(ConfigTaskWidget &parent); virtual void resetActuators(GUIConfigDataUnion *configData); + virtual void resetRcOutputs(GUIConfigDataUnion *configData); bool setupQuad(bool pLayout); bool setupHexa(bool pLayout); bool setupOcto(); bool setupMultiRotorMixer(double mixerFactors[8][3]); void setupMotors(QList motorList); + void setupRcOutputs(QList rcOutputList); + void resetMixers(); void setupQuadMotor(int channel, double roll, double pitch, double yaw); void setYawMixLevel(int); diff --git a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/vehicleconfig.h b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/vehicleconfig.h index 6dfe1760a..0a27e8390 100644 --- a/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/vehicleconfig.h +++ b/ground/openpilotgcs/src/plugins/config/cfg_vehicletypes/vehicleconfig.h @@ -52,7 +52,10 @@ typedef struct { uint VTOLMotorWNW : 4; uint VTOLMotorNNW : 4; // 64 bits uint TRIYaw : 4; - quint32 padding : 28; // 96 bits + uint Accessory0 : 4; + uint Accessory1 : 4; + uint Accessory2 : 4; + quint32 padding : 16; // 96 bits quint32 padding1; // 128 bits } __attribute__((packed)) multiGUISettingsStruct;