Merged in paul_jewell/librepilot/LP-94-set-up-wiki-link-in-gcs (pull request #38)
[librepilot.git] / ground / gcs / src / plugins / setupwizard / vehicleconfigurationhelper.cpp
bloba836b72b3e99f104bb33244c51a204859afb5e85
1 /**
2 ******************************************************************************
4 * @file vehicleconfigurationhelper.cpp
5 * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015.
6 * @author 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 "hwsettings.h"
32 #include "actuatorsettings.h"
33 #include "attitudesettings.h"
34 #include "mixersettings.h"
35 #include "systemsettings.h"
36 #include "manualcontrolsettings.h"
37 #include "flightmodesettings.h"
38 #include "stabilizationsettings.h"
39 #include "stabilizationbank.h"
40 #include "stabilizationsettingsbank1.h"
41 #include "revocalibration.h"
42 #include "accelgyrosettings.h"
43 #include "gpssettings.h"
44 #include "airspeedsettings.h"
45 #include <QtCore/qmath.h>
46 #include <QJsonObject>
47 #include "auxmagsettings.h"
49 VehicleConfigurationHelper::VehicleConfigurationHelper(VehicleConfigurationSource *configSource)
50 : m_configSource(configSource), m_uavoManager(0),
51 m_transactionOK(false), m_transactionTimeout(false), m_currentTransactionObjectID(-1),
52 m_progress(0)
54 Q_ASSERT(m_configSource);
55 ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
56 m_uavoManager = pm->getObject<UAVObjectManager>();
57 Q_ASSERT(m_uavoManager);
60 bool VehicleConfigurationHelper::setupVehicle(bool save)
62 m_progress = 0;
63 clearModifiedObjects();
64 resetVehicleConfig();
65 resetGUIData();
66 if (!saveChangesToController(save)) {
67 return false;
70 m_progress = 0;
71 applyHardwareConfiguration();
72 applyVehicleConfiguration();
73 applyActuatorConfiguration();
74 applyFlightModeConfiguration();
76 if (save) {
77 applySensorBiasConfiguration();
80 applyStabilizationConfiguration();
81 applyManualControlDefaults();
83 applyTemplateSettings();
85 bool result = saveChangesToController(save);
86 emit saveProgress(m_modifiedObjects.count() + 1, ++m_progress, result ? tr("Done!") : tr("Failed!"));
87 return result;
90 bool VehicleConfigurationHelper::setupHardwareSettings(bool save)
92 m_progress = 0;
93 clearModifiedObjects();
94 applyHardwareConfiguration();
95 applyManualControlDefaults();
97 bool result = saveChangesToController(save);
98 emit saveProgress(m_modifiedObjects.count() + 1, ++m_progress, result ? tr("Done!") : tr("Failed!"));
99 return result;
102 bool VehicleConfigurationHelper::isApplicable(UAVObject *dataObj)
104 switch (m_configSource->getControllerType()) {
105 case VehicleConfigurationSource::CONTROLLER_CC:
106 case VehicleConfigurationSource::CONTROLLER_CC3D:
107 if (dataObj->getName() == "EKFConfiguration") {
108 return false;
110 default:
111 return true;
115 void VehicleConfigurationHelper::addModifiedObject(UAVDataObject *object, QString description)
117 m_modifiedObjects << new QPair<UAVDataObject *, QString>(object, description);
120 void VehicleConfigurationHelper::clearModifiedObjects()
122 for (int i = 0; i < m_modifiedObjects.count(); i++) {
123 QPair<UAVDataObject *, QString> *pair = m_modifiedObjects.at(i);
124 delete pair;
126 m_modifiedObjects.clear();
129 void VehicleConfigurationHelper::applyHardwareConfiguration()
131 HwSettings *hwSettings = HwSettings::GetInstance(m_uavoManager);
133 Q_ASSERT(hwSettings);
134 HwSettings::DataFields data = hwSettings->getData();
136 data.OptionalModules[HwSettings::OPTIONALMODULES_GPS] = 0;
137 data.OptionalModules[HwSettings::OPTIONALMODULES_AIRSPEED] = 0;
139 switch (m_configSource->getControllerType()) {
140 case VehicleConfigurationSource::CONTROLLER_CC:
141 case VehicleConfigurationSource::CONTROLLER_CC3D:
142 // Reset all ports
143 data.CC_RcvrPort = HwSettings::CC_RCVRPORT_DISABLEDONESHOT;
145 // Default mainport to be active telemetry link
146 data.CC_MainPort = HwSettings::CC_MAINPORT_TELEMETRY;
148 data.CC_FlexiPort = HwSettings::CC_FLEXIPORT_DISABLED;
149 switch (m_configSource->getInputType()) {
150 case VehicleConfigurationSource::INPUT_PWM:
151 data.CC_RcvrPort = HwSettings::CC_RCVRPORT_PWMNOONESHOT;
152 break;
153 case VehicleConfigurationSource::INPUT_PPM:
154 if (m_configSource->getEscType() == VehicleConfigurationSource::ESC_ONESHOT ||
155 m_configSource->getEscType() == VehicleConfigurationSource::ESC_SYNCHED) {
156 data.CC_RcvrPort = HwSettings::CC_RCVRPORT_PPM_PIN8ONESHOT;
157 } else {
158 data.CC_RcvrPort = HwSettings::CC_RCVRPORT_PPMNOONESHOT;
160 break;
161 case VehicleConfigurationSource::INPUT_SBUS:
162 // We have to set teletry on flexport since s.bus needs the mainport.
163 data.CC_MainPort = HwSettings::CC_MAINPORT_SBUS;
164 data.CC_FlexiPort = HwSettings::CC_FLEXIPORT_TELEMETRY;
165 break;
166 case VehicleConfigurationSource::INPUT_DSM:
167 data.CC_FlexiPort = HwSettings::CC_FLEXIPORT_DSM;
168 break;
169 default:
170 break;
172 break;
173 case VehicleConfigurationSource::CONTROLLER_REVO:
174 case VehicleConfigurationSource::CONTROLLER_NANO:
175 case VehicleConfigurationSource::CONTROLLER_DISCOVERYF4:
176 // Reset all ports to their defaults
177 data.RM_RcvrPort = HwSettings::RM_RCVRPORT_DISABLED;
178 data.RM_FlexiPort = HwSettings::RM_FLEXIPORT_DISABLED;
180 // Revo uses inbuilt Modem do not set mainport to be active telemetry link for the Revo
181 if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_REVO) {
182 data.RM_MainPort = HwSettings::RM_MAINPORT_DISABLED;
183 } else {
184 data.RM_MainPort = HwSettings::RM_MAINPORT_TELEMETRY;
187 switch (m_configSource->getInputType()) {
188 case VehicleConfigurationSource::INPUT_PWM:
189 data.RM_RcvrPort = HwSettings::RM_RCVRPORT_PWM;
190 break;
191 case VehicleConfigurationSource::INPUT_PPM:
192 data.RM_RcvrPort = HwSettings::RM_RCVRPORT_PPM;
193 break;
194 case VehicleConfigurationSource::INPUT_SBUS:
195 data.RM_MainPort = HwSettings::RM_MAINPORT_SBUS;
196 // We have to set telemetry on flexport since s.bus needs the mainport on all but Revo.
197 if (m_configSource->getControllerType() != VehicleConfigurationSource::CONTROLLER_REVO) {
198 data.RM_FlexiPort = HwSettings::RM_FLEXIPORT_TELEMETRY;
200 break;
201 case VehicleConfigurationSource::INPUT_DSM:
202 data.RM_FlexiPort = HwSettings::RM_FLEXIPORT_DSM;
203 break;
204 case VehicleConfigurationSource::INPUT_SRXL:
205 data.RM_FlexiPort = HwSettings::RM_FLEXIPORT_SRXL;
206 break;
207 default:
208 break;
211 if (m_configSource->getGpsType() != VehicleConfigurationSource::GPS_DISABLED) {
212 data.OptionalModules[HwSettings::OPTIONALMODULES_GPS] = 1;
213 data.GPSSpeed = HwSettings::GPSSPEED_57600;
215 if (m_configSource->getInputType() == VehicleConfigurationSource::INPUT_SBUS) {
216 data.RM_FlexiPort = HwSettings::RM_FLEXIPORT_GPS;
217 } else {
218 data.RM_MainPort = HwSettings::RM_MAINPORT_GPS;
221 GPSSettings *gpsSettings = GPSSettings::GetInstance(m_uavoManager);
222 Q_ASSERT(gpsSettings);
223 GPSSettings::DataFields gpsData = gpsSettings->getData();
225 switch (m_configSource->getGpsType()) {
226 case VehicleConfigurationSource::GPS_NMEA:
227 gpsData.DataProtocol = GPSSettings::DATAPROTOCOL_NMEA;
228 gpsData.UbxAutoConfig = GPSSettings::UBXAUTOCONFIG_DISABLED;
229 break;
230 case VehicleConfigurationSource::GPS_UBX:
231 gpsData.DataProtocol = GPSSettings::DATAPROTOCOL_UBX;
232 gpsData.UbxAutoConfig = GPSSettings::UBXAUTOCONFIG_AUTOBAUDANDCONFIGURE;
233 break;
234 case VehicleConfigurationSource::GPS_PLATINUM:
236 gpsData.DataProtocol = GPSSettings::DATAPROTOCOL_UBX;
237 gpsData.UbxAutoConfig = GPSSettings::UBXAUTOCONFIG_AUTOBAUDANDCONFIGURE;
238 AuxMagSettings *magSettings = AuxMagSettings::GetInstance(m_uavoManager);
239 Q_ASSERT(magSettings);
240 AuxMagSettings::DataFields magsData = magSettings->getData();
241 magsData.Usage = AuxMagSettings::USAGE_AUXONLY;
242 magSettings->setData(magsData);
243 addModifiedObject(magSettings, tr("Writing External Mag sensor settings"));
244 break;
246 case VehicleConfigurationSource::GPS_DISABLED:
247 // Should not be able to reach here
248 break;
251 gpsSettings->setData(gpsData);
252 addModifiedObject(gpsSettings, tr("Writing GPS sensor settings"));
253 } else {
254 data.OptionalModules[HwSettings::OPTIONALMODULES_GPS] = 0;
257 if (m_configSource->getVehicleType() == VehicleConfigurationSource::VEHICLE_FIXEDWING &&
258 m_configSource->getAirspeedType() != VehicleConfigurationSource::AIRSPEED_DISABLED) {
259 AirspeedSettings *airspeedSettings = AirspeedSettings::GetInstance(m_uavoManager);
260 Q_ASSERT(airspeedSettings);
261 AirspeedSettings::DataFields airspeedData = airspeedSettings->getData();
263 switch (m_configSource->getAirspeedType()) {
264 case VehicleConfigurationSource::AIRSPEED_ESTIMATE:
265 data.OptionalModules[HwSettings::OPTIONALMODULES_AIRSPEED] = 1;
266 airspeedData.AirspeedSensorType = AirspeedSettings::AIRSPEEDSENSORTYPE_GROUNDSPEEDBASEDWINDESTIMATION;
267 break;
268 case VehicleConfigurationSource::AIRSPEED_EAGLETREE:
269 data.OptionalModules[HwSettings::OPTIONALMODULES_AIRSPEED] = 1;
270 data.RM_FlexiPort = HwSettings::RM_FLEXIPORT_I2C;
271 airspeedData.AirspeedSensorType = AirspeedSettings::AIRSPEEDSENSORTYPE_EAGLETREEAIRSPEEDV3;
272 break;
273 case VehicleConfigurationSource::AIRSPEED_MS4525:
274 data.OptionalModules[HwSettings::OPTIONALMODULES_AIRSPEED] = 1;
275 data.RM_FlexiPort = HwSettings::RM_FLEXIPORT_I2C;
276 airspeedData.AirspeedSensorType = AirspeedSettings::AIRSPEEDSENSORTYPE_PIXHAWKAIRSPEEDMS4525DO;
277 break;
278 default:
279 data.OptionalModules[HwSettings::OPTIONALMODULES_AIRSPEED] = 0;
280 break;
283 airspeedSettings->setData(airspeedData);
284 addModifiedObject(airspeedSettings, tr("Writing Airspeed sensor settings"));
286 break;
287 default:
288 break;
290 hwSettings->setData(data);
291 addModifiedObject(hwSettings, tr("Writing hardware settings"));
294 void VehicleConfigurationHelper::applyVehicleConfiguration()
296 switch (m_configSource->getVehicleType()) {
297 case VehicleConfigurationSource::VEHICLE_MULTI:
299 switch (m_configSource->getVehicleSubType()) {
300 case VehicleConfigurationSource::MULTI_ROTOR_TRI_Y:
301 setupTriCopter();
302 break;
303 case VehicleConfigurationSource::MULTI_ROTOR_QUAD_X:
304 case VehicleConfigurationSource::MULTI_ROTOR_QUAD_PLUS:
305 setupQuadCopter();
306 break;
307 case VehicleConfigurationSource::MULTI_ROTOR_HEXA:
308 case VehicleConfigurationSource::MULTI_ROTOR_HEXA_COAX_Y:
309 case VehicleConfigurationSource::MULTI_ROTOR_HEXA_H:
310 case VehicleConfigurationSource::MULTI_ROTOR_HEXA_X:
311 setupHexaCopter();
312 break;
313 case VehicleConfigurationSource::MULTI_ROTOR_OCTO:
314 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_X:
315 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_COAX_X:
316 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_COAX_PLUS:
317 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_V:
318 setupOctoCopter();
319 break;
320 default:
321 break;
323 break;
325 case VehicleConfigurationSource::VEHICLE_FIXEDWING:
327 switch (m_configSource->getVehicleSubType()) {
328 case VehicleConfigurationSource::FIXED_WING_DUAL_AILERON:
329 setupDualAileron();
330 break;
331 case VehicleConfigurationSource::FIXED_WING_AILERON:
332 setupAileron();
333 break;
334 case VehicleConfigurationSource::FIXED_WING_ELEVON:
335 setupElevon();
336 break;
337 case VehicleConfigurationSource::FIXED_WING_VTAIL:
338 setupVtail();
339 break;
340 default:
341 break;
343 break;
345 case VehicleConfigurationSource::VEHICLE_HELI:
346 // TODO: Implement settings for Helis
347 break;
349 case VehicleConfigurationSource::VEHICLE_SURFACE:
351 switch (m_configSource->getVehicleSubType()) {
352 case VehicleConfigurationSource::GROUNDVEHICLE_CAR:
353 setupCar();
354 break;
355 case VehicleConfigurationSource::GROUNDVEHICLE_DIFFERENTIAL:
356 setupTank();
357 break;
358 case VehicleConfigurationSource::GROUNDVEHICLE_MOTORCYCLE:
359 setupMotorcycle();
360 break;
361 default:
362 break;
364 break;
367 default:
368 break;
372 void VehicleConfigurationHelper::applyActuatorConfiguration()
374 ActuatorSettings *actSettings = ActuatorSettings::GetInstance(m_uavoManager);
376 qint16 escFrequence = LEGACY_ESC_FREQUENCY;
377 ActuatorSettings::BankModeOptions bankMode = ActuatorSettings::BANKMODE_PWM;
379 switch (m_configSource->getEscType()) {
380 case VehicleConfigurationSource::ESC_STANDARD:
381 escFrequence = LEGACY_ESC_FREQUENCY;
382 bankMode = ActuatorSettings::BANKMODE_PWM;
383 break;
384 case VehicleConfigurationSource::ESC_RAPID:
385 bankMode = ActuatorSettings::BANKMODE_PWM;
386 escFrequence = RAPID_ESC_FREQUENCY;
387 break;
388 case VehicleConfigurationSource::ESC_SYNCHED:
389 bankMode = ActuatorSettings::BANKMODE_PWMSYNC;
390 escFrequence = PWMSYNC_ESC_FREQUENCY;
391 break;
392 case VehicleConfigurationSource::ESC_ONESHOT:
393 bankMode = ActuatorSettings::BANKMODE_ONESHOT125;
394 escFrequence = ONESHOT_ESC_FREQUENCY;
395 break;
396 default:
397 break;
400 qint16 servoFrequence = ANALOG_SERVO_FREQUENCY;
401 switch (m_configSource->getServoType()) {
402 case VehicleConfigurationSource::SERVO_ANALOG:
403 servoFrequence = ANALOG_SERVO_FREQUENCY;
404 break;
405 case VehicleConfigurationSource::SERVO_DIGITAL:
406 servoFrequence = DIGITAL_SERVO_FREQUENCY;
407 break;
408 default:
409 break;
412 switch (m_configSource->getVehicleType()) {
413 case VehicleConfigurationSource::VEHICLE_MULTI:
415 ActuatorSettings::DataFields data = actSettings->getData();
417 QList<actuatorChannelSettings> actuatorSettings = m_configSource->getActuatorSettings();
418 for (quint16 i = 0; i < ActuatorSettings::CHANNELMAX_NUMELEM; i++) {
419 data.ChannelType[i] = ActuatorSettings::CHANNELTYPE_PWM;
420 data.ChannelAddr[i] = i;
421 data.ChannelMin[i] = actuatorSettings[i].channelMin;
422 data.ChannelNeutral[i] = actuatorSettings[i].channelNeutral;
423 data.ChannelMax[i] = actuatorSettings[i].channelMax;
426 data.MotorsSpinWhileArmed = ActuatorSettings::MOTORSSPINWHILEARMED_FALSE;
428 for (quint16 i = 0; i < ActuatorSettings::BANKUPDATEFREQ_NUMELEM; i++) {
429 data.BankUpdateFreq[i] = LEGACY_ESC_FREQUENCY;
430 data.BankMode[i] = ActuatorSettings::BANKMODE_PWM;
433 switch (m_configSource->getVehicleSubType()) {
434 case VehicleConfigurationSource::MULTI_ROTOR_TRI_Y:
435 // Servo always on channel 4
436 data.BankUpdateFreq[0] = escFrequence;
437 data.BankMode[0] = bankMode;
438 if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_REVO) {
439 data.BankUpdateFreq[1] = escFrequence;
440 data.BankMode[1] = bankMode;
441 data.BankUpdateFreq[2] = servoFrequence;
442 } else if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_NANO) {
443 data.BankUpdateFreq[1] = escFrequence;
444 data.BankMode[1] = bankMode;
445 data.BankUpdateFreq[2] = escFrequence;
446 data.BankMode[2] = bankMode;
447 data.BankUpdateFreq[3] = servoFrequence;
449 break;
450 case VehicleConfigurationSource::MULTI_ROTOR_QUAD_X:
451 case VehicleConfigurationSource::MULTI_ROTOR_QUAD_PLUS:
452 data.BankUpdateFreq[0] = escFrequence;
453 data.BankMode[0] = bankMode;
454 data.BankUpdateFreq[1] = escFrequence;
455 data.BankMode[1] = bankMode;
456 if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_REVO) {
457 data.BankUpdateFreq[2] = escFrequence;
458 data.BankMode[2] = bankMode;
459 } else if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_NANO) {
460 data.BankUpdateFreq[1] = escFrequence;
461 data.BankMode[1] = bankMode;
462 data.BankUpdateFreq[2] = escFrequence;
463 data.BankMode[2] = bankMode;
464 data.BankUpdateFreq[3] = escFrequence;
465 data.BankMode[3] = bankMode;
467 break;
468 case VehicleConfigurationSource::MULTI_ROTOR_HEXA:
469 case VehicleConfigurationSource::MULTI_ROTOR_HEXA_COAX_Y:
470 case VehicleConfigurationSource::MULTI_ROTOR_HEXA_H:
471 case VehicleConfigurationSource::MULTI_ROTOR_HEXA_X:
472 case VehicleConfigurationSource::MULTI_ROTOR_OCTO:
473 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_X:
474 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_COAX_X:
475 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_COAX_PLUS:
476 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_V:
477 data.BankUpdateFreq[0] = escFrequence;
478 data.BankMode[0] = bankMode;
479 data.BankUpdateFreq[1] = escFrequence;
480 data.BankMode[1] = bankMode;
481 data.BankUpdateFreq[2] = escFrequence;
482 data.BankMode[2] = bankMode;
483 data.BankUpdateFreq[3] = escFrequence;
484 data.BankMode[3] = bankMode;
485 if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_NANO) {
486 data.BankUpdateFreq[4] = escFrequence;
487 data.BankMode[4] = bankMode;
489 break;
490 default:
491 break;
493 actSettings->setData(data);
494 addModifiedObject(actSettings, tr("Writing actuator settings"));
495 break;
498 case VehicleConfigurationSource::VEHICLE_FIXEDWING:
500 ActuatorSettings::DataFields data = actSettings->getData();
502 QList<actuatorChannelSettings> actuatorSettings = m_configSource->getActuatorSettings();
503 for (quint16 i = 0; i < ActuatorSettings::CHANNELMAX_NUMELEM; i++) {
504 data.ChannelType[i] = ActuatorSettings::CHANNELTYPE_PWM;
505 data.ChannelAddr[i] = i;
506 data.ChannelMin[i] = actuatorSettings[i].channelMin;
507 data.ChannelNeutral[i] = actuatorSettings[i].channelNeutral;
508 data.ChannelMax[i] = actuatorSettings[i].channelMax;
511 for (quint16 i = 0; i < ActuatorSettings::BANKUPDATEFREQ_NUMELEM; i++) {
512 data.BankUpdateFreq[i] = servoFrequence;
513 data.BankMode[i] = ActuatorSettings::BANKMODE_PWM;
514 if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_REVO) {
515 if (i == 1) {
516 data.BankUpdateFreq[i] = escFrequence;
518 } else if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_NANO) {
519 if (i == 2) {
520 data.BankUpdateFreq[i] = escFrequence;
525 actSettings->setData(data);
526 addModifiedObject(actSettings, tr("Writing actuator settings"));
528 break;
531 case VehicleConfigurationSource::VEHICLE_HELI:
532 // TODO: Implement settings for Heli vehicle types
533 break;
535 case VehicleConfigurationSource::VEHICLE_SURFACE:
537 ActuatorSettings::DataFields data = actSettings->getData();
539 QList<actuatorChannelSettings> actuatorSettings = m_configSource->getActuatorSettings();
540 for (quint16 i = 0; i < ActuatorSettings::CHANNELMAX_NUMELEM; i++) {
541 data.ChannelType[i] = ActuatorSettings::CHANNELTYPE_PWM;
542 data.ChannelAddr[i] = i;
543 data.ChannelMin[i] = actuatorSettings[i].channelMin;
544 data.ChannelNeutral[i] = actuatorSettings[i].channelNeutral;
545 data.ChannelMax[i] = actuatorSettings[i].channelMax;
548 for (quint16 i = 0; i < ActuatorSettings::BANKUPDATEFREQ_NUMELEM; i++) {
549 data.BankUpdateFreq[i] = servoFrequence;
550 data.BankMode[i] = ActuatorSettings::BANKMODE_PWM;
551 if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_REVO) {
552 if (i == 1) {
553 data.BankUpdateFreq[i] = escFrequence;
555 } else if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_NANO) {
556 if (i == 2) {
557 data.BankUpdateFreq[i] = escFrequence;
562 actSettings->setData(data);
563 addModifiedObject(actSettings, tr("Writing actuator settings"));
565 break;
568 default:
569 break;
573 void VehicleConfigurationHelper::applyFlightModeConfiguration()
575 FlightModeSettings *modeSettings = FlightModeSettings::GetInstance(m_uavoManager);
576 ManualControlSettings *controlSettings = ManualControlSettings::GetInstance(m_uavoManager);
578 Q_ASSERT(modeSettings);
579 Q_ASSERT(controlSettings);
581 FlightModeSettings::DataFields data = modeSettings->getData();
582 ManualControlSettings::DataFields data2 = controlSettings->getData();
583 data.Stabilization1Settings[0] = FlightModeSettings::STABILIZATION1SETTINGS_ATTITUDE;
584 data.Stabilization1Settings[1] = FlightModeSettings::STABILIZATION1SETTINGS_ATTITUDE;
585 data.Stabilization1Settings[2] = FlightModeSettings::STABILIZATION1SETTINGS_AXISLOCK;
586 data.Stabilization1Settings[3] = FlightModeSettings::STABILIZATION1SETTINGS_MANUAL;
587 data.Stabilization2Settings[0] = FlightModeSettings::STABILIZATION2SETTINGS_ATTITUDE;
588 data.Stabilization2Settings[1] = FlightModeSettings::STABILIZATION2SETTINGS_ATTITUDE;
589 data.Stabilization2Settings[2] = FlightModeSettings::STABILIZATION2SETTINGS_RATE;
590 data.Stabilization2Settings[3] = FlightModeSettings::STABILIZATION2SETTINGS_MANUAL;
591 data.Stabilization3Settings[0] = FlightModeSettings::STABILIZATION3SETTINGS_RATE;
592 data.Stabilization3Settings[1] = FlightModeSettings::STABILIZATION3SETTINGS_RATE;
593 data.Stabilization3Settings[2] = FlightModeSettings::STABILIZATION3SETTINGS_RATE;
594 data.Stabilization3Settings[3] = FlightModeSettings::STABILIZATION3SETTINGS_MANUAL;
595 data.Stabilization4Settings[0] = FlightModeSettings::STABILIZATION4SETTINGS_ATTITUDE;
596 data.Stabilization4Settings[1] = FlightModeSettings::STABILIZATION4SETTINGS_ATTITUDE;
597 data.Stabilization4Settings[2] = FlightModeSettings::STABILIZATION4SETTINGS_AXISLOCK;
598 data.Stabilization4Settings[3] = FlightModeSettings::STABILIZATION4SETTINGS_CRUISECONTROL;
599 data.Stabilization5Settings[0] = FlightModeSettings::STABILIZATION5SETTINGS_ATTITUDE;
600 data.Stabilization5Settings[1] = FlightModeSettings::STABILIZATION5SETTINGS_ATTITUDE;
601 data.Stabilization5Settings[2] = FlightModeSettings::STABILIZATION5SETTINGS_RATE;
602 data.Stabilization5Settings[3] = FlightModeSettings::STABILIZATION5SETTINGS_CRUISECONTROL;
603 data.Stabilization6Settings[0] = FlightModeSettings::STABILIZATION6SETTINGS_RATE;
604 data.Stabilization6Settings[1] = FlightModeSettings::STABILIZATION6SETTINGS_RATE;
605 data.Stabilization6Settings[2] = FlightModeSettings::STABILIZATION6SETTINGS_RATE;
606 data.Stabilization6Settings[3] = FlightModeSettings::STABILIZATION6SETTINGS_MANUAL;
607 data2.FlightModeNumber = 3;
608 data.FlightModePosition[0] = FlightModeSettings::FLIGHTMODEPOSITION_STABILIZED1;
609 data.FlightModePosition[1] = FlightModeSettings::FLIGHTMODEPOSITION_STABILIZED2;
610 data.FlightModePosition[2] = FlightModeSettings::FLIGHTMODEPOSITION_STABILIZED3;
611 data.FlightModePosition[3] = FlightModeSettings::FLIGHTMODEPOSITION_STABILIZED4;
612 data.FlightModePosition[4] = FlightModeSettings::FLIGHTMODEPOSITION_STABILIZED5;
613 data.FlightModePosition[5] = FlightModeSettings::FLIGHTMODEPOSITION_STABILIZED6;
614 modeSettings->setData(data);
615 addModifiedObject(modeSettings, tr("Writing flight mode settings 1/2"));
616 controlSettings->setData(data2);
617 addModifiedObject(controlSettings, tr("Writing flight mode settings 2/2"));
620 void VehicleConfigurationHelper::applySensorBiasConfiguration()
622 if (m_configSource->isCalibrationPerformed()) {
623 accelGyroBias bias = m_configSource->getCalibrationBias();
624 float G = 9.81f;
626 AccelGyroSettings *accelGyroSettings = AccelGyroSettings::GetInstance(m_uavoManager);
627 Q_ASSERT(accelGyroSettings);
628 AccelGyroSettings::DataFields accelGyroSettingsData = accelGyroSettings->getData();
630 accelGyroSettingsData.accel_bias[AccelGyroSettings::ACCEL_BIAS_X] += bias.m_accelerometerXBias;
631 accelGyroSettingsData.accel_bias[AccelGyroSettings::ACCEL_BIAS_Y] += bias.m_accelerometerYBias;
632 accelGyroSettingsData.accel_bias[AccelGyroSettings::ACCEL_BIAS_Z] += bias.m_accelerometerZBias + G;
633 accelGyroSettingsData.gyro_bias[AccelGyroSettings::GYRO_BIAS_X] = bias.m_gyroXBias;
634 accelGyroSettingsData.gyro_bias[AccelGyroSettings::GYRO_BIAS_Y] = bias.m_gyroYBias;
635 accelGyroSettingsData.gyro_bias[AccelGyroSettings::GYRO_BIAS_Z] = bias.m_gyroZBias;
637 accelGyroSettings->setData(accelGyroSettingsData);
638 addModifiedObject(accelGyroSettings, tr("Writing gyro and accelerometer bias settings"));
640 switch (m_configSource->getControllerType()) {
641 case VehicleConfigurationSource::CONTROLLER_CC:
642 case VehicleConfigurationSource::CONTROLLER_CC3D:
644 AttitudeSettings *copterControlCalibration = AttitudeSettings::GetInstance(m_uavoManager);
645 Q_ASSERT(copterControlCalibration);
646 AttitudeSettings::DataFields data = copterControlCalibration->getData();
648 data.AccelTau = DEFAULT_ENABLED_ACCEL_TAU;
649 data.BiasCorrectGyro = AttitudeSettings::BIASCORRECTGYRO_TRUE;
651 copterControlCalibration->setData(data);
652 addModifiedObject(copterControlCalibration, tr("Writing board settings"));
653 break;
655 case VehicleConfigurationSource::CONTROLLER_REVO:
656 case VehicleConfigurationSource::CONTROLLER_NANO:
658 RevoCalibration *revolutionCalibration = RevoCalibration::GetInstance(m_uavoManager);
659 Q_ASSERT(revolutionCalibration);
660 RevoCalibration::DataFields data = revolutionCalibration->getData();
662 data.BiasCorrectedRaw = RevoCalibration::BIASCORRECTEDRAW_TRUE;
664 revolutionCalibration->setData(data);
665 addModifiedObject(revolutionCalibration, tr("Writing board settings"));
666 break;
668 default:
669 // Something went terribly wrong.
670 break;
675 void VehicleConfigurationHelper::applyStabilizationConfiguration()
677 StabilizationSettings *stabSettings = StabilizationSettings::GetInstance(m_uavoManager);
679 Q_ASSERT(stabSettings);
681 StabilizationSettings defaultSettings;
682 stabSettings->setData(defaultSettings.getData());
683 addModifiedObject(stabSettings, tr("Writing stabilization settings"));
686 void VehicleConfigurationHelper::applyMixerConfiguration(mixerChannelSettings channels[])
688 // Set all mixer data
689 MixerSettings *mSettings = MixerSettings::GetInstance(m_uavoManager);
691 Q_ASSERT(mSettings);
693 // Set Mixer types and values
694 QString mixerTypePattern = "Mixer%1Type";
695 QString mixerVectorPattern = "Mixer%1Vector";
696 for (quint32 i = 0; i < ActuatorSettings::CHANNELADDR_NUMELEM; i++) {
697 UAVObjectField *field = mSettings->getField(mixerTypePattern.arg(i + 1));
698 Q_ASSERT(field);
699 field->setValue(field->getOptions().at(channels[i].type));
701 field = mSettings->getField(mixerVectorPattern.arg(i + 1));
702 Q_ASSERT(field);
703 field->setValue((channels[i].throttle1 * 127) / 100, 0);
704 field->setValue((channels[i].throttle2 * 127) / 100, 1);
706 // Normalize mixer values, allow a well balanced mixer saved
707 if (channels[i].roll < 0) {
708 field->setValue(qFloor((double)(channels[i].roll * 127) / 100), 2);
709 } else {
710 field->setValue(qCeil((double)(channels[i].roll * 127) / 100), 2);
713 if (channels[i].pitch < 0) {
714 field->setValue(qFloor((double)(channels[i].pitch * 127) / 100), 3);
715 } else {
716 field->setValue(qCeil((double)(channels[i].pitch * 127) / 100), 3);
719 if (channels[i].yaw < 0) {
720 field->setValue(qFloor((double)(channels[i].yaw * 127) / 100), 4);
721 } else {
722 field->setValue(qCeil((double)(channels[i].yaw * 127) / 100), 4);
726 // Default maxThrottle and minThrottle
727 float maxThrottle = 1;
728 float minThrottle = 0;
731 // Save mixer values for sliders
732 switch (m_configSource->getVehicleType()) {
733 case VehicleConfigurationSource::VEHICLE_MULTI:
735 switch (m_configSource->getVehicleSubType()) {
736 case VehicleConfigurationSource::MULTI_ROTOR_TRI_Y:
737 case VehicleConfigurationSource::MULTI_ROTOR_HEXA:
738 case VehicleConfigurationSource::MULTI_ROTOR_HEXA_H:
739 case VehicleConfigurationSource::MULTI_ROTOR_HEXA_X:
740 mSettings->setMixerValueRoll(100);
741 mSettings->setMixerValuePitch(100);
742 mSettings->setMixerValueYaw(100);
743 break;
744 case VehicleConfigurationSource::MULTI_ROTOR_QUAD_X:
745 mSettings->setMixerValueRoll(50);
746 mSettings->setMixerValuePitch(50);
747 mSettings->setMixerValueYaw(50);
748 break;
749 case VehicleConfigurationSource::MULTI_ROTOR_QUAD_PLUS:
750 mSettings->setMixerValueRoll(100);
751 mSettings->setMixerValuePitch(100);
752 mSettings->setMixerValueYaw(50);
753 break;
754 case VehicleConfigurationSource::MULTI_ROTOR_HEXA_COAX_Y:
755 mSettings->setMixerValueRoll(100);
756 mSettings->setMixerValuePitch(50);
757 mSettings->setMixerValueYaw(66);
758 break;
759 case VehicleConfigurationSource::MULTI_ROTOR_OCTO:
760 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_X:
761 mSettings->setMixerValueRoll(100);
762 mSettings->setMixerValuePitch(100);
763 mSettings->setMixerValueYaw(100);
764 break;
765 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_COAX_X:
766 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_COAX_PLUS:
767 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_V:
768 break;
769 default:
770 break;
772 break;
774 case VehicleConfigurationSource::VEHICLE_FIXEDWING:
775 mSettings->setMixerValueRoll(100);
776 mSettings->setMixerValuePitch(100);
777 mSettings->setMixerValueYaw(100);
778 maxThrottle = 1;
779 break;
780 case VehicleConfigurationSource::VEHICLE_HELI:
781 break;
782 case VehicleConfigurationSource::VEHICLE_SURFACE:
784 switch (m_configSource->getVehicleSubType()) {
785 case VehicleConfigurationSource::GROUNDVEHICLE_MOTORCYCLE:
786 mSettings->setMixerValueRoll(100);
787 mSettings->setMixerValuePitch(100);
788 mSettings->setMixerValueYaw(100);
789 maxThrottle = 1;
790 break;
791 case VehicleConfigurationSource::GROUNDVEHICLE_CAR:
792 mSettings->setMixerValueRoll(100);
793 mSettings->setMixerValuePitch(100);
794 mSettings->setMixerValueYaw(100);
795 maxThrottle = 1;
796 minThrottle = 0;
797 break;
798 case VehicleConfigurationSource::GROUNDVEHICLE_DIFFERENTIAL:
799 mSettings->setMixerValueRoll(100);
800 mSettings->setMixerValuePitch(100);
801 mSettings->setMixerValueYaw(100);
802 maxThrottle = 0.8;
803 minThrottle = 0;
804 break;
805 default:
806 break;
810 break;
811 default:
812 break;
815 // Apply Throttle curve max 90% for Multis, 100% for FixedWing/car/Motorbike, 80% for Tank
816 QString throttlePattern = "ThrottleCurve%1";
817 for (int i = 1; i <= 2; i++) {
818 UAVObjectField *field = mSettings->getField(throttlePattern.arg(i));
819 Q_ASSERT(field);
820 for (quint32 i = 0; i < field->getNumElements(); i++) {
821 field->setValue(minThrottle + (i * ((maxThrottle - minThrottle) / (field->getNumElements() - 1))), i);
825 // Apply updates
826 mSettings->setData(mSettings->getData());
827 addModifiedObject(mSettings, tr("Writing mixer settings"));
830 void VehicleConfigurationHelper::applyMultiGUISettings(SystemSettings::AirframeTypeOptions airframe, GUIConfigDataUnion guiConfig)
832 SystemSettings *sSettings = SystemSettings::GetInstance(m_uavoManager);
834 Q_ASSERT(sSettings);
835 SystemSettings::DataFields data = sSettings->getData();
836 data.AirframeType = airframe;
838 for (int i = 0; i < (int)(SystemSettings::GUICONFIGDATA_NUMELEM); i++) {
839 data.GUIConfigData[i] = guiConfig.UAVObject[i];
842 sSettings->setData(data);
843 addModifiedObject(sSettings, tr("Writing vehicle settings"));
846 void VehicleConfigurationHelper::applyManualControlDefaults()
848 ManualControlSettings *mcSettings = ManualControlSettings::GetInstance(m_uavoManager);
850 Q_ASSERT(mcSettings);
851 ManualControlSettings::DataFields cData = mcSettings->getData();
853 ManualControlSettings::ChannelGroupsOptions channelType = ManualControlSettings::CHANNELGROUPS_PWM;
854 switch (m_configSource->getInputType()) {
855 case VehicleConfigurationSource::INPUT_PWM:
856 channelType = ManualControlSettings::CHANNELGROUPS_PWM;
857 break;
858 case VehicleConfigurationSource::INPUT_PPM:
859 channelType = ManualControlSettings::CHANNELGROUPS_PPM;
860 break;
861 case VehicleConfigurationSource::INPUT_SBUS:
862 channelType = ManualControlSettings::CHANNELGROUPS_SBUS;
863 break;
864 case VehicleConfigurationSource::INPUT_DSM:
865 channelType = ManualControlSettings::CHANNELGROUPS_DSMFLEXIPORT;
866 break;
867 case VehicleConfigurationSource::INPUT_SRXL:
868 channelType = ManualControlSettings::CHANNELGROUPS_SRXL;
869 break;
870 default:
871 break;
874 cData.ChannelGroups[ManualControlSettings::CHANNELGROUPS_THROTTLE] = channelType;
875 cData.ChannelGroups[ManualControlSettings::CHANNELGROUPS_ROLL] = channelType;
876 cData.ChannelGroups[ManualControlSettings::CHANNELGROUPS_YAW] = channelType;
877 cData.ChannelGroups[ManualControlSettings::CHANNELGROUPS_PITCH] = channelType;
878 cData.ChannelGroups[ManualControlSettings::CHANNELGROUPS_FLIGHTMODE] = channelType;
880 mcSettings->setData(cData);
881 addModifiedObject(mcSettings, tr("Writing manual control defaults"));
884 void VehicleConfigurationHelper::applyTemplateSettings()
886 if (m_configSource->getVehicleTemplate() != NULL) {
887 QJsonObject *json = m_configSource->getVehicleTemplate();
888 QList<UAVObject *> updatedObjects;
889 m_uavoManager->fromJson(*json, &updatedObjects);
890 foreach(UAVObject * object, updatedObjects) {
891 UAVDataObject *dataObj = dynamic_cast<UAVDataObject *>(object);
893 if (dataObj != NULL && isApplicable(dataObj)) {
894 addModifiedObject(dataObj, tr("Writing template settings for %1").arg(object->getName()));
900 bool VehicleConfigurationHelper::saveChangesToController(bool save)
902 qDebug() << "Saving modified objects to controller. " << m_modifiedObjects.count() << " objects in found.";
903 const int OUTER_TIMEOUT = 3000 * 20; // 10 seconds timeout for saving all objects
904 const int INNER_TIMEOUT = 2000; // 1 second timeout on every save attempt
906 ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
907 Q_ASSERT(pm);
908 UAVObjectUtilManager *utilMngr = pm->getObject<UAVObjectUtilManager>();
909 Q_ASSERT(utilMngr);
911 QTimer outerTimeoutTimer;
912 outerTimeoutTimer.setSingleShot(true);
914 QTimer innerTimeoutTimer;
915 innerTimeoutTimer.setSingleShot(true);
917 connect(utilMngr, SIGNAL(saveCompleted(int, bool)), this, SLOT(uAVOTransactionCompleted(int, bool)));
918 connect(&innerTimeoutTimer, SIGNAL(timeout()), &m_eventLoop, SLOT(quit()));
919 connect(&outerTimeoutTimer, SIGNAL(timeout()), this, SLOT(saveChangesTimeout()));
921 outerTimeoutTimer.start(OUTER_TIMEOUT);
922 for (int i = 0; i < m_modifiedObjects.count(); i++) {
923 QPair<UAVDataObject *, QString> *objPair = m_modifiedObjects.at(i);
924 m_transactionOK = false;
925 UAVDataObject *obj = objPair->first;
926 QString objDescription = objPair->second;
927 if (UAVObject::GetGcsAccess(obj->getMetadata()) != UAVObject::ACCESS_READONLY && obj->isSettingsObject()) {
928 emit saveProgress(m_modifiedObjects.count() + 1, ++m_progress, objDescription);
930 m_currentTransactionObjectID = obj->getObjID();
932 connect(obj, SIGNAL(transactionCompleted(UAVObject *, bool)), this, SLOT(uAVOTransactionCompleted(UAVObject *, bool)));
933 while (!m_transactionOK && !m_transactionTimeout) {
934 // Allow the transaction to take some time
935 innerTimeoutTimer.start(INNER_TIMEOUT);
937 // Set object updated
938 obj->updated();
939 if (!m_transactionOK) {
940 m_eventLoop.exec();
942 innerTimeoutTimer.stop();
944 disconnect(obj, SIGNAL(transactionCompleted(UAVObject *, bool)), this, SLOT(uAVOTransactionCompleted(UAVObject *, bool)));
945 if (m_transactionOK) {
946 qDebug() << "Object " << obj->getName() << " was successfully updated.";
947 if (save) {
948 m_transactionOK = false;
949 m_currentTransactionObjectID = obj->getObjID();
950 // Try to save until success or timeout
951 while (!m_transactionOK && !m_transactionTimeout) {
952 // Allow the transaction to take some time
953 innerTimeoutTimer.start(INNER_TIMEOUT);
955 // Persist object in controller
956 utilMngr->saveObjectToSD(obj);
957 if (!m_transactionOK) {
958 m_eventLoop.exec();
960 innerTimeoutTimer.stop();
962 m_currentTransactionObjectID = -1;
966 if (!m_transactionOK) {
967 qDebug() << "Transaction timed out when trying to save: " << obj->getName();
968 } else {
969 qDebug() << "Object " << obj->getName() << " was successfully saved.";
971 } else {
972 qDebug() << "Trying to save a UAVDataObject that is read only or is not a settings object.";
974 if (m_transactionTimeout) {
975 qDebug() << "Transaction timed out when trying to save " << m_modifiedObjects.count() << " objects.";
976 break;
980 outerTimeoutTimer.stop();
981 disconnect(&outerTimeoutTimer, SIGNAL(timeout()), this, SLOT(saveChangesTimeout()));
982 disconnect(&innerTimeoutTimer, SIGNAL(timeout()), &m_eventLoop, SLOT(quit()));
983 disconnect(utilMngr, SIGNAL(saveCompleted(int, bool)), this, SLOT(uAVOTransactionCompleted(int, bool)));
985 qDebug() << "Finished saving modified objects to controller. Success = " << m_transactionOK;
987 return m_transactionOK;
990 void VehicleConfigurationHelper::uAVOTransactionCompleted(int oid, bool success)
992 if (oid == m_currentTransactionObjectID) {
993 m_transactionOK = success;
994 m_eventLoop.quit();
998 void VehicleConfigurationHelper::uAVOTransactionCompleted(UAVObject *object, bool success)
1000 if (object) {
1001 uAVOTransactionCompleted(object->getObjID(), success);
1005 void VehicleConfigurationHelper::saveChangesTimeout()
1007 m_transactionOK = false;
1008 m_transactionTimeout = true;
1009 m_eventLoop.quit();
1012 void VehicleConfigurationHelper::resetVehicleConfig()
1014 // Reset all vehicle data
1015 MixerSettings *mSettings = MixerSettings::GetInstance(m_uavoManager);
1017 // Reset throttle curves
1018 QString throttlePattern = "ThrottleCurve%1";
1019 for (int i = 1; i <= 2; i++) {
1020 UAVObjectField *field = mSettings->getField(throttlePattern.arg(i));
1021 Q_ASSERT(field);
1022 // Set default curve at 90% max for Multirotors
1023 for (quint32 i = 0; i < field->getNumElements(); i++) {
1024 field->setValue(i * (1.0f / (field->getNumElements() - 1)), i);
1028 // Reset Mixer types and values
1029 QString mixerTypePattern = "Mixer%1Type";
1030 QString mixerVectorPattern = "Mixer%1Vector";
1031 for (int i = 1; i <= 10; i++) {
1032 UAVObjectField *field = mSettings->getField(mixerTypePattern.arg(i));
1033 Q_ASSERT(field);
1034 field->setValue(field->getOptions().at(0));
1036 field = mSettings->getField(mixerVectorPattern.arg(i));
1037 Q_ASSERT(field);
1038 for (quint32 i = 0; i < field->getNumElements(); i++) {
1039 field->setValue(0, i);
1043 // Apply updates
1044 // mSettings->setData(mSettings->getData());
1045 addModifiedObject(mSettings, tr("Preparing mixer settings"));
1048 void VehicleConfigurationHelper::resetGUIData()
1050 SystemSettings *sSettings = SystemSettings::GetInstance(m_uavoManager);
1052 Q_ASSERT(sSettings);
1053 SystemSettings::DataFields data = sSettings->getData();
1054 data.AirframeType = SystemSettings::AIRFRAMETYPE_CUSTOM;
1055 for (quint32 i = 0; i < SystemSettings::GUICONFIGDATA_NUMELEM; i++) {
1056 data.GUIConfigData[i] = 0;
1058 sSettings->setData(data);
1059 addModifiedObject(sSettings, tr("Preparing vehicle settings"));
1063 void VehicleConfigurationHelper::setupTriCopter()
1065 // Typical vehicle setup
1066 // 1. Setup mixer data
1067 // 2. Setup GUI data
1068 // 3. Apply changes
1070 mixerChannelSettings channels[ActuatorSettings::CHANNELADDR_NUMELEM];
1071 GUIConfigDataUnion guiSettings = getGUIConfigData();
1073 channels[0].type = MIXER_TYPE_MOTOR;
1074 channels[0].throttle1 = 100;
1075 channels[0].throttle2 = 0;
1076 channels[0].roll = 100;
1077 channels[0].pitch = 50;
1078 channels[0].yaw = 0;
1080 channels[1].type = MIXER_TYPE_MOTOR;
1081 channels[1].throttle1 = 100;
1082 channels[1].throttle2 = 0;
1083 channels[1].roll = -100;
1084 channels[1].pitch = 50;
1085 channels[1].yaw = 0;
1087 channels[2].type = MIXER_TYPE_MOTOR;
1088 channels[2].throttle1 = 100;
1089 channels[2].throttle2 = 0;
1090 channels[2].roll = 0;
1091 channels[2].pitch = -100;
1092 channels[2].yaw = 0;
1094 channels[3].type = MIXER_TYPE_SERVO;
1095 channels[3].throttle1 = 0;
1096 channels[3].throttle2 = 0;
1097 channels[3].roll = 0;
1098 channels[3].pitch = 0;
1099 channels[3].yaw = 100;
1101 guiSettings.multi.VTOLMotorNW = 1;
1102 guiSettings.multi.VTOLMotorNE = 2;
1103 guiSettings.multi.VTOLMotorS = 3;
1104 guiSettings.multi.TRIYaw = 4;
1106 applyMixerConfiguration(channels);
1107 applyMultiGUISettings(SystemSettings::AIRFRAMETYPE_TRI, guiSettings);
1110 GUIConfigDataUnion VehicleConfigurationHelper::getGUIConfigData()
1112 GUIConfigDataUnion configData;
1114 for (int i = 0; i < (int)(SystemSettings::GUICONFIGDATA_NUMELEM); i++) {
1115 configData.UAVObject[i] = 0; // systemSettingsData.GUIConfigData[i];
1118 return configData;
1121 void VehicleConfigurationHelper::setupQuadCopter()
1123 mixerChannelSettings channels[ActuatorSettings::CHANNELADDR_NUMELEM];
1124 GUIConfigDataUnion guiSettings = getGUIConfigData();
1125 SystemSettings::AirframeTypeOptions frame = SystemSettings::AIRFRAMETYPE_QUADX;
1127 switch (m_configSource->getVehicleSubType()) {
1128 case VehicleConfigurationSource::MULTI_ROTOR_QUAD_PLUS:
1130 frame = SystemSettings::AIRFRAMETYPE_QUADP;
1131 channels[0].type = MIXER_TYPE_MOTOR;
1132 channels[0].throttle1 = 100;
1133 channels[0].throttle2 = 0;
1134 channels[0].roll = 0;
1135 channels[0].pitch = 100;
1136 channels[0].yaw = -50;
1138 channels[1].type = MIXER_TYPE_MOTOR;
1139 channels[1].throttle1 = 100;
1140 channels[1].throttle2 = 0;
1141 channels[1].roll = -100;
1142 channels[1].pitch = 0;
1143 channels[1].yaw = 50;
1145 channels[2].type = MIXER_TYPE_MOTOR;
1146 channels[2].throttle1 = 100;
1147 channels[2].throttle2 = 0;
1148 channels[2].roll = 0;
1149 channels[2].pitch = -100;
1150 channels[2].yaw = -50;
1152 channels[3].type = MIXER_TYPE_MOTOR;
1153 channels[3].throttle1 = 100;
1154 channels[3].throttle2 = 0;
1155 channels[3].roll = 100;
1156 channels[3].pitch = 0;
1157 channels[3].yaw = 50;
1159 guiSettings.multi.VTOLMotorN = 1;
1160 guiSettings.multi.VTOLMotorE = 2;
1161 guiSettings.multi.VTOLMotorS = 3;
1162 guiSettings.multi.VTOLMotorW = 4;
1164 break;
1166 case VehicleConfigurationSource::MULTI_ROTOR_QUAD_X:
1168 frame = SystemSettings::AIRFRAMETYPE_QUADX;
1169 channels[0].type = MIXER_TYPE_MOTOR;
1170 channels[0].throttle1 = 100;
1171 channels[0].throttle2 = 0;
1172 channels[0].roll = 50;
1173 channels[0].pitch = 50;
1174 channels[0].yaw = -50;
1176 channels[1].type = MIXER_TYPE_MOTOR;
1177 channels[1].throttle1 = 100;
1178 channels[1].throttle2 = 0;
1179 channels[1].roll = -50;
1180 channels[1].pitch = 50;
1181 channels[1].yaw = 50;
1183 channels[2].type = MIXER_TYPE_MOTOR;
1184 channels[2].throttle1 = 100;
1185 channels[2].throttle2 = 0;
1186 channels[2].roll = -50;
1187 channels[2].pitch = -50;
1188 channels[2].yaw = -50;
1190 channels[3].type = MIXER_TYPE_MOTOR;
1191 channels[3].throttle1 = 100;
1192 channels[3].throttle2 = 0;
1193 channels[3].roll = 50;
1194 channels[3].pitch = -50;
1195 channels[3].yaw = 50;
1197 guiSettings.multi.VTOLMotorNW = 1;
1198 guiSettings.multi.VTOLMotorNE = 2;
1199 guiSettings.multi.VTOLMotorSE = 3;
1200 guiSettings.multi.VTOLMotorSW = 4;
1202 break;
1204 default:
1205 break;
1207 applyMixerConfiguration(channels);
1208 applyMultiGUISettings(frame, guiSettings);
1211 void VehicleConfigurationHelper::setupHexaCopter()
1213 mixerChannelSettings channels[ActuatorSettings::CHANNELADDR_NUMELEM];
1214 GUIConfigDataUnion guiSettings = getGUIConfigData();
1215 SystemSettings::AirframeTypeOptions frame = SystemSettings::AIRFRAMETYPE_HEXA;
1217 switch (m_configSource->getVehicleSubType()) {
1218 case VehicleConfigurationSource::MULTI_ROTOR_HEXA:
1220 frame = SystemSettings::AIRFRAMETYPE_HEXA;
1221 // HexaPlus according to new mixer table and pitch-roll-yaw mixing at 100%
1222 // Pitch Roll Yaw
1223 // M1 { 1 , 0 , -1 },
1224 // M2 { 0.5, -1, 1 },
1225 // M3 { -0.5, -1, -1 },
1226 // M4 { -1 , 0 , 1 },
1227 // M5 { -0.5, 1 , -1 },
1228 // M6 { 0.5, 1 , 1 },
1229 channels[0].type = MIXER_TYPE_MOTOR;
1230 channels[0].throttle1 = 100;
1231 channels[0].throttle2 = 0;
1232 channels[0].roll = 0;
1233 channels[0].pitch = 100;
1234 channels[0].yaw = -100;
1236 channels[1].type = MIXER_TYPE_MOTOR;
1237 channels[1].throttle1 = 100;
1238 channels[1].throttle2 = 0;
1239 channels[1].roll = -100;
1240 channels[1].pitch = 50;
1241 channels[1].yaw = 100;
1243 channels[2].type = MIXER_TYPE_MOTOR;
1244 channels[2].throttle1 = 100;
1245 channels[2].throttle2 = 0;
1246 channels[2].roll = -100;
1247 channels[2].pitch = -50;
1248 channels[2].yaw = -100;
1250 channels[3].type = MIXER_TYPE_MOTOR;
1251 channels[3].throttle1 = 100;
1252 channels[3].throttle2 = 0;
1253 channels[3].roll = 0;
1254 channels[3].pitch = -100;
1255 channels[3].yaw = 100;
1257 channels[4].type = MIXER_TYPE_MOTOR;
1258 channels[4].throttle1 = 100;
1259 channels[4].throttle2 = 0;
1260 channels[4].roll = 100;
1261 channels[4].pitch = -50;
1262 channels[4].yaw = -100;
1264 channels[5].type = MIXER_TYPE_MOTOR;
1265 channels[5].throttle1 = 100;
1266 channels[5].throttle2 = 0;
1267 channels[5].roll = 100;
1268 channels[5].pitch = 50;
1269 channels[5].yaw = 100;
1271 guiSettings.multi.VTOLMotorN = 1;
1272 guiSettings.multi.VTOLMotorNE = 2;
1273 guiSettings.multi.VTOLMotorSE = 3;
1274 guiSettings.multi.VTOLMotorS = 4;
1275 guiSettings.multi.VTOLMotorSW = 5;
1276 guiSettings.multi.VTOLMotorNW = 6;
1278 break;
1280 case VehicleConfigurationSource::MULTI_ROTOR_HEXA_COAX_Y:
1282 frame = SystemSettings::AIRFRAMETYPE_HEXACOAX;
1284 channels[0].type = MIXER_TYPE_MOTOR;
1285 channels[0].throttle1 = 100;
1286 channels[0].throttle2 = 0;
1287 channels[0].roll = 100;
1288 channels[0].pitch = 25;
1289 channels[0].yaw = -66;
1291 channels[1].type = MIXER_TYPE_MOTOR;
1292 channels[1].throttle1 = 100;
1293 channels[1].throttle2 = 0;
1294 channels[1].roll = 100;
1295 channels[1].pitch = 25;
1296 channels[1].yaw = 66;
1298 channels[2].type = MIXER_TYPE_MOTOR;
1299 channels[2].throttle1 = 100;
1300 channels[2].throttle2 = 0;
1301 channels[2].roll = -100;
1302 channels[2].pitch = 25;
1303 channels[2].yaw = -66;
1305 channels[3].type = MIXER_TYPE_MOTOR;
1306 channels[3].throttle1 = 100;
1307 channels[3].throttle2 = 0;
1308 channels[3].roll = -100;
1309 channels[3].pitch = 25;
1310 channels[3].yaw = 66;
1312 channels[4].type = MIXER_TYPE_MOTOR;
1313 channels[4].throttle1 = 100;
1314 channels[4].throttle2 = 0;
1315 channels[4].roll = 0;
1316 channels[4].pitch = -50;
1317 channels[4].yaw = -66;
1319 channels[5].type = MIXER_TYPE_MOTOR;
1320 channels[5].throttle1 = 100;
1321 channels[5].throttle2 = 0;
1322 channels[5].roll = 0;
1323 channels[5].pitch = -50;
1324 channels[5].yaw = 66;
1326 guiSettings.multi.VTOLMotorNW = 1;
1327 guiSettings.multi.VTOLMotorW = 2;
1328 guiSettings.multi.VTOLMotorNE = 3;
1329 guiSettings.multi.VTOLMotorE = 4;
1330 guiSettings.multi.VTOLMotorS = 5;
1331 guiSettings.multi.VTOLMotorSE = 6;
1333 break;
1335 case VehicleConfigurationSource::MULTI_ROTOR_HEXA_H:
1337 frame = SystemSettings::AIRFRAMETYPE_HEXAH;
1338 // HexaH according to new mixer table and pitch-roll-yaw mixing at 100%
1339 // Pitch Roll Yaw
1340 // M1 { 1 , -0.5, -0.5 },
1341 // M2 { 0 , -1 , 1 },
1342 // M3 { -1 , -0.5, -0.5 },
1343 // M4 { -1 , 0.5, 0.5 },
1344 // M5 { 0 , 1 , -1 },
1345 // M6 { 1 , 0.5, 0.5 },
1346 channels[0].type = MIXER_TYPE_MOTOR;
1347 channels[0].throttle1 = 100;
1348 channels[0].throttle2 = 0;
1349 channels[0].roll = -50;
1350 channels[0].pitch = 100;
1351 channels[0].yaw = -50;
1353 channels[1].type = MIXER_TYPE_MOTOR;
1354 channels[1].throttle1 = 100;
1355 channels[1].throttle2 = 0;
1356 channels[1].roll = -100;
1357 channels[1].pitch = 0;
1358 channels[1].yaw = 100;
1360 channels[2].type = MIXER_TYPE_MOTOR;
1361 channels[2].throttle1 = 100;
1362 channels[2].throttle2 = 0;
1363 channels[2].roll = -50;
1364 channels[2].pitch = -100;
1365 channels[2].yaw = -50;
1367 channels[3].type = MIXER_TYPE_MOTOR;
1368 channels[3].throttle1 = 100;
1369 channels[3].throttle2 = 0;
1370 channels[3].roll = 50;
1371 channels[3].pitch = -100;
1372 channels[3].yaw = 50;
1374 channels[4].type = MIXER_TYPE_MOTOR;
1375 channels[4].throttle1 = 100;
1376 channels[4].throttle2 = 0;
1377 channels[4].roll = 100;
1378 channels[4].pitch = 0;
1379 channels[4].yaw = -100;
1381 channels[5].type = MIXER_TYPE_MOTOR;
1382 channels[5].throttle1 = 100;
1383 channels[5].throttle2 = 0;
1384 channels[5].roll = 50;
1385 channels[5].pitch = 100;
1386 channels[5].yaw = 50;
1388 guiSettings.multi.VTOLMotorNE = 1;
1389 guiSettings.multi.VTOLMotorE = 2;
1390 guiSettings.multi.VTOLMotorSE = 3;
1391 guiSettings.multi.VTOLMotorSW = 4;
1392 guiSettings.multi.VTOLMotorW = 5;
1393 guiSettings.multi.VTOLMotorNW = 6;
1395 break;
1397 case VehicleConfigurationSource::MULTI_ROTOR_HEXA_X:
1399 frame = SystemSettings::AIRFRAMETYPE_HEXAX;
1400 // HexaX according to new mixer table and pitch-roll-yaw mixing at 100%
1401 // Pitch Roll Yaw
1402 // M1 { 1, -0.5, -1 },
1403 // M2 { 0, -1 , 1 },
1404 // M3 { -1, -0.5, -1 },
1405 // M4 { -1, 0.5, 1 },
1406 // M5 { 0, 1 , -1 },
1407 // M6 { 1, 0.5, 1 },
1408 channels[0].type = MIXER_TYPE_MOTOR;
1409 channels[0].throttle1 = 100;
1410 channels[0].throttle2 = 0;
1411 channels[0].roll = -50;
1412 channels[0].pitch = 100;
1413 channels[0].yaw = -100;
1415 channels[1].type = MIXER_TYPE_MOTOR;
1416 channels[1].throttle1 = 100;
1417 channels[1].throttle2 = 0;
1418 channels[1].roll = -100;
1419 channels[1].pitch = 0;
1420 channels[1].yaw = 100;
1422 channels[2].type = MIXER_TYPE_MOTOR;
1423 channels[2].throttle1 = 100;
1424 channels[2].throttle2 = 0;
1425 channels[2].roll = -50;
1426 channels[2].pitch = -100;
1427 channels[2].yaw = -100;
1429 channels[3].type = MIXER_TYPE_MOTOR;
1430 channels[3].throttle1 = 100;
1431 channels[3].throttle2 = 0;
1432 channels[3].roll = 50;
1433 channels[3].pitch = -100;
1434 channels[3].yaw = 100;
1436 channels[4].type = MIXER_TYPE_MOTOR;
1437 channels[4].throttle1 = 100;
1438 channels[4].throttle2 = 0;
1439 channels[4].roll = 100;
1440 channels[4].pitch = 0;
1441 channels[4].yaw = -100;
1443 channels[5].type = MIXER_TYPE_MOTOR;
1444 channels[5].throttle1 = 100;
1445 channels[5].throttle2 = 0;
1446 channels[5].roll = 50;
1447 channels[5].pitch = 100;
1448 channels[5].yaw = 100;
1450 guiSettings.multi.VTOLMotorNE = 1;
1451 guiSettings.multi.VTOLMotorE = 2;
1452 guiSettings.multi.VTOLMotorSE = 3;
1453 guiSettings.multi.VTOLMotorSW = 4;
1454 guiSettings.multi.VTOLMotorW = 5;
1455 guiSettings.multi.VTOLMotorNW = 6;
1457 break;
1459 default:
1460 break;
1462 applyMixerConfiguration(channels);
1463 applyMultiGUISettings(frame, guiSettings);
1466 void VehicleConfigurationHelper::setupOctoCopter()
1468 mixerChannelSettings channels[ActuatorSettings::CHANNELADDR_NUMELEM];
1469 GUIConfigDataUnion guiSettings = getGUIConfigData();
1470 SystemSettings::AirframeTypeOptions frame = SystemSettings::AIRFRAMETYPE_OCTO;
1472 switch (m_configSource->getVehicleSubType()) {
1473 case VehicleConfigurationSource::MULTI_ROTOR_OCTO:
1475 frame = SystemSettings::AIRFRAMETYPE_OCTO;
1476 // OctoP according to new mixer table and pitch-roll-yaw mixing at 100%
1477 // Pitch Roll Yaw
1478 // M1{ 1 , 0 , -1 },
1479 // M2{ 0.71,-0.71, 1 },
1480 // M3{ 0 ,-1 , -1 },
1481 // M4{ -0.71,-0.71, 1 },
1482 // M5{ -1 , 0 , -1 },
1483 // M6{ -0.71, 0.71, 1 },
1484 // M7{ 0 , 1 , -1 },
1485 // M8{ 0.71, 0.71, 1 }
1486 channels[0].type = MIXER_TYPE_MOTOR;
1487 channels[0].throttle1 = 100;
1488 channels[0].throttle2 = 0;
1489 channels[0].roll = 0;
1490 channels[0].pitch = 100;
1491 channels[0].yaw = -100;
1493 channels[1].type = MIXER_TYPE_MOTOR;
1494 channels[1].throttle1 = 100;
1495 channels[1].throttle2 = 0;
1496 channels[1].roll = -71;
1497 channels[1].pitch = 71;
1498 channels[1].yaw = 100;
1500 channels[2].type = MIXER_TYPE_MOTOR;
1501 channels[2].throttle1 = 100;
1502 channels[2].throttle2 = 0;
1503 channels[2].roll = -71;
1504 channels[2].pitch = 0;
1505 channels[2].yaw = -100;
1507 channels[3].type = MIXER_TYPE_MOTOR;
1508 channels[3].throttle1 = 100;
1509 channels[3].throttle2 = 0;
1510 channels[3].roll = -71;
1511 channels[3].pitch = -71;
1512 channels[3].yaw = 100;
1514 channels[4].type = MIXER_TYPE_MOTOR;
1515 channels[4].throttle1 = 100;
1516 channels[4].throttle2 = 0;
1517 channels[4].roll = 0;
1518 channels[4].pitch = -100;
1519 channels[4].yaw = -100;
1521 channels[5].type = MIXER_TYPE_MOTOR;
1522 channels[5].throttle1 = 100;
1523 channels[5].throttle2 = 0;
1524 channels[5].roll = 71;
1525 channels[5].pitch = -71;
1526 channels[5].yaw = 100;
1528 channels[6].type = MIXER_TYPE_MOTOR;
1529 channels[6].throttle1 = 100;
1530 channels[6].throttle2 = 0;
1531 channels[6].roll = 100;
1532 channels[6].pitch = 0;
1533 channels[6].yaw = -100;
1535 channels[7].type = MIXER_TYPE_MOTOR;
1536 channels[7].throttle1 = 100;
1537 channels[7].throttle2 = 0;
1538 channels[7].roll = 71;
1539 channels[7].pitch = 71;
1540 channels[7].yaw = 100;
1542 guiSettings.multi.VTOLMotorN = 1;
1543 guiSettings.multi.VTOLMotorNE = 2;
1544 guiSettings.multi.VTOLMotorE = 3;
1545 guiSettings.multi.VTOLMotorSE = 4;
1546 guiSettings.multi.VTOLMotorS = 5;
1547 guiSettings.multi.VTOLMotorSW = 6;
1548 guiSettings.multi.VTOLMotorW = 7;
1549 guiSettings.multi.VTOLMotorNW = 8;
1551 break;
1553 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_X:
1555 frame = SystemSettings::AIRFRAMETYPE_OCTOX;
1556 // OctoX according to new mixer table and pitch-roll-yaw mixing at 100%
1557 // Pitch Roll Yaw
1558 // M1{ 1 ,-0.41, -1 },
1559 // M2{ 0.41, -1 , 1 },
1560 // M3{ -0.41, -1 , -1 },
1561 // M4{ -1 ,-0.41, 1 },
1562 // M5{ -1 , 0.41, -1 },
1563 // M6{ -0.41, 1 , 1 },
1564 // M7{ 0.41, 1 , -1 },
1565 // M8{ 1 , 0.41, 1 }
1566 channels[0].type = MIXER_TYPE_MOTOR;
1567 channels[0].throttle1 = 100;
1568 channels[0].throttle2 = 0;
1569 channels[0].roll = -41;
1570 channels[0].pitch = 100;
1571 channels[0].yaw = -100;
1573 channels[1].type = MIXER_TYPE_MOTOR;
1574 channels[1].throttle1 = 100;
1575 channels[1].throttle2 = 0;
1576 channels[1].roll = -100;
1577 channels[1].pitch = 41;
1578 channels[1].yaw = 100;
1580 channels[2].type = MIXER_TYPE_MOTOR;
1581 channels[2].throttle1 = 100;
1582 channels[2].throttle2 = 0;
1583 channels[2].roll = -100;
1584 channels[2].pitch = -41;
1585 channels[2].yaw = -100;
1587 channels[3].type = MIXER_TYPE_MOTOR;
1588 channels[3].throttle1 = 100;
1589 channels[3].throttle2 = 0;
1590 channels[3].roll = -41;
1591 channels[3].pitch = -100;
1592 channels[3].yaw = 100;
1594 channels[4].type = MIXER_TYPE_MOTOR;
1595 channels[4].throttle1 = 100;
1596 channels[4].throttle2 = 0;
1597 channels[4].roll = 41;
1598 channels[4].pitch = -100;
1599 channels[4].yaw = -100;
1601 channels[5].type = MIXER_TYPE_MOTOR;
1602 channels[5].throttle1 = 100;
1603 channels[5].throttle2 = 0;
1604 channels[5].roll = 100;
1605 channels[5].pitch = -41;
1606 channels[5].yaw = 100;
1608 channels[6].type = MIXER_TYPE_MOTOR;
1609 channels[6].throttle1 = 100;
1610 channels[6].throttle2 = 0;
1611 channels[6].roll = 100;
1612 channels[6].pitch = 41;
1613 channels[6].yaw = -100;
1615 channels[7].type = MIXER_TYPE_MOTOR;
1616 channels[7].throttle1 = 100;
1617 channels[7].throttle2 = 0;
1618 channels[7].roll = 41;
1619 channels[7].pitch = 100;
1620 channels[7].yaw = 100;
1622 guiSettings.multi.VTOLMotorNNE = 1;
1623 guiSettings.multi.VTOLMotorENE = 2;
1624 guiSettings.multi.VTOLMotorESE = 3;
1625 guiSettings.multi.VTOLMotorSSE = 4;
1626 guiSettings.multi.VTOLMotorSSW = 5;
1627 guiSettings.multi.VTOLMotorWSW = 6;
1628 guiSettings.multi.VTOLMotorWNW = 7;
1629 guiSettings.multi.VTOLMotorNNW = 8;
1631 break;
1633 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_COAX_X:
1635 frame = SystemSettings::AIRFRAMETYPE_OCTOCOAXX;
1637 channels[0].type = MIXER_TYPE_MOTOR;
1638 channels[0].throttle1 = 100;
1639 channels[0].throttle2 = 0;
1640 channels[0].roll = 50;
1641 channels[0].pitch = 50;
1642 channels[0].yaw = -50;
1644 channels[1].type = MIXER_TYPE_MOTOR;
1645 channels[1].throttle1 = 100;
1646 channels[1].throttle2 = 0;
1647 channels[1].roll = 50;
1648 channels[1].pitch = 50;
1649 channels[1].yaw = 50;
1651 channels[2].type = MIXER_TYPE_MOTOR;
1652 channels[2].throttle1 = 100;
1653 channels[2].throttle2 = 0;
1654 channels[2].roll = -50;
1655 channels[2].pitch = 50;
1656 channels[2].yaw = -50;
1658 channels[3].type = MIXER_TYPE_MOTOR;
1659 channels[3].throttle1 = 100;
1660 channels[3].throttle2 = 0;
1661 channels[3].roll = -50;
1662 channels[3].pitch = 50;
1663 channels[3].yaw = 50;
1665 channels[4].type = MIXER_TYPE_MOTOR;
1666 channels[4].throttle1 = 100;
1667 channels[4].throttle2 = 0;
1668 channels[4].roll = -50;
1669 channels[4].pitch = -50;
1670 channels[4].yaw = -50;
1672 channels[5].type = MIXER_TYPE_MOTOR;
1673 channels[5].throttle1 = 100;
1674 channels[5].throttle2 = 0;
1675 channels[5].roll = -50;
1676 channels[5].pitch = -50;
1677 channels[5].yaw = 50;
1679 channels[6].type = MIXER_TYPE_MOTOR;
1680 channels[6].throttle1 = 100;
1681 channels[6].throttle2 = 0;
1682 channels[6].roll = 50;
1683 channels[6].pitch = -50;
1684 channels[6].yaw = -50;
1686 channels[7].type = MIXER_TYPE_MOTOR;
1687 channels[7].throttle1 = 100;
1688 channels[7].throttle2 = 0;
1689 channels[7].roll = 50;
1690 channels[7].pitch = -50;
1691 channels[7].yaw = 50;
1693 guiSettings.multi.VTOLMotorNW = 1;
1694 guiSettings.multi.VTOLMotorN = 2;
1695 guiSettings.multi.VTOLMotorNE = 3;
1696 guiSettings.multi.VTOLMotorE = 4;
1697 guiSettings.multi.VTOLMotorSE = 5;
1698 guiSettings.multi.VTOLMotorS = 6;
1699 guiSettings.multi.VTOLMotorSW = 7;
1700 guiSettings.multi.VTOLMotorW = 8;
1702 break;
1704 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_COAX_PLUS:
1706 frame = SystemSettings::AIRFRAMETYPE_OCTOCOAXP;
1708 channels[0].type = MIXER_TYPE_MOTOR;
1709 channels[0].throttle1 = 100;
1710 channels[0].throttle2 = 0;
1711 channels[0].roll = 0;
1712 channels[0].pitch = 100;
1713 channels[0].yaw = -50;
1715 channels[1].type = MIXER_TYPE_MOTOR;
1716 channels[1].throttle1 = 100;
1717 channels[1].throttle2 = 0;
1718 channels[1].roll = 0;
1719 channels[1].pitch = 100;
1720 channels[1].yaw = 50;
1722 channels[2].type = MIXER_TYPE_MOTOR;
1723 channels[2].throttle1 = 100;
1724 channels[2].throttle2 = 0;
1725 channels[2].roll = -100;
1726 channels[2].pitch = 0;
1727 channels[2].yaw = -50;
1729 channels[3].type = MIXER_TYPE_MOTOR;
1730 channels[3].throttle1 = 100;
1731 channels[3].throttle2 = 0;
1732 channels[3].roll = -100;
1733 channels[3].pitch = 0;
1734 channels[3].yaw = 50;
1736 channels[4].type = MIXER_TYPE_MOTOR;
1737 channels[4].throttle1 = 100;
1738 channels[4].throttle2 = 0;
1739 channels[4].roll = 0;
1740 channels[4].pitch = -100;
1741 channels[4].yaw = -50;
1743 channels[5].type = MIXER_TYPE_MOTOR;
1744 channels[5].throttle1 = 100;
1745 channels[5].throttle2 = 0;
1746 channels[5].roll = 0;
1747 channels[5].pitch = -100;
1748 channels[5].yaw = 50;
1750 channels[6].type = MIXER_TYPE_MOTOR;
1751 channels[6].throttle1 = 100;
1752 channels[6].throttle2 = 0;
1753 channels[6].roll = 100;
1754 channels[6].pitch = 0;
1755 channels[6].yaw = -50;
1757 channels[7].type = MIXER_TYPE_MOTOR;
1758 channels[7].throttle1 = 100;
1759 channels[7].throttle2 = 0;
1760 channels[7].roll = 100;
1761 channels[7].pitch = 0;
1762 channels[7].yaw = 50;
1764 guiSettings.multi.VTOLMotorN = 1;
1765 guiSettings.multi.VTOLMotorNE = 2;
1766 guiSettings.multi.VTOLMotorE = 3;
1767 guiSettings.multi.VTOLMotorSE = 4;
1768 guiSettings.multi.VTOLMotorS = 5;
1769 guiSettings.multi.VTOLMotorSW = 6;
1770 guiSettings.multi.VTOLMotorW = 7;
1771 guiSettings.multi.VTOLMotorNW = 8;
1773 break;
1775 case VehicleConfigurationSource::MULTI_ROTOR_OCTO_V:
1777 frame = SystemSettings::AIRFRAMETYPE_OCTOV;
1778 channels[0].type = MIXER_TYPE_MOTOR;
1779 channels[0].throttle1 = 100;
1780 channels[0].throttle2 = 0;
1781 channels[0].roll = -25;
1782 channels[0].pitch = 8;
1783 channels[0].yaw = -25;
1785 channels[1].type = MIXER_TYPE_MOTOR;
1786 channels[1].throttle1 = 100;
1787 channels[1].throttle2 = 0;
1788 channels[1].roll = -25;
1789 channels[1].pitch = 25;
1790 channels[1].yaw = 25;
1792 channels[2].type = MIXER_TYPE_MOTOR;
1793 channels[2].throttle1 = 100;
1794 channels[2].throttle2 = 0;
1795 channels[2].roll = -25;
1796 channels[2].pitch = -25;
1797 channels[2].yaw = -25;
1799 channels[3].type = MIXER_TYPE_MOTOR;
1800 channels[3].throttle1 = 100;
1801 channels[3].throttle2 = 0;
1802 channels[3].roll = -25;
1803 channels[3].pitch = -8;
1804 channels[3].yaw = 25;
1806 channels[4].type = MIXER_TYPE_MOTOR;
1807 channels[4].throttle1 = 100;
1808 channels[4].throttle2 = 0;
1809 channels[4].roll = 25;
1810 channels[4].pitch = -8;
1811 channels[4].yaw = -25;
1813 channels[5].type = MIXER_TYPE_MOTOR;
1814 channels[5].throttle1 = 100;
1815 channels[5].throttle2 = 0;
1816 channels[5].roll = 25;
1817 channels[5].pitch = -25;
1818 channels[5].yaw = 25;
1820 channels[6].type = MIXER_TYPE_MOTOR;
1821 channels[6].throttle1 = 100;
1822 channels[6].throttle2 = 0;
1823 channels[6].roll = 25;
1824 channels[6].pitch = 25;
1825 channels[6].yaw = -25;
1827 channels[7].type = MIXER_TYPE_MOTOR;
1828 channels[7].throttle1 = 100;
1829 channels[7].throttle2 = 0;
1830 channels[7].roll = 25;
1831 channels[7].pitch = 8;
1832 channels[7].yaw = 25;
1834 guiSettings.multi.VTOLMotorN = 1;
1835 guiSettings.multi.VTOLMotorNE = 2;
1836 guiSettings.multi.VTOLMotorE = 3;
1837 guiSettings.multi.VTOLMotorSE = 4;
1838 guiSettings.multi.VTOLMotorS = 5;
1839 guiSettings.multi.VTOLMotorSW = 6;
1840 guiSettings.multi.VTOLMotorW = 7;
1841 guiSettings.multi.VTOLMotorNW = 8;
1843 break;
1845 default:
1846 break;
1849 applyMixerConfiguration(channels);
1850 applyMultiGUISettings(frame, guiSettings);
1853 void VehicleConfigurationHelper::setupElevon()
1855 mixerChannelSettings channels[ActuatorSettings::CHANNELADDR_NUMELEM];
1856 GUIConfigDataUnion guiSettings = getGUIConfigData();
1858 // Motor (Chan 3)
1859 channels[2].type = MIXER_TYPE_MOTOR;
1860 channels[2].throttle1 = 100;
1861 channels[2].throttle2 = 0;
1862 channels[2].roll = 0;
1863 channels[2].pitch = 0;
1864 channels[2].yaw = 0;
1866 // Elevon Servo 1 (Chan 1)
1867 channels[0].type = MIXER_TYPE_SERVO;
1868 channels[0].throttle1 = 0;
1869 channels[0].throttle2 = 0;
1870 channels[0].roll = 100;
1871 channels[0].pitch = -100;
1872 channels[0].yaw = 0;
1874 // Elevon Servo 2 (Chan 2)
1875 channels[1].type = MIXER_TYPE_SERVO;
1876 channels[1].throttle1 = 0;
1877 channels[1].throttle2 = 0;
1878 channels[1].roll = 100;
1879 channels[1].pitch = 100;
1880 channels[1].yaw = 0;
1882 guiSettings.fixedwing.FixedWingThrottle = 3;
1883 guiSettings.fixedwing.FixedWingRoll1 = 1;
1884 guiSettings.fixedwing.FixedWingRoll2 = 2;
1886 applyMixerConfiguration(channels);
1887 applyMultiGUISettings(SystemSettings::AIRFRAMETYPE_FIXEDWINGELEVON, guiSettings);
1890 void VehicleConfigurationHelper::setupDualAileron()
1892 // Typical vehicle setup
1893 // 1. Setup mixer data
1894 // 2. Setup GUI data
1895 // 3. Apply changes
1897 mixerChannelSettings channels[ActuatorSettings::CHANNELADDR_NUMELEM];
1898 GUIConfigDataUnion guiSettings = getGUIConfigData();
1900 // Motor (Chan 3)
1901 channels[2].type = MIXER_TYPE_MOTOR;
1902 channels[2].throttle1 = 100;
1903 channels[2].throttle2 = 0;
1904 channels[2].roll = 0;
1905 channels[2].pitch = 0;
1906 channels[2].yaw = 0;
1908 // Aileron Servo 1 (Chan 1)
1909 channels[0].type = MIXER_TYPE_SERVO;
1910 channels[0].throttle1 = 0;
1911 channels[0].throttle2 = 0;
1912 channels[0].roll = 100;
1913 channels[0].pitch = 0;
1914 channels[0].yaw = 0;
1916 // Aileron Servo 2 (Chan 6)
1917 channels[5].type = MIXER_TYPE_SERVO;
1918 channels[5].throttle1 = 0;
1919 channels[5].throttle2 = 0;
1920 channels[5].roll = 100;
1921 channels[5].pitch = 0;
1922 channels[5].yaw = 0;
1924 // Elevator Servo (Chan 2)
1925 channels[1].type = MIXER_TYPE_SERVO;
1926 channels[1].throttle1 = 0;
1927 channels[1].throttle2 = 0;
1928 channels[1].roll = 0;
1929 channels[1].pitch = 100;
1930 channels[1].yaw = 0;
1932 // Rudder Servo (Chan 4)
1933 channels[3].type = MIXER_TYPE_SERVO;
1934 channels[3].throttle1 = 0;
1935 channels[3].throttle2 = 0;
1936 channels[3].roll = 0;
1937 channels[3].pitch = 0;
1938 channels[3].yaw = -100;
1940 guiSettings.fixedwing.FixedWingThrottle = 3;
1941 guiSettings.fixedwing.FixedWingRoll1 = 1;
1942 guiSettings.fixedwing.FixedWingRoll2 = 6;
1943 guiSettings.fixedwing.FixedWingPitch1 = 2;
1944 guiSettings.fixedwing.FixedWingYaw1 = 4;
1946 applyMixerConfiguration(channels);
1947 applyMultiGUISettings(SystemSettings::AIRFRAMETYPE_FIXEDWING, guiSettings);
1950 void VehicleConfigurationHelper::setupAileron()
1952 // Typical vehicle setup
1953 // 1. Setup mixer data
1954 // 2. Setup GUI data
1955 // 3. Apply changes
1957 mixerChannelSettings channels[ActuatorSettings::CHANNELADDR_NUMELEM];
1958 GUIConfigDataUnion guiSettings = getGUIConfigData();
1960 // Motor (Chan 3)
1961 channels[2].type = MIXER_TYPE_MOTOR;
1962 channels[2].throttle1 = 100;
1963 channels[2].throttle2 = 0;
1964 channels[2].roll = 0;
1965 channels[2].pitch = 0;
1966 channels[2].yaw = 0;
1968 // Aileron Servo (Chan 1)
1969 channels[0].type = MIXER_TYPE_SERVO;
1970 channels[0].throttle1 = 0;
1971 channels[0].throttle2 = 0;
1972 channels[0].roll = 100;
1973 channels[0].pitch = 0;
1974 channels[0].yaw = 0;
1976 // Elevator Servo (Chan 2)
1977 channels[1].type = MIXER_TYPE_SERVO;
1978 channels[1].throttle1 = 0;
1979 channels[1].throttle2 = 0;
1980 channels[1].roll = 0;
1981 channels[1].pitch = 100;
1982 channels[1].yaw = 0;
1984 // Rudder Servo (Chan 4)
1985 channels[3].type = MIXER_TYPE_SERVO;
1986 channels[3].throttle1 = 0;
1987 channels[3].throttle2 = 0;
1988 channels[3].roll = 0;
1989 channels[3].pitch = 0;
1990 channels[3].yaw = -100;
1992 guiSettings.fixedwing.FixedWingThrottle = 3;
1993 guiSettings.fixedwing.FixedWingRoll1 = 1;
1994 guiSettings.fixedwing.FixedWingPitch1 = 2;
1995 guiSettings.fixedwing.FixedWingYaw1 = 4;
1997 applyMixerConfiguration(channels);
1998 applyMultiGUISettings(SystemSettings::AIRFRAMETYPE_FIXEDWING, guiSettings);
2001 void VehicleConfigurationHelper::setupVtail()
2003 // Typical vehicle setup
2004 // 1. Setup mixer data
2005 // 2. Setup GUI data
2006 // 3. Apply changes
2008 mixerChannelSettings channels[ActuatorSettings::CHANNELADDR_NUMELEM];
2009 GUIConfigDataUnion guiSettings = getGUIConfigData();
2011 // Motor (Chan 3)
2012 channels[2].type = MIXER_TYPE_MOTOR;
2013 channels[2].throttle1 = 100;
2014 channels[2].throttle2 = 0;
2015 channels[2].roll = 0;
2016 channels[2].pitch = 0;
2017 channels[2].yaw = 0;
2019 // Aileron Servo (Chan 1)
2020 channels[0].type = MIXER_TYPE_SERVO;
2021 channels[0].throttle1 = 0;
2022 channels[0].throttle2 = 0;
2023 channels[0].roll = 100;
2024 channels[0].pitch = 0;
2025 channels[0].yaw = 0;
2027 // Aileron Servo 2 (Chan 6)
2028 channels[5].type = MIXER_TYPE_SERVO;
2029 channels[5].throttle1 = 0;
2030 channels[5].throttle2 = 0;
2031 channels[5].roll = 100;
2032 channels[5].pitch = 0;
2033 channels[5].yaw = 0;
2035 // Right Vtail Servo (Chan 2)
2036 channels[1].type = MIXER_TYPE_SERVO;
2037 channels[1].throttle1 = 0;
2038 channels[1].throttle2 = 0;
2039 channels[1].roll = 0;
2040 channels[1].pitch = 100;
2041 channels[1].yaw = -100;
2043 // Left Vtail Servo (Chan 4)
2044 channels[3].type = MIXER_TYPE_SERVO;
2045 channels[3].throttle1 = 0;
2046 channels[3].throttle2 = 0;
2047 channels[3].roll = 0;
2048 channels[3].pitch = -100;
2049 channels[3].yaw = -100;
2051 guiSettings.fixedwing.FixedWingThrottle = 3;
2052 guiSettings.fixedwing.FixedWingRoll1 = 1;
2053 guiSettings.fixedwing.FixedWingRoll2 = 6;
2054 guiSettings.fixedwing.FixedWingPitch1 = 4; // Vtail left (top view, nose up)
2055 guiSettings.fixedwing.FixedWingPitch2 = 2; // Vtail right
2057 applyMixerConfiguration(channels);
2058 applyMultiGUISettings(SystemSettings::AIRFRAMETYPE_FIXEDWINGVTAIL, guiSettings);
2063 * Ground vehicles
2067 void VehicleConfigurationHelper::setupCar()
2069 // Typical vehicle setup
2070 // 1. Setup mixer data
2071 // 2. Setup GUI data
2072 // 3. Apply changes
2074 mixerChannelSettings channels[ActuatorSettings::CHANNELADDR_NUMELEM];
2075 GUIConfigDataUnion guiSettings = getGUIConfigData();
2077 // Steering Servo (Chan 1)
2078 channels[0].type = MIXER_TYPE_SERVO;
2079 channels[0].throttle1 = 0;
2080 channels[0].throttle2 = 0;
2081 channels[0].roll = 0;
2082 channels[0].pitch = 0;
2083 channels[0].yaw = 100;
2085 // Motor (Chan 2)
2086 channels[1].type = MIXER_TYPE_REVERSABLEMOTOR;
2087 channels[1].throttle1 = 100;
2088 channels[1].throttle2 = 0;
2089 channels[1].roll = 0;
2090 channels[1].pitch = 0;
2091 channels[1].yaw = 0;
2093 guiSettings.ground.GroundVehicleSteering1 = 1;
2094 guiSettings.ground.GroundVehicleThrottle2 = 2;
2096 applyMixerConfiguration(channels);
2097 applyMultiGUISettings(SystemSettings::AIRFRAMETYPE_GROUNDVEHICLECAR, guiSettings);
2100 void VehicleConfigurationHelper::setupTank()
2102 // Typical vehicle setup
2103 // 1. Setup mixer data
2104 // 2. Setup GUI data
2105 // 3. Apply changes
2107 mixerChannelSettings channels[ActuatorSettings::CHANNELADDR_NUMELEM];
2108 GUIConfigDataUnion guiSettings = getGUIConfigData();
2110 // Left Motor (Chan 1)
2111 channels[0].type = MIXER_TYPE_REVERSABLEMOTOR;
2112 channels[0].throttle1 = 100;
2113 channels[0].throttle2 = 0;
2114 channels[0].roll = 0;
2115 channels[0].pitch = 0;
2116 channels[0].yaw = 100;
2118 // Right Motor (Chan 2)
2119 channels[1].type = MIXER_TYPE_REVERSABLEMOTOR;
2120 channels[1].throttle1 = 100;
2121 channels[1].throttle2 = 0;
2122 channels[1].roll = 0;
2123 channels[1].pitch = 0;
2124 channels[1].yaw = -100;
2126 guiSettings.ground.GroundVehicleThrottle1 = 1;
2127 guiSettings.ground.GroundVehicleThrottle2 = 2;
2129 applyMixerConfiguration(channels);
2130 applyMultiGUISettings(SystemSettings::AIRFRAMETYPE_GROUNDVEHICLEDIFFERENTIAL, guiSettings);
2133 void VehicleConfigurationHelper::setupMotorcycle()
2135 // Typical vehicle setup
2136 // 1. Setup mixer data
2137 // 2. Setup GUI data
2138 // 3. Apply changes
2140 mixerChannelSettings channels[ActuatorSettings::CHANNELADDR_NUMELEM];
2141 GUIConfigDataUnion guiSettings = getGUIConfigData();
2143 // Steering Servo (Chan 1)
2144 channels[0].type = MIXER_TYPE_SERVO;
2145 channels[0].throttle1 = 0;
2146 channels[0].throttle2 = 0;
2147 channels[0].roll = 0;
2148 channels[0].pitch = 0;
2149 channels[0].yaw = 100;
2151 // Motor (Chan 2)
2152 channels[1].type = MIXER_TYPE_MOTOR;
2153 channels[1].throttle1 = 100;
2154 channels[1].throttle2 = 0;
2155 channels[1].roll = 0;
2156 channels[1].pitch = 0;
2157 channels[1].yaw = 0;
2159 guiSettings.ground.GroundVehicleSteering1 = 1;
2160 guiSettings.ground.GroundVehicleThrottle2 = 2;
2162 applyMixerConfiguration(channels);
2163 applyMultiGUISettings(SystemSettings::AIRFRAMETYPE_GROUNDVEHICLEMOTORCYCLE, guiSettings);