diff --git a/ground/openpilotgcs/src/plugins/setupwizard/pages/flashpage.cpp b/ground/openpilotgcs/src/plugins/setupwizard/pages/flashpage.cpp index 452adaf02..713270d83 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/pages/flashpage.cpp +++ b/ground/openpilotgcs/src/plugins/setupwizard/pages/flashpage.cpp @@ -35,6 +35,7 @@ FlashPage::FlashPage(SetupWizard *wizard, QWidget *parent) : ui(new Ui::FlashPage) { ui->setupUi(this); + connect(ui->applyButton, SIGNAL(clicked()), wizard, SLOT(writeConfiguration())); } FlashPage::~FlashPage() diff --git a/ground/openpilotgcs/src/plugins/setupwizard/pages/flashpage.ui b/ground/openpilotgcs/src/plugins/setupwizard/pages/flashpage.ui index a354302b8..37929e802 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/pages/flashpage.ui +++ b/ground/openpilotgcs/src/plugins/setupwizard/pages/flashpage.ui @@ -45,9 +45,9 @@ p, li { white-space: pre-wrap; } 20 - 240 + 230 561 - 141 + 151 @@ -62,6 +62,19 @@ p, li { white-space: pre-wrap; } Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + 440 + 30 + 100 + 100 + + + + Apply + + diff --git a/ground/openpilotgcs/src/plugins/setupwizard/pages/multipage.cpp b/ground/openpilotgcs/src/plugins/setupwizard/pages/multipage.cpp index 56ffa5fb0..9963422ea 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/pages/multipage.cpp +++ b/ground/openpilotgcs/src/plugins/setupwizard/pages/multipage.cpp @@ -57,16 +57,23 @@ MultiPage::~MultiPage() void MultiPage::initializePage() { + updateAvailableTypes(); updateImageAndDescription(); } +bool MultiPage::validatePage() +{ + SetupWizard::VEHICLE_SUB_TYPE type = (SetupWizard::VEHICLE_SUB_TYPE) ui->typeCombo->itemData(ui->typeCombo->currentIndex()).toInt(); + getWizard()->setVehicleSubType(type); +} + void MultiPage::setupMultiTypesCombo() { ui->typeCombo->addItem("Tricopter", SetupWizard::MULTI_ROTOR_TRI_Y); ui->typeCombo->addItem("Quadcopter X", SetupWizard::MULTI_ROTOR_QUAD_X); ui->typeCombo->addItem("Quadcopter +", SetupWizard::MULTI_ROTOR_QUAD_PLUS); ui->typeCombo->addItem("Hexacopter", SetupWizard::MULTI_ROTOR_HEXA); - ui->typeCombo->addItem("Hexacopter Coax", SetupWizard::MULTI_ROTOR_HEXA_COAX_Y); + ui->typeCombo->addItem("Hexacopter Coax (Y6)", SetupWizard::MULTI_ROTOR_HEXA_COAX_Y); ui->typeCombo->addItem("Hexacopter H", SetupWizard::MULTI_ROTOR_HEXA_H); ui->typeCombo->addItem("Octocopter", SetupWizard::MULTI_ROTOR_OCTO); ui->typeCombo->addItem("Octocopter Coax X", SetupWizard::MULTI_ROTOR_OCTO_COAX_X); @@ -74,9 +81,18 @@ void MultiPage::setupMultiTypesCombo() ui->typeCombo->addItem("Octocopter V", SetupWizard::MULTI_ROTOR_OCTO_V); } +void MultiPage::updateAvailableTypes() +{ + QVariant enable = (getWizard()->getInputType() == SetupWizard::INPUT_PWM) ? QVariant(0) : QVariant(1 | 32); + ui->typeCombo->model()->setData(ui->typeCombo->model()->index(6, 0), enable, Qt::UserRole - 1); + ui->typeCombo->model()->setData(ui->typeCombo->model()->index(7, 0), enable, Qt::UserRole - 1); + ui->typeCombo->model()->setData(ui->typeCombo->model()->index(8, 0), enable, Qt::UserRole - 1); + ui->typeCombo->model()->setData(ui->typeCombo->model()->index(9, 0), enable, Qt::UserRole - 1); +} + void MultiPage::updateImageAndDescription() { - SetupWizard::MULTI_ROTOR_SUB_TYPE type = (SetupWizard::MULTI_ROTOR_SUB_TYPE) ui->typeCombo->itemData(ui->typeCombo->currentIndex()).toInt(); + SetupWizard::VEHICLE_SUB_TYPE type = (SetupWizard::VEHICLE_SUB_TYPE) ui->typeCombo->itemData(ui->typeCombo->currentIndex()).toInt(); QString elementId = ""; QString description = "Descriptive text with information about "; description.append(ui->typeCombo->currentText()); diff --git a/ground/openpilotgcs/src/plugins/setupwizard/pages/multipage.h b/ground/openpilotgcs/src/plugins/setupwizard/pages/multipage.h index bc9f822ad..0ffa84a36 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/pages/multipage.h +++ b/ground/openpilotgcs/src/plugins/setupwizard/pages/multipage.h @@ -46,11 +46,14 @@ public: ~MultiPage(); void initializePage(); + bool validatePage(); + private: Ui::MultiPage *ui; void setupMultiTypesCombo(); QGraphicsSvgItem *multiPic; + void updateAvailableTypes(); private slots: void updateImageAndDescription(); diff --git a/ground/openpilotgcs/src/plugins/setupwizard/setupwizard.cpp b/ground/openpilotgcs/src/plugins/setupwizard/setupwizard.cpp index f68c942ef..313623248 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/setupwizard.cpp +++ b/ground/openpilotgcs/src/plugins/setupwizard/setupwizard.cpp @@ -40,6 +40,11 @@ #include "pages/summarypage.h" #include "pages/flashpage.h" #include "pages/notyetimplementedpage.h" +#include "extensionsystem/pluginmanager.h" +#include "hwsettings.h" +#include "actuatorsettings.h" +#include "attitudesettings.h" + SetupWizard::SetupWizard(QWidget *parent) : QWizard(parent), m_controllerSelectionMode(CONTROLLER_SELECTION_UNKNOWN), m_controllerType(CONTROLLER_UNKNOWN), @@ -47,6 +52,7 @@ SetupWizard::SetupWizard(QWidget *parent) : QWizard(parent), m_levellingPerformed(false), m_connectionManager(0) { setWindowTitle("OpenPilot Setup Wizard"); + setOption(QWizard::IndependentPages, false); createPages(); } @@ -60,7 +66,7 @@ int SetupWizard::nextId() const { case CONTROLLER_CC: case CONTROLLER_CC3D: - return PAGE_VEHICLES; + return PAGE_INPUT; case CONTROLLER_REVO: case CONTROLLER_PIPX: default: @@ -83,9 +89,9 @@ int SetupWizard::nextId() const } } case PAGE_MULTI: - return PAGE_INPUT; - case PAGE_INPUT: return PAGE_OUTPUT; + case PAGE_INPUT: + return PAGE_VEHICLES; case PAGE_OUTPUT: { if(getControllerSelectionMode() == CONTROLLER_SELECTION_AUTOMATIC) { @@ -196,6 +202,197 @@ 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); + + switch(getControllerType()) + { + case CONTROLLER_CC: + case CONTROLLER_CC3D: + // Reset all ports + hwSettings->setCC_RcvrPort(HwSettings::CC_RCVRPORT_DISABLED); + hwSettings->setCC_FlexiPort(HwSettings::CC_FLEXIPORT_DISABLED); + hwSettings->setCC_MainPort(HwSettings::CC_MAINPORT_DISABLED); + switch(getInputType()) + { + case INPUT_PWM: + hwSettings->setCC_RcvrPort(HwSettings::CC_RCVRPORT_PWM); + break; + case INPUT_PPM: + hwSettings->setCC_RcvrPort(HwSettings::CC_RCVRPORT_PPM); + break; + case INPUT_SBUS: + hwSettings->setCC_MainPort(HwSettings::CC_MAINPORT_SBUS); + break; + case INPUT_DSM: + // TODO: Handle all of the DSM types ?? Which is most common? + hwSettings->setCC_MainPort(HwSettings::CC_MAINPORT_DSM2); + break; + } + break; + case CONTROLLER_REVO: + // TODO: Implement Revo settings + break; + } +} + +void SetupWizard::applyVehicleConfiguration(UAVObjectManager *uavoMgr) +{ + + switch(getVehicleType()) + { + case VEHICLE_MULTI: + { + 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: + { + actSettings->setChannelUpdateFreq(0, DEFAULT_ESC_FREQUENCE); + actSettings->setChannelUpdateFreq(1, DEFAULT_ESC_FREQUENCE); + actSettings->setChannelUpdateFreq(2, DEFAULT_ESC_FREQUENCE); + actSettings->setChannelUpdateFreq(3, 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: + actSettings->setChannelUpdateFreq(0, updateFrequence); + break; + case SetupWizard::MULTI_ROTOR_QUAD_X: + case SetupWizard::MULTI_ROTOR_QUAD_PLUS: + actSettings->setChannelUpdateFreq(0, updateFrequence); + actSettings->setChannelUpdateFreq(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: + actSettings->setChannelUpdateFreq(0, updateFrequence); + actSettings->setChannelUpdateFreq(1, updateFrequence); + actSettings->setChannelUpdateFreq(2, updateFrequence); + actSettings->setChannelUpdateFreq(3, updateFrequence); + break; + } + 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::setupTriCopter(UAVObjectManager *uavoMgr) +{ + +} + +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 +} + void SetupWizard::createPages() { setPage(PAGE_START, new StartPage(this)); diff --git a/ground/openpilotgcs/src/plugins/setupwizard/setupwizard.h b/ground/openpilotgcs/src/plugins/setupwizard/setupwizard.h index b88f5e4c9..55246afa0 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/setupwizard.h +++ b/ground/openpilotgcs/src/plugins/setupwizard/setupwizard.h @@ -32,6 +32,8 @@ #include "levellingutil.h" #include #include +#include "uavobjectmanager.h" + class SetupWizard : public QWizard { @@ -43,9 +45,10 @@ public: 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 MULTI_ROTOR_SUB_TYPE {MULTI_ROTOR_UNKNOWN, MULTI_ROTOR_TRI_Y, MULTI_ROTOR_QUAD_X, MULTI_ROTOR_QUAD_PLUS, + 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}; + 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}; @@ -58,6 +61,9 @@ public: void setVehicleType(SetupWizard::VEHICLE_TYPE type) { m_vehicleType = type; } SetupWizard::VEHICLE_TYPE getVehicleType() const { return m_vehicleType; } + void setVehicleSubType(SetupWizard::VEHICLE_SUB_TYPE type) { m_vehicleSubType = type; } + SetupWizard::VEHICLE_SUB_TYPE getVehicleSubType() const { return m_vehicleSubType; } + void setInputType(SetupWizard::INPUT_TYPE type) { m_inputType = type; } SetupWizard::INPUT_TYPE getInputType() const { return m_inputType; } @@ -78,8 +84,14 @@ public: } return m_connectionManager; } +public slots: + void exportConfiguration(); + void writeConfiguration(); private: + static const qint16 DEFAULT_ESC_FREQUENCE = 50; + static const qint16 RAPID_ESC_FREQUENCE = 50; + 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}; @@ -88,6 +100,7 @@ private: CONTROLLER_SELECTION_MODE m_controllerSelectionMode; CONTROLLER_TYPE m_controllerType; VEHICLE_TYPE m_vehicleType; + VEHICLE_SUB_TYPE m_vehicleSubType; INPUT_TYPE m_inputType; ESC_TYPE m_escType; bool m_levellingPerformed; @@ -95,6 +108,18 @@ private: 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 setupTriCopter(UAVObjectManager *uavoMgr); + void setupQuadCopter(UAVObjectManager *uavoMgr); + void setupHexaCopter(UAVObjectManager *uavoMgr); + void setupOctoCopter(UAVObjectManager *uavoMgr); }; #endif // SETUPWIZARD_H