1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-30 08:24:11 +01:00

Finished coding part of new input calibration wizard. Waiting for some artwork to send it for review.

This commit is contained in:
zedamota 2011-08-10 15:24:35 +01:00
parent 5d0095f00d
commit e221ecbaf4
5 changed files with 411 additions and 18 deletions

View File

@ -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 <QUrl>
#include <QMessageBox>
#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<UAVObjectManager>();
UAVDataObject * obj = dynamic_cast<UAVDataObject*>(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<QRadioButton *>(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;i<ManualControlCommand::CHANNEL_NUMELEM;++i)
{
manualSettingsData.ChannelNeutral[i]=manualCommandData.Channel[i];
}
manualSettingsObj->setData(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;i<ManualControlSettings::CHANNELMAX_NUMELEM;++i)
{
manualSettingsData.ChannelMin[i]=manualSettingsData.ChannelNeutral[i];
manualSettingsData.ChannelMax[i]=manualSettingsData.ChannelNeutral[i];
}
connect(manualCommandObj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(identifyLimits()));
}
else if(step==wizardIdentifyInverted)
{
if(wizardStep==wizardIdentifyLimits)
{
disconnect(manualCommandObj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(identifyLimits()));
manualSettingsObj->setData(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<QCheckBox *>(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;i<ManualControlSettings::CHANNELMAX_NUMELEM;++i)
{
if(manualSettingsData.ChannelMin[i]>manualCommandData.Channel[i])
manualSettingsData.ChannelMin[i]=manualCommandData.Channel[i];
if(manualSettingsData.ChannelMax[i]<manualCommandData.Channel[i])
manualSettingsData.ChannelMax[i]=manualCommandData.Channel[i];
}
}

View File

@ -36,24 +36,67 @@
#include <QList>
#include "inputchannelform.h"
#include "ui_inputchannelform.h"
#include <QRadioButton>
#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<QWidget*> 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<channelsStruct> 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

View File

@ -257,7 +257,6 @@ void ConfigTaskWidget::clearDirty()
}
void ConfigTaskWidget::setDirty(bool value)
{
qDebug()<<"dirty="<<value;
dirty=value;
}
bool ConfigTaskWidget::isDirty()

View File

@ -26,10 +26,68 @@
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>1</number>
</property>
<widget class="QWidget" name="advancedPage">
<layout class="QVBoxLayout" name="verticalLayout_4"/>
</widget>
<widget class="QWidget" name="page"/>
<widget class="QWidget" name="wizard">
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QLabel" name="wzText">
<property name="font">
<font>
<pointsize>10</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>TextLabel</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QGraphicsView" name="graphicsView"/>
</item>
<item>
<layout class="QVBoxLayout" name="checkBoxesLayout"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="wzBack">
<property name="text">
<string>Back</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="wzNext">
<property name="text">
<string>Next</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="wzCancel">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
</layout>

View File

@ -6,14 +6,26 @@
<rect>
<x>0</x>
<y>0</y>
<width>389</width>
<height>57</height>
<width>404</width>
<height>43</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="topMargin">
<number>1</number>
</property>
<property name="bottomMargin">
<number>1</number>
</property>
<property name="horizontalSpacing">
<number>2</number>
</property>
<property name="verticalSpacing">
<number>0</number>
</property>
<item row="0" column="3">
<widget class="QLabel" name="legend2">
<property name="enabled">
@ -56,6 +68,18 @@
</item>
<item row="1" column="1">
<widget class="QLabel" name="channelName">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>66</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>TextLabel</string>
</property>