From e221ecbaf41a9e88b0db640d666ff4c0d35a5652 Mon Sep 17 00:00:00 2001 From: zedamota Date: Wed, 10 Aug 2011 15:24:35 +0100 Subject: [PATCH] Finished coding part of new input calibration wizard. Waiting for some artwork to send it for review. --- .../src/plugins/config/configinputwidget.cpp | 291 +++++++++++++++++- .../src/plugins/config/configinputwidget.h | 49 ++- .../src/plugins/config/configtaskwidget.cpp | 1 - .../openpilotgcs/src/plugins/config/input.ui | 60 +++- .../src/plugins/config/inputchannelform.ui | 28 +- 5 files changed, 411 insertions(+), 18 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp b/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp index 18841b9df..8f9934ddd 100644 --- a/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configinputwidget.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file configservowidget.cpp - * @author E. Lafargue & The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @addtogroup GCSPlugins GCS Plugins * @{ * @addtogroup ConfigPlugin Config Plugin @@ -39,21 +39,19 @@ #include #include -#include "manualcontrolsettings.h" -ConfigInputWidget::ConfigInputWidget(QWidget *parent) : ConfigTaskWidget(parent) +ConfigInputWidget::ConfigInputWidget(QWidget *parent) : ConfigTaskWidget(parent),wizardStep(wizardWelcome),skipflag(false),loop(NULL) { + manualCommandObj = ManualControlCommand::GetInstance(getObjectManager()); + manualSettingsObj = ManualControlSettings::GetInstance(getObjectManager()); + receiverActivityObj=ReceiverActivity::GetInstance(getObjectManager()); m_config = new Ui_InputWidget(); m_config->setupUi(this); setupButtons(m_config->saveRCInputToRAM,m_config->saveRCInputToSD); - ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); - UAVObjectManager *objManager = pm->getObject(); - UAVDataObject * obj = dynamic_cast(objManager->getObject(QString("ManualControlSettings"))); - UAVObjectField * field = obj->getField(QString("ChannelGroups")); int index=0; - foreach(QString name,field->getElementNames()) + foreach(QString name,manualSettingsObj->getFields().at(0)->getElementNames()) { inputChannelForm * inp=new inputChannelForm(this,index==0); m_config->advancedPage->layout()->addWidget(inp); @@ -65,7 +63,14 @@ ConfigInputWidget::ConfigInputWidget(QWidget *parent) : ConfigTaskWidget(parent) addUAVObjectToWidgetRelation("ManualControlSettings","ChannelMax",inp->ui->channelMax,index); ++index; } + QPushButton * goWizard=new QPushButton(tr("Start Wizard"),this); + m_config->advancedPage->layout()->addWidget(goWizard); + connect(goWizard,SIGNAL(clicked()),this,SLOT(goToWizard())); + connect(m_config->wzNext,SIGNAL(clicked()),this,SLOT(wzNext())); + connect(m_config->wzCancel,SIGNAL(clicked()),this,SLOT(wzCancel())); + connect(m_config->wzBack,SIGNAL(clicked()),this,SLOT(wzBack())); + m_config->stackedWidget->setCurrentIndex(0); addUAVObjectToWidgetRelation("ManualControlSettings","FlightModePosition",m_config->fmsModePos1,0); addUAVObjectToWidgetRelation("ManualControlSettings","FlightModePosition",m_config->fmsModePos2,1); addUAVObjectToWidgetRelation("ManualControlSettings","FlightModePosition",m_config->fmsModePos3,2); @@ -82,17 +87,16 @@ ConfigInputWidget::ConfigInputWidget(QWidget *parent) : ConfigTaskWidget(parent) addUAVObjectToWidgetRelation("ManualControlSettings","Arming",m_config->armControl); addUAVObjectToWidgetRelation("ManualControlSettings","armTimeout",m_config->armTimeout,0,1000); - + enableControls(false); populateWidgets(); refreshWidgetsValues(); // Connect the help button connect(m_config->inputHelp, SIGNAL(clicked()), this, SLOT(openHelp())); - } ConfigInputWidget::~ConfigInputWidget() { - // Do nothing + } void ConfigInputWidget::openHelp() @@ -101,4 +105,269 @@ void ConfigInputWidget::openHelp() QDesktopServices::openUrl( QUrl("http://wiki.openpilot.org/display/Doc/Input+Configuration", QUrl::StrictMode) ); } +void ConfigInputWidget::goToWizard() +{ + setupWizardWidget(wizardWelcome); +} + +void ConfigInputWidget::wzCancel() +{ + m_config->stackedWidget->setCurrentIndex(0); + foreach (QWidget * wd, extraWidgets) + { + if(wd) + delete wd; + } + extraWidgets.clear(); + switch(wizardStep) + { + case wizardWelcome: + break; + case wizardChooseMode: + break; + case wizardIdentifySticks: + disconnect(receiverActivityObj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(identifyControls())); + break; + case wizardIdentifyCenter: + break; + case wizardIdentifyLimits: + disconnect(manualCommandObj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(identifyLimits())); + manualSettingsObj->setData(manualSettingsData); + manualCommandObj->setMetadata(manualCommandObj->getDefaultMetadata()); + break; + case wizardIdentifyInverted: + break; + case wizardFinish: + break; + default: + break; + } + wizardStep=wizardWelcome; +} + +void ConfigInputWidget::wzNext() +{ + setupWizardWidget(wizardStep+1); +} + +void ConfigInputWidget::wzBack() +{ + setupWizardWidget(wizardStep-1); +} + +void ConfigInputWidget::setupWizardWidget(int step) +{ + if(step==wizardWelcome) + { + if(wizardStep==wizardChooseMode) + { + delete extraWidgets.at(0); + delete extraWidgets.at(1); + extraWidgets.clear(); + } + manualSettingsData=manualSettingsObj->getData(); + manualSettingsData.Arming=ManualControlSettings::ARMING_ALWAYSDISARMED; + manualSettingsObj->setData(manualSettingsData); + m_config->wzText->setText(tr("Welcome to the inputs configuration wizard.\n" + "Please follow the instruction on the screen and only move your controls when asked to.\n" + "At any time you can press 'back' to return to the previous screeen or 'Cancel' to cancel the wizard" + "For your safety your arming setting is now 'Always Disarmed' please reenable it after this wizard.")); + m_config->stackedWidget->setCurrentIndex(1); + m_config->wzBack->setEnabled(false); + wizardStep=wizardWelcome; + } + else if(step==wizardChooseMode) + { + if(wizardStep==wizardIdentifySticks) + { + disconnect(receiverActivityObj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(identifyControls())); + m_config->wzNext->setEnabled(true); + } + m_config->wzText->setText(tr("Please choose your transmiter type.\n" + "Mode 1 means your throttle stick is on the right\n" + "Mode 2 means your throttle stick is on the left\n")); + m_config->wzBack->setEnabled(true); + QRadioButton * mode1=new QRadioButton(tr("Mode 1"),this); + QRadioButton * mode2=new QRadioButton(tr("Mode 2"),this); + mode2->setChecked(true); + extraWidgets.clear(); + extraWidgets.append(mode1); + extraWidgets.append(mode2); + m_config->checkBoxesLayout->layout()->addWidget(mode1); + m_config->checkBoxesLayout->layout()->addWidget(mode2); + wizardStep=wizardChooseMode; + } + else if(step==wizardIdentifySticks) + { + usedChannels.clear(); + if(wizardStep==wizardChooseMode) + { + QRadioButton * mode=qobject_cast(extraWidgets.at(0)); + if(mode->isChecked()) + transmitterMode=mode1; + else + transmitterMode=mode2; + delete extraWidgets.at(0); + delete extraWidgets.at(1); + extraWidgets.clear(); + } + wizardStep=wizardIdentifySticks; + currentCommand=0; + m_config->wzText->setText(QString(tr("Please move each control once at a time according to the instructions and picture below.\n\n" + "Move the %1 stick")).arg(manualSettingsObj->getField("ChannelGroups")->getElementNames().at(currentCommand))); + manualSettingsData=manualSettingsObj->getData(); + connect(receiverActivityObj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(identifyControls())); + m_config->wzNext->setEnabled(false); + } + else if(step==wizardIdentifyCenter) + { + if(wizardStep==wizardIdentifySticks) + disconnect(receiverActivityObj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(identifyControls())); + else + { + disconnect(manualCommandObj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(identifyLimits())); + manualSettingsObj->setData(manualSettingsData); + manualCommandObj->setMetadata(manualCommandObj->getDefaultMetadata()); + } + wizardStep=wizardIdentifyCenter; + m_config->wzText->setText(QString(tr("Please center all control controls and press next when ready"))); + } + else if(step==wizardIdentifyLimits) + { + if(wizardStep==wizardIdentifyCenter) + { + wizardStep=wizardIdentifyLimits; + manualCommandData=manualCommandObj->getData(); + manualSettingsData=manualSettingsObj->getData(); + for(int i=0;isetData(manualSettingsData); + } + wizardStep=wizardIdentifyLimits; + m_config->wzText->setText(QString(tr("Please move all controls to their maximum extends on both directions and press next when ready"))); + UAVObject::Metadata mdata= manualCommandObj->getMetadata(); + mdata.flightTelemetryUpdateMode = UAVObject::UPDATEMODE_PERIODIC; + mdata.flightTelemetryUpdatePeriod = 150; + manualCommandObj->setMetadata(mdata); + manualSettingsData=manualSettingsObj->getData(); + for(int i=0;isetData(manualSettingsData); + manualCommandObj->setMetadata(manualCommandObj->getDefaultMetadata()); + } + extraWidgets.clear(); + foreach(QString name,manualSettingsObj->getFields().at(0)->getElementNames()) + { + QCheckBox * cb=new QCheckBox(name,this); + extraWidgets.append(cb); + m_config->checkBoxesLayout->layout()->addWidget(cb); + } + wizardStep=wizardIdentifyInverted; + m_config->wzText->setText(QString(tr("Please check the picture below and check all controls which show an inverted movement and press next when ready"))); + } + else if(step==wizardFinish) + { + manualSettingsData=manualSettingsObj->getData(); + foreach(QWidget * wd,extraWidgets) + { + QCheckBox * cb=qobject_cast(wd); + if(cb) + { + if(cb->isChecked()) + { + int index=manualSettingsObj->getFields().at(0)->getElementNames().indexOf(cb->text()); + qint16 aux; + aux=manualSettingsData.ChannelMax[index]; + manualSettingsData.ChannelMax[index]=manualSettingsData.ChannelMin[index]; + manualSettingsData.ChannelMin[index]=aux; + } + } + delete cb; + } + wizardStep=wizardFinish; + manualSettingsObj->setData(manualSettingsData); + extraWidgets.clear(); + m_config->wzText->setText(QString(tr("You have completed this wizard, please check below if the picture below mimics your controls movement.\n" + "This new settings aren't saved to the board yet, after pressing next you will go to the initial screen where you can do that."))); + + } + + else if(step==wizardFinish+1) + { + manualSettingsData=manualSettingsObj->getData(); + manualSettingsData.ChannelNeutral[ManualControlSettings::CHANNELNEUTRAL_THROTTLE]= + manualSettingsData.ChannelMin[ManualControlSettings::CHANNELMIN_THROTTLE]+ + ((manualSettingsData.ChannelMax[ManualControlSettings::CHANNELMAX_THROTTLE]- + manualSettingsData.ChannelMin[ManualControlSettings::CHANNELMIN_THROTTLE])*0.02); + manualSettingsObj->setData(manualSettingsData); + m_config->stackedWidget->setCurrentIndex(0); + wizardStep=wizardWelcome; + } + +} + +void ConfigInputWidget::identifyControls() +{ + static int debounce=0; + receiverActivityData=receiverActivityObj->getData(); + if(receiverActivityData.ActiveChannel==255) + return; + else + { + receiverActivityData=receiverActivityObj->getData(); + currentChannel.group=receiverActivityData.ActiveGroup; + currentChannel.number=receiverActivityData.ActiveChannel; + if(currentChannel==lastChannel) + ++debounce; + lastChannel.group= currentChannel.group; + lastChannel.number=currentChannel.number; + if(!usedChannels.contains(lastChannel) && debounce>5) + { + debounce=0; + usedChannels.append(lastChannel); + manualSettingsData=manualSettingsObj->getData(); + manualSettingsData.ChannelGroups[currentCommand]=currentChannel.group; + manualSettingsData.ChannelNumber[currentCommand]=currentChannel.number; + manualSettingsObj->setData(manualSettingsData); + } + else + return; + } + ++currentCommand; + if(currentCommand>ManualControlSettings::CHANNELGROUPS_NUMELEM-1) + { + disconnect(receiverActivityObj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(identifyControls())); + m_config->wzNext->setEnabled(true); + } + m_config->wzText->setText(QString(tr("Please move each control once at a time according to the instructions and picture below.\n\n" + "Move the %1 stick")).arg(manualSettingsObj->getFields().at(0)->getElementNames().at(currentCommand))); + if(manualSettingsObj->getField("ChannelGroups")->getElementNames().at(currentCommand).contains("Accessory")) + { + m_config->wzNext->setEnabled(true); + } +} + +void ConfigInputWidget::identifyLimits() +{ + manualCommandData=manualCommandObj->getData(); + for(int i=0;imanualCommandData.Channel[i]) + manualSettingsData.ChannelMin[i]=manualCommandData.Channel[i]; + if(manualSettingsData.ChannelMax[i] #include "inputchannelform.h" #include "ui_inputchannelform.h" +#include +#include "manualcontrolcommand.h" +#include "manualcontrolsettings.h" +#include "receiveractivity.h" class Ui_InputWidget; class ConfigInputWidget: public ConfigTaskWidget { Q_OBJECT - public: ConfigInputWidget(QWidget *parent = 0); ~ConfigInputWidget(); - + enum wizardSteps{wizardWelcome,wizardChooseMode,wizardIdentifySticks,wizardIdentifyCenter,wizardIdentifyLimits,wizardIdentifyInverted,wizardFinish}; + enum txMode{mode1,mode2}; public slots: private: Ui_InputWidget *m_config; + wizardSteps wizardStep; + void setupWizardWidget(int step); + QList extraWidgets; + txMode transmitterMode; + struct channelsStruct + { + bool operator ==(const channelsStruct& rhs) const + { + return((group==rhs.group) &&(number==rhs.number)); + } + int group; + int number; + }lastChannel; + channelsStruct currentChannel; + QList usedChannels; + QEventLoop * loop; + bool skipflag; + int currentCommand; + + ManualControlCommand * manualCommandObj; + ManualControlCommand::DataFields manualCommandData; + ManualControlSettings * manualSettingsObj; + ManualControlSettings::DataFields manualSettingsData; + ReceiverActivity * receiverActivityObj; + ReceiverActivity::DataFields receiverActivityData; + + /* + ManualControlCommand * manualCommandObj = ManualControlCommand::GetInstance(getObjectManager()); + ManualControlCommand::DataFields manualCommandData = manualCommandObj->getData(); + ManualControlSettings * manualSettingsObj = ManualControlSettings::GetInstance(getObjectManager()); + ManualControlSettings::DataFields manualSettingsData; + ReceiverActivity * receiverActivityObj=ReceiverActivity::GetInstance(getObjectManager()); + ReceiverActivity::DataFields receiverActivityData =receiverActivityObj->getData(); +*/ private slots: - + void wzNext(); + void wzBack(); + void wzCancel(); + void goToWizard(); void openHelp(); + void identifyControls(); + void identifyLimits(); }; #endif diff --git a/ground/openpilotgcs/src/plugins/config/configtaskwidget.cpp b/ground/openpilotgcs/src/plugins/config/configtaskwidget.cpp index 90d21e494..8aa6a3f33 100644 --- a/ground/openpilotgcs/src/plugins/config/configtaskwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configtaskwidget.cpp @@ -257,7 +257,6 @@ void ConfigTaskWidget::clearDirty() } void ConfigTaskWidget::setDirty(bool value) { - qDebug()<<"dirty="< + + 1 + - + + + + + + + 10 + 75 + true + + + + TextLabel + + + true + + + + + + + + + + + + + + + + + + + Back + + + + + + + Next + + + + + + + Cancel + + + + + + + diff --git a/ground/openpilotgcs/src/plugins/config/inputchannelform.ui b/ground/openpilotgcs/src/plugins/config/inputchannelform.ui index 0c602a21b..4d7f07d9d 100644 --- a/ground/openpilotgcs/src/plugins/config/inputchannelform.ui +++ b/ground/openpilotgcs/src/plugins/config/inputchannelform.ui @@ -6,14 +6,26 @@ 0 0 - 389 - 57 + 404 + 43 Form + + 1 + + + 1 + + + 2 + + + 0 + @@ -56,6 +68,18 @@ + + + 0 + 0 + + + + + 66 + 0 + + TextLabel