diff --git a/ground/openpilotgcs/src/plugins/setupwizard/levellingutil.h b/ground/openpilotgcs/src/plugins/setupwizard/levellingutil.h index 0db8a23c0..fb8ffcdce 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/levellingutil.h +++ b/ground/openpilotgcs/src/plugins/setupwizard/levellingutil.h @@ -33,16 +33,7 @@ #include #include "uavobject.h" - -struct accelGyroBias { - float m_accelerometerXBias; - float m_accelerometerYBias; - float m_accelerometerZBias; - - float m_gyroXBias; - float m_gyroYBias; - float m_gyroZBias; -}; +#include "vehicleconfigurationsource.h" class LevellingUtil : public QObject { diff --git a/ground/openpilotgcs/src/plugins/setupwizard/pages/outputpage.cpp b/ground/openpilotgcs/src/plugins/setupwizard/pages/outputpage.cpp index 3e7313c37..d9903af57 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/pages/outputpage.cpp +++ b/ground/openpilotgcs/src/plugins/setupwizard/pages/outputpage.cpp @@ -48,7 +48,7 @@ bool OutputPage::validatePage() getWizard()->setESCType(SetupWizard::ESC_RAPID); } else { - getWizard()->setESCType(SetupWizard::ESC_DEFAULT); + getWizard()->setESCType(SetupWizard::ESC_LEGACY); } return true; diff --git a/ground/openpilotgcs/src/plugins/setupwizard/pages/outputpage.ui b/ground/openpilotgcs/src/plugins/setupwizard/pages/outputpage.ui index 37a5a9bb5..7b290cece 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/pages/outputpage.ui +++ b/ground/openpilotgcs/src/plugins/setupwizard/pages/outputpage.ui @@ -64,7 +64,7 @@ p, li { white-space: pre-wrap; } - 50 + 160 40 100 100 @@ -74,14 +74,14 @@ p, li { white-space: pre-wrap; } Tricopter, Quadcopter, Hexacopter, Octocopter - Default ESC + Legacy ESC 50 Hz true - true + false true @@ -93,7 +93,7 @@ p, li { white-space: pre-wrap; } - 170 + 30 40 100 100 @@ -109,6 +109,9 @@ p, li { white-space: pre-wrap; } true + + true + true diff --git a/ground/openpilotgcs/src/plugins/setupwizard/setupwizard.cpp b/ground/openpilotgcs/src/plugins/setupwizard/setupwizard.cpp index 7fdcc921c..0dc44c62d 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/setupwizard.cpp +++ b/ground/openpilotgcs/src/plugins/setupwizard/setupwizard.cpp @@ -41,11 +41,9 @@ #include "pages/flashpage.h" #include "pages/notyetimplementedpage.h" #include "extensionsystem/pluginmanager.h" -#include "hwsettings.h" -#include "actuatorsettings.h" -#include "attitudesettings.h" +#include "vehicleconfigurationhelper.h" -SetupWizard::SetupWizard(QWidget *parent) : QWizard(parent), +SetupWizard::SetupWizard(QWidget *parent) : QWizard(parent), VehicleConfigurationSource(), m_controllerSelectionMode(CONTROLLER_SELECTION_UNKNOWN), m_controllerType(CONTROLLER_UNKNOWN), m_vehicleType(VEHICLE_UNKNOWN), m_inputType(INPUT_UNKNOWN), m_escType(ESC_UNKNOWN), m_levellingPerformed(false), m_connectionManager(0) @@ -179,8 +177,8 @@ QString SetupWizard::getSummaryText() summary.append(tr("ESC type: ")); switch (getESCType()) { - case ESC_DEFAULT: - summary.append(tr("Default ESC (50 Hz)")); + case ESC_LEGACY: + summary.append(tr("Legacy ESC (50 Hz)")); break; case ESC_RAPID: summary.append(tr("Rapid ESC (400 Hz)")); @@ -201,239 +199,11 @@ QString SetupWizard::getSummaryText() return summary; } -void SetupWizard::applyConfiguration() -{ - UAVObjectManager* uavoMgr = getUAVObjectManager(); - applyHardwareConfiguration(uavoMgr); - applyVehicleConfiguration(uavoMgr); - applyOutputConfiguration(uavoMgr); - applyLevellingConfiguration(uavoMgr); -} - -UAVObjectManager* SetupWizard::getUAVObjectManager() -{ - ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); - UAVObjectManager * uavObjectManager = pm->getObject(); - Q_ASSERT(uavObjectManager); - return uavObjectManager; -} - -void SetupWizard::applyHardwareConfiguration(UAVObjectManager* uavoMgr) -{ - HwSettings* hwSettings = HwSettings::GetInstance(uavoMgr); - HwSettings::DataFields data = hwSettings->getData(); - switch(getControllerType()) - { - case CONTROLLER_CC: - case CONTROLLER_CC3D: - // Reset all ports - data.CC_RcvrPort = HwSettings::CC_RCVRPORT_DISABLED; - data.CC_FlexiPort = HwSettings::CC_FLEXIPORT_DISABLED; - data.CC_MainPort = HwSettings::CC_MAINPORT_DISABLED; - switch(getInputType()) - { - case INPUT_PWM: - data.CC_RcvrPort = HwSettings::CC_RCVRPORT_PWM; - break; - case INPUT_PPM: - data.CC_RcvrPort = HwSettings::CC_RCVRPORT_PPM; - break; - case INPUT_SBUS: - data.CC_MainPort = HwSettings::CC_MAINPORT_SBUS; - break; - case INPUT_DSM: - // TODO: Handle all of the DSM types ?? Which is most common? - data.CC_MainPort = HwSettings::CC_MAINPORT_DSM2; - break; - } - break; - case CONTROLLER_REVO: - // TODO: Implement Revo settings - break; - } - hwSettings->setData(data); -} - -void SetupWizard::applyVehicleConfiguration(UAVObjectManager *uavoMgr) -{ - - switch(getVehicleType()) - { - case VEHICLE_MULTI: - { - resetVehicleConfig(uavoMgr); - - switch(getVehicleSubType()) - { - case SetupWizard::MULTI_ROTOR_TRI_Y: - setupTriCopter(uavoMgr); - break; - case SetupWizard::MULTI_ROTOR_QUAD_X: - case SetupWizard::MULTI_ROTOR_QUAD_PLUS: - setupQuadCopter(uavoMgr); - break; - case SetupWizard::MULTI_ROTOR_HEXA: - case SetupWizard::MULTI_ROTOR_HEXA_COAX_Y: - case SetupWizard::MULTI_ROTOR_HEXA_H: - setupHexaCopter(uavoMgr); - break; - case SetupWizard::MULTI_ROTOR_OCTO: - case SetupWizard::MULTI_ROTOR_OCTO_COAX_X: - case SetupWizard::MULTI_ROTOR_OCTO_COAX_PLUS: - case SetupWizard::MULTI_ROTOR_OCTO_V: - setupOctoCopter(uavoMgr); - break; - } - break; - } - case VEHICLE_FIXEDWING: - case VEHICLE_HELI: - case VEHICLE_SURFACE: - // TODO: Implement settings for other vehicle types? - break; - } -} - -void SetupWizard::applyOutputConfiguration(UAVObjectManager *uavoMgr) -{ - ActuatorSettings* actSettings = ActuatorSettings::GetInstance(uavoMgr); - switch(getVehicleType()) - { - case VEHICLE_MULTI: - { - ActuatorSettings::DataFields data = actSettings->getData(); - - data.ChannelUpdateFreq[0] = DEFAULT_ESC_FREQUENCE; - data.ChannelUpdateFreq[1] = DEFAULT_ESC_FREQUENCE; - data.ChannelUpdateFreq[3] = DEFAULT_ESC_FREQUENCE; - data.ChannelUpdateFreq[4] = DEFAULT_ESC_FREQUENCE; - - qint16 updateFrequence = DEFAULT_ESC_FREQUENCE; - switch(getESCType()) - { - case ESC_DEFAULT: - updateFrequence = DEFAULT_ESC_FREQUENCE; - break; - case ESC_RAPID: - updateFrequence = RAPID_ESC_FREQUENCE; - break; - } - - switch(getVehicleSubType()) - { - case SetupWizard::MULTI_ROTOR_TRI_Y: - data.ChannelUpdateFreq[0] = updateFrequence; - break; - case SetupWizard::MULTI_ROTOR_QUAD_X: - case SetupWizard::MULTI_ROTOR_QUAD_PLUS: - data.ChannelUpdateFreq[0] = updateFrequence; - data.ChannelUpdateFreq[1] = updateFrequence; - break; - case SetupWizard::MULTI_ROTOR_HEXA: - case SetupWizard::MULTI_ROTOR_HEXA_COAX_Y: - case SetupWizard::MULTI_ROTOR_HEXA_H: - case SetupWizard::MULTI_ROTOR_OCTO: - case SetupWizard::MULTI_ROTOR_OCTO_COAX_X: - case SetupWizard::MULTI_ROTOR_OCTO_COAX_PLUS: - case SetupWizard::MULTI_ROTOR_OCTO_V: - data.ChannelUpdateFreq[0] = updateFrequence; - data.ChannelUpdateFreq[1] = updateFrequence; - data.ChannelUpdateFreq[3] = updateFrequence; - data.ChannelUpdateFreq[4] = updateFrequence; - break; - } - actSettings->setData(data); - break; - } - case VEHICLE_FIXEDWING: - case VEHICLE_HELI: - case VEHICLE_SURFACE: - // TODO: Implement settings for other vehicle types? - break; - } -} - -void SetupWizard::applyLevellingConfiguration(UAVObjectManager *uavoMgr) -{ - if(isLevellingPerformed()) - { - accelGyroBias bias = getLevellingBias(); - AttitudeSettings::DataFields attitudeSettingsData = AttitudeSettings::GetInstance(uavoMgr)->getData(); - attitudeSettingsData.AccelBias[0] += bias.m_accelerometerXBias; - attitudeSettingsData.AccelBias[1] += bias.m_accelerometerYBias; - attitudeSettingsData.AccelBias[2] += bias.m_accelerometerZBias; - attitudeSettingsData.GyroBias[0] = -bias.m_gyroXBias; - attitudeSettingsData.GyroBias[1] = -bias.m_gyroYBias; - attitudeSettingsData.GyroBias[2] = -bias.m_gyroZBias; - AttitudeSettings::GetInstance(uavoMgr)->setData(attitudeSettingsData); - } -} - - -void SetupWizard::resetVehicleConfig(UAVObjectManager *uavoMgr) -{ - // Reset all mixers - MixerSettings* mSettings = MixerSettings::GetInstance(uavoMgr); - - QString mixerTypePattern = "Mixer%1Type"; - QString mixerVectorPattern = "Mixer%1Vector"; - for(int i = 1; i <= 10; i++) { - UAVObjectField *field = mSettings->getField(mixerTypePattern.arg(i)); - Q_ASSERT(field); - field->setValue(field->getOptions().at(0)); - - field = mSettings->getField(mixerVectorPattern.arg(i)); - Q_ASSERT(field); - for(int i = 0; i < field->getNumElements(); i++){ - field->setValue(0, i); - } - } - mSettings->setData(mSettings->getData()); - -} - - -void SetupWizard::setupTriCopter(UAVObjectManager *uavoMgr) -{ - // Typical vehicle setup - // 1. Setup and apply mixer - // 2. Setup GUI data - - double mixer [8][3] = { - { 0.5, 1, 0}, - { 0.5, -1, 0}, - { -1, 0, 0}, - { 0, 0, 0}, - { 0, 0, 0}, - { 0, 0, 0}, - { 0, 0, 0}, - { 0, 0, 0} - }; - -} - -void SetupWizard::setupQuadCopter(UAVObjectManager *uavoMgr) -{ -} - -void SetupWizard::setupHexaCopter(UAVObjectManager *uavoMgr) -{ -} - -void SetupWizard::setupOctoCopter(UAVObjectManager *uavoMgr) -{ -} - -void SetupWizard::exportConfiguration() -{ - applyConfiguration(); - // Call export configuration function... -} - void SetupWizard::writeConfiguration() { - applyConfiguration(); - // Call Save UAVOs to controller + VehicleConfigurationHelper *helper = new VehicleConfigurationHelper(this); + Q_ASSERT(helper); + helper->setupVehicle(); } void SetupWizard::createPages() diff --git a/ground/openpilotgcs/src/plugins/setupwizard/setupwizard.h b/ground/openpilotgcs/src/plugins/setupwizard/setupwizard.h index 4fcd97422..566ec46ab 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/setupwizard.h +++ b/ground/openpilotgcs/src/plugins/setupwizard/setupwizard.h @@ -32,26 +32,16 @@ #include "levellingutil.h" #include #include -#include "uavobjectmanager.h" -#include "mixersettings.h" +#include "vehicleconfigurationsource.h" -class SetupWizard : public QWizard +class SetupWizard : public QWizard, public VehicleConfigurationSource { Q_OBJECT public: SetupWizard(QWidget *parent = 0); int nextId() const; - enum CONTROLLER_SELECTION_MODE {CONTROLLER_SELECTION_AUTOMATIC, CONTROLLER_SELECTION_MANUAL, CONTROLLER_SELECTION_UNKNOWN}; - enum CONTROLLER_TYPE {CONTROLLER_UNKNOWN, CONTROLLER_CC, CONTROLLER_CC3D, CONTROLLER_REVO, CONTROLLER_PIPX}; - enum VEHICLE_TYPE {VEHICLE_UNKNOWN, VEHICLE_MULTI, VEHICLE_FIXEDWING, VEHICLE_HELI, VEHICLE_SURFACE}; - enum VEHICLE_SUB_TYPE {MULTI_ROTOR_UNKNOWN, MULTI_ROTOR_TRI_Y, MULTI_ROTOR_QUAD_X, MULTI_ROTOR_QUAD_PLUS, - MULTI_ROTOR_HEXA, MULTI_ROTOR_HEXA_H, MULTI_ROTOR_HEXA_COAX_Y, MULTI_ROTOR_OCTO, - MULTI_ROTOR_OCTO_V, MULTI_ROTOR_OCTO_COAX_X, MULTI_ROTOR_OCTO_COAX_PLUS, FIXED_WING_AILERON, - FIXED_WING_VTAIL, HELI_CCPM}; - enum ESC_TYPE {ESC_DEFAULT, ESC_RAPID, ESC_UNKNOWN}; - enum INPUT_TYPE {INPUT_PWM, INPUT_PPM, INPUT_SBUS, INPUT_DSM, INPUT_UNKNOWN}; void setControllerSelectionMode(SetupWizard::CONTROLLER_SELECTION_MODE mode) { m_controllerSelectionMode = mode; } SetupWizard::CONTROLLER_SELECTION_MODE getControllerSelectionMode() const { return m_controllerSelectionMode; } @@ -86,13 +76,9 @@ public: return m_connectionManager; } public slots: - void exportConfiguration(); void writeConfiguration(); private: - static const qint16 DEFAULT_ESC_FREQUENCE = 50; - static const qint16 RAPID_ESC_FREQUENCE = 400; - enum {PAGE_START, PAGE_CONTROLLER, PAGE_VEHICLES, PAGE_MULTI, PAGE_FIXEDWING, PAGE_HELI, PAGE_SURFACE, PAGE_INPUT, PAGE_OUTPUT, PAGE_LEVELLING, PAGE_FLASH, PAGE_SUMMARY, PAGE_NOTYETIMPLEMENTED, PAGE_END}; @@ -108,22 +94,6 @@ private: accelGyroBias m_levellingBias; Core::ConnectionManager *m_connectionManager; - - UAVObjectManager *getUAVObjectManager(); - - void applyConfiguration(); - void applyHardwareConfiguration(UAVObjectManager *uavoMgr); - void applyVehicleConfiguration(UAVObjectManager *uavoMgr); - void applyOutputConfiguration(UAVObjectManager *uavoMgr); - void applyLevellingConfiguration(UAVObjectManager *uavoMgr); - - void resetVehicleConfig(UAVObjectManager *uavoMgr); - void resetMixerVectors(MixerSettings::DataFields data, qint8 channelIndex); - - void setupTriCopter(UAVObjectManager *uavoMgr); - void setupQuadCopter(UAVObjectManager *uavoMgr); - void setupHexaCopter(UAVObjectManager *uavoMgr); - void setupOctoCopter(UAVObjectManager *uavoMgr); }; #endif // SETUPWIZARD_H diff --git a/ground/openpilotgcs/src/plugins/setupwizard/setupwizard.pro b/ground/openpilotgcs/src/plugins/setupwizard/setupwizard.pro index d3a6dc0da..3f1876bfa 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/setupwizard.pro +++ b/ground/openpilotgcs/src/plugins/setupwizard/setupwizard.pro @@ -25,7 +25,9 @@ HEADERS += setupwizardplugin.h \ pages/summarypage.h \ pages/flashpage.h \ pages/levellingpage.h \ - levellingutil.h + levellingutil.h \ + vehicleconfigurationsource.h \ + vehicleconfigurationhelper.h SOURCES += setupwizardplugin.cpp \ setupwizard.cpp \ @@ -44,7 +46,9 @@ SOURCES += setupwizardplugin.cpp \ pages/summarypage.cpp \ pages/flashpage.cpp \ pages/levellingpage.cpp \ - levellingutil.cpp + levellingutil.cpp \ + vehicleconfigurationsource.cpp \ + vehicleconfigurationhelper.cpp OTHER_FILES += SetupWizard.pluginspec diff --git a/ground/openpilotgcs/src/plugins/setupwizard/vehicleconfigurationhelper.cpp b/ground/openpilotgcs/src/plugins/setupwizard/vehicleconfigurationhelper.cpp new file mode 100644 index 000000000..945d38b1e --- /dev/null +++ b/ground/openpilotgcs/src/plugins/setupwizard/vehicleconfigurationhelper.cpp @@ -0,0 +1,298 @@ +/** + ****************************************************************************** + * + * @file vehicleconfigurationhelper.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. + * @addtogroup + * @{ + * @addtogroup VehicleConfigurationHelper + * @{ + * @brief + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "vehicleconfigurationhelper.h" +#include "extensionsystem/pluginmanager.h" +#include "hwsettings.h" +#include "actuatorsettings.h" +#include "attitudesettings.h" +#include "mixersettings.h" +#include "systemsettings.h" + +VehicleConfigurationHelper::VehicleConfigurationHelper(VehicleConfigurationSource *configSource) + : m_configSource(configSource), m_uavoManager(0) +{ + Q_ASSERT(m_configSource); + ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); + m_uavoManager = pm->getObject(); + Q_ASSERT(m_uavoManager); +} + +void VehicleConfigurationHelper::setupVehicle() +{ + applyHardwareConfiguration(); + applyVehicleConfiguration(); + applyOutputConfiguration(); + applyFlighModeConfiguration(); + applyLevellingConfiguration(); +} + +void VehicleConfigurationHelper::applyHardwareConfiguration() +{ + HwSettings* hwSettings = HwSettings::GetInstance(m_uavoManager); + HwSettings::DataFields data = hwSettings->getData(); + switch(m_configSource->getControllerType()) + { + case VehicleConfigurationSource::CONTROLLER_CC: + case VehicleConfigurationSource::CONTROLLER_CC3D: + // Reset all ports + data.CC_RcvrPort = HwSettings::CC_RCVRPORT_DISABLED; + data.CC_FlexiPort = HwSettings::CC_FLEXIPORT_DISABLED; + data.CC_MainPort = HwSettings::CC_MAINPORT_DISABLED; + switch(m_configSource->getInputType()) + { + case VehicleConfigurationSource::INPUT_PWM: + data.CC_RcvrPort = HwSettings::CC_RCVRPORT_PWM; + break; + case VehicleConfigurationSource::INPUT_PPM: + data.CC_RcvrPort = HwSettings::CC_RCVRPORT_PPM; + break; + case VehicleConfigurationSource::INPUT_SBUS: + data.CC_MainPort = HwSettings::CC_MAINPORT_SBUS; + break; + case VehicleConfigurationSource::INPUT_DSM: + // TODO: Handle all of the DSM types ?? Which is most common? + data.CC_MainPort = HwSettings::CC_MAINPORT_DSM2; + break; + default: + break; + } + break; + case VehicleConfigurationSource::CONTROLLER_REVO: + // TODO: Implement Revo settings + break; + default: + break; + } + hwSettings->setData(data); +} + +void VehicleConfigurationHelper::applyVehicleConfiguration() +{ + + switch(m_configSource->getVehicleType()) + { + case VehicleConfigurationSource::VEHICLE_MULTI: + { + resetGUIData(); + resetVehicleConfig(); + + switch(m_configSource->getVehicleSubType()) + { + case VehicleConfigurationSource::MULTI_ROTOR_TRI_Y: + setupTriCopter(); + break; + case VehicleConfigurationSource::MULTI_ROTOR_QUAD_X: + case VehicleConfigurationSource::MULTI_ROTOR_QUAD_PLUS: + setupQuadCopter(); + break; + case VehicleConfigurationSource::MULTI_ROTOR_HEXA: + case VehicleConfigurationSource::MULTI_ROTOR_HEXA_COAX_Y: + case VehicleConfigurationSource::MULTI_ROTOR_HEXA_H: + setupHexaCopter(); + break; + case VehicleConfigurationSource::MULTI_ROTOR_OCTO: + case VehicleConfigurationSource::MULTI_ROTOR_OCTO_COAX_X: + case VehicleConfigurationSource::MULTI_ROTOR_OCTO_COAX_PLUS: + case VehicleConfigurationSource::MULTI_ROTOR_OCTO_V: + setupOctoCopter(); + break; + default: + break; + } + break; + } + case VehicleConfigurationSource::VEHICLE_FIXEDWING: + case VehicleConfigurationSource::VEHICLE_HELI: + case VehicleConfigurationSource::VEHICLE_SURFACE: + // TODO: Implement settings for other vehicle types? + break; + default: + break; + } +} + +void VehicleConfigurationHelper::applyOutputConfiguration() +{ + ActuatorSettings* actSettings = ActuatorSettings::GetInstance(m_uavoManager); + switch(m_configSource->getVehicleType()) + { + case VehicleConfigurationSource::VEHICLE_MULTI: + { + ActuatorSettings::DataFields data = actSettings->getData(); + + data.ChannelUpdateFreq[0] = LEGACY_ESC_FREQUENCE; + data.ChannelUpdateFreq[1] = LEGACY_ESC_FREQUENCE; + data.ChannelUpdateFreq[3] = LEGACY_ESC_FREQUENCE; + data.ChannelUpdateFreq[4] = LEGACY_ESC_FREQUENCE; + + qint16 updateFrequence = LEGACY_ESC_FREQUENCE; + switch(m_configSource->getESCType()) + { + case VehicleConfigurationSource::ESC_LEGACY: + updateFrequence = LEGACY_ESC_FREQUENCE; + break; + case VehicleConfigurationSource::ESC_RAPID: + updateFrequence = RAPID_ESC_FREQUENCE; + break; + default: + break; + } + + switch(m_configSource->getVehicleSubType()) + { + case VehicleConfigurationSource::MULTI_ROTOR_TRI_Y: + data.ChannelUpdateFreq[0] = updateFrequence; + break; + case VehicleConfigurationSource::MULTI_ROTOR_QUAD_X: + case VehicleConfigurationSource::MULTI_ROTOR_QUAD_PLUS: + data.ChannelUpdateFreq[0] = updateFrequence; + data.ChannelUpdateFreq[1] = updateFrequence; + break; + case VehicleConfigurationSource::MULTI_ROTOR_HEXA: + case VehicleConfigurationSource::MULTI_ROTOR_HEXA_COAX_Y: + case VehicleConfigurationSource::MULTI_ROTOR_HEXA_H: + case VehicleConfigurationSource::MULTI_ROTOR_OCTO: + case VehicleConfigurationSource::MULTI_ROTOR_OCTO_COAX_X: + case VehicleConfigurationSource::MULTI_ROTOR_OCTO_COAX_PLUS: + case VehicleConfigurationSource::MULTI_ROTOR_OCTO_V: + data.ChannelUpdateFreq[0] = updateFrequence; + data.ChannelUpdateFreq[1] = updateFrequence; + data.ChannelUpdateFreq[3] = updateFrequence; + data.ChannelUpdateFreq[4] = updateFrequence; + break; + default: + break; + } + actSettings->setData(data); + break; + } + case VehicleConfigurationSource::VEHICLE_FIXEDWING: + case VehicleConfigurationSource::VEHICLE_HELI: + case VehicleConfigurationSource::VEHICLE_SURFACE: + // TODO: Implement settings for other vehicle types? + break; + default: + break; + } +} + +void VehicleConfigurationHelper::applyFlighModeConfiguration() +{ +} + +void VehicleConfigurationHelper::applyLevellingConfiguration() +{ + if(m_configSource->isLevellingPerformed()) + { + accelGyroBias bias = m_configSource->getLevellingBias(); + AttitudeSettings::DataFields attitudeSettingsData = AttitudeSettings::GetInstance(m_uavoManager)->getData(); + attitudeSettingsData.AccelBias[0] += bias.m_accelerometerXBias; + attitudeSettingsData.AccelBias[1] += bias.m_accelerometerYBias; + attitudeSettingsData.AccelBias[2] += bias.m_accelerometerZBias; + attitudeSettingsData.GyroBias[0] = -bias.m_gyroXBias; + attitudeSettingsData.GyroBias[1] = -bias.m_gyroYBias; + attitudeSettingsData.GyroBias[2] = -bias.m_gyroZBias; + AttitudeSettings::GetInstance(m_uavoManager)->setData(attitudeSettingsData); + } +} + + +void VehicleConfigurationHelper::resetVehicleConfig() +{ + // Reset all vehicle data + MixerSettings* mSettings = MixerSettings::GetInstance(m_uavoManager); + + // Reset feed forward, accel times etc + mSettings->setFeedForward(0.0f); + mSettings->setMaxAccel(1000.0f); + mSettings->setAccelTime(0.0f); + mSettings->setDecelTime(0.0f); + + // Reset throttle curves + QString throttlePattern = "ThrottleCurve%1"; + for(int i = 1; i <= 2; i++) { + UAVObjectField *field = mSettings->getField(throttlePattern.arg(i)); + Q_ASSERT(field); + for(int i = 0; i < field->getNumElements(); i++){ + field->setValue(i * ( 1.0f / field->getNumElements()), i); + } + } + + // Reset Mixer types and values + QString mixerTypePattern = "Mixer%1Type"; + QString mixerVectorPattern = "Mixer%1Vector"; + for(int i = 1; i <= 10; i++) { + UAVObjectField *field = mSettings->getField(mixerTypePattern.arg(i)); + Q_ASSERT(field); + field->setValue(field->getOptions().at(0)); + + field = mSettings->getField(mixerVectorPattern.arg(i)); + Q_ASSERT(field); + for(int i = 0; i < field->getNumElements(); i++){ + field->setValue(0, i); + } + } + + // Apply updates + mSettings->setData(mSettings->getData()); +} + +void VehicleConfigurationHelper::resetGUIData() +{ + SystemSettings * sSettings = SystemSettings::GetInstance(m_uavoManager); + Q_ASSERT(sSettings); + SystemSettings::DataFields data = sSettings->getData(); + data.AirframeType = SystemSettings::AIRFRAMETYPE_CUSTOM; + for(int i = 0; i < SystemSettings::GUICONFIGDATA_NUMELEM; i++) + { + data.GUIConfigData[i] = 0; + } + sSettings->setData(data); +} + + +void VehicleConfigurationHelper::setupTriCopter() +{ + // Typical vehicle setup + // 1. Setup and apply mixer + // 2. Setup GUI data + mixerSettings mixer; + mixer.channels[0].type = 0; +} + +void VehicleConfigurationHelper::setupQuadCopter() +{ +} + +void VehicleConfigurationHelper::setupHexaCopter() +{ +} + +void VehicleConfigurationHelper::setupOctoCopter() +{ +} diff --git a/ground/openpilotgcs/src/plugins/setupwizard/vehicleconfigurationhelper.h b/ground/openpilotgcs/src/plugins/setupwizard/vehicleconfigurationhelper.h new file mode 100644 index 000000000..4c795d8c1 --- /dev/null +++ b/ground/openpilotgcs/src/plugins/setupwizard/vehicleconfigurationhelper.h @@ -0,0 +1,80 @@ +/** + ****************************************************************************** + * + * @file vehicleconfigurationhelper.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. + * @addtogroup + * @{ + * @addtogroup VehicleConfigurationHelper + * @{ + * @brief + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef VEHICLECONFIGURATIONHELPER_H +#define VEHICLECONFIGURATIONHELPER_H + +#include "vehicleconfigurationsource.h" +#include "uavobjectmanager.h" + +struct channelSettings { + int type; + int throttle1; + int throttle2; + int roll; + int pitch; + int yaw; + + channelSettings() : type(), throttle1(), throttle2(), roll(), pitch(), yaw() {} + + channelSettings(int t, int th1, int th2, int r, int p, int y) + : type(t), throttle1(th1), throttle2(th2), roll(r), pitch(p), yaw(y) {} +}; + +struct mixerSettings { + channelSettings channels[10]; +}; + +class VehicleConfigurationHelper +{ +public: + VehicleConfigurationHelper(VehicleConfigurationSource* configSource); + void setupVehicle(); +private: + static const qint16 LEGACY_ESC_FREQUENCE = 50; + static const qint16 RAPID_ESC_FREQUENCE = 400; + + VehicleConfigurationSource *m_configSource; + UAVObjectManager *m_uavoManager; + + void applyHardwareConfiguration(); + void applyVehicleConfiguration(); + void applyOutputConfiguration(); + void applyFlighModeConfiguration(); + void applyLevellingConfiguration(); + + void resetVehicleConfig(); + void resetGUIData(); + + void setupTriCopter(); + void setupQuadCopter(); + void setupHexaCopter(); + void setupOctoCopter(); + +}; + +#endif // VEHICLECONFIGURATIONHELPER_H diff --git a/ground/openpilotgcs/src/plugins/setupwizard/vehicleconfigurationsource.cpp b/ground/openpilotgcs/src/plugins/setupwizard/vehicleconfigurationsource.cpp new file mode 100644 index 000000000..3acb2400d --- /dev/null +++ b/ground/openpilotgcs/src/plugins/setupwizard/vehicleconfigurationsource.cpp @@ -0,0 +1,32 @@ +/** + ****************************************************************************** + * + * @file vehicleconfigurationsource.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. + * @addtogroup + * @{ + * @addtogroup VehicleConfigurationSource + * @{ + * @brief + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "vehicleconfigurationsource.h" + +VehicleConfigurationSource::VehicleConfigurationSource() +{ +} diff --git a/ground/openpilotgcs/src/plugins/setupwizard/vehicleconfigurationsource.h b/ground/openpilotgcs/src/plugins/setupwizard/vehicleconfigurationsource.h new file mode 100644 index 000000000..fb4924fe7 --- /dev/null +++ b/ground/openpilotgcs/src/plugins/setupwizard/vehicleconfigurationsource.h @@ -0,0 +1,72 @@ +/** + ****************************************************************************** + * + * @file vehicleconfigurationsource.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. + * @addtogroup + * @{ + * @addtogroup VehicleConfigurationSource + * @{ + * @brief + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef VEHICLECONFIGURATIONSOURCE_H +#define VEHICLECONFIGURATIONSOURCE_H + +#include + +struct accelGyroBias { + float m_accelerometerXBias; + float m_accelerometerYBias; + float m_accelerometerZBias; + + float m_gyroXBias; + float m_gyroYBias; + float m_gyroZBias; +}; + +class VehicleConfigurationSource +{ +public: + VehicleConfigurationSource(); + + enum CONTROLLER_SELECTION_MODE {CONTROLLER_SELECTION_AUTOMATIC, CONTROLLER_SELECTION_MANUAL, CONTROLLER_SELECTION_UNKNOWN}; + enum CONTROLLER_TYPE {CONTROLLER_UNKNOWN, CONTROLLER_CC, CONTROLLER_CC3D, CONTROLLER_REVO, CONTROLLER_PIPX}; + enum VEHICLE_TYPE {VEHICLE_UNKNOWN, VEHICLE_MULTI, VEHICLE_FIXEDWING, VEHICLE_HELI, VEHICLE_SURFACE}; + enum VEHICLE_SUB_TYPE {MULTI_ROTOR_UNKNOWN, MULTI_ROTOR_TRI_Y, MULTI_ROTOR_QUAD_X, MULTI_ROTOR_QUAD_PLUS, + MULTI_ROTOR_HEXA, MULTI_ROTOR_HEXA_H, MULTI_ROTOR_HEXA_COAX_Y, MULTI_ROTOR_OCTO, + MULTI_ROTOR_OCTO_V, MULTI_ROTOR_OCTO_COAX_X, MULTI_ROTOR_OCTO_COAX_PLUS, FIXED_WING_AILERON, + FIXED_WING_VTAIL, HELI_CCPM}; + enum ESC_TYPE {ESC_RAPID, ESC_LEGACY, ESC_UNKNOWN}; + enum INPUT_TYPE {INPUT_PWM, INPUT_PPM, INPUT_SBUS, INPUT_DSM, INPUT_UNKNOWN}; + + virtual VehicleConfigurationSource::CONTROLLER_SELECTION_MODE getControllerSelectionMode() const = 0; + virtual VehicleConfigurationSource::CONTROLLER_TYPE getControllerType() const = 0; + virtual VehicleConfigurationSource::VEHICLE_TYPE getVehicleType() const = 0; + virtual VehicleConfigurationSource::VEHICLE_SUB_TYPE getVehicleSubType() const = 0; + virtual VehicleConfigurationSource::INPUT_TYPE getInputType() const = 0; + virtual VehicleConfigurationSource::ESC_TYPE getESCType() const = 0; + + virtual bool isLevellingPerformed() = 0; + virtual accelGyroBias getLevellingBias() const = 0; + + virtual QString getSummaryText() = 0; + +}; + +#endif // VEHICLECONFIGURATIONSOURCE_H