27 #include "actuatorcommand.h"
30 #include "mixersettings.h"
33 #include <QStringList>
36 #include <QVBoxLayout>
37 #include <QPushButton>
47 m_aircraft = aircraft;
61 void ConfigGroundVehicleWidget::setupUI(SystemSettings::AirframeTypeOptions frameType)
63 m_aircraft->differentialSteeringMixBox->setHidden(
true);
68 m_aircraft->gvEngineChannelBox->setEnabled(
false);
69 m_aircraft->gvEngineLabel->setEnabled(
false);
71 m_aircraft->gvAileron1ChannelBox->setEnabled(
false);
72 m_aircraft->gvAileron1Label->setEnabled(
false);
74 m_aircraft->gvAileron2ChannelBox->setEnabled(
false);
75 m_aircraft->gvAileron2Label->setEnabled(
false);
77 if (frameType == SystemSettings::AIRFRAMETYPE_GROUNDVEHICLEDIFFERENTIAL) {
79 m_aircraft->groundVehicleType->findText(
"Differential (tank)"));
80 m_aircraft->gvMotor1ChannelBox->setEnabled(
true);
81 m_aircraft->gvMotor1Label->setEnabled(
true);
83 m_aircraft->gvMotor2ChannelBox->setEnabled(
true);
84 m_aircraft->gvMotor2Label->setEnabled(
true);
86 m_aircraft->gvMotor1Label->setText(
"Left motor");
87 m_aircraft->gvMotor2Label->setText(
"Right motor");
89 m_aircraft->gvSteering1ChannelBox->setEnabled(
false);
90 m_aircraft->gvSteering1Label->setEnabled(
false);
92 m_aircraft->gvSteering2ChannelBox->setEnabled(
false);
93 m_aircraft->gvSteering2Label->setEnabled(
false);
95 m_aircraft->gvSteering2Label->setText(
"Rear steering");
97 m_aircraft->differentialSteeringMixBox->setHidden(
false);
99 }
else if (frameType == SystemSettings::AIRFRAMETYPE_GROUNDVEHICLEMOTORCYCLE) {
101 m_aircraft->groundVehicleType->findText(
"Motorcycle"));
102 m_aircraft->gvMotor1ChannelBox->setEnabled(
false);
103 m_aircraft->gvMotor1Label->setEnabled(
false);
105 m_aircraft->gvMotor2ChannelBox->setEnabled(
true);
106 m_aircraft->gvMotor2Label->setEnabled(
true);
108 m_aircraft->gvMotor1Label->setText(
"Front motor");
109 m_aircraft->gvMotor2Label->setText(
"Rear motor");
111 m_aircraft->gvSteering1ChannelBox->setEnabled(
true);
112 m_aircraft->gvSteering1Label->setEnabled(
true);
114 m_aircraft->gvSteering2ChannelBox->setEnabled(
true);
115 m_aircraft->gvSteering2Label->setEnabled(
true);
117 m_aircraft->gvSteering2Label->setText(
"Balancing");
119 m_aircraft->differentialSteeringMixBox->setHidden(
true);
122 m_aircraft->groundVehicleType->findText(
"Turnable (car)"));
124 m_aircraft->gvMotor1ChannelBox->setEnabled(
true);
125 m_aircraft->gvMotor1Label->setEnabled(
true);
127 m_aircraft->gvMotor2ChannelBox->setEnabled(
true);
128 m_aircraft->gvMotor2Label->setEnabled(
true);
130 m_aircraft->gvMotor1Label->setText(
"Front motor");
131 m_aircraft->gvMotor2Label->setText(
"Rear motor");
133 m_aircraft->gvSteering1ChannelBox->setEnabled(
true);
134 m_aircraft->gvSteering1Label->setEnabled(
true);
136 m_aircraft->gvSteering2ChannelBox->setEnabled(
true);
137 m_aircraft->gvSteering2Label->setEnabled(
true);
139 m_aircraft->differentialSteeringMixBox->setHidden(
true);
145 configData->
ground.GroundVehicleSteering1 = 0;
146 configData->
ground.GroundVehicleSteering2 = 0;
147 configData->
ground.GroundVehicleThrottle1 = 0;
148 configData->
ground.GroundVehicleThrottle2 = 0;
151 QStringList ConfigGroundVehicleWidget::getChannelDescriptions()
154 QStringList channelDesc;
157 for (i = 0; i < (int)(ActuatorCommand::CHANNEL_NUMELEM); i++) {
158 channelDesc.append(QString(
"-"));
164 if (configData.
ground.GroundVehicleSteering1 > 0)
165 channelDesc[configData.
ground.GroundVehicleSteering1 - 1] = QString(
"GroundSteering1");
166 if (configData.
ground.GroundVehicleSteering2 > 0)
167 channelDesc[configData.
ground.GroundVehicleSteering2 - 1] = QString(
"GroundSteering2");
168 if (configData.
ground.GroundVehicleThrottle1 > 0)
169 channelDesc[configData.
ground.GroundVehicleThrottle1 - 1] = QString(
"GroundThrottle1");
170 if (configData.
ground.GroundVehicleThrottle2 > 0)
171 channelDesc[configData.
ground.GroundVehicleThrottle2 - 1] = QString(
"GroundThrottle2");
180 SystemSettings::AirframeTypeOptions ConfigGroundVehicleWidget::updateConfigObjectsFromWidgets()
182 SystemSettings::AirframeTypeOptions airframeType =
183 SystemSettings::AIRFRAMETYPE_GROUNDVEHICLECAR;
186 MixerSettings *mixerSettings = MixerSettings::GetInstance(
getObjectManager());
187 Q_ASSERT(mixerSettings);
190 if (m_aircraft->groundVehicleType->currentText() ==
"Turnable (car)") {
191 airframeType = SystemSettings::AIRFRAMETYPE_GROUNDVEHICLECAR;
192 setupGroundVehicleCar(airframeType);
193 }
else if (m_aircraft->groundVehicleType->currentText() ==
"Differential (tank)") {
194 airframeType = SystemSettings::AIRFRAMETYPE_GROUNDVEHICLEDIFFERENTIAL;
195 setupGroundVehicleDifferential(airframeType);
197 airframeType = SystemSettings::AIRFRAMETYPE_GROUNDVEHICLEMOTORCYCLE;
198 setupGroundVehicleMotorcycle(airframeType);
207 void ConfigGroundVehicleWidget::refreshAirframeWidgetsValues(
208 SystemSettings::AirframeTypeOptions frameType)
210 MixerSettings *mixerSettings = MixerSettings::GetInstance(
getObjectManager());
211 Q_ASSERT(mixerSettings);
223 if (frameType == SystemSettings::AIRFRAMETYPE_GROUNDVEHICLEDIFFERENTIAL) {
228 int channel = m_aircraft->gvMotor1ChannelBox->currentIndex() - 1;
232 m_aircraft->differentialSteeringSlider1->setValue(
235 m_aircraft->differentialSteeringSlider2->setValue(
240 if (frameType == SystemSettings::AIRFRAMETYPE_GROUNDVEHICLEMOTORCYCLE) {
262 bool ConfigGroundVehicleWidget::setupGroundVehicleMotorcycle(
263 SystemSettings::AirframeTypeOptions airframeType)
267 if (throwConfigError(airframeType)) {
273 ResetActuators(&config);
275 config.
ground.GroundVehicleThrottle1 = m_aircraft->gvMotor1ChannelBox->currentIndex();
276 config.
ground.GroundVehicleThrottle2 = m_aircraft->gvMotor2ChannelBox->currentIndex();
278 SetConfigData(config, SystemSettings::AIRFRAMETYPE_GROUNDVEHICLEMOTORCYCLE);
280 MixerSettings *mixerSettings = MixerSettings::GetInstance(
getObjectManager());
281 Q_ASSERT(mixerSettings);
285 int channel = m_aircraft->gvMotor2ChannelBox->currentIndex() - 1;
286 setMixerType(mixerSettings, channel, MixerSettings::MIXER1TYPE_MOTOR);
292 channel = m_aircraft->gvSteering1ChannelBox->currentIndex() - 1;
293 setMixerType(mixerSettings, channel, MixerSettings::MIXER1TYPE_SERVO);
298 channel = m_aircraft->gvSteering2ChannelBox->currentIndex() - 1;
299 setMixerType(mixerSettings, channel, MixerSettings::MIXER1TYPE_SERVO);
303 m_aircraft->gvStatusLabel->setText(
"Mixer generated");
313 bool ConfigGroundVehicleWidget::setupGroundVehicleDifferential(
314 SystemSettings::AirframeTypeOptions airframeType)
319 if (throwConfigError(airframeType)) {
325 ResetActuators(&config);
327 config.
ground.GroundVehicleThrottle1 = m_aircraft->gvMotor1ChannelBox->currentIndex();
328 config.
ground.GroundVehicleThrottle2 = m_aircraft->gvMotor2ChannelBox->currentIndex();
330 SetConfigData(config, SystemSettings::AIRFRAMETYPE_GROUNDVEHICLEDIFFERENTIAL);
332 MixerSettings *mixerSettings = MixerSettings::GetInstance(
getObjectManager());
333 Q_ASSERT(mixerSettings);
337 int channel = m_aircraft->gvMotor1ChannelBox->currentIndex() - 1;
338 setMixerType(mixerSettings, channel, MixerSettings::MIXER1TYPE_MOTOR);
344 channel = m_aircraft->gvMotor2ChannelBox->currentIndex() - 1;
345 setMixerType(mixerSettings, channel, MixerSettings::MIXER1TYPE_MOTOR);
351 m_aircraft->gvStatusLabel->setText(
"Mixer generated");
361 bool ConfigGroundVehicleWidget::setupGroundVehicleCar(
362 SystemSettings::AirframeTypeOptions airframeType)
366 if (throwConfigError(airframeType)) {
372 ResetActuators(&config);
374 config.
ground.GroundVehicleThrottle1 = m_aircraft->gvMotor1ChannelBox->currentIndex();
375 config.
ground.GroundVehicleThrottle2 = m_aircraft->gvMotor2ChannelBox->currentIndex();
376 config.
ground.GroundVehicleSteering1 = m_aircraft->gvSteering1ChannelBox->currentIndex();
377 config.
ground.GroundVehicleSteering2 = m_aircraft->gvSteering2ChannelBox->currentIndex();
379 SetConfigData(config, SystemSettings::AIRFRAMETYPE_GROUNDVEHICLECAR);
381 MixerSettings *mixerSettings = MixerSettings::GetInstance(
getObjectManager());
382 Q_ASSERT(mixerSettings);
385 int channel = m_aircraft->gvSteering1ChannelBox->currentIndex() - 1;
386 setMixerType(mixerSettings, channel, MixerSettings::MIXER1TYPE_SERVO);
389 channel = m_aircraft->gvSteering2ChannelBox->currentIndex() - 1;
390 setMixerType(mixerSettings, channel, MixerSettings::MIXER1TYPE_SERVO);
393 channel = m_aircraft->gvMotor1ChannelBox->currentIndex() - 1;
394 setMixerType(mixerSettings, channel, MixerSettings::MIXER1TYPE_MOTOR);
398 channel = m_aircraft->gvMotor2ChannelBox->currentIndex() - 1;
399 setMixerType(mixerSettings, channel, MixerSettings::MIXER1TYPE_MOTOR);
404 m_aircraft->gvStatusLabel->setText(
"Mixer generated");
413 bool ConfigGroundVehicleWidget::throwConfigError(SystemSettings::AirframeTypeOptions airframeType)
419 int size = m_aircraft->gvEngineChannelBox->style()->pixelMetric(QStyle::PM_SmallIconSize);
420 QPixmap pixmap(size, size);
421 pixmap.fill(QColor(
"red"));
423 if (airframeType == SystemSettings::AIRFRAMETYPE_GROUNDVEHICLECAR) {
424 if (m_aircraft->gvMotor1ChannelBox->currentText() ==
"None"
425 && m_aircraft->gvMotor2ChannelBox->currentText() ==
"None") {
426 pixmap.fill(QColor(
"green"));
427 m_aircraft->gvMotor1ChannelBox->setItemData(0, pixmap,
429 m_aircraft->gvMotor2ChannelBox->setItemData(0, pixmap,
438 m_aircraft->gvMotor1ChannelBox->setItemData(0, 0,
440 m_aircraft->gvMotor2ChannelBox->setItemData(0, 0,
452 if (m_aircraft->gvSteering1ChannelBox->currentText() ==
"None"
453 && m_aircraft->gvSteering2ChannelBox->currentText() ==
"None") {
454 m_aircraft->gvSteering1ChannelBox->setItemData(
455 0, pixmap, Qt::DecorationRole);
456 m_aircraft->gvSteering2ChannelBox->setItemData(
457 0, pixmap, Qt::DecorationRole);
466 m_aircraft->gvSteering1ChannelBox->setItemData(
467 0, 0, Qt::DecorationRole);
468 m_aircraft->gvSteering2ChannelBox->setItemData(
469 0, 0, Qt::DecorationRole);
480 }
else if (airframeType == SystemSettings::AIRFRAMETYPE_GROUNDVEHICLEDIFFERENTIAL) {
481 if (m_aircraft->gvMotor1ChannelBox->currentText() ==
"None"
482 || m_aircraft->gvMotor2ChannelBox->currentText() ==
"None") {
483 m_aircraft->gvMotor1ChannelBox->setItemData(0, pixmap,
485 m_aircraft->gvMotor2ChannelBox->setItemData(0, pixmap,
489 m_aircraft->gvMotor1ChannelBox->setItemData(0, 0,
491 m_aircraft->gvMotor2ChannelBox->setItemData(0, 0,
496 m_aircraft->gvSteering1ChannelBox->setItemData(0, 0,
498 m_aircraft->gvSteering2ChannelBox->setItemData(0, 0,
500 }
else if (airframeType == SystemSettings::AIRFRAMETYPE_GROUNDVEHICLEMOTORCYCLE) {
501 if (m_aircraft->gvMotor1ChannelBox->currentText() ==
"None"
502 && m_aircraft->gvMotor2ChannelBox->currentText() ==
"None") {
503 m_aircraft->gvMotor2ChannelBox->setItemData(0, pixmap,
507 m_aircraft->gvMotor2ChannelBox->setItemData(0, 0,
511 if (m_aircraft->gvSteering1ChannelBox->currentText() ==
"None"
512 && m_aircraft->gvSteering2ChannelBox->currentText() ==
"None") {
513 m_aircraft->gvSteering1ChannelBox->setItemData(
514 0, pixmap, Qt::DecorationRole);
517 m_aircraft->gvSteering1ChannelBox->setItemData(
518 0, 0, Qt::DecorationRole);
522 m_aircraft->gvMotor1ChannelBox->setItemData(0, 0,
524 m_aircraft->gvSteering2ChannelBox->setItemData(0, 0,
529 m_aircraft->gvStatusLabel->setText(
530 QString(
"<font color='red'>ERROR: Assign all necessary channels</font>"));
static void SetConfigData(GUIConfigDataUnion configData, SystemSettings::AirframeTypeOptions vehicle)
static GUIConfigDataUnion GetConfigData()
~ConfigGroundVehicleWidget()
double getMixerVectorValue(UAVDataObject *mixer, int channel, MixerSettings::Mixer1VectorElem elementName)
groundGUISettingsStruct ground
void resetMixers(UAVDataObject *mixer)
void setMixerType(UAVDataObject *mixer, int channel, MixerSettings::Mixer1TypeOptions mixerType)
void setMixerVectorValue(UAVDataObject *mixer, int channel, MixerSettings::Mixer1VectorElem elementName, double value)
ConfigGroundVehicleWidget(Ui_AircraftWidget *aircraft=nullptr, QWidget *parent=nullptr)
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)