26 #include "actuatorcommand.h"
29 #include "mixersettings.h"
32 #include <QStringList>
35 #include <QVBoxLayout>
36 #include <QPushButton>
46 m_aircraft = aircraft;
60 void ConfigFixedWingWidget::setupUI(SystemSettings::AirframeTypeOptions frameType)
64 if (frameType == SystemSettings::AIRFRAMETYPE_FIXEDWING) {
67 m_aircraft->aircraftType->findText(
"Fixed Wing"));
69 m_aircraft->fixedWingType->findText(
"Elevator aileron rudder"));
70 m_aircraft->fwRudder1ChannelBox->setEnabled(
true);
71 m_aircraft->fwRudder1Label->setEnabled(
true);
72 m_aircraft->fwRudder2ChannelBox->setEnabled(
true);
73 m_aircraft->fwRudder2Label->setEnabled(
true);
74 m_aircraft->fwElevator1ChannelBox->setEnabled(
true);
75 m_aircraft->fwElevator1Label->setEnabled(
true);
76 m_aircraft->fwElevator2ChannelBox->setEnabled(
true);
77 m_aircraft->fwElevator2Label->setEnabled(
true);
78 m_aircraft->fwAileron1ChannelBox->setEnabled(
true);
79 m_aircraft->fwAileron1Label->setEnabled(
true);
80 m_aircraft->fwAileron2ChannelBox->setEnabled(
true);
81 m_aircraft->fwAileron2Label->setEnabled(
true);
83 m_aircraft->fwAileron1Label->setText(
"Aileron 1");
84 m_aircraft->fwAileron2Label->setText(
"Aileron 2");
85 m_aircraft->fwElevator1Label->setText(
"Elevator 1");
86 m_aircraft->fwElevator2Label->setText(
"Elevator 2");
87 m_aircraft->elevonMixBox->setHidden(
true);
89 }
else if (frameType == SystemSettings::AIRFRAMETYPE_FIXEDWINGELEVON) {
91 m_aircraft->aircraftType->findText(
"Fixed Wing"));
93 m_aircraft->fixedWingType->findText(
"Elevon"));
94 m_aircraft->fwAileron1Label->setText(
"Elevon 1");
95 m_aircraft->fwAileron2Label->setText(
"Elevon 2");
96 m_aircraft->fwElevator1ChannelBox->setEnabled(
false);
97 m_aircraft->fwElevator1Label->setEnabled(
false);
98 m_aircraft->fwElevator2ChannelBox->setEnabled(
false);
99 m_aircraft->fwElevator2Label->setEnabled(
false);
100 m_aircraft->fwRudder1ChannelBox->setEnabled(
true);
101 m_aircraft->fwRudder1Label->setEnabled(
true);
102 m_aircraft->fwRudder2ChannelBox->setEnabled(
true);
103 m_aircraft->fwRudder2Label->setEnabled(
true);
104 m_aircraft->fwElevator1Label->setText(
"Elevator 1");
105 m_aircraft->fwElevator2Label->setText(
"Elevator 2");
106 m_aircraft->elevonMixBox->setHidden(
false);
107 m_aircraft->elevonLabel1->setText(
"Roll");
108 m_aircraft->elevonLabel2->setText(
"Pitch");
110 }
else if (frameType == SystemSettings::AIRFRAMETYPE_FIXEDWINGVTAIL) {
112 m_aircraft->aircraftType->findText(
"Fixed Wing"));
114 m_aircraft->fixedWingType->findText(
"Vtail"));
115 m_aircraft->fwRudder1ChannelBox->setEnabled(
false);
116 m_aircraft->fwRudder1Label->setEnabled(
false);
117 m_aircraft->fwRudder2ChannelBox->setEnabled(
false);
118 m_aircraft->fwRudder2Label->setEnabled(
false);
119 m_aircraft->fwElevator1ChannelBox->setEnabled(
true);
120 m_aircraft->fwElevator1Label->setEnabled(
true);
121 m_aircraft->fwElevator1Label->setText(
"Vtail 1");
122 m_aircraft->fwElevator2Label->setText(
"Vtail 2");
123 m_aircraft->elevonMixBox->setHidden(
false);
124 m_aircraft->fwElevator2ChannelBox->setEnabled(
true);
125 m_aircraft->fwElevator2Label->setEnabled(
true);
126 m_aircraft->fwAileron1Label->setText(
"Aileron 1");
127 m_aircraft->fwAileron2Label->setText(
"Aileron 2");
128 m_aircraft->elevonLabel1->setText(
"Rudder");
129 m_aircraft->elevonLabel2->setText(
"Pitch");
135 configData->
fixedwing.FixedWingPitch1 = 0;
136 configData->
fixedwing.FixedWingPitch2 = 0;
137 configData->
fixedwing.FixedWingRoll1 = 0;
138 configData->
fixedwing.FixedWingRoll2 = 0;
141 configData->
fixedwing.FixedWingThrottle = 0;
144 QStringList ConfigFixedWingWidget::getChannelDescriptions()
147 QStringList channelDesc;
150 for (i = 0; i < (int)(ActuatorCommand::CHANNEL_NUMELEM); i++) {
151 channelDesc.append(QString(
"-"));
157 if (configData.
fixedwing.FixedWingPitch1 > 0)
158 channelDesc[configData.
fixedwing.FixedWingPitch1 - 1] = QString(
"FixedWingPitch1");
159 if (configData.
fixedwing.FixedWingPitch2 > 0)
160 channelDesc[configData.
fixedwing.FixedWingPitch2 - 1] = QString(
"FixedWingPitch2");
161 if (configData.
fixedwing.FixedWingRoll1 > 0)
162 channelDesc[configData.
fixedwing.FixedWingRoll1 - 1] = QString(
"FixedWingRoll1");
163 if (configData.
fixedwing.FixedWingRoll2 > 0)
164 channelDesc[configData.
fixedwing.FixedWingRoll2 - 1] = QString(
"FixedWingRoll2");
165 if (configData.
fixedwing.FixedWingYaw1 > 0)
166 channelDesc[configData.
fixedwing.FixedWingYaw1 - 1] = QString(
"FixedWingYaw1");
167 if (configData.
fixedwing.FixedWingYaw2 > 0)
168 channelDesc[configData.
fixedwing.FixedWingYaw2 - 1] = QString(
"FixedWingYaw2");
169 if (configData.
fixedwing.FixedWingThrottle > 0)
170 channelDesc[configData.
fixedwing.FixedWingThrottle - 1] = QString(
"FixedWingThrottle");
179 SystemSettings::AirframeTypeOptions ConfigFixedWingWidget::updateConfigObjectsFromWidgets()
181 MixerSettings *mixerSettings = MixerSettings::GetInstance(
getObjectManager());
182 Q_ASSERT(mixerSettings);
185 SystemSettings::AirframeTypeOptions airframeType = SystemSettings::AIRFRAMETYPE_FIXEDWING;
188 if (m_aircraft->fixedWingType->currentText() ==
"Elevator aileron rudder") {
189 airframeType = SystemSettings::AIRFRAMETYPE_FIXEDWING;
190 setupFrameFixedWing(airframeType);
191 }
else if (m_aircraft->fixedWingType->currentText() ==
"Elevon") {
192 airframeType = SystemSettings::AIRFRAMETYPE_FIXEDWINGELEVON;
193 setupFrameElevon(airframeType);
195 airframeType = SystemSettings::AIRFRAMETYPE_FIXEDWINGVTAIL;
196 setupFrameVtail(airframeType);
205 void ConfigFixedWingWidget::refreshAirframeWidgetsValues(
206 SystemSettings::AirframeTypeOptions frameType)
208 Q_ASSERT(m_aircraft);
211 fixedGUISettingsStruct fixed = config.
fixedwing;
222 MixerSettings *mixerSettings = MixerSettings::GetInstance(
getObjectManager());
223 Q_ASSERT(mixerSettings);
226 if (frameType == SystemSettings::AIRFRAMETYPE_FIXEDWINGELEVON) {
229 channel = m_aircraft->fwAileron1ChannelBox->currentIndex() - 1;
232 m_aircraft->elevonSlider1->setValue(
235 m_aircraft->elevonSlider2->setValue(
240 if (frameType == SystemSettings::AIRFRAMETYPE_FIXEDWINGVTAIL) {
241 channel = m_aircraft->fwElevator1ChannelBox->currentIndex() - 1;
244 m_aircraft->elevonSlider1->setValue(
246 m_aircraft->elevonSlider2->setValue(
260 bool ConfigFixedWingWidget::setupFrameFixedWing(SystemSettings::AirframeTypeOptions airframeType)
264 if (throwConfigError(airframeType)) {
271 ResetActuators(&config);
273 config.
fixedwing.FixedWingPitch1 = m_aircraft->fwElevator1ChannelBox->currentIndex();
274 config.
fixedwing.FixedWingPitch2 = m_aircraft->fwElevator2ChannelBox->currentIndex();
275 config.
fixedwing.FixedWingRoll1 = m_aircraft->fwAileron1ChannelBox->currentIndex();
276 config.
fixedwing.FixedWingRoll2 = m_aircraft->fwAileron2ChannelBox->currentIndex();
277 config.
fixedwing.FixedWingYaw1 = m_aircraft->fwRudder1ChannelBox->currentIndex();
278 config.
fixedwing.FixedWingThrottle = m_aircraft->fwEngineChannelBox->currentIndex();
280 SetConfigData(config, SystemSettings::AIRFRAMETYPE_FIXEDWING);
282 MixerSettings *mixerSettings = MixerSettings::GetInstance(
getObjectManager());
283 Q_ASSERT(mixerSettings);
293 int channel = m_aircraft->fwEngineChannelBox->currentIndex() - 1;
294 setMixerType(mixerSettings, channel, MixerSettings::MIXER1TYPE_MOTOR);
299 channel = m_aircraft->fwRudder1ChannelBox->currentIndex() - 1;
301 setMixerType(mixerSettings, channel, MixerSettings::MIXER1TYPE_SERVO);
304 channel = m_aircraft->fwRudder2ChannelBox->currentIndex() - 1;
305 setMixerType(mixerSettings, channel, MixerSettings::MIXER1TYPE_SERVO);
310 channel = m_aircraft->fwAileron1ChannelBox->currentIndex() - 1;
312 setMixerType(mixerSettings, channel, MixerSettings::MIXER1TYPE_SERVO);
315 channel = m_aircraft->fwAileron2ChannelBox->currentIndex() - 1;
316 setMixerType(mixerSettings, channel, MixerSettings::MIXER1TYPE_SERVO);
321 channel = m_aircraft->fwElevator1ChannelBox->currentIndex() - 1;
323 setMixerType(mixerSettings, channel, MixerSettings::MIXER1TYPE_SERVO);
326 channel = m_aircraft->fwElevator2ChannelBox->currentIndex() - 1;
327 setMixerType(mixerSettings, channel, MixerSettings::MIXER1TYPE_SERVO);
331 m_aircraft->fwStatusLabel->setText(
"Mixer generated");
339 bool ConfigFixedWingWidget::setupFrameElevon(SystemSettings::AirframeTypeOptions airframeType)
343 if (throwConfigError(airframeType)) {
348 ResetActuators(&config);
350 config.
fixedwing.FixedWingRoll1 = m_aircraft->fwAileron1ChannelBox->currentIndex();
351 config.
fixedwing.FixedWingRoll2 = m_aircraft->fwAileron2ChannelBox->currentIndex();
352 config.
fixedwing.FixedWingYaw1 = m_aircraft->fwRudder1ChannelBox->currentIndex();
353 config.
fixedwing.FixedWingYaw2 = m_aircraft->fwRudder2ChannelBox->currentIndex();
354 config.
fixedwing.FixedWingThrottle = m_aircraft->fwEngineChannelBox->currentIndex();
356 SetConfigData(config, SystemSettings::AIRFRAMETYPE_FIXEDWINGELEVON);
358 MixerSettings *mixerSettings = MixerSettings::GetInstance(
getObjectManager());
359 Q_ASSERT(mixerSettings);
372 int channel = m_aircraft->fwEngineChannelBox->currentIndex() - 1;
373 setMixerType(mixerSettings, channel, MixerSettings::MIXER1TYPE_MOTOR);
378 channel = m_aircraft->fwRudder1ChannelBox->currentIndex() - 1;
379 setMixerType(mixerSettings, channel, MixerSettings::MIXER1TYPE_SERVO);
382 channel = m_aircraft->fwRudder2ChannelBox->currentIndex() - 1;
383 setMixerType(mixerSettings, channel, MixerSettings::MIXER1TYPE_SERVO);
387 channel = m_aircraft->fwAileron1ChannelBox->currentIndex() - 1;
389 setMixerType(mixerSettings, channel, MixerSettings::MIXER1TYPE_SERVO);
390 value = (double)(m_aircraft->elevonSlider2->value() * (
mixerScale / 100.0));
392 value = (double)(m_aircraft->elevonSlider1->value() * (
mixerScale / 100.0));
395 channel = m_aircraft->fwAileron2ChannelBox->currentIndex() - 1;
396 setMixerType(mixerSettings, channel, MixerSettings::MIXER1TYPE_SERVO);
397 value = (double)(m_aircraft->elevonSlider2->value() * (
mixerScale / 100.0));
399 value = (double)(m_aircraft->elevonSlider1->value() * (
mixerScale / 100.0));
403 m_aircraft->fwStatusLabel->setText(
"Mixer generated");
410 bool ConfigFixedWingWidget::setupFrameVtail(SystemSettings::AirframeTypeOptions airframeType)
414 if (throwConfigError(airframeType)) {
419 ResetActuators(&config);
421 config.
fixedwing.FixedWingPitch1 = m_aircraft->fwElevator1ChannelBox->currentIndex();
422 config.
fixedwing.FixedWingPitch2 = m_aircraft->fwElevator2ChannelBox->currentIndex();
423 config.
fixedwing.FixedWingRoll1 = m_aircraft->fwAileron1ChannelBox->currentIndex();
424 config.
fixedwing.FixedWingRoll2 = m_aircraft->fwAileron2ChannelBox->currentIndex();
425 config.
fixedwing.FixedWingThrottle = m_aircraft->fwEngineChannelBox->currentIndex();
427 SetConfigData(config, SystemSettings::AIRFRAMETYPE_FIXEDWINGVTAIL);
429 MixerSettings *mixerSettings = MixerSettings::GetInstance(
getObjectManager());
430 Q_ASSERT(mixerSettings);
443 int channel = m_aircraft->fwEngineChannelBox->currentIndex() - 1;
444 setMixerType(mixerSettings, channel, MixerSettings::MIXER1TYPE_MOTOR);
449 channel = m_aircraft->fwRudder1ChannelBox->currentIndex() - 1;
450 setMixerType(mixerSettings, channel, MixerSettings::MIXER1TYPE_SERVO);
453 channel = m_aircraft->fwRudder2ChannelBox->currentIndex() - 1;
454 setMixerType(mixerSettings, channel, MixerSettings::MIXER1TYPE_SERVO);
458 channel = m_aircraft->fwAileron1ChannelBox->currentIndex() - 1;
460 setMixerType(mixerSettings, channel, MixerSettings::MIXER1TYPE_SERVO);
463 channel = m_aircraft->fwAileron2ChannelBox->currentIndex() - 1;
464 setMixerType(mixerSettings, channel, MixerSettings::MIXER1TYPE_SERVO);
469 channel = m_aircraft->fwElevator1ChannelBox->currentIndex() - 1;
471 setMixerType(mixerSettings, channel, MixerSettings::MIXER1TYPE_SERVO);
472 value = (double)(m_aircraft->elevonSlider2->value() * (
mixerScale / 100.0));
474 value = (double)(m_aircraft->elevonSlider1->value() * (
mixerScale / 100.0));
477 channel = m_aircraft->fwElevator2ChannelBox->currentIndex() - 1;
478 setMixerType(mixerSettings, channel, MixerSettings::MIXER1TYPE_SERVO);
479 value = (double)(m_aircraft->elevonSlider2->value() * (
mixerScale / 100.0));
481 value = (double)(m_aircraft->elevonSlider1->value() * (
mixerScale / 100.0));
485 m_aircraft->fwStatusLabel->setText(
"Mixer generated");
493 bool ConfigFixedWingWidget::throwConfigError(SystemSettings::AirframeTypeOptions airframeType)
499 int size = m_aircraft->fwEngineChannelBox->style()->pixelMetric(QStyle::PM_SmallIconSize);
500 QPixmap pixmap(size, size);
501 pixmap.fill(QColor(
"red"));
503 if (airframeType == SystemSettings::AIRFRAMETYPE_FIXEDWING) {
504 if (m_aircraft->fwEngineChannelBox->currentText() ==
"None") {
505 m_aircraft->fwEngineChannelBox->setItemData(0, pixmap,
509 m_aircraft->fwEngineChannelBox->setItemData(0, 0,
513 if (m_aircraft->fwElevator1ChannelBox->currentText() ==
"None") {
514 m_aircraft->fwElevator1ChannelBox->setItemData(
515 0, pixmap, Qt::DecorationRole);
518 m_aircraft->fwElevator1ChannelBox->setItemData(
519 0, 0, Qt::DecorationRole);
522 if ((m_aircraft->fwAileron1ChannelBox->currentText() ==
"None")
523 && (m_aircraft->fwRudder1ChannelBox->currentText() ==
"None")) {
524 pixmap.fill(QColor(
"green"));
525 m_aircraft->fwAileron1ChannelBox->setItemData(0, pixmap,
527 m_aircraft->fwRudder1ChannelBox->setItemData(0, pixmap,
531 m_aircraft->fwAileron1ChannelBox->setItemData(
532 0, 0, Qt::DecorationRole);
533 m_aircraft->fwRudder1ChannelBox->setItemData(
534 0, 0, Qt::DecorationRole);
536 }
else if (airframeType == SystemSettings::AIRFRAMETYPE_FIXEDWINGELEVON) {
537 if (m_aircraft->fwEngineChannelBox->currentText() ==
"None") {
538 m_aircraft->fwEngineChannelBox->setItemData(0, pixmap,
542 m_aircraft->fwEngineChannelBox->setItemData(0, 0,
546 if (m_aircraft->fwAileron1ChannelBox->currentText() ==
"None") {
547 m_aircraft->fwAileron1ChannelBox->setItemData(0, pixmap,
551 m_aircraft->fwAileron1ChannelBox->setItemData(
552 0, 0, Qt::DecorationRole);
555 if (m_aircraft->fwAileron2ChannelBox->currentText() ==
"None") {
556 m_aircraft->fwAileron2ChannelBox->setItemData(0, pixmap,
560 m_aircraft->fwAileron2ChannelBox->setItemData(
561 0, 0, Qt::DecorationRole);
564 }
else if (airframeType == SystemSettings::AIRFRAMETYPE_FIXEDWINGVTAIL) {
565 if (m_aircraft->fwEngineChannelBox->currentText() ==
"None") {
566 m_aircraft->fwEngineChannelBox->setItemData(0, pixmap,
570 m_aircraft->fwEngineChannelBox->setItemData(0, 0,
574 if (m_aircraft->fwElevator1ChannelBox->currentText() ==
"None") {
575 m_aircraft->fwElevator1ChannelBox->setItemData(
576 0, pixmap, Qt::DecorationRole);
579 m_aircraft->fwElevator1ChannelBox->setItemData(
580 0, 0, Qt::DecorationRole);
583 if (m_aircraft->fwElevator2ChannelBox->currentText() ==
"None") {
584 m_aircraft->fwElevator2ChannelBox->setItemData(
585 0, pixmap, Qt::DecorationRole);
588 m_aircraft->fwElevator2ChannelBox->setItemData(
589 0, 0, Qt::DecorationRole);
594 m_aircraft->fwStatusLabel->setText(
595 QString(
"<font color='red'>ERROR: Assign all necessary channels</font>"));
static void SetConfigData(GUIConfigDataUnion configData, SystemSettings::AirframeTypeOptions vehicle)
static GUIConfigDataUnion GetConfigData()
double getMixerVectorValue(UAVDataObject *mixer, int channel, MixerSettings::Mixer1VectorElem elementName)
ConfigFixedWingWidget(Ui_AircraftWidget *aircraft=nullptr, QWidget *parent=nullptr)
fixedGUISettingsStruct fixedwing
void resetMixers(UAVDataObject *mixer)
void setMixerType(UAVDataObject *mixer, int channel, MixerSettings::Mixer1TypeOptions mixerType)
void setMixerVectorValue(UAVDataObject *mixer, int channel, MixerSettings::Mixer1VectorElem elementName, double value)
else error('Your technical computing program does not support file choosers.Please input the file name in the argument. ') end elseif nargin >0 logfile
static const double mixerScale
static void setComboCurrentIndex(QComboBox *box, int index)