LP-454 Add boat to the Vehicle Wizard
[librepilot.git] / ground / gcs / src / plugins / setupwizard / vehicleconfigurationhelper.cpp
blob395e8f9d614ecc73057c9ed0aac3d79137e6ffc3
1 /**
2 ***********************************************************************************
4 * @file vehicleconfigurationhelper.cpp
5 * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015-2016.
6 * The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
7 * @addtogroup
8 * @{
9 * @addtogroup VehicleConfigurationHelper
10 * @{
11 * @brief
12 **********************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "vehicleconfigurationhelper.h"
30 #include "extensionsystem/pluginmanager.h"
31 #include "uavobjectutilmanager.h"
32 #include <uavobjecthelper.h>
34 #include "hwsettings.h"
35 #include "actuatorsettings.h"
36 #include "attitudesettings.h"
37 #include "mixersettings.h"
38 #include "systemsettings.h"
39 #include "manualcontrolsettings.h"
40 #include "flightmodesettings.h"
41 #include "stabilizationsettings.h"
42 #include "stabilizationbank.h"
43 #include "stabilizationsettingsbank1.h"
44 #include "revocalibration.h"
45 #include "accelgyrosettings.h"
46 #include "gpssettings.h"
47 #include "airspeedsettings.h"
48 #include "auxmagsettings.h"
50 #include <QtCore/qmath.h>
51 #include <QDebug>
52 #include <QJsonObject>
53 #include <QTimer>
55 VehicleConfigurationHelper::VehicleConfigurationHelper(VehicleConfigurationSource *configSource)
56 : m_configSource(configSource), m_uavoManager(0),
57 m_transactionOK(false), m_transactionTimeout(false), m_currentTransactionObjectID(-1),
58 m_progress(0)
60 Q_ASSERT(m_configSource);
61 ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
62 m_uavoManager = pm->getObject<UAVObjectManager>();
63 Q_ASSERT(m_uavoManager);
66 bool VehicleConfigurationHelper::setupVehicle(bool save)
68 m_progress = 0;
69 clearModifiedObjects();
70 resetVehicleConfig();
71 resetGUIData();
72 if (!saveChangesToController(save)) {
73 return false;
76 m_progress = 0;
77 applyHardwareConfiguration();
78 applyVehicleConfiguration();
79 applyActuatorConfiguration();
80 applyFlightModeConfiguration();
82 if (save) {
83 applySensorBiasConfiguration();
86 applyStabilizationConfiguration();
87 applyManualControlDefaults();
89 applyTemplateSettings();
91 bool result = saveChangesToController(save);
92 emit saveProgress(m_modifiedObjects.count() + 1, ++m_progress, result ? tr("Done!") : tr("Failed!"));
93 return result;
96 bool VehicleConfigurationHelper::setupHardwareSettings(bool save)
98 m_progress = 0;
99 clearModifiedObjects();
100 applyHardwareConfiguration();
101 applyManualControlDefaults();
103 bool result = saveChangesToController(save);
104 emit saveProgress(m_modifiedObjects.count() + 1, ++m_progress, result ? tr("Done!") : tr("Failed!"));
105 return result;
108 bool VehicleConfigurationHelper::isApplicable(UAVObject *dataObj)
110 switch (m_configSource->getControllerType()) {
111 case VehicleConfigurationSource::CONTROLLER_CC:
112 case VehicleConfigurationSource::CONTROLLER_CC3D:
113 if (dataObj->getName() == "EKFConfiguration") {
114 return false;
116 default:
117 return true;
121 void VehicleConfigurationHelper::addModifiedObject(UAVDataObject *object, QString description)
123 m_modifiedObjects << new QPair<UAVDataObject *, QString>(object, description);
126 void VehicleConfigurationHelper::clearModifiedObjects()
128 for (int i = 0; i < m_modifiedObjects.count(); i++) {
129 QPair<UAVDataObject *, QString> *pair = m_modifiedObjects.at(i);
130 delete pair;
132 m_modifiedObjects.clear();
135 void VehicleConfigurationHelper::applyHardwareConfiguration()
137 HwSettings *hwSettings = HwSettings::GetInstance(m_uavoManager);
139 Q_ASSERT(hwSettings);
140 HwSettings::DataFields data = hwSettings->getData();
142 data.OptionalModules[HwSettings::OPTIONALMODULES_GPS] = 0;
143 data.OptionalModules[HwSettings::OPTIONALMODULES_AIRSPEED] = 0;
145 switch (m_configSource->getControllerType()) {
146 case VehicleConfigurationSource::CONTROLLER_CC:
147 case VehicleConfigurationSource::CONTROLLER_CC3D:
148 // Reset all ports
149 data.CC_RcvrPort = HwSettings::CC_RCVRPORT_DISABLEDONESHOT;
151 // Default mainport to be active telemetry link
152 data.CC_MainPort = HwSettings::CC_MAINPORT_TELEMETRY;
154 data.CC_FlexiPort = HwSettings::CC_FLEXIPORT_DISABLED;
155 switch (m_configSource->getInputType()) {
156 case VehicleConfigurationSource::INPUT_PWM:
157 data.CC_RcvrPort = HwSettings::CC_RCVRPORT_PWMNOONESHOT;
158 break;
159 case VehicleConfigurationSource::INPUT_PPM:
160 if (m_configSource->getEscType() == VehicleConfigurationSource::ESC_ONESHOT ||
161 m_configSource->getEscType() == VehicleConfigurationSource::ESC_SYNCHED) {
162 data.CC_RcvrPort = HwSettings::CC_RCVRPORT_PPM_PIN8ONESHOT;
163 } else {
164 data.CC_RcvrPort = HwSettings::CC_RCVRPORT_PPMNOONESHOT;
166 break;
167 case VehicleConfigurationSource::INPUT_SBUS:
168 // We have to set telemetry on flexiport since s.bus needs the mainport.
169 data.CC_MainPort = HwSettings::CC_MAINPORT_SBUS;
170 data.CC_FlexiPort = HwSettings::CC_FLEXIPORT_TELEMETRY;
171 break;
172 case VehicleConfigurationSource::INPUT_DSM:
173 data.CC_FlexiPort = HwSettings::CC_FLEXIPORT_DSM;
174 break;
175 case VehicleConfigurationSource::INPUT_SRXL:
176 data.CC_FlexiPort = HwSettings::CC_FLEXIPORT_SRXL;
177 break;
178 case VehicleConfigurationSource::INPUT_HOTT_SUMD:
179 data.CC_FlexiPort = HwSettings::CC_FLEXIPORT_HOTTSUMD;
180 break;
181 case VehicleConfigurationSource::INPUT_EXBUS:
182 data.CC_FlexiPort = HwSettings::CC_FLEXIPORT_EXBUS;
183 break;
184 case VehicleConfigurationSource::INPUT_IBUS:
185 data.CC_FlexiPort = HwSettings::CC_FLEXIPORT_IBUS;
186 break;
187 default:
188 break;
190 break;
191 case VehicleConfigurationSource::CONTROLLER_REVO:
192 case VehicleConfigurationSource::CONTROLLER_NANO:
193 case VehicleConfigurationSource::CONTROLLER_SPARKY2:
194 case VehicleConfigurationSource::CONTROLLER_DISCOVERYF4:
195 // Reset all ports to their defaults
196 if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_SPARKY2) {
197 data.SPK2_RcvrPort = HwSettings::SPK2_RCVRPORT_DISABLED;
198 data.SPK2_FlexiPort = HwSettings::SPK2_FLEXIPORT_DISABLED;
199 } else {
200 data.RM_RcvrPort = HwSettings::RM_RCVRPORT_DISABLED;
201 data.RM_FlexiPort = HwSettings::RM_FLEXIPORT_DISABLED;
204 // Revo/Sparky2 uses inbuilt Modem do not set mainport to be active telemetry link for Revo/Sparky2
205 if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_REVO) {
206 data.RM_MainPort = HwSettings::RM_MAINPORT_DISABLED;
207 } else if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_SPARKY2) {
208 data.SPK2_MainPort = HwSettings::SPK2_MAINPORT_DISABLED;
209 } else {
210 data.RM_MainPort = HwSettings::RM_MAINPORT_TELEMETRY;
213 switch (m_configSource->getInputType()) {
214 case VehicleConfigurationSource::INPUT_PWM:
215 if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_SPARKY2) {
216 // this should not happen, sparky2 does not allow pwm
217 data.SPK2_RcvrPort = HwSettings::SPK2_RCVRPORT_DISABLED;
218 } else {
219 data.RM_RcvrPort = HwSettings::RM_RCVRPORT_PWM;
221 break;
222 case VehicleConfigurationSource::INPUT_PPM:
223 if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_SPARKY2) {
224 data.SPK2_RcvrPort = HwSettings::SPK2_RCVRPORT_PPM;
225 } else {
226 data.RM_RcvrPort = HwSettings::RM_RCVRPORT_PPM;
228 break;
229 case VehicleConfigurationSource::INPUT_SBUS:
230 if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_SPARKY2) {
231 data.SPK2_RcvrPort = HwSettings::SPK2_RCVRPORT_SBUS;
232 } else {
233 data.RM_MainPort = HwSettings::RM_MAINPORT_SBUS;
234 // We have to set telemetry to flexiport on all except Revo (and except Sparky2) since s.bus needs mainport.
235 if (m_configSource->getControllerType() != VehicleConfigurationSource::CONTROLLER_REVO) {
236 data.RM_FlexiPort = HwSettings::RM_FLEXIPORT_TELEMETRY;
239 break;
240 case VehicleConfigurationSource::INPUT_DSM:
241 if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_SPARKY2) {
242 data.SPK2_RcvrPort = HwSettings::SPK2_RCVRPORT_DSM;
243 } else {
244 data.RM_FlexiPort = HwSettings::RM_FLEXIPORT_DSM;
246 break;
247 case VehicleConfigurationSource::INPUT_SRXL:
248 if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_SPARKY2) {
249 data.SPK2_RcvrPort = HwSettings::SPK2_RCVRPORT_SRXL;
250 } else {
251 data.RM_FlexiPort = HwSettings::RM_FLEXIPORT_SRXL;
253 break;
254 case VehicleConfigurationSource::INPUT_HOTT_SUMD:
255 if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_SPARKY2) {
256 data.SPK2_RcvrPort = HwSettings::SPK2_RCVRPORT_HOTTSUMD;
257 } else {
258 data.RM_FlexiPort = HwSettings::RM_FLEXIPORT_HOTTSUMD;
260 break;
261 case VehicleConfigurationSource::INPUT_EXBUS:
262 if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_SPARKY2) {
263 data.SPK2_RcvrPort = HwSettings::SPK2_RCVRPORT_EXBUS;
264 } else {
265 data.RM_FlexiPort = HwSettings::RM_FLEXIPORT_EXBUS;
267 break;
268 case VehicleConfigurationSource::INPUT_IBUS:
269 if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_SPARKY2) {
270 data.SPK2_RcvrPort = HwSettings::SPK2_RCVRPORT_IBUS;
271 } else {
272 data.RM_FlexiPort = HwSettings::RM_FLEXIPORT_IBUS;
274 break;
275 default:
276 break;
279 if (m_configSource->getGpsType() != VehicleConfigurationSource::GPS_DISABLED) {
280 data.OptionalModules[HwSettings::OPTIONALMODULES_GPS] = 1;
281 data.GPSSpeed = HwSettings::GPSSPEED_57600;
283 // if using GPS and SBUS on Revo or Nano, we must use FlexiPort for GPS
284 // since we must use MainPort for SBUS
285 if (m_configSource->getControllerType() != VehicleConfigurationSource::CONTROLLER_SPARKY2) {
286 if (m_configSource->getInputType() == VehicleConfigurationSource::INPUT_SBUS) {
287 data.RM_FlexiPort = HwSettings::RM_FLEXIPORT_GPS;
288 } else {
289 data.RM_MainPort = HwSettings::RM_MAINPORT_GPS;
291 } else {
292 data.SPK2_MainPort = HwSettings::SPK2_MAINPORT_GPS;
295 GPSSettings *gpsSettings = GPSSettings::GetInstance(m_uavoManager);
296 Q_ASSERT(gpsSettings);
297 GPSSettings::DataFields gpsData = gpsSettings->getData();
299 switch (m_configSource->getGpsType()) {
300 case VehicleConfigurationSource::GPS_NMEA:
301 gpsData.DataProtocol = GPSSettings::DATAPROTOCOL_NMEA;
302 gpsData.UbxAutoConfig = GPSSettings::UBXAUTOCONFIG_DISABLED;
303 break;
304 case VehicleConfigurationSource::GPS_UBX:
305 gpsData.DataProtocol = GPSSettings::DATAPROTOCOL_UBX;
306 gpsData.UbxAutoConfig = GPSSettings::UBXAUTOCONFIG_AUTOBAUDANDCONFIGURE;
307 break;
308 case VehicleConfigurationSource::GPS_PLATINUM:
310 gpsData.DataProtocol = GPSSettings::DATAPROTOCOL_UBX;
311 gpsData.UbxAutoConfig = GPSSettings::UBXAUTOCONFIG_AUTOBAUDANDCONFIGURE;
312 AuxMagSettings *magSettings = AuxMagSettings::GetInstance(m_uavoManager);
313 Q_ASSERT(magSettings);
314 AuxMagSettings::DataFields magsData = magSettings->getData();
315 magsData.Type = AuxMagSettings::TYPE_GPSV9;
316 magsData.Usage = AuxMagSettings::USAGE_AUXONLY;
317 magSettings->setData(magsData);
318 addModifiedObject(magSettings, tr("Writing External Mag sensor settings"));
319 break;
321 case VehicleConfigurationSource::GPS_NAZA:
323 gpsData.DataProtocol = GPSSettings::DATAPROTOCOL_DJI;
324 gpsData.UbxAutoConfig = GPSSettings::UBXAUTOCONFIG_DISABLED;
325 AuxMagSettings *magSettings = AuxMagSettings::GetInstance(m_uavoManager);
326 Q_ASSERT(magSettings);
327 AuxMagSettings::DataFields magsData = magSettings->getData();
328 magsData.Type = AuxMagSettings::TYPE_DJI;
329 magsData.Usage = AuxMagSettings::USAGE_AUXONLY;
330 magSettings->setData(magsData);
331 addModifiedObject(magSettings, tr("Writing External Mag sensor settings"));
332 break;
334 case VehicleConfigurationSource::GPS_UBX_FLEXI_I2CMAG:
336 AuxMagSettings *magSettings = AuxMagSettings::GetInstance(m_uavoManager);
337 Q_ASSERT(magSettings);
338 AuxMagSettings::DataFields magsData = magSettings->getData();
340 gpsData.DataProtocol = GPSSettings::DATAPROTOCOL_UBX;
341 gpsData.UbxAutoConfig = GPSSettings::UBXAUTOCONFIG_AUTOBAUDANDCONFIGURE;
342 if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_SPARKY2) {
343 data.SPK2_FlexiPort = HwSettings::SPK2_FLEXIPORT_I2C;
344 } else {
345 data.RM_FlexiPort = HwSettings::RM_FLEXIPORT_I2C;
347 magsData.Type = AuxMagSettings::TYPE_FLEXI;
348 magsData.Usage = AuxMagSettings::USAGE_AUXONLY;
349 magSettings->setData(magsData);
350 addModifiedObject(magSettings, tr("Writing I2C Mag sensor settings"));
353 case VehicleConfigurationSource::GPS_DISABLED:
354 // Should not be able to reach here
355 break;
358 gpsSettings->setData(gpsData);
359 addModifiedObject(gpsSettings, tr("Writing GPS sensor settings"));
360 } else {
361 data.OptionalModules[HwSettings::OPTIONALMODULES_GPS] = 0;
364 if (m_configSource->getVehicleType() == VehicleConfigurationSource::VEHICLE_FIXEDWING &&
365 m_configSource->getAirspeedType() != VehicleConfigurationSource::AIRSPEED_DISABLED) {
366 AirspeedSettings *airspeedSettings = AirspeedSettings::GetInstance(m_uavoManager);
367 Q_ASSERT(airspeedSettings);
368 AirspeedSettings::DataFields airspeedData = airspeedSettings->getData();
370 switch (m_configSource->getAirspeedType()) {
371 case VehicleConfigurationSource::AIRSPEED_ESTIMATE:
372 data.OptionalModules[HwSettings::OPTIONALMODULES_AIRSPEED] = 1;
373 airspeedData.AirspeedSensorType = AirspeedSettings::AIRSPEEDSENSORTYPE_GROUNDSPEEDBASEDWINDESTIMATION;
374 break;
375 case VehicleConfigurationSource::AIRSPEED_EAGLETREE:
376 data.OptionalModules[HwSettings::OPTIONALMODULES_AIRSPEED] = 1;
377 if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_SPARKY2) {
378 // sparky2: put I2C airspeed on flexiport, but it could be put on i2cport
379 data.SPK2_FlexiPort = HwSettings::SPK2_FLEXIPORT_I2C;
380 } else {
381 data.RM_FlexiPort = HwSettings::RM_FLEXIPORT_I2C;
383 airspeedData.AirspeedSensorType = AirspeedSettings::AIRSPEEDSENSORTYPE_EAGLETREEAIRSPEEDV3;
384 break;
385 case VehicleConfigurationSource::AIRSPEED_MS4525:
386 data.OptionalModules[HwSettings::OPTIONALMODULES_AIRSPEED] = 1;
387 if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_SPARKY2) {
388 // sparky2: put I2C airspeed on flexiport, but it could be put on i2cport
389 data.SPK2_FlexiPort = HwSettings::SPK2_FLEXIPORT_I2C;
390 } else {
391 data.RM_FlexiPort = HwSettings::RM_FLEXIPORT_I2C;
393 airspeedData.AirspeedSensorType = AirspeedSettings::AIRSPEEDSENSORTYPE_PIXHAWKAIRSPEEDMS4525DO;
394 break;
395 default:
396 data.OptionalModules[HwSettings::OPTIONALMODULES_AIRSPEED] = 0;
397 break;
400 airspeedSettings->setData(airspeedData);
401 addModifiedObject(airspeedSettings, tr("Writing Airspeed sensor settings"));
403 break;
404 default:
405 break;
407 UAVObjectUpdaterHelper updateHelper;
408 hwSettings->setData(data, false);
409 updateHelper.doObjectAndWait(hwSettings);
411 addModifiedObject(hwSettings, tr("Writing hardware settings"));
414 void VehicleConfigurationHelper::applyVehicleConfiguration()
416 switch (m_configSource->getVehicleType()) {
417 case VehicleConfigurationSource::VEHICLE_MULTI:
419 switch (m_configSource->getVehicleSubType()) {
420 case VehicleConfigurationSource::MULTI_ROTOR_TRI_Y:
421 setupTriCopter();
422 break;
423 case VehicleConfigurationSource::MULTI_ROTOR_QUAD_X:
424 case VehicleConfigurationSource::MULTI_ROTOR_QUAD_PLUS:
425 setupQuadCopter();
426 break;
427 case VehicleConfigurationSource::MULTI_ROTOR_HEXA:
428 case VehicleConfigurationSource::MULTI_ROTOR_HEXA_COAX_Y:
429 case VehicleConfigurationSource::MULTI_ROTOR_HEXA_H:
430 case VehicleConfigurationSource::MULTI_ROTOR_HEXA_X:
431 setupHexaCopter();
432 break;
433 case VehicleConfigurationSource::MULTI_ROTOR_OCTO:
434 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_X:
435 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_COAX_X:
436 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_COAX_PLUS:
437 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_V:
438 setupOctoCopter();
439 break;
440 default:
441 break;
443 break;
445 case VehicleConfigurationSource::VEHICLE_FIXEDWING:
447 switch (m_configSource->getVehicleSubType()) {
448 case VehicleConfigurationSource::FIXED_WING_DUAL_AILERON:
449 setupDualAileron();
450 break;
451 case VehicleConfigurationSource::FIXED_WING_AILERON:
452 setupAileron();
453 break;
454 case VehicleConfigurationSource::FIXED_WING_ELEVON:
455 setupElevon();
456 break;
457 case VehicleConfigurationSource::FIXED_WING_VTAIL:
458 setupVtail();
459 break;
460 default:
461 break;
463 break;
465 case VehicleConfigurationSource::VEHICLE_HELI:
466 // TODO: Implement settings for Helis
467 break;
469 case VehicleConfigurationSource::VEHICLE_SURFACE:
471 switch (m_configSource->getVehicleSubType()) {
472 case VehicleConfigurationSource::GROUNDVEHICLE_CAR:
473 setupCar();
474 break;
475 case VehicleConfigurationSource::GROUNDVEHICLE_DIFFERENTIAL:
476 setupTank();
477 break;
478 case VehicleConfigurationSource::GROUNDVEHICLE_MOTORCYCLE:
479 setupMotorcycle();
480 break;
481 case VehicleConfigurationSource::GROUNDVEHICLE_BOAT:
482 setupBoat();
483 break;
484 case VehicleConfigurationSource::GROUNDVEHICLE_DIFFERENTIAL_BOAT:
485 setupBoatDiff();
486 break;
487 default:
488 break;
490 break;
493 default:
494 break;
498 void VehicleConfigurationHelper::applyActuatorConfiguration()
500 ActuatorSettings *actSettings = ActuatorSettings::GetInstance(m_uavoManager);
502 qint16 escFrequence = LEGACY_ESC_FREQUENCY;
503 ActuatorSettings::BankModeOptions bankMode = ActuatorSettings::BANKMODE_PWM;
505 switch (m_configSource->getEscType()) {
506 case VehicleConfigurationSource::ESC_STANDARD:
507 escFrequence = LEGACY_ESC_FREQUENCY;
508 bankMode = ActuatorSettings::BANKMODE_PWM;
509 break;
510 case VehicleConfigurationSource::ESC_RAPID:
511 bankMode = ActuatorSettings::BANKMODE_PWM;
512 escFrequence = RAPID_ESC_FREQUENCY;
513 break;
514 case VehicleConfigurationSource::ESC_SYNCHED:
515 bankMode = ActuatorSettings::BANKMODE_PWMSYNC;
516 escFrequence = PWMSYNC_ESC_FREQUENCY;
517 break;
518 case VehicleConfigurationSource::ESC_ONESHOT:
519 bankMode = ActuatorSettings::BANKMODE_ONESHOT125;
520 escFrequence = ONESHOT_ESC_FREQUENCY;
521 break;
522 default:
523 break;
526 qint16 servoFrequence = ANALOG_SERVO_FREQUENCY;
527 switch (m_configSource->getServoType()) {
528 case VehicleConfigurationSource::SERVO_ANALOG:
529 servoFrequence = ANALOG_SERVO_FREQUENCY;
530 break;
531 case VehicleConfigurationSource::SERVO_DIGITAL:
532 servoFrequence = DIGITAL_SERVO_FREQUENCY;
533 break;
534 default:
535 break;
538 switch (m_configSource->getVehicleType()) {
539 case VehicleConfigurationSource::VEHICLE_MULTI:
541 ActuatorSettings::DataFields data = actSettings->getData();
543 QList<actuatorChannelSettings> actuatorSettings = m_configSource->getActuatorSettings();
544 for (quint16 i = 0; i < ActuatorSettings::CHANNELMAX_NUMELEM; i++) {
545 data.ChannelType[i] = ActuatorSettings::CHANNELTYPE_PWM;
546 data.ChannelAddr[i] = i;
547 data.ChannelMin[i] = actuatorSettings[i].channelMin;
548 data.ChannelNeutral[i] = actuatorSettings[i].channelNeutral;
549 data.ChannelMax[i] = actuatorSettings[i].channelMax;
552 data.MotorsSpinWhileArmed = ActuatorSettings::MOTORSSPINWHILEARMED_FALSE;
554 for (quint16 i = 0; i < ActuatorSettings::BANKUPDATEFREQ_NUMELEM; i++) {
555 data.BankUpdateFreq[i] = LEGACY_ESC_FREQUENCY;
556 data.BankMode[i] = ActuatorSettings::BANKMODE_PWM;
559 switch (m_configSource->getVehicleSubType()) {
560 case VehicleConfigurationSource::MULTI_ROTOR_TRI_Y:
561 // Servo always on channel 4
562 data.BankUpdateFreq[0] = escFrequence;
563 data.BankMode[0] = bankMode;
564 if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_REVO
565 || m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_SPARKY2) {
566 data.BankUpdateFreq[1] = escFrequence;
567 data.BankMode[1] = bankMode;
568 data.BankUpdateFreq[2] = servoFrequence;
569 } else if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_NANO) {
570 data.BankUpdateFreq[1] = escFrequence;
571 data.BankMode[1] = bankMode;
572 data.BankUpdateFreq[2] = escFrequence;
573 data.BankMode[2] = bankMode;
574 data.BankUpdateFreq[3] = servoFrequence;
576 break;
577 case VehicleConfigurationSource::MULTI_ROTOR_QUAD_X:
578 case VehicleConfigurationSource::MULTI_ROTOR_QUAD_PLUS:
579 data.BankUpdateFreq[0] = escFrequence;
580 data.BankMode[0] = bankMode;
581 data.BankUpdateFreq[1] = escFrequence;
582 data.BankMode[1] = bankMode;
583 if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_REVO
584 || m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_SPARKY2) {
585 data.BankUpdateFreq[2] = escFrequence;
586 data.BankMode[2] = bankMode;
587 } else if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_NANO) {
588 data.BankUpdateFreq[1] = escFrequence;
589 data.BankMode[1] = bankMode;
590 data.BankUpdateFreq[2] = escFrequence;
591 data.BankMode[2] = bankMode;
592 data.BankUpdateFreq[3] = escFrequence;
593 data.BankMode[3] = bankMode;
595 break;
596 case VehicleConfigurationSource::MULTI_ROTOR_HEXA:
597 case VehicleConfigurationSource::MULTI_ROTOR_HEXA_COAX_Y:
598 case VehicleConfigurationSource::MULTI_ROTOR_HEXA_H:
599 case VehicleConfigurationSource::MULTI_ROTOR_HEXA_X:
600 case VehicleConfigurationSource::MULTI_ROTOR_OCTO:
601 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_X:
602 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_COAX_X:
603 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_COAX_PLUS:
604 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_V:
605 data.BankUpdateFreq[0] = escFrequence;
606 data.BankMode[0] = bankMode;
607 data.BankUpdateFreq[1] = escFrequence;
608 data.BankMode[1] = bankMode;
609 data.BankUpdateFreq[2] = escFrequence;
610 data.BankMode[2] = bankMode;
611 data.BankUpdateFreq[3] = escFrequence;
612 data.BankMode[3] = bankMode;
613 if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_NANO) {
614 data.BankUpdateFreq[4] = escFrequence;
615 data.BankMode[4] = bankMode;
617 break;
618 default:
619 break;
621 actSettings->setData(data);
622 addModifiedObject(actSettings, tr("Writing actuator settings"));
623 break;
626 case VehicleConfigurationSource::VEHICLE_FIXEDWING:
628 ActuatorSettings::DataFields data = actSettings->getData();
630 QList<actuatorChannelSettings> actuatorSettings = m_configSource->getActuatorSettings();
631 for (quint16 i = 0; i < ActuatorSettings::CHANNELMAX_NUMELEM; i++) {
632 data.ChannelType[i] = ActuatorSettings::CHANNELTYPE_PWM;
633 data.ChannelAddr[i] = i;
634 data.ChannelMin[i] = actuatorSettings[i].channelMin;
635 data.ChannelNeutral[i] = actuatorSettings[i].channelNeutral;
636 data.ChannelMax[i] = actuatorSettings[i].channelMax;
639 for (quint16 i = 0; i < ActuatorSettings::BANKUPDATEFREQ_NUMELEM; i++) {
640 data.BankUpdateFreq[i] = servoFrequence;
641 data.BankMode[i] = ActuatorSettings::BANKMODE_PWM;
642 if ((m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_CC) ||
643 (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_CC3D)) {
644 // Motor output4, bank2
645 if (i == 1) {
646 data.BankUpdateFreq[i] = escFrequence;
648 } else if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_REVO
649 || m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_SPARKY2) {
650 // Motor output4, bank3
651 if (i == 2) {
652 data.BankUpdateFreq[i] = escFrequence;
654 } else if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_NANO) {
655 // Motor output4, bank4
656 if (i == 3) {
657 data.BankUpdateFreq[i] = escFrequence;
662 actSettings->setData(data);
663 addModifiedObject(actSettings, tr("Writing actuator settings"));
665 break;
668 case VehicleConfigurationSource::VEHICLE_HELI:
669 // TODO: Implement settings for Heli vehicle types
670 break;
672 case VehicleConfigurationSource::VEHICLE_SURFACE:
674 ActuatorSettings::DataFields data = actSettings->getData();
676 QList<actuatorChannelSettings> actuatorSettings = m_configSource->getActuatorSettings();
677 for (quint16 i = 0; i < ActuatorSettings::CHANNELMAX_NUMELEM; i++) {
678 data.ChannelType[i] = ActuatorSettings::CHANNELTYPE_PWM;
679 data.ChannelAddr[i] = i;
680 data.ChannelMin[i] = actuatorSettings[i].channelMin;
681 data.ChannelNeutral[i] = actuatorSettings[i].channelNeutral;
682 data.ChannelMax[i] = actuatorSettings[i].channelMax;
685 for (quint16 i = 0; i < ActuatorSettings::BANKUPDATEFREQ_NUMELEM; i++) {
686 data.BankUpdateFreq[i] = servoFrequence;
687 data.BankMode[i] = ActuatorSettings::BANKMODE_PWM;
688 if ((m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_CC) ||
689 (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_CC3D)) {
690 // Motor output4, bank2
691 if (i == 1) {
692 data.BankUpdateFreq[i] = escFrequence;
694 } else if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_REVO
695 || m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_SPARKY2) {
696 // Motor output4, bank3
697 if (i == 1) {
698 data.BankUpdateFreq[i] = escFrequence;
700 } else if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_NANO) {
701 // Motor output4, bank4
702 if (i == 2) {
703 data.BankUpdateFreq[i] = escFrequence;
708 actSettings->setData(data);
709 addModifiedObject(actSettings, tr("Writing actuator settings"));
711 break;
714 default:
715 break;
719 void VehicleConfigurationHelper::applyFlightModeConfiguration()
721 FlightModeSettings *modeSettings = FlightModeSettings::GetInstance(m_uavoManager);
722 ManualControlSettings *controlSettings = ManualControlSettings::GetInstance(m_uavoManager);
724 Q_ASSERT(modeSettings);
725 Q_ASSERT(controlSettings);
727 FlightModeSettings::DataFields data = modeSettings->getData();
728 ManualControlSettings::DataFields data2 = controlSettings->getData();
729 data.Stabilization1Settings[0] = FlightModeSettings::STABILIZATION1SETTINGS_ATTITUDE;
730 data.Stabilization1Settings[1] = FlightModeSettings::STABILIZATION1SETTINGS_ATTITUDE;
731 data.Stabilization1Settings[2] = FlightModeSettings::STABILIZATION1SETTINGS_AXISLOCK;
732 data.Stabilization1Settings[3] = FlightModeSettings::STABILIZATION1SETTINGS_MANUAL;
733 data.Stabilization2Settings[0] = FlightModeSettings::STABILIZATION2SETTINGS_ATTITUDE;
734 data.Stabilization2Settings[1] = FlightModeSettings::STABILIZATION2SETTINGS_ATTITUDE;
735 data.Stabilization2Settings[2] = FlightModeSettings::STABILIZATION2SETTINGS_RATE;
736 data.Stabilization2Settings[3] = FlightModeSettings::STABILIZATION2SETTINGS_MANUAL;
737 data.Stabilization3Settings[0] = FlightModeSettings::STABILIZATION3SETTINGS_RATE;
738 data.Stabilization3Settings[1] = FlightModeSettings::STABILIZATION3SETTINGS_RATE;
739 data.Stabilization3Settings[2] = FlightModeSettings::STABILIZATION3SETTINGS_RATE;
740 data.Stabilization3Settings[3] = FlightModeSettings::STABILIZATION3SETTINGS_MANUAL;
741 data.Stabilization4Settings[0] = FlightModeSettings::STABILIZATION4SETTINGS_ATTITUDE;
742 data.Stabilization4Settings[1] = FlightModeSettings::STABILIZATION4SETTINGS_ATTITUDE;
743 data.Stabilization4Settings[2] = FlightModeSettings::STABILIZATION4SETTINGS_AXISLOCK;
744 data.Stabilization4Settings[3] = FlightModeSettings::STABILIZATION4SETTINGS_CRUISECONTROL;
745 data.Stabilization5Settings[0] = FlightModeSettings::STABILIZATION5SETTINGS_ATTITUDE;
746 data.Stabilization5Settings[1] = FlightModeSettings::STABILIZATION5SETTINGS_ATTITUDE;
747 data.Stabilization5Settings[2] = FlightModeSettings::STABILIZATION5SETTINGS_RATE;
748 data.Stabilization5Settings[3] = FlightModeSettings::STABILIZATION5SETTINGS_CRUISECONTROL;
749 data.Stabilization6Settings[0] = FlightModeSettings::STABILIZATION6SETTINGS_RATE;
750 data.Stabilization6Settings[1] = FlightModeSettings::STABILIZATION6SETTINGS_RATE;
751 data.Stabilization6Settings[2] = FlightModeSettings::STABILIZATION6SETTINGS_RATE;
752 data.Stabilization6Settings[3] = FlightModeSettings::STABILIZATION6SETTINGS_MANUAL;
753 data2.FlightModeNumber = 3;
754 data.FlightModePosition[0] = FlightModeSettings::FLIGHTMODEPOSITION_STABILIZED1;
755 data.FlightModePosition[1] = FlightModeSettings::FLIGHTMODEPOSITION_STABILIZED2;
756 data.FlightModePosition[2] = FlightModeSettings::FLIGHTMODEPOSITION_STABILIZED3;
757 data.FlightModePosition[3] = FlightModeSettings::FLIGHTMODEPOSITION_STABILIZED4;
758 data.FlightModePosition[4] = FlightModeSettings::FLIGHTMODEPOSITION_STABILIZED5;
759 data.FlightModePosition[5] = FlightModeSettings::FLIGHTMODEPOSITION_STABILIZED6;
761 UAVObjectUpdaterHelper updateHelper;
763 modeSettings->setData(data, false);
764 updateHelper.doObjectAndWait(modeSettings);
765 addModifiedObject(modeSettings, tr("Writing flight mode settings 1/2"));
767 controlSettings->setData(data2, false);
768 updateHelper.doObjectAndWait(controlSettings);
769 addModifiedObject(controlSettings, tr("Writing flight mode settings 2/2"));
772 void VehicleConfigurationHelper::applySensorBiasConfiguration()
774 if (m_configSource->isCalibrationPerformed()) {
775 accelGyroBias bias = m_configSource->getCalibrationBias();
776 float G = 9.81f;
778 AccelGyroSettings *accelGyroSettings = AccelGyroSettings::GetInstance(m_uavoManager);
779 Q_ASSERT(accelGyroSettings);
780 AccelGyroSettings::DataFields accelGyroSettingsData = accelGyroSettings->getData();
782 accelGyroSettingsData.accel_bias[AccelGyroSettings::ACCEL_BIAS_X] += bias.m_accelerometerXBias;
783 accelGyroSettingsData.accel_bias[AccelGyroSettings::ACCEL_BIAS_Y] += bias.m_accelerometerYBias;
784 accelGyroSettingsData.accel_bias[AccelGyroSettings::ACCEL_BIAS_Z] += bias.m_accelerometerZBias + G;
785 accelGyroSettingsData.gyro_bias[AccelGyroSettings::GYRO_BIAS_X] = bias.m_gyroXBias;
786 accelGyroSettingsData.gyro_bias[AccelGyroSettings::GYRO_BIAS_Y] = bias.m_gyroYBias;
787 accelGyroSettingsData.gyro_bias[AccelGyroSettings::GYRO_BIAS_Z] = bias.m_gyroZBias;
789 accelGyroSettings->setData(accelGyroSettingsData);
790 addModifiedObject(accelGyroSettings, tr("Writing gyro and accelerometer bias settings"));
792 switch (m_configSource->getControllerType()) {
793 case VehicleConfigurationSource::CONTROLLER_CC:
794 case VehicleConfigurationSource::CONTROLLER_CC3D:
796 AttitudeSettings *copterControlCalibration = AttitudeSettings::GetInstance(m_uavoManager);
797 Q_ASSERT(copterControlCalibration);
798 AttitudeSettings::DataFields data = copterControlCalibration->getData();
800 data.BiasCorrectGyro = AttitudeSettings::BIASCORRECTGYRO_TRUE;
802 copterControlCalibration->setData(data);
803 addModifiedObject(copterControlCalibration, tr("Writing board settings"));
804 break;
806 case VehicleConfigurationSource::CONTROLLER_REVO:
807 case VehicleConfigurationSource::CONTROLLER_NANO:
808 case VehicleConfigurationSource::CONTROLLER_SPARKY2:
810 RevoCalibration *revolutionCalibration = RevoCalibration::GetInstance(m_uavoManager);
811 Q_ASSERT(revolutionCalibration);
812 RevoCalibration::DataFields data = revolutionCalibration->getData();
814 data.BiasCorrectedRaw = RevoCalibration::BIASCORRECTEDRAW_TRUE;
816 revolutionCalibration->setData(data);
817 addModifiedObject(revolutionCalibration, tr("Writing board settings"));
818 break;
820 default:
821 // Something went terribly wrong.
822 break;
827 void VehicleConfigurationHelper::applyStabilizationConfiguration()
829 StabilizationSettings *stabSettings = StabilizationSettings::GetInstance(m_uavoManager);
831 Q_ASSERT(stabSettings);
833 UAVObjectUpdaterHelper updateHelper;
834 StabilizationSettings defaultSettings;
835 stabSettings->setData(defaultSettings.getData(), false);
836 updateHelper.doObjectAndWait(stabSettings);
837 addModifiedObject(stabSettings, tr("Writing stabilization settings"));
840 void VehicleConfigurationHelper::applyMixerConfiguration(mixerChannelSettings channels[])
842 // Set all mixer data
843 MixerSettings *mSettings = MixerSettings::GetInstance(m_uavoManager);
845 Q_ASSERT(mSettings);
847 // Set Mixer types and values
848 QString mixerTypePattern = "Mixer%1Type";
849 QString mixerVectorPattern = "Mixer%1Vector";
850 for (quint32 i = 0; i < ActuatorSettings::CHANNELADDR_NUMELEM; i++) {
851 UAVObjectField *field = mSettings->getField(mixerTypePattern.arg(i + 1));
852 Q_ASSERT(field);
853 field->setValue(field->getOptions().at(channels[i].type));
855 field = mSettings->getField(mixerVectorPattern.arg(i + 1));
856 Q_ASSERT(field);
857 field->setValue((channels[i].throttle1 * 127) / 100, 0);
858 field->setValue((channels[i].throttle2 * 127) / 100, 1);
860 // Normalize mixer values, allow a well balanced mixer saved
861 if (channels[i].roll < 0) {
862 field->setValue(qFloor((double)(channels[i].roll * 127) / 100), 2);
863 } else {
864 field->setValue(qCeil((double)(channels[i].roll * 127) / 100), 2);
867 if (channels[i].pitch < 0) {
868 field->setValue(qFloor((double)(channels[i].pitch * 127) / 100), 3);
869 } else {
870 field->setValue(qCeil((double)(channels[i].pitch * 127) / 100), 3);
873 if (channels[i].yaw < 0) {
874 field->setValue(qFloor((double)(channels[i].yaw * 127) / 100), 4);
875 } else {
876 field->setValue(qCeil((double)(channels[i].yaw * 127) / 100), 4);
880 // Default maxThrottle and minThrottle
881 float maxThrottle = 1;
882 float minThrottle = 0;
885 // Save mixer values for sliders
886 switch (m_configSource->getVehicleType()) {
887 case VehicleConfigurationSource::VEHICLE_MULTI:
889 switch (m_configSource->getVehicleSubType()) {
890 case VehicleConfigurationSource::MULTI_ROTOR_TRI_Y:
891 case VehicleConfigurationSource::MULTI_ROTOR_HEXA:
892 case VehicleConfigurationSource::MULTI_ROTOR_HEXA_H:
893 case VehicleConfigurationSource::MULTI_ROTOR_HEXA_X:
894 mSettings->setMixerValueRoll((qint8)100);
895 mSettings->setMixerValuePitch((qint8)100);
896 mSettings->setMixerValueYaw((qint8)100);
897 break;
898 case VehicleConfigurationSource::MULTI_ROTOR_QUAD_X:
899 mSettings->setMixerValueRoll((qint8)50);
900 mSettings->setMixerValuePitch((qint8)50);
901 mSettings->setMixerValueYaw((qint8)50);
902 break;
903 case VehicleConfigurationSource::MULTI_ROTOR_QUAD_PLUS:
904 mSettings->setMixerValueRoll((qint8)100);
905 mSettings->setMixerValuePitch((qint8)100);
906 mSettings->setMixerValueYaw((qint8)50);
907 break;
908 case VehicleConfigurationSource::MULTI_ROTOR_HEXA_COAX_Y:
909 mSettings->setMixerValueRoll((qint8)86);
910 mSettings->setMixerValuePitch((qint8)100);
911 mSettings->setMixerValueYaw((qint8)100);
912 break;
913 case VehicleConfigurationSource::MULTI_ROTOR_OCTO:
914 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_X:
915 mSettings->setMixerValueRoll((qint8)100);
916 mSettings->setMixerValuePitch((qint8)100);
917 mSettings->setMixerValueYaw((qint8)100);
918 break;
919 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_COAX_X:
920 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_COAX_PLUS:
921 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_V:
922 break;
923 default:
924 break;
926 break;
928 case VehicleConfigurationSource::VEHICLE_FIXEDWING:
929 mSettings->setMixerValueRoll((qint8)100);
930 mSettings->setMixerValuePitch((qint8)100);
931 mSettings->setMixerValueYaw((qint8)100);
932 maxThrottle = 1;
933 break;
934 case VehicleConfigurationSource::VEHICLE_HELI:
935 break;
936 case VehicleConfigurationSource::VEHICLE_SURFACE:
938 switch (m_configSource->getVehicleSubType()) {
939 case VehicleConfigurationSource::GROUNDVEHICLE_MOTORCYCLE:
940 mSettings->setMixerValueRoll((qint8)100);
941 mSettings->setMixerValuePitch((qint8)100);
942 mSettings->setMixerValueYaw((qint8)100);
943 maxThrottle = 1;
944 break;
945 case VehicleConfigurationSource::GROUNDVEHICLE_CAR:
946 mSettings->setMixerValueRoll((qint8)100);
947 mSettings->setMixerValuePitch((qint8)100);
948 mSettings->setMixerValueYaw((qint8)100);
949 maxThrottle = 1;
950 minThrottle = 0;
951 break;
952 case VehicleConfigurationSource::GROUNDVEHICLE_DIFFERENTIAL:
953 mSettings->setMixerValueRoll((qint8)100);
954 mSettings->setMixerValuePitch((qint8)100);
955 mSettings->setMixerValueYaw((qint8)100);
956 maxThrottle = 0.8;
957 minThrottle = 0;
958 break;
959 case VehicleConfigurationSource::GROUNDVEHICLE_BOAT:
960 mSettings->setMixerValueRoll((qint8)100);
961 mSettings->setMixerValuePitch((qint8)100);
962 mSettings->setMixerValueYaw((qint8)100);
963 maxThrottle = 1;
964 minThrottle = 0;
965 break;
966 case VehicleConfigurationSource::GROUNDVEHICLE_DIFFERENTIAL_BOAT:
967 mSettings->setMixerValueRoll((qint8)100);
968 mSettings->setMixerValuePitch((qint8)100);
969 mSettings->setMixerValueYaw((qint8)100);
970 maxThrottle = 0.8;
971 minThrottle = 0;
972 break;
973 default:
974 break;
978 break;
979 default:
980 break;
983 // Apply Throttle curve max 90% for Multis, 100% for FixedWing/car/Motorbike, 80% for Tank
984 QString throttlePattern = "ThrottleCurve%1";
985 for (int i = 1; i <= 2; i++) {
986 UAVObjectField *field = mSettings->getField(throttlePattern.arg(i));
987 Q_ASSERT(field);
988 for (quint32 i = 0; i < field->getNumElements(); i++) {
989 field->setValue(minThrottle + (i * ((maxThrottle - minThrottle) / (field->getNumElements() - 1))), i);
993 // Apply updates
994 UAVObjectUpdaterHelper updateHelper;
995 mSettings->setData(mSettings->getData(), false);
996 updateHelper.doObjectAndWait(mSettings);
997 addModifiedObject(mSettings, tr("Writing mixer settings"));
1000 void VehicleConfigurationHelper::applyMultiGUISettings(SystemSettings::AirframeTypeOptions airframe, GUIConfigDataUnion guiConfig)
1002 SystemSettings *sSettings = SystemSettings::GetInstance(m_uavoManager);
1004 Q_ASSERT(sSettings);
1005 SystemSettings::DataFields data = sSettings->getData();
1006 data.AirframeType = airframe;
1008 for (int i = 0; i < (int)(SystemSettings::GUICONFIGDATA_NUMELEM); i++) {
1009 data.GUIConfigData[i] = guiConfig.UAVObject[i];
1012 UAVObjectUpdaterHelper updateHelper;
1013 sSettings->setData(data, false);
1014 updateHelper.doObjectAndWait(sSettings);
1015 addModifiedObject(sSettings, tr("Writing vehicle settings"));
1018 void VehicleConfigurationHelper::applyManualControlDefaults()
1020 ManualControlSettings *mcSettings = ManualControlSettings::GetInstance(m_uavoManager);
1022 Q_ASSERT(mcSettings);
1023 ManualControlSettings::DataFields cData = mcSettings->getData();
1025 ManualControlSettings::ChannelGroupsOptions channelType = ManualControlSettings::CHANNELGROUPS_PWM;
1026 switch (m_configSource->getInputType()) {
1027 case VehicleConfigurationSource::INPUT_PWM:
1028 channelType = ManualControlSettings::CHANNELGROUPS_PWM;
1029 break;
1030 case VehicleConfigurationSource::INPUT_PPM:
1031 channelType = ManualControlSettings::CHANNELGROUPS_PPM;
1032 break;
1033 case VehicleConfigurationSource::INPUT_SBUS:
1034 channelType = ManualControlSettings::CHANNELGROUPS_SBUS;
1035 break;
1036 case VehicleConfigurationSource::INPUT_DSM:
1037 channelType = ManualControlSettings::CHANNELGROUPS_DSMFLEXIPORT;
1038 break;
1039 case VehicleConfigurationSource::INPUT_SRXL:
1040 channelType = ManualControlSettings::CHANNELGROUPS_SRXL;
1041 break;
1042 case VehicleConfigurationSource::INPUT_HOTT_SUMD:
1043 channelType = ManualControlSettings::CHANNELGROUPS_HOTT;
1044 break;
1045 case VehicleConfigurationSource::INPUT_EXBUS:
1046 channelType = ManualControlSettings::CHANNELGROUPS_EXBUS;
1047 break;
1048 case VehicleConfigurationSource::INPUT_IBUS:
1049 channelType = ManualControlSettings::CHANNELGROUPS_IBUS;
1050 break;
1051 default:
1052 break;
1055 cData.ChannelGroups[ManualControlSettings::CHANNELGROUPS_THROTTLE] = channelType;
1056 cData.ChannelGroups[ManualControlSettings::CHANNELGROUPS_ROLL] = channelType;
1057 cData.ChannelGroups[ManualControlSettings::CHANNELGROUPS_YAW] = channelType;
1058 cData.ChannelGroups[ManualControlSettings::CHANNELGROUPS_PITCH] = channelType;
1059 cData.ChannelGroups[ManualControlSettings::CHANNELGROUPS_FLIGHTMODE] = channelType;
1061 mcSettings->setData(cData);
1062 addModifiedObject(mcSettings, tr("Writing manual control defaults"));
1065 void VehicleConfigurationHelper::applyTemplateSettings()
1067 if (m_configSource->getVehicleTemplate() != NULL) {
1068 QJsonObject *json = m_configSource->getVehicleTemplate();
1069 QList<UAVObject *> updatedObjects;
1070 m_uavoManager->fromJson(*json, &updatedObjects);
1071 foreach(UAVObject * object, updatedObjects) {
1072 UAVDataObject *dataObj = dynamic_cast<UAVDataObject *>(object);
1074 if (dataObj != NULL && isApplicable(dataObj)) {
1075 addModifiedObject(dataObj, tr("Writing template settings for %1").arg(object->getName()));
1081 bool VehicleConfigurationHelper::saveChangesToController(bool save)
1083 qDebug() << "Saving modified objects to controller. " << m_modifiedObjects.count() << " objects in found.";
1084 const int OUTER_TIMEOUT = 3000 * 20; // 10 seconds timeout for saving all objects
1085 const int INNER_TIMEOUT = 2000; // 1 second timeout on every save attempt
1087 ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
1088 Q_ASSERT(pm);
1089 UAVObjectUtilManager *utilMngr = pm->getObject<UAVObjectUtilManager>();
1090 Q_ASSERT(utilMngr);
1092 QTimer outerTimeoutTimer;
1093 outerTimeoutTimer.setSingleShot(true);
1095 QTimer innerTimeoutTimer;
1096 innerTimeoutTimer.setSingleShot(true);
1098 connect(utilMngr, SIGNAL(saveCompleted(int, bool)), this, SLOT(uAVOTransactionCompleted(int, bool)));
1099 connect(&innerTimeoutTimer, SIGNAL(timeout()), &m_eventLoop, SLOT(quit()));
1100 connect(&outerTimeoutTimer, SIGNAL(timeout()), this, SLOT(saveChangesTimeout()));
1102 outerTimeoutTimer.start(OUTER_TIMEOUT);
1103 for (int i = 0; i < m_modifiedObjects.count(); i++) {
1104 QPair<UAVDataObject *, QString> *objPair = m_modifiedObjects.at(i);
1105 m_transactionOK = false;
1106 UAVDataObject *obj = objPair->first;
1107 QString objDescription = objPair->second;
1108 if (UAVObject::GetGcsAccess(obj->getMetadata()) != UAVObject::ACCESS_READONLY && obj->isSettingsObject()) {
1109 emit saveProgress(m_modifiedObjects.count() + 1, ++m_progress, objDescription);
1111 m_currentTransactionObjectID = obj->getObjID();
1113 connect(obj, SIGNAL(transactionCompleted(UAVObject *, bool)), this, SLOT(uAVOTransactionCompleted(UAVObject *, bool)));
1114 while (!m_transactionOK && !m_transactionTimeout) {
1115 // Allow the transaction to take some time
1116 innerTimeoutTimer.start(INNER_TIMEOUT);
1118 // Set object updated
1119 obj->updated();
1120 if (!m_transactionOK) {
1121 m_eventLoop.exec();
1123 innerTimeoutTimer.stop();
1125 disconnect(obj, SIGNAL(transactionCompleted(UAVObject *, bool)), this, SLOT(uAVOTransactionCompleted(UAVObject *, bool)));
1126 if (m_transactionOK) {
1127 qDebug() << "Object " << obj->getName() << " was successfully updated.";
1128 if (save) {
1129 m_transactionOK = false;
1130 m_currentTransactionObjectID = obj->getObjID();
1131 // Try to save until success or timeout
1132 while (!m_transactionOK && !m_transactionTimeout) {
1133 // Allow the transaction to take some time
1134 innerTimeoutTimer.start(INNER_TIMEOUT);
1136 // Persist object in controller
1137 utilMngr->saveObjectToSD(obj);
1138 if (!m_transactionOK) {
1139 m_eventLoop.exec();
1141 innerTimeoutTimer.stop();
1143 m_currentTransactionObjectID = -1;
1147 if (!m_transactionOK) {
1148 qDebug() << "Transaction timed out when trying to save: " << obj->getName();
1149 } else {
1150 qDebug() << "Object " << obj->getName() << " was successfully saved.";
1152 } else {
1153 qDebug() << "Trying to save a UAVDataObject that is read only or is not a settings object.";
1155 if (m_transactionTimeout) {
1156 qDebug() << "Transaction timed out when trying to save " << m_modifiedObjects.count() << " objects.";
1157 break;
1161 outerTimeoutTimer.stop();
1162 disconnect(&outerTimeoutTimer, SIGNAL(timeout()), this, SLOT(saveChangesTimeout()));
1163 disconnect(&innerTimeoutTimer, SIGNAL(timeout()), &m_eventLoop, SLOT(quit()));
1164 disconnect(utilMngr, SIGNAL(saveCompleted(int, bool)), this, SLOT(uAVOTransactionCompleted(int, bool)));
1166 qDebug() << "Finished saving modified objects to controller. Success = " << m_transactionOK;
1168 return m_transactionOK;
1171 void VehicleConfigurationHelper::uAVOTransactionCompleted(int oid, bool success)
1173 if (oid == m_currentTransactionObjectID) {
1174 m_transactionOK = success;
1175 m_eventLoop.quit();
1179 void VehicleConfigurationHelper::uAVOTransactionCompleted(UAVObject *object, bool success)
1181 if (object) {
1182 uAVOTransactionCompleted(object->getObjID(), success);
1186 void VehicleConfigurationHelper::saveChangesTimeout()
1188 m_transactionOK = false;
1189 m_transactionTimeout = true;
1190 m_eventLoop.quit();
1193 void VehicleConfigurationHelper::resetVehicleConfig()
1195 // Reset all vehicle data
1196 MixerSettings *mSettings = MixerSettings::GetInstance(m_uavoManager);
1198 // Reset throttle curves
1199 QString throttlePattern = "ThrottleCurve%1";
1201 for (int i = 1; i <= 2; i++) {
1202 UAVObjectField *field = mSettings->getField(throttlePattern.arg(i));
1203 Q_ASSERT(field);
1204 // Set default curve at 90% max for Multirotors
1205 for (quint32 i = 0; i < field->getNumElements(); i++) {
1206 field->setValue(i * (1.0f / (field->getNumElements() - 1)), i);
1210 // Reset Mixer types and values
1211 QString mixerTypePattern = "Mixer%1Type";
1212 QString mixerVectorPattern = "Mixer%1Vector";
1213 for (int i = 1; i <= 10; i++) {
1214 UAVObjectField *field = mSettings->getField(mixerTypePattern.arg(i));
1215 Q_ASSERT(field);
1216 field->setValue(field->getOptions().at(0));
1218 field = mSettings->getField(mixerVectorPattern.arg(i));
1219 Q_ASSERT(field);
1220 for (quint32 i = 0; i < field->getNumElements(); i++) {
1221 field->setValue(0, i);
1225 // Apply updates
1226 // mSettings->setData(mSettings->getData());
1227 addModifiedObject(mSettings, tr("Preparing mixer settings"));
1230 void VehicleConfigurationHelper::resetGUIData()
1232 SystemSettings *sSettings = SystemSettings::GetInstance(m_uavoManager);
1234 Q_ASSERT(sSettings);
1235 SystemSettings::DataFields data = sSettings->getData();
1236 data.AirframeType = SystemSettings::AIRFRAMETYPE_CUSTOM;
1237 for (quint32 i = 0; i < SystemSettings::GUICONFIGDATA_NUMELEM; i++) {
1238 data.GUIConfigData[i] = 0;
1240 sSettings->setData(data);
1241 addModifiedObject(sSettings, tr("Preparing vehicle settings"));
1245 void VehicleConfigurationHelper::setupTriCopter()
1247 // Typical vehicle setup
1248 // 1. Setup mixer data
1249 // 2. Setup GUI data
1250 // 3. Apply changes
1252 mixerChannelSettings channels[ActuatorSettings::CHANNELADDR_NUMELEM];
1253 GUIConfigDataUnion guiSettings = getGUIConfigData();
1255 channels[0].type = MIXER_TYPE_MOTOR;
1256 channels[0].throttle1 = 100;
1257 channels[0].throttle2 = 0;
1258 channels[0].roll = 100;
1259 channels[0].pitch = 50;
1260 channels[0].yaw = 0;
1262 channels[1].type = MIXER_TYPE_MOTOR;
1263 channels[1].throttle1 = 100;
1264 channels[1].throttle2 = 0;
1265 channels[1].roll = -100;
1266 channels[1].pitch = 50;
1267 channels[1].yaw = 0;
1269 channels[2].type = MIXER_TYPE_MOTOR;
1270 channels[2].throttle1 = 100;
1271 channels[2].throttle2 = 0;
1272 channels[2].roll = 0;
1273 channels[2].pitch = -100;
1274 channels[2].yaw = 0;
1276 channels[3].type = MIXER_TYPE_SERVO;
1277 channels[3].throttle1 = 0;
1278 channels[3].throttle2 = 0;
1279 channels[3].roll = 0;
1280 channels[3].pitch = 0;
1281 channels[3].yaw = 100;
1283 guiSettings.multi.VTOLMotorNW = 1;
1284 guiSettings.multi.VTOLMotorNE = 2;
1285 guiSettings.multi.VTOLMotorS = 3;
1286 guiSettings.multi.TRIYaw = 4;
1288 applyMixerConfiguration(channels);
1289 applyMultiGUISettings(SystemSettings::AIRFRAMETYPE_TRI, guiSettings);
1292 GUIConfigDataUnion VehicleConfigurationHelper::getGUIConfigData()
1294 GUIConfigDataUnion configData;
1296 for (int i = 0; i < (int)(SystemSettings::GUICONFIGDATA_NUMELEM); i++) {
1297 configData.UAVObject[i] = 0; // systemSettingsData.GUIConfigData[i];
1300 return configData;
1303 void VehicleConfigurationHelper::setupQuadCopter()
1305 mixerChannelSettings channels[ActuatorSettings::CHANNELADDR_NUMELEM];
1306 GUIConfigDataUnion guiSettings = getGUIConfigData();
1307 SystemSettings::AirframeTypeOptions frame = SystemSettings::AIRFRAMETYPE_QUADX;
1309 switch (m_configSource->getVehicleSubType()) {
1310 case VehicleConfigurationSource::MULTI_ROTOR_QUAD_PLUS:
1312 frame = SystemSettings::AIRFRAMETYPE_QUADP;
1313 channels[0].type = MIXER_TYPE_MOTOR;
1314 channels[0].throttle1 = 100;
1315 channels[0].throttle2 = 0;
1316 channels[0].roll = 0;
1317 channels[0].pitch = 100;
1318 channels[0].yaw = -50;
1320 channels[1].type = MIXER_TYPE_MOTOR;
1321 channels[1].throttle1 = 100;
1322 channels[1].throttle2 = 0;
1323 channels[1].roll = -100;
1324 channels[1].pitch = 0;
1325 channels[1].yaw = 50;
1327 channels[2].type = MIXER_TYPE_MOTOR;
1328 channels[2].throttle1 = 100;
1329 channels[2].throttle2 = 0;
1330 channels[2].roll = 0;
1331 channels[2].pitch = -100;
1332 channels[2].yaw = -50;
1334 channels[3].type = MIXER_TYPE_MOTOR;
1335 channels[3].throttle1 = 100;
1336 channels[3].throttle2 = 0;
1337 channels[3].roll = 100;
1338 channels[3].pitch = 0;
1339 channels[3].yaw = 50;
1341 guiSettings.multi.VTOLMotorN = 1;
1342 guiSettings.multi.VTOLMotorE = 2;
1343 guiSettings.multi.VTOLMotorS = 3;
1344 guiSettings.multi.VTOLMotorW = 4;
1346 break;
1348 case VehicleConfigurationSource::MULTI_ROTOR_QUAD_X:
1350 frame = SystemSettings::AIRFRAMETYPE_QUADX;
1351 channels[0].type = MIXER_TYPE_MOTOR;
1352 channels[0].throttle1 = 100;
1353 channels[0].throttle2 = 0;
1354 channels[0].roll = 50;
1355 channels[0].pitch = 50;
1356 channels[0].yaw = -50;
1358 channels[1].type = MIXER_TYPE_MOTOR;
1359 channels[1].throttle1 = 100;
1360 channels[1].throttle2 = 0;
1361 channels[1].roll = -50;
1362 channels[1].pitch = 50;
1363 channels[1].yaw = 50;
1365 channels[2].type = MIXER_TYPE_MOTOR;
1366 channels[2].throttle1 = 100;
1367 channels[2].throttle2 = 0;
1368 channels[2].roll = -50;
1369 channels[2].pitch = -50;
1370 channels[2].yaw = -50;
1372 channels[3].type = MIXER_TYPE_MOTOR;
1373 channels[3].throttle1 = 100;
1374 channels[3].throttle2 = 0;
1375 channels[3].roll = 50;
1376 channels[3].pitch = -50;
1377 channels[3].yaw = 50;
1379 guiSettings.multi.VTOLMotorNW = 1;
1380 guiSettings.multi.VTOLMotorNE = 2;
1381 guiSettings.multi.VTOLMotorSE = 3;
1382 guiSettings.multi.VTOLMotorSW = 4;
1384 break;
1386 default:
1387 break;
1389 applyMixerConfiguration(channels);
1390 applyMultiGUISettings(frame, guiSettings);
1393 void VehicleConfigurationHelper::setupHexaCopter()
1395 mixerChannelSettings channels[ActuatorSettings::CHANNELADDR_NUMELEM];
1396 GUIConfigDataUnion guiSettings = getGUIConfigData();
1397 SystemSettings::AirframeTypeOptions frame = SystemSettings::AIRFRAMETYPE_HEXA;
1399 switch (m_configSource->getVehicleSubType()) {
1400 case VehicleConfigurationSource::MULTI_ROTOR_HEXA:
1402 frame = SystemSettings::AIRFRAMETYPE_HEXA;
1403 // HexaPlus according to new mixer table and pitch-roll-yaw mixing at 100%
1404 // Pitch Roll Yaw
1405 // M1 { 1 , 0 , -1 },
1406 // M2 { 0.5, -1, 1 },
1407 // M3 { -0.5, -1, -1 },
1408 // M4 { -1 , 0 , 1 },
1409 // M5 { -0.5, 1 , -1 },
1410 // M6 { 0.5, 1 , 1 },
1411 channels[0].type = MIXER_TYPE_MOTOR;
1412 channels[0].throttle1 = 100;
1413 channels[0].throttle2 = 0;
1414 channels[0].roll = 0;
1415 channels[0].pitch = 100;
1416 channels[0].yaw = -100;
1418 channels[1].type = MIXER_TYPE_MOTOR;
1419 channels[1].throttle1 = 100;
1420 channels[1].throttle2 = 0;
1421 channels[1].roll = -100;
1422 channels[1].pitch = 50;
1423 channels[1].yaw = 100;
1425 channels[2].type = MIXER_TYPE_MOTOR;
1426 channels[2].throttle1 = 100;
1427 channels[2].throttle2 = 0;
1428 channels[2].roll = -100;
1429 channels[2].pitch = -50;
1430 channels[2].yaw = -100;
1432 channels[3].type = MIXER_TYPE_MOTOR;
1433 channels[3].throttle1 = 100;
1434 channels[3].throttle2 = 0;
1435 channels[3].roll = 0;
1436 channels[3].pitch = -100;
1437 channels[3].yaw = 100;
1439 channels[4].type = MIXER_TYPE_MOTOR;
1440 channels[4].throttle1 = 100;
1441 channels[4].throttle2 = 0;
1442 channels[4].roll = 100;
1443 channels[4].pitch = -50;
1444 channels[4].yaw = -100;
1446 channels[5].type = MIXER_TYPE_MOTOR;
1447 channels[5].throttle1 = 100;
1448 channels[5].throttle2 = 0;
1449 channels[5].roll = 100;
1450 channels[5].pitch = 50;
1451 channels[5].yaw = 100;
1453 guiSettings.multi.VTOLMotorN = 1;
1454 guiSettings.multi.VTOLMotorNE = 2;
1455 guiSettings.multi.VTOLMotorSE = 3;
1456 guiSettings.multi.VTOLMotorS = 4;
1457 guiSettings.multi.VTOLMotorSW = 5;
1458 guiSettings.multi.VTOLMotorNW = 6;
1460 break;
1462 case VehicleConfigurationSource::MULTI_ROTOR_HEXA_COAX_Y:
1464 frame = SystemSettings::AIRFRAMETYPE_HEXACOAX;
1466 channels[0].type = MIXER_TYPE_MOTOR;
1467 channels[0].throttle1 = 100;
1468 channels[0].throttle2 = 0;
1469 channels[0].roll = 100;
1470 channels[0].pitch = 25;
1471 channels[0].yaw = -66;
1474 channels[1].type = MIXER_TYPE_MOTOR;
1475 channels[1].throttle1 = 100;
1476 channels[1].throttle2 = 0;
1477 channels[1].roll = 100;
1478 channels[1].pitch = 25;
1479 channels[1].yaw = 66;
1481 channels[2].type = MIXER_TYPE_MOTOR;
1482 channels[2].throttle1 = 100;
1483 channels[2].throttle2 = 0;
1484 channels[2].roll = -100;
1485 channels[2].pitch = 25;
1486 channels[2].yaw = -66;
1488 channels[3].type = MIXER_TYPE_MOTOR;
1489 channels[3].throttle1 = 100;
1490 channels[3].throttle2 = 0;
1491 channels[3].roll = -100;
1492 channels[3].pitch = 25;
1493 channels[3].yaw = 66;
1495 channels[4].type = MIXER_TYPE_MOTOR;
1496 channels[4].throttle1 = 100;
1497 channels[4].throttle2 = 0;
1498 channels[4].roll = 0;
1499 channels[4].pitch = -50;
1500 channels[4].yaw = -66;
1502 channels[5].type = MIXER_TYPE_MOTOR;
1503 channels[5].throttle1 = 100;
1504 channels[5].throttle2 = 0;
1505 channels[5].roll = 0;
1506 channels[5].pitch = -50;
1507 channels[5].yaw = 66;
1509 guiSettings.multi.VTOLMotorNW = 1;
1510 guiSettings.multi.VTOLMotorW = 2;
1511 guiSettings.multi.VTOLMotorNE = 3;
1512 guiSettings.multi.VTOLMotorE = 4;
1513 guiSettings.multi.VTOLMotorS = 5;
1514 guiSettings.multi.VTOLMotorSE = 6;
1516 break;
1518 case VehicleConfigurationSource::MULTI_ROTOR_HEXA_H:
1520 frame = SystemSettings::AIRFRAMETYPE_HEXAH;
1521 // HexaH according to new mixer table and pitch-roll-yaw mixing at 100%
1522 // Pitch Roll Yaw
1523 // M1 { 1 , -0.5, -0.5 },
1524 // M2 { 0 , -1 , 1 },
1525 // M3 { -1 , -0.5, -0.5 },
1526 // M4 { -1 , 0.5, 0.5 },
1527 // M5 { 0 , 1 , -1 },
1528 // M6 { 1 , 0.5, 0.5 },
1529 channels[0].type = MIXER_TYPE_MOTOR;
1530 channels[0].throttle1 = 100;
1531 channels[0].throttle2 = 0;
1532 channels[0].roll = -50;
1533 channels[0].pitch = 100;
1534 channels[0].yaw = -50;
1536 channels[1].type = MIXER_TYPE_MOTOR;
1537 channels[1].throttle1 = 100;
1538 channels[1].throttle2 = 0;
1539 channels[1].roll = -100;
1540 channels[1].pitch = 0;
1541 channels[1].yaw = 100;
1543 channels[2].type = MIXER_TYPE_MOTOR;
1544 channels[2].throttle1 = 100;
1545 channels[2].throttle2 = 0;
1546 channels[2].roll = -50;
1547 channels[2].pitch = -100;
1548 channels[2].yaw = -50;
1550 channels[3].type = MIXER_TYPE_MOTOR;
1551 channels[3].throttle1 = 100;
1552 channels[3].throttle2 = 0;
1553 channels[3].roll = 50;
1554 channels[3].pitch = -100;
1555 channels[3].yaw = 50;
1557 channels[4].type = MIXER_TYPE_MOTOR;
1558 channels[4].throttle1 = 100;
1559 channels[4].throttle2 = 0;
1560 channels[4].roll = 100;
1561 channels[4].pitch = 0;
1562 channels[4].yaw = -100;
1564 channels[5].type = MIXER_TYPE_MOTOR;
1565 channels[5].throttle1 = 100;
1566 channels[5].throttle2 = 0;
1567 channels[5].roll = 50;
1568 channels[5].pitch = 100;
1569 channels[5].yaw = 50;
1571 guiSettings.multi.VTOLMotorNE = 1;
1572 guiSettings.multi.VTOLMotorE = 2;
1573 guiSettings.multi.VTOLMotorSE = 3;
1574 guiSettings.multi.VTOLMotorSW = 4;
1575 guiSettings.multi.VTOLMotorW = 5;
1576 guiSettings.multi.VTOLMotorNW = 6;
1578 break;
1580 case VehicleConfigurationSource::MULTI_ROTOR_HEXA_X:
1582 frame = SystemSettings::AIRFRAMETYPE_HEXAX;
1583 // HexaX according to new mixer table and pitch-roll-yaw mixing at 100%
1584 // Pitch Roll Yaw
1585 // M1 { 1, -0.5, -1 },
1586 // M2 { 0, -1 , 1 },
1587 // M3 { -1, -0.5, -1 },
1588 // M4 { -1, 0.5, 1 },
1589 // M5 { 0, 1 , -1 },
1590 // M6 { 1, 0.5, 1 },
1591 channels[0].type = MIXER_TYPE_MOTOR;
1592 channels[0].throttle1 = 100;
1593 channels[0].throttle2 = 0;
1594 channels[0].roll = -50;
1595 channels[0].pitch = 100;
1596 channels[0].yaw = -100;
1598 channels[1].type = MIXER_TYPE_MOTOR;
1599 channels[1].throttle1 = 100;
1600 channels[1].throttle2 = 0;
1601 channels[1].roll = -100;
1602 channels[1].pitch = 0;
1603 channels[1].yaw = 100;
1605 channels[2].type = MIXER_TYPE_MOTOR;
1606 channels[2].throttle1 = 100;
1607 channels[2].throttle2 = 0;
1608 channels[2].roll = -50;
1609 channels[2].pitch = -100;
1610 channels[2].yaw = -100;
1612 channels[3].type = MIXER_TYPE_MOTOR;
1613 channels[3].throttle1 = 100;
1614 channels[3].throttle2 = 0;
1615 channels[3].roll = 50;
1616 channels[3].pitch = -100;
1617 channels[3].yaw = 100;
1619 channels[4].type = MIXER_TYPE_MOTOR;
1620 channels[4].throttle1 = 100;
1621 channels[4].throttle2 = 0;
1622 channels[4].roll = 100;
1623 channels[4].pitch = 0;
1624 channels[4].yaw = -100;
1626 channels[5].type = MIXER_TYPE_MOTOR;
1627 channels[5].throttle1 = 100;
1628 channels[5].throttle2 = 0;
1629 channels[5].roll = 50;
1630 channels[5].pitch = 100;
1631 channels[5].yaw = 100;
1633 guiSettings.multi.VTOLMotorNE = 1;
1634 guiSettings.multi.VTOLMotorE = 2;
1635 guiSettings.multi.VTOLMotorSE = 3;
1636 guiSettings.multi.VTOLMotorSW = 4;
1637 guiSettings.multi.VTOLMotorW = 5;
1638 guiSettings.multi.VTOLMotorNW = 6;
1640 break;
1642 default:
1643 break;
1645 applyMixerConfiguration(channels);
1646 applyMultiGUISettings(frame, guiSettings);
1649 void VehicleConfigurationHelper::setupOctoCopter()
1651 mixerChannelSettings channels[ActuatorSettings::CHANNELADDR_NUMELEM];
1652 GUIConfigDataUnion guiSettings = getGUIConfigData();
1653 SystemSettings::AirframeTypeOptions frame = SystemSettings::AIRFRAMETYPE_OCTO;
1655 switch (m_configSource->getVehicleSubType()) {
1656 case VehicleConfigurationSource::MULTI_ROTOR_OCTO:
1658 frame = SystemSettings::AIRFRAMETYPE_OCTO;
1659 // OctoP according to new mixer table and pitch-roll-yaw mixing at 100%
1660 // Pitch Roll Yaw
1661 // M1{ 1 , 0 , -1 },
1662 // M2{ 0.71,-0.71, 1 },
1663 // M3{ 0 ,-1 , -1 },
1664 // M4{ -0.71,-0.71, 1 },
1665 // M5{ -1 , 0 , -1 },
1666 // M6{ -0.71, 0.71, 1 },
1667 // M7{ 0 , 1 , -1 },
1668 // M8{ 0.71, 0.71, 1 }
1669 channels[0].type = MIXER_TYPE_MOTOR;
1670 channels[0].throttle1 = 100;
1671 channels[0].throttle2 = 0;
1672 channels[0].roll = 0;
1673 channels[0].pitch = 100;
1674 channels[0].yaw = -100;
1676 channels[1].type = MIXER_TYPE_MOTOR;
1677 channels[1].throttle1 = 100;
1678 channels[1].throttle2 = 0;
1679 channels[1].roll = -71;
1680 channels[1].pitch = 71;
1681 channels[1].yaw = 100;
1683 channels[2].type = MIXER_TYPE_MOTOR;
1684 channels[2].throttle1 = 100;
1685 channels[2].throttle2 = 0;
1686 channels[2].roll = -71;
1687 channels[2].pitch = 0;
1688 channels[2].yaw = -100;
1690 channels[3].type = MIXER_TYPE_MOTOR;
1691 channels[3].throttle1 = 100;
1692 channels[3].throttle2 = 0;
1693 channels[3].roll = -71;
1694 channels[3].pitch = -71;
1695 channels[3].yaw = 100;
1697 channels[4].type = MIXER_TYPE_MOTOR;
1698 channels[4].throttle1 = 100;
1699 channels[4].throttle2 = 0;
1700 channels[4].roll = 0;
1701 channels[4].pitch = -100;
1702 channels[4].yaw = -100;
1704 channels[5].type = MIXER_TYPE_MOTOR;
1705 channels[5].throttle1 = 100;
1706 channels[5].throttle2 = 0;
1707 channels[5].roll = 71;
1708 channels[5].pitch = -71;
1709 channels[5].yaw = 100;
1711 channels[6].type = MIXER_TYPE_MOTOR;
1712 channels[6].throttle1 = 100;
1713 channels[6].throttle2 = 0;
1714 channels[6].roll = 100;
1715 channels[6].pitch = 0;
1716 channels[6].yaw = -100;
1718 channels[7].type = MIXER_TYPE_MOTOR;
1719 channels[7].throttle1 = 100;
1720 channels[7].throttle2 = 0;
1721 channels[7].roll = 71;
1722 channels[7].pitch = 71;
1723 channels[7].yaw = 100;
1725 guiSettings.multi.VTOLMotorN = 1;
1726 guiSettings.multi.VTOLMotorNE = 2;
1727 guiSettings.multi.VTOLMotorE = 3;
1728 guiSettings.multi.VTOLMotorSE = 4;
1729 guiSettings.multi.VTOLMotorS = 5;
1730 guiSettings.multi.VTOLMotorSW = 6;
1731 guiSettings.multi.VTOLMotorW = 7;
1732 guiSettings.multi.VTOLMotorNW = 8;
1734 break;
1736 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_X:
1738 frame = SystemSettings::AIRFRAMETYPE_OCTOX;
1739 // OctoX according to new mixer table and pitch-roll-yaw mixing at 100%
1740 // Pitch Roll Yaw
1741 // M1{ 1 ,-0.41, -1 },
1742 // M2{ 0.41, -1 , 1 },
1743 // M3{ -0.41, -1 , -1 },
1744 // M4{ -1 ,-0.41, 1 },
1745 // M5{ -1 , 0.41, -1 },
1746 // M6{ -0.41, 1 , 1 },
1747 // M7{ 0.41, 1 , -1 },
1748 // M8{ 1 , 0.41, 1 }
1749 channels[0].type = MIXER_TYPE_MOTOR;
1750 channels[0].throttle1 = 100;
1751 channels[0].throttle2 = 0;
1752 channels[0].roll = -41;
1753 channels[0].pitch = 100;
1754 channels[0].yaw = -100;
1756 channels[1].type = MIXER_TYPE_MOTOR;
1757 channels[1].throttle1 = 100;
1758 channels[1].throttle2 = 0;
1759 channels[1].roll = -100;
1760 channels[1].pitch = 41;
1761 channels[1].yaw = 100;
1763 channels[2].type = MIXER_TYPE_MOTOR;
1764 channels[2].throttle1 = 100;
1765 channels[2].throttle2 = 0;
1766 channels[2].roll = -100;
1767 channels[2].pitch = -41;
1768 channels[2].yaw = -100;
1770 channels[3].type = MIXER_TYPE_MOTOR;
1771 channels[3].throttle1 = 100;
1772 channels[3].throttle2 = 0;
1773 channels[3].roll = -41;
1774 channels[3].pitch = -100;
1775 channels[3].yaw = 100;
1777 channels[4].type = MIXER_TYPE_MOTOR;
1778 channels[4].throttle1 = 100;
1779 channels[4].throttle2 = 0;
1780 channels[4].roll = 41;
1781 channels[4].pitch = -100;
1782 channels[4].yaw = -100;
1784 channels[5].type = MIXER_TYPE_MOTOR;
1785 channels[5].throttle1 = 100;
1786 channels[5].throttle2 = 0;
1787 channels[5].roll = 100;
1788 channels[5].pitch = -41;
1789 channels[5].yaw = 100;
1791 channels[6].type = MIXER_TYPE_MOTOR;
1792 channels[6].throttle1 = 100;
1793 channels[6].throttle2 = 0;
1794 channels[6].roll = 100;
1795 channels[6].pitch = 41;
1796 channels[6].yaw = -100;
1798 channels[7].type = MIXER_TYPE_MOTOR;
1799 channels[7].throttle1 = 100;
1800 channels[7].throttle2 = 0;
1801 channels[7].roll = 41;
1802 channels[7].pitch = 100;
1803 channels[7].yaw = 100;
1805 guiSettings.multi.VTOLMotorNNE = 1;
1806 guiSettings.multi.VTOLMotorENE = 2;
1807 guiSettings.multi.VTOLMotorESE = 3;
1808 guiSettings.multi.VTOLMotorSSE = 4;
1809 guiSettings.multi.VTOLMotorSSW = 5;
1810 guiSettings.multi.VTOLMotorWSW = 6;
1811 guiSettings.multi.VTOLMotorWNW = 7;
1812 guiSettings.multi.VTOLMotorNNW = 8;
1814 break;
1816 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_COAX_X:
1818 frame = SystemSettings::AIRFRAMETYPE_OCTOCOAXX;
1820 channels[0].type = MIXER_TYPE_MOTOR;
1821 channels[0].throttle1 = 100;
1822 channels[0].throttle2 = 0;
1823 channels[0].roll = 50;
1824 channels[0].pitch = 50;
1825 channels[0].yaw = -50;
1827 channels[1].type = MIXER_TYPE_MOTOR;
1828 channels[1].throttle1 = 100;
1829 channels[1].throttle2 = 0;
1830 channels[1].roll = 50;
1831 channels[1].pitch = 50;
1832 channels[1].yaw = 50;
1834 channels[2].type = MIXER_TYPE_MOTOR;
1835 channels[2].throttle1 = 100;
1836 channels[2].throttle2 = 0;
1837 channels[2].roll = -50;
1838 channels[2].pitch = 50;
1839 channels[2].yaw = -50;
1841 channels[3].type = MIXER_TYPE_MOTOR;
1842 channels[3].throttle1 = 100;
1843 channels[3].throttle2 = 0;
1844 channels[3].roll = -50;
1845 channels[3].pitch = 50;
1846 channels[3].yaw = 50;
1848 channels[4].type = MIXER_TYPE_MOTOR;
1849 channels[4].throttle1 = 100;
1850 channels[4].throttle2 = 0;
1851 channels[4].roll = -50;
1852 channels[4].pitch = -50;
1853 channels[4].yaw = -50;
1855 channels[5].type = MIXER_TYPE_MOTOR;
1856 channels[5].throttle1 = 100;
1857 channels[5].throttle2 = 0;
1858 channels[5].roll = -50;
1859 channels[5].pitch = -50;
1860 channels[5].yaw = 50;
1862 channels[6].type = MIXER_TYPE_MOTOR;
1863 channels[6].throttle1 = 100;
1864 channels[6].throttle2 = 0;
1865 channels[6].roll = 50;
1866 channels[6].pitch = -50;
1867 channels[6].yaw = -50;
1869 channels[7].type = MIXER_TYPE_MOTOR;
1870 channels[7].throttle1 = 100;
1871 channels[7].throttle2 = 0;
1872 channels[7].roll = 50;
1873 channels[7].pitch = -50;
1874 channels[7].yaw = 50;
1876 guiSettings.multi.VTOLMotorNW = 1;
1877 guiSettings.multi.VTOLMotorN = 2;
1878 guiSettings.multi.VTOLMotorNE = 3;
1879 guiSettings.multi.VTOLMotorE = 4;
1880 guiSettings.multi.VTOLMotorSE = 5;
1881 guiSettings.multi.VTOLMotorS = 6;
1882 guiSettings.multi.VTOLMotorSW = 7;
1883 guiSettings.multi.VTOLMotorW = 8;
1885 break;
1887 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_COAX_PLUS:
1889 frame = SystemSettings::AIRFRAMETYPE_OCTOCOAXP;
1891 channels[0].type = MIXER_TYPE_MOTOR;
1892 channels[0].throttle1 = 100;
1893 channels[0].throttle2 = 0;
1894 channels[0].roll = 0;
1895 channels[0].pitch = 100;
1896 channels[0].yaw = -50;
1898 channels[1].type = MIXER_TYPE_MOTOR;
1899 channels[1].throttle1 = 100;
1900 channels[1].throttle2 = 0;
1901 channels[1].roll = 0;
1902 channels[1].pitch = 100;
1903 channels[1].yaw = 50;
1905 channels[2].type = MIXER_TYPE_MOTOR;
1906 channels[2].throttle1 = 100;
1907 channels[2].throttle2 = 0;
1908 channels[2].roll = -100;
1909 channels[2].pitch = 0;
1910 channels[2].yaw = -50;
1912 channels[3].type = MIXER_TYPE_MOTOR;
1913 channels[3].throttle1 = 100;
1914 channels[3].throttle2 = 0;
1915 channels[3].roll = -100;
1916 channels[3].pitch = 0;
1917 channels[3].yaw = 50;
1919 channels[4].type = MIXER_TYPE_MOTOR;
1920 channels[4].throttle1 = 100;
1921 channels[4].throttle2 = 0;
1922 channels[4].roll = 0;
1923 channels[4].pitch = -100;
1924 channels[4].yaw = -50;
1926 channels[5].type = MIXER_TYPE_MOTOR;
1927 channels[5].throttle1 = 100;
1928 channels[5].throttle2 = 0;
1929 channels[5].roll = 0;
1930 channels[5].pitch = -100;
1931 channels[5].yaw = 50;
1933 channels[6].type = MIXER_TYPE_MOTOR;
1934 channels[6].throttle1 = 100;
1935 channels[6].throttle2 = 0;
1936 channels[6].roll = 100;
1937 channels[6].pitch = 0;
1938 channels[6].yaw = -50;
1940 channels[7].type = MIXER_TYPE_MOTOR;
1941 channels[7].throttle1 = 100;
1942 channels[7].throttle2 = 0;
1943 channels[7].roll = 100;
1944 channels[7].pitch = 0;
1945 channels[7].yaw = 50;
1947 guiSettings.multi.VTOLMotorN = 1;
1948 guiSettings.multi.VTOLMotorNE = 2;
1949 guiSettings.multi.VTOLMotorE = 3;
1950 guiSettings.multi.VTOLMotorSE = 4;
1951 guiSettings.multi.VTOLMotorS = 5;
1953 guiSettings.multi.VTOLMotorSW = 6;
1954 guiSettings.multi.VTOLMotorW = 7;
1955 guiSettings.multi.VTOLMotorNW = 8;
1957 break;
1959 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_V:
1961 frame = SystemSettings::AIRFRAMETYPE_OCTOV;
1962 channels[0].type = MIXER_TYPE_MOTOR;
1963 channels[0].throttle1 = 100;
1964 channels[0].throttle2 = 0;
1965 channels[0].roll = -25;
1966 channels[0].pitch = 8;
1967 channels[0].yaw = -25;
1969 channels[1].type = MIXER_TYPE_MOTOR;
1970 channels[1].throttle1 = 100;
1971 channels[1].throttle2 = 0;
1972 channels[1].roll = -25;
1973 channels[1].pitch = 25;
1974 channels[1].yaw = 25;
1976 channels[2].type = MIXER_TYPE_MOTOR;
1977 channels[2].throttle1 = 100;
1978 channels[2].throttle2 = 0;
1979 channels[2].roll = -25;
1980 channels[2].pitch = -25;
1981 channels[2].yaw = -25;
1983 channels[3].type = MIXER_TYPE_MOTOR;
1984 channels[3].throttle1 = 100;
1985 channels[3].throttle2 = 0;
1986 channels[3].roll = -25;
1987 channels[3].pitch = -8;
1988 channels[3].yaw = 25;
1990 channels[4].type = MIXER_TYPE_MOTOR;
1991 channels[4].throttle1 = 100;
1992 channels[4].throttle2 = 0;
1993 channels[4].roll = 25;
1994 channels[4].pitch = -8;
1995 channels[4].yaw = -25;
1997 channels[5].type = MIXER_TYPE_MOTOR;
1998 channels[5].throttle1 = 100;
1999 channels[5].throttle2 = 0;
2000 channels[5].roll = 25;
2001 channels[5].pitch = -25;
2002 channels[5].yaw = 25;
2004 channels[6].type = MIXER_TYPE_MOTOR;
2005 channels[6].throttle1 = 100;
2006 channels[6].throttle2 = 0;
2007 channels[6].roll = 25;
2008 channels[6].pitch = 25;
2009 channels[6].yaw = -25;
2011 channels[7].type = MIXER_TYPE_MOTOR;
2012 channels[7].throttle1 = 100;
2013 channels[7].throttle2 = 0;
2014 channels[7].roll = 25;
2015 channels[7].pitch = 8;
2016 channels[7].yaw = 25;
2018 guiSettings.multi.VTOLMotorN = 1;
2019 guiSettings.multi.VTOLMotorNE = 2;
2020 guiSettings.multi.VTOLMotorE = 3;
2021 guiSettings.multi.VTOLMotorSE = 4;
2022 guiSettings.multi.VTOLMotorS = 5;
2023 guiSettings.multi.VTOLMotorSW = 6;
2024 guiSettings.multi.VTOLMotorW = 7;
2025 guiSettings.multi.VTOLMotorNW = 8;
2027 break;
2029 default:
2030 break;
2033 applyMixerConfiguration(channels);
2034 applyMultiGUISettings(frame, guiSettings);
2037 void VehicleConfigurationHelper::setupElevon()
2039 mixerChannelSettings channels[ActuatorSettings::CHANNELADDR_NUMELEM];
2040 GUIConfigDataUnion guiSettings = getGUIConfigData();
2042 // Motor (Chan 4)
2043 channels[3].type = MIXER_TYPE_MOTOR;
2044 channels[3].throttle1 = 100;
2045 channels[3].throttle2 = 0;
2046 channels[3].roll = 0;
2047 channels[3].pitch = 0;
2048 channels[3].yaw = 0;
2050 // Elevon Servo 1 (Chan 1)
2051 channels[0].type = MIXER_TYPE_SERVO;
2052 channels[0].throttle1 = 0;
2053 channels[0].throttle2 = 0;
2054 channels[0].roll = 100;
2055 channels[0].pitch = -100;
2056 channels[0].yaw = 0;
2058 // Elevon Servo 2 (Chan 2)
2059 channels[1].type = MIXER_TYPE_SERVO;
2060 channels[1].throttle1 = 0;
2061 channels[1].throttle2 = 0;
2062 channels[1].roll = 100;
2063 channels[1].pitch = 100;
2064 channels[1].yaw = 0;
2066 guiSettings.fixedwing.FixedWingThrottle = 4;
2067 guiSettings.fixedwing.FixedWingRoll1 = 1;
2068 guiSettings.fixedwing.FixedWingRoll2 = 2;
2070 applyMixerConfiguration(channels);
2071 applyMultiGUISettings(SystemSettings::AIRFRAMETYPE_FIXEDWINGELEVON, guiSettings);
2074 void VehicleConfigurationHelper::setupDualAileron()
2076 // Typical vehicle setup
2077 // 1. Setup mixer data
2078 // 2. Setup GUI data
2079 // 3. Apply changes
2081 mixerChannelSettings channels[ActuatorSettings::CHANNELADDR_NUMELEM];
2082 GUIConfigDataUnion guiSettings = getGUIConfigData();
2084 // Motor (Chan 4)
2085 channels[3].type = MIXER_TYPE_MOTOR;
2086 channels[3].throttle1 = 100;
2087 channels[3].throttle2 = 0;
2088 channels[3].roll = 0;
2089 channels[3].pitch = 0;
2090 channels[3].yaw = 0;
2092 // Aileron Servo 1 (Chan 1)
2093 channels[0].type = MIXER_TYPE_SERVO;
2094 channels[0].throttle1 = 0;
2095 channels[0].throttle2 = 0;
2096 channels[0].roll = 100;
2097 channels[0].pitch = 0;
2098 channels[0].yaw = 0;
2100 // Aileron Servo 2 (Chan 6)
2101 channels[5].type = MIXER_TYPE_SERVO;
2102 channels[5].throttle1 = 0;
2103 channels[5].throttle2 = 0;
2104 channels[5].roll = 100;
2105 channels[5].pitch = 0;
2106 channels[5].yaw = 0;
2108 // Elevator Servo (Chan 2)
2109 channels[1].type = MIXER_TYPE_SERVO;
2110 channels[1].throttle1 = 0;
2111 channels[1].throttle2 = 0;
2112 channels[1].roll = 0;
2113 channels[1].pitch = 100;
2114 channels[1].yaw = 0;
2116 // Rudder Servo (Chan 3)
2117 channels[2].type = MIXER_TYPE_SERVO;
2118 channels[2].throttle1 = 0;
2119 channels[2].throttle2 = 0;
2120 channels[2].roll = 0;
2121 channels[2].pitch = 0;
2122 channels[2].yaw = -100;
2124 guiSettings.fixedwing.FixedWingThrottle = 4;
2125 guiSettings.fixedwing.FixedWingRoll1 = 1;
2126 guiSettings.fixedwing.FixedWingRoll2 = 6;
2127 guiSettings.fixedwing.FixedWingPitch1 = 2;
2128 guiSettings.fixedwing.FixedWingYaw1 = 3;
2130 applyMixerConfiguration(channels);
2131 applyMultiGUISettings(SystemSettings::AIRFRAMETYPE_FIXEDWING, guiSettings);
2134 void VehicleConfigurationHelper::setupAileron()
2136 // Typical vehicle setup
2137 // 1. Setup mixer data
2138 // 2. Setup GUI data
2139 // 3. Apply changes
2141 mixerChannelSettings channels[ActuatorSettings::CHANNELADDR_NUMELEM];
2142 GUIConfigDataUnion guiSettings = getGUIConfigData();
2144 // Motor (Chan 4)
2145 channels[3].type = MIXER_TYPE_MOTOR;
2146 channels[3].throttle1 = 100;
2147 channels[3].throttle2 = 0;
2148 channels[3].roll = 0;
2149 channels[3].pitch = 0;
2150 channels[3].yaw = 0;
2152 // Aileron Servo (Chan 1)
2153 channels[0].type = MIXER_TYPE_SERVO;
2154 channels[0].throttle1 = 0;
2155 channels[0].throttle2 = 0;
2156 channels[0].roll = 100;
2157 channels[0].pitch = 0;
2158 channels[0].yaw = 0;
2160 // Elevator Servo (Chan 2)
2161 channels[1].type = MIXER_TYPE_SERVO;
2162 channels[1].throttle1 = 0;
2163 channels[1].throttle2 = 0;
2164 channels[1].roll = 0;
2165 channels[1].pitch = 100;
2166 channels[1].yaw = 0;
2168 // Rudder Servo (Chan 3)
2169 channels[2].type = MIXER_TYPE_SERVO;
2170 channels[2].throttle1 = 0;
2171 channels[2].throttle2 = 0;
2172 channels[2].roll = 0;
2173 channels[2].pitch = 0;
2174 channels[2].yaw = -100;
2176 guiSettings.fixedwing.FixedWingThrottle = 4;
2177 guiSettings.fixedwing.FixedWingRoll1 = 1;
2178 guiSettings.fixedwing.FixedWingPitch1 = 2;
2179 guiSettings.fixedwing.FixedWingYaw1 = 3;
2181 applyMixerConfiguration(channels);
2182 applyMultiGUISettings(SystemSettings::AIRFRAMETYPE_FIXEDWING, guiSettings);
2185 void VehicleConfigurationHelper::setupVtail()
2187 // Typical vehicle setup
2188 // 1. Setup mixer data
2189 // 2. Setup GUI data
2190 // 3. Apply changes
2192 mixerChannelSettings channels[ActuatorSettings::CHANNELADDR_NUMELEM];
2193 GUIConfigDataUnion guiSettings = getGUIConfigData();
2195 // Motor (Chan 4)
2196 channels[3].type = MIXER_TYPE_MOTOR;
2197 channels[3].throttle1 = 100;
2198 channels[3].throttle2 = 0;
2199 channels[3].roll = 0;
2200 channels[3].pitch = 0;
2201 channels[3].yaw = 0;
2203 // Aileron Servo (Chan 1)
2204 channels[0].type = MIXER_TYPE_SERVO;
2205 channels[0].throttle1 = 0;
2206 channels[0].throttle2 = 0;
2207 channels[0].roll = 100;
2208 channels[0].pitch = 0;
2209 channels[0].yaw = 0;
2211 // Aileron Servo 2 (Chan 6)
2212 channels[5].type = MIXER_TYPE_SERVO;
2213 channels[5].throttle1 = 0;
2214 channels[5].throttle2 = 0;
2215 channels[5].roll = 100;
2216 channels[5].pitch = 0;
2217 channels[5].yaw = 0;
2219 // Right Vtail Servo (Chan 2)
2220 channels[1].type = MIXER_TYPE_SERVO;
2221 channels[1].throttle1 = 0;
2222 channels[1].throttle2 = 0;
2223 channels[1].roll = 0;
2224 channels[1].pitch = 100;
2225 channels[1].yaw = -100;
2227 // Left Vtail Servo (Chan 3)
2228 channels[2].type = MIXER_TYPE_SERVO;
2229 channels[2].throttle1 = 0;
2230 channels[2].throttle2 = 0;
2231 channels[2].roll = 0;
2232 channels[2].pitch = -100;
2233 channels[2].yaw = -100;
2235 guiSettings.fixedwing.FixedWingThrottle = 4;
2236 guiSettings.fixedwing.FixedWingRoll1 = 1;
2237 guiSettings.fixedwing.FixedWingRoll2 = 6;
2238 guiSettings.fixedwing.FixedWingPitch1 = 3; // Vtail left (top view, nose up)
2239 guiSettings.fixedwing.FixedWingPitch2 = 2; // Vtail right
2241 applyMixerConfiguration(channels);
2242 applyMultiGUISettings(SystemSettings::AIRFRAMETYPE_FIXEDWINGVTAIL, guiSettings);
2247 * Ground vehicles
2251 void VehicleConfigurationHelper::setupCar()
2253 // Typical vehicle setup
2254 // 1. Setup mixer data
2255 // 2. Setup GUI data
2256 // 3. Apply changes
2258 mixerChannelSettings channels[ActuatorSettings::CHANNELADDR_NUMELEM];
2259 GUIConfigDataUnion guiSettings = getGUIConfigData();
2261 // Steering Servo (Chan 1)
2262 channels[0].type = MIXER_TYPE_SERVO;
2263 channels[0].throttle1 = 0;
2264 channels[0].throttle2 = 0;
2265 channels[0].roll = 0;
2266 channels[0].pitch = 0;
2267 channels[0].yaw = 100;
2269 // Motor (Chan 4)
2270 channels[3].type = MIXER_TYPE_REVERSABLEMOTOR;
2271 channels[3].throttle1 = 100;
2272 channels[3].throttle2 = 0;
2273 channels[3].roll = 0;
2274 channels[3].pitch = 0;
2275 channels[3].yaw = 0;
2277 guiSettings.ground.GroundVehicleSteering1 = 1;
2278 guiSettings.ground.GroundVehicleThrottle2 = 4;
2280 applyMixerConfiguration(channels);
2281 applyMultiGUISettings(SystemSettings::AIRFRAMETYPE_GROUNDVEHICLECAR, guiSettings);
2284 void VehicleConfigurationHelper::setupTank()
2286 // Typical vehicle setup
2287 // 1. Setup mixer data
2288 // 2. Setup GUI data
2289 // 3. Apply changes
2291 mixerChannelSettings channels[ActuatorSettings::CHANNELADDR_NUMELEM];
2292 GUIConfigDataUnion guiSettings = getGUIConfigData();
2294 // Left Motor (Chan 1)
2295 channels[0].type = MIXER_TYPE_REVERSABLEMOTOR;
2296 channels[0].throttle1 = 100;
2297 channels[0].throttle2 = 0;
2298 channels[0].roll = 0;
2299 channels[0].pitch = 0;
2300 channels[0].yaw = 100;
2302 // Right Motor (Chan 2)
2303 channels[1].type = MIXER_TYPE_REVERSABLEMOTOR;
2304 channels[1].throttle1 = 100;
2305 channels[1].throttle2 = 0;
2306 channels[1].roll = 0;
2307 channels[1].pitch = 0;
2308 channels[1].yaw = -100;
2310 guiSettings.ground.GroundVehicleThrottle1 = 1;
2311 guiSettings.ground.GroundVehicleThrottle2 = 2;
2313 applyMixerConfiguration(channels);
2314 applyMultiGUISettings(SystemSettings::AIRFRAMETYPE_GROUNDVEHICLEDIFFERENTIAL, guiSettings);
2317 void VehicleConfigurationHelper::setupMotorcycle()
2319 // Typical vehicle setup
2320 // 1. Setup mixer data
2321 // 2. Setup GUI data
2322 // 3. Apply changes
2324 mixerChannelSettings channels[ActuatorSettings::CHANNELADDR_NUMELEM];
2325 GUIConfigDataUnion guiSettings = getGUIConfigData();
2327 // Steering Servo (Chan 1)
2328 channels[0].type = MIXER_TYPE_SERVO;
2329 channels[0].throttle1 = 0;
2330 channels[0].throttle2 = 0;
2331 channels[0].roll = 0;
2332 channels[0].pitch = 0;
2333 channels[0].yaw = 100;
2335 // Motor (Chan 4)
2336 channels[3].type = MIXER_TYPE_MOTOR;
2337 channels[3].throttle1 = 100;
2338 channels[3].throttle2 = 0;
2339 channels[3].roll = 0;
2340 channels[3].pitch = 0;
2341 channels[3].yaw = 0;
2343 guiSettings.ground.GroundVehicleSteering1 = 1;
2344 guiSettings.ground.GroundVehicleThrottle2 = 4;
2346 applyMixerConfiguration(channels);
2347 applyMultiGUISettings(SystemSettings::AIRFRAMETYPE_GROUNDVEHICLEMOTORCYCLE, guiSettings);
2350 void VehicleConfigurationHelper::setupBoat()
2352 // Typical vehicle setup
2353 // 1. Setup mixer data
2354 // 2. Setup GUI data
2355 // 3. Apply changes
2357 mixerChannelSettings channels[ActuatorSettings::CHANNELADDR_NUMELEM];
2358 GUIConfigDataUnion guiSettings = getGUIConfigData();
2360 // Rudder Servo (Chan 1)
2361 channels[0].type = MIXER_TYPE_SERVO;
2362 channels[0].throttle1 = 0;
2363 channels[0].throttle2 = 0;
2364 channels[0].roll = 0;
2365 channels[0].pitch = 0;
2366 channels[0].yaw = 100;
2368 // Motor (Chan 4)
2369 channels[3].type = MIXER_TYPE_REVERSABLEMOTOR;
2370 channels[3].throttle1 = 100;
2371 channels[3].throttle2 = 0;
2372 channels[3].roll = 0;
2373 channels[3].pitch = 0;
2374 channels[3].yaw = 0;
2376 guiSettings.ground.GroundVehicleSteering1 = 1;
2377 guiSettings.ground.GroundVehicleThrottle2 = 4;
2379 applyMixerConfiguration(channels);
2380 applyMultiGUISettings(SystemSettings::AIRFRAMETYPE_GROUNDVEHICLEBOAT, guiSettings);
2383 void VehicleConfigurationHelper::setupBoatDiff()
2385 // Typical vehicle setup
2386 // 1. Setup mixer data
2387 // 2. Setup GUI data
2388 // 3. Apply changes
2390 mixerChannelSettings channels[ActuatorSettings::CHANNELADDR_NUMELEM];
2391 GUIConfigDataUnion guiSettings = getGUIConfigData();
2393 // Left Motor (Chan 1)
2394 channels[0].type = MIXER_TYPE_REVERSABLEMOTOR;
2395 channels[0].throttle1 = 100;
2396 channels[0].throttle2 = 0;
2397 channels[0].roll = 0;
2398 channels[0].pitch = 0;
2399 channels[0].yaw = 100;
2401 // Right Motor (Chan 2)
2402 channels[1].type = MIXER_TYPE_REVERSABLEMOTOR;
2403 channels[1].throttle1 = 100;
2404 channels[1].throttle2 = 0;
2405 channels[1].roll = 0;
2406 channels[1].pitch = 0;
2407 channels[1].yaw = -100;
2409 guiSettings.ground.GroundVehicleThrottle1 = 1;
2410 guiSettings.ground.GroundVehicleThrottle2 = 2;
2412 applyMixerConfiguration(channels);
2413 applyMultiGUISettings(SystemSettings::AIRFRAMETYPE_GROUNDVEHICLEDIFFERENTIALBOAT, guiSettings);