From 4dae7ef2df5d7eafa2f052c6204d83225744327f Mon Sep 17 00:00:00 2001 From: edouard Date: Sun, 10 Oct 2010 12:04:05 +0000 Subject: [PATCH] OP-138 Multirotor mixer supports adjustment of weight of Roll/Pitch/Yaw on quad + and X configurations. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1937 ebee16cc-31ac-478f-84a7-5cbb03baadba --- ground/src/plugins/config/airframe.ui | 228 +++++++++++++++++- .../plugins/config/configairframewidget.cpp | 65 ++++- 2 files changed, 275 insertions(+), 18 deletions(-) diff --git a/ground/src/plugins/config/airframe.ui b/ground/src/plugins/config/airframe.ui index 6fbf4225f..4758a4eb4 100644 --- a/ground/src/plugins/config/airframe.ui +++ b/ground/src/plugins/config/airframe.ui @@ -69,7 +69,7 @@ - 2 + 1 @@ -444,7 +444,11 @@ - + + + Select the Multirotor frame type here. + + @@ -475,7 +479,163 @@ - + + + + + + + + 75 + true + + + + Mix Level + + + + + + + + + + + 100 + + + + + + + Weight of Roll mixing in percent. Typical values are 100% for + configuration and 50% for X configuration on quads. + + + 100 + + + 100 + + + Qt::Vertical + + + + + + + R + + + + + + + false + + + All checked sliders will move together. + + + + + + + + + + + + + + 100 + + + + + + + Weight of Pitch mixing in percent. Typical values are 100% for + configuration and 50% for X configuration on quads. + + + 100 + + + 100 + + + Qt::Vertical + + + + + + + P + + + + + + + false + + + + + + + + + + + + + + 50 + + + + + + + Weight of Yaw mixing in percent. Typical value is 50% for + or X configuration on quads. + + + 100 + + + 50 + + + Qt::Vertical + + + + + + + Y + + + + + + + false + + + + + + + + + + + + @@ -1487,12 +1647,12 @@ setNum(int) - 284 + 496 171 - 156 - 170 + 271 + 171 @@ -1503,12 +1663,60 @@ setNum(int) - 198 - 234 + 488 + 262 - 127 - 235 + 249 + 262 + + + + + mrPitchMixLevel + valueChanged(int) + label_44 + setNum(int) + + + 76 + 210 + + + 80 + 149 + + + + + mrYawMixLevel + valueChanged(int) + label_45 + setNum(int) + + + 119 + 199 + + + 108 + 151 + + + + + mrRollMixLevel + valueChanged(int) + label_43 + setNum(int) + + + 39 + 217 + + + 43 + 149 diff --git a/ground/src/plugins/config/configairframewidget.cpp b/ground/src/plugins/config/configairframewidget.cpp index 59eef7807..3a7cd7150 100644 --- a/ground/src/plugins/config/configairframewidget.cpp +++ b/ground/src/plugins/config/configairframewidget.cpp @@ -335,6 +335,27 @@ void ConfigAirframeWidget::requestAircraftUpdate() field = obj->getField(QString("VTOLMotorW")); Q_ASSERT(field); m_aircraft->multiMotor4->setCurrentIndex(m_aircraft->multiMotor4->findText(field->getValue().toString())); + // Now, read the 1st mixer R/P/Y levels and initialize the mix sliders. + // This assumes that all vectors are identical - if not, the user should use the + // "custom" setting. + obj = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); + Q_ASSERT(obj); + int eng= m_aircraft->multiMotor1->currentIndex()-1; + // eng will be -1 if value is set to "None" + if (eng > -1) { + field = obj->getField(mixerVectors.at(eng)); + int i = field->getElementNames().indexOf("Pitch"); + double val = field->getDouble(i)/1.27; + m_aircraft->mrPitchMixLevel->setValue(val); + i = field->getElementNames().indexOf("Yaw"); + val = (1-field->getDouble(i)/1.27); + m_aircraft->mrYawMixLevel->setValue(val); + eng = m_aircraft->multiMotor2->currentIndex()-1; + field = obj->getField(mixerVectors.at(eng)); + i = field->getElementNames().indexOf("Roll"); + val = -field->getDouble(i)/1.27; + m_aircraft->mrRollMixLevel->setValue(val); + } } else if (frameType == "QuadX") { // Motors 1/2/3/4 are: NW / NE / SE / SW field = obj->getField(QString("VTOLMotorNW")); @@ -349,7 +370,26 @@ void ConfigAirframeWidget::requestAircraftUpdate() field = obj->getField(QString("VTOLMotorSW")); Q_ASSERT(field); m_aircraft->multiMotor4->setCurrentIndex(m_aircraft->multiMotor4->findText(field->getValue().toString())); + // Now, read the 1st mixer R/P/Y levels and initialize the mix sliders. + // This assumes that all vectors are identical - if not, the user should use the + // "custom" setting. + obj = dynamic_cast(getObjectManager()->getObject(QString("MixerSettings"))); + Q_ASSERT(obj); + int eng= m_aircraft->multiMotor1->currentIndex()-1; + // eng will be -1 if value is set to "None" + if (eng > -1) { + field = obj->getField(mixerVectors.at(eng)); + int i = field->getElementNames().indexOf("Pitch"); + double val = field->getDouble(i)/1.27; + m_aircraft->mrPitchMixLevel->setValue(val); + i = field->getElementNames().indexOf("Yaw"); + val = 1-field->getDouble(i)/1.27; + m_aircraft->mrYawMixLevel->setValue(val); + i = field->getElementNames().indexOf("Roll"); + val = field->getDouble(i)/1.27; + m_aircraft->mrRollMixLevel->setValue(val); + } } else if (frameType == "Hexa") { // Motors 1/2/3 4/5/6 are: NW / N / NE and SE / S / SW field = obj->getField(QString("VTOLMotorNW")); @@ -488,6 +528,9 @@ void ConfigAirframeWidget::setupAirframeUI(QString frameType) m_aircraft->multiMotor6->setEnabled(false); m_aircraft->multiMotor7->setEnabled(false); m_aircraft->multiMotor8->setEnabled(false); + m_aircraft->mrRollMixLevel->setValue(50); + m_aircraft->mrPitchMixLevel->setValue(50); + m_aircraft->mrYawMixLevel->setValue(50); } else if (frameType == "QuadP" || frameType == "Quad +") { m_aircraft->aircraftType->setCurrentIndex(m_aircraft->aircraftType->findText("Multirotor")); m_aircraft->multirotorFrameType->setCurrentIndex(m_aircraft->multirotorFrameType->findText("Quad +")); @@ -498,6 +541,9 @@ void ConfigAirframeWidget::setupAirframeUI(QString frameType) m_aircraft->multiMotor6->setEnabled(false); m_aircraft->multiMotor7->setEnabled(false); m_aircraft->multiMotor8->setEnabled(false); + m_aircraft->mrRollMixLevel->setValue(100); + m_aircraft->mrPitchMixLevel->setValue(100); + m_aircraft->mrYawMixLevel->setValue(50); } else if (frameType == "Hexa" || frameType == "Hexacopter") { m_aircraft->aircraftType->setCurrentIndex(m_aircraft->aircraftType->findText("Multirotor")); m_aircraft->multirotorFrameType->setCurrentIndex(m_aircraft->multirotorFrameType->findText("Hexacopter")); @@ -979,18 +1025,21 @@ bool ConfigAirframeWidget::setupQuad(bool pLayout) // {0 ,-1 ,0.5 //Right motor(CCW) // {-1 ,0 ,-0.5 //Rear motor (CW) // {0 ,1 ,0.5 //Left motor (CCW) + double pFactor = (double)m_aircraft->mrPitchMixLevel->value()/100; + double rFactor = (double)m_aircraft->mrRollMixLevel->value()/100; + double yFactor = (double)m_aircraft->mrYawMixLevel->value()/100; int channel = m_aircraft->multiMotor1->currentIndex()-1; - pLayout ? setupQuadMotor(channel, 1, 0, -0.5) - : setupQuadMotor(channel, 0.5, 0.5, -0.5); + pLayout ? setupQuadMotor(channel, pFactor, 0, -yFactor) + : setupQuadMotor(channel, pFactor, rFactor, -yFactor); channel = m_aircraft->multiMotor2->currentIndex()-1; - pLayout ? setupQuadMotor(channel, 0, -1, 0.5) - : setupQuadMotor(channel, 0.5, -0.5, 0.5); + pLayout ? setupQuadMotor(channel, 0, -rFactor, yFactor) + : setupQuadMotor(channel, pFactor, -rFactor, yFactor); channel = m_aircraft->multiMotor3->currentIndex()-1; - pLayout ? setupQuadMotor(channel, -1, 0, -0.5) - : setupQuadMotor(channel, -0.5, -0.5, -0.5); + pLayout ? setupQuadMotor(channel, -pFactor, 0, -yFactor) + : setupQuadMotor(channel, -pFactor, -rFactor, -yFactor); channel = m_aircraft->multiMotor4->currentIndex()-1; - pLayout ? setupQuadMotor(channel, 0, 1, 0.5) - : setupQuadMotor(channel, -0.5, 0.5, 0.5); + pLayout ? setupQuadMotor(channel, 0, rFactor, yFactor) + : setupQuadMotor(channel, -pFactor, rFactor, yFactor); obj->updated(); m_aircraft->mrStatusLabel->setText("SUCCESS: Mixer Saved OK");