1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-01 09:24:10 +01:00

OP-38 Working version of the RC Receiver calibration tab: lets you calibrate the Min/Max/Neutral values of the OP receiver inputs in just a few seconds. Binding of channel to action is not done yet, but save to SD works.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1186 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
edouard 2010-07-30 06:43:50 +00:00 committed by edouard
parent daf88b2175
commit 737abfcb34
3 changed files with 489 additions and 37 deletions

View File

@ -47,6 +47,11 @@ ConfigGadgetWidget::ConfigGadgetWidget(QWidget *parent) : QWidget(parent)
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(objManager->getObject(QString("ManualControlCommand")));
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(updateChannels(UAVObject*)));
connect(m_config->saveRCInputToSD, SIGNAL(clicked()), this, SLOT(saveRCInputObject()));
connect(m_config->saveRCInputToRAM, SIGNAL(clicked()), this, SLOT(sendRCInputUpdate()));
connect(m_config->getRCInputCurrent, SIGNAL(clicked()), this, SLOT(requestRCInputUpdate()));
firstUpdate = true;
}
@ -63,6 +68,155 @@ void ConfigGadgetWidget::resizeEvent(QResizeEvent *event)
}
/**
Request the current config from the board
*/
void ConfigGadgetWidget::requestRCInputUpdate()
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(objManager->getObject(QString("ManualControlSettings")));
Q_ASSERT(obj);
obj->requestUpdate();
// Now update all the slider values:
QString fieldName = QString("ChannelMax");
UAVObjectField *field = obj->getField(fieldName);
m_config->ch0Max->setText(field->getValue(0).toString());
m_config->ch0Slider->setMaximum(field->getValue(0).toInt());
m_config->ch1Max->setText(field->getValue(1).toString());
m_config->ch1Slider->setMaximum(field->getValue(1).toInt());
m_config->ch2Max->setText(field->getValue(2).toString());
m_config->ch2Slider->setMaximum(field->getValue(2).toInt());
m_config->ch3Max->setText(field->getValue(3).toString());
m_config->ch3Slider->setMaximum(field->getValue(3).toInt());
m_config->ch4Max->setText(field->getValue(4).toString());
m_config->ch4Slider->setMaximum(field->getValue(4).toInt());
m_config->ch5Max->setText(field->getValue(5).toString());
m_config->ch5Slider->setMaximum(field->getValue(5).toInt());
m_config->ch6Max->setText(field->getValue(6).toString());
m_config->ch6Slider->setMaximum(field->getValue(6).toInt());
m_config->ch7Max->setText(field->getValue(7).toString());
m_config->ch7Slider->setMaximum(field->getValue(7).toInt());
fieldName = QString("ChannelMin");
field = obj->getField(fieldName);
m_config->ch0Min->setText(field->getValue(0).toString());
m_config->ch0Slider->setMinimum(field->getValue(0).toInt());
m_config->ch1Min->setText(field->getValue(1).toString());
m_config->ch1Slider->setMinimum(field->getValue(1).toInt());
m_config->ch2Min->setText(field->getValue(2).toString());
m_config->ch2Slider->setMinimum(field->getValue(2).toInt());
m_config->ch3Min->setText(field->getValue(3).toString());
m_config->ch3Slider->setMinimum(field->getValue(3).toInt());
m_config->ch4Min->setText(field->getValue(4).toString());
m_config->ch4Slider->setMinimum(field->getValue(4).toInt());
m_config->ch5Min->setText(field->getValue(5).toString());
m_config->ch5Slider->setMinimum(field->getValue(5).toInt());
m_config->ch6Min->setText(field->getValue(6).toString());
m_config->ch6Slider->setMinimum(field->getValue(6).toInt());
m_config->ch7Min->setText(field->getValue(7).toString());
m_config->ch7Slider->setMinimum(field->getValue(7).toInt());
fieldName = QString("ChannelNeutral");
field = obj->getField(fieldName);
m_config->ch0Slider->setValue(field->getValue(0).toInt());
m_config->ch1Slider->setValue(field->getValue(1).toInt());
m_config->ch2Slider->setValue(field->getValue(2).toInt());
m_config->ch3Slider->setValue(field->getValue(3).toInt());
m_config->ch4Slider->setValue(field->getValue(4).toInt());
m_config->ch5Slider->setValue(field->getValue(5).toInt());
m_config->ch6Slider->setValue(field->getValue(6).toInt());
m_config->ch7Slider->setValue(field->getValue(7).toInt());
}
/**
* Sends the config to the board, without saving to the SD card
*/
void ConfigGadgetWidget::sendRCInputUpdate()
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(objManager->getObject(QString("ManualControlSettings")));
Q_ASSERT(obj);
// Now update all fields from the sliders:
QString fieldName = QString("ChannelMax");
UAVObjectField * field = obj->getField(fieldName);
field->setValue(m_config->ch0Max->text().toInt(),0);
field->setValue(m_config->ch1Max->text().toInt(),1);
field->setValue(m_config->ch2Max->text().toInt(),2);
field->setValue(m_config->ch3Max->text().toInt(),3);
field->setValue(m_config->ch4Max->text().toInt(),4);
field->setValue(m_config->ch5Max->text().toInt(),5);
field->setValue(m_config->ch6Max->text().toInt(),6);
field->setValue(m_config->ch7Max->text().toInt(),7);
fieldName = QString("ChannelMin");
field = obj->getField(fieldName);
field->setValue(m_config->ch0Min->text().toInt(),0);
field->setValue(m_config->ch1Min->text().toInt(),1);
field->setValue(m_config->ch2Min->text().toInt(),2);
field->setValue(m_config->ch3Min->text().toInt(),3);
field->setValue(m_config->ch4Min->text().toInt(),4);
field->setValue(m_config->ch5Min->text().toInt(),5);
field->setValue(m_config->ch6Min->text().toInt(),6);
field->setValue(m_config->ch7Min->text().toInt(),7);
fieldName = QString("ChannelNeutral");
field = obj->getField(fieldName);
field->setValue(m_config->ch0Slider->value(),0);
field->setValue(m_config->ch1Slider->value(),1);
field->setValue(m_config->ch2Slider->value(),2);
field->setValue(m_config->ch3Slider->value(),3);
field->setValue(m_config->ch4Slider->value(),4);
field->setValue(m_config->ch5Slider->value(),5);
field->setValue(m_config->ch6Slider->value(),6);
field->setValue(m_config->ch7Slider->value(),7);
// ... and send to the OP Board
obj->updated();
}
/**
Sends the config to the board and request saving into the SD card
*/
void ConfigGadgetWidget::saveRCInputObject()
{
// Send update so that the latest value is saved
sendRCInputUpdate();
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(objManager->getObject(QString("ManualControlSettings")));
Q_ASSERT(obj);
updateObjectPersistance(ObjectPersistence::OPERATION_SAVE, obj);
}
void ConfigGadgetWidget::updateObjectPersistance(ObjectPersistence::OperationOptions op, UAVObject *obj)
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
ObjectPersistence* objper = dynamic_cast<ObjectPersistence*>( objManager->getObject(ObjectPersistence::NAME) );
if (obj != NULL)
{
ObjectPersistence::DataFields data;
data.Operation = op;
data.Selection = ObjectPersistence::SELECTION_SINGLEOBJECT;
data.ObjectID = obj->getObjID();
data.InstanceID = obj->getInstID();
objper->setData(data);
objper->updated();
}
}
/**
* Updates the slider positions and min/max values
*
@ -72,59 +226,55 @@ void ConfigGadgetWidget::updateChannels(UAVObject* controlCommand)
QString fieldName = QString("Connected");
UAVObjectField *field = controlCommand->getField(fieldName);
if (!field->getValue().toBool()) {
// Currently causes a problem because throttle going too low
// makes "Connected" go to false. Some kind of failsafe??
firstUpdate = true;
if (field->getValue().toBool()) {
m_config->RCInputConnected->setText("RC Receiver Connected");
} else {
m_config->RCInputConnected->setText("RC Receiver Not Connected");
}
if (m_config->doRCInputCalibration->isChecked()) {
fieldName = QString("Channel");
field = controlCommand->getField(fieldName);
// Hey: if you find a nicer way of doing this, be my guest!
this->updateChannelSlider(&*m_config->ch0Slider,
&*m_config->ch0Min,
&*m_config->ch0Max,
&*m_config->ch0Cur,
&*m_config->ch0Rev,field->getValue(0).toInt());
this->updateChannelSlider(&*m_config->ch1Slider,
&*m_config->ch1Min,
&*m_config->ch1Max,
&*m_config->ch1Cur,
&*m_config->ch1Rev,field->getValue(1).toInt());
this->updateChannelSlider(&*m_config->ch2Slider,
&*m_config->ch2Min,
&*m_config->ch2Max,
&*m_config->ch2Cur,
&*m_config->ch2Rev,field->getValue(2).toInt());
this->updateChannelSlider(&*m_config->ch3Slider,
&*m_config->ch3Min,
&*m_config->ch3Max,
&*m_config->ch3Cur,
&*m_config->ch3Rev,field->getValue(3).toInt());
this->updateChannelSlider(&*m_config->ch4Slider,
&*m_config->ch4Min,
&*m_config->ch4Max,
&*m_config->ch4Cur,
&*m_config->ch4Rev,field->getValue(4).toInt());
this->updateChannelSlider(&*m_config->ch5Slider,
&*m_config->ch5Min,
&*m_config->ch5Max,
&*m_config->ch5Cur,
&*m_config->ch5Rev,field->getValue(5).toInt());
this->updateChannelSlider(&*m_config->ch6Slider,
&*m_config->ch6Min,
&*m_config->ch6Max,
&*m_config->ch6Cur,
&*m_config->ch6Rev,field->getValue(6).toInt());
this->updateChannelSlider(&*m_config->ch7Slider,
&*m_config->ch7Min,
&*m_config->ch7Max,
&*m_config->ch7Cur,
&*m_config->ch7Rev,field->getValue(7).toInt());
firstUpdate = false;
} else {
firstUpdate = true;
}
}
void ConfigGadgetWidget::updateChannelSlider(QSlider* slider, QLabel* min, QLabel* max, QLabel* cur, QCheckBox* rev, int value) {
void ConfigGadgetWidget::updateChannelSlider(QSlider* slider, QLabel* min, QLabel* max, QCheckBox* rev, int value) {
if (firstUpdate) {
slider->setMaximum(value);
@ -132,20 +282,20 @@ void ConfigGadgetWidget::updateChannelSlider(QSlider* slider, QLabel* min, QLabe
slider->setValue(value);
max->setText(QString::number(value));
min->setText(QString::number(value));
cur->setText(QString::number(value));
return;
}
if (value > slider->maximum()) {
slider->setMaximum(value);
max->setText(QString::number(value));
if (value != 0) { // Avoids glitches...
if (value > slider->maximum()) {
slider->setMaximum(value);
max->setText(QString::number(value));
}
if (value < slider->minimum()) {
slider->setMinimum(value);
min->setText(QString::number(value));
}
slider->setValue(value);
}
if (value < slider->minimum()) {
slider->setMinimum(value);
min->setText(QString::number(value));
}
slider->setValue(value);
cur->setText(QString::number(value));
}

View File

@ -31,6 +31,7 @@
#include "extensionsystem/pluginmanager.h"
#include "uavobjects/uavobjectmanager.h"
#include "uavobjects/uavobject.h"
#include "uavobjects/objectpersistence.h"
#include <QtGui/QWidget>
#include <QList>
@ -50,14 +51,17 @@ protected:
private:
Ui_SettingsWidget *m_config;
QList<QSlider> sliders;
void updateChannelSlider(QSlider* slider, QLabel* min, QLabel* Max, QLabel* cur, QCheckBox* rev, int value);
int ch0Min;
int ch0Max;
int ch0Rev;
void updateChannelSlider(QSlider* slider, QLabel* min, QLabel* Max, QCheckBox* rev, int value);
void updateObjectPersistance(ObjectPersistence::OperationOptions op, UAVObject *obj);
bool firstUpdate;
private slots:
void updateChannels(UAVObject* obj);
void requestRCInputUpdate();
void sendRCInputUpdate();
void saveRCInputObject();
};

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>544</width>
<height>339</height>
<height>346</height>
</rect>
</property>
<property name="windowTitle">
@ -19,7 +19,7 @@
<x>10</x>
<y>20</y>
<width>521</width>
<height>281</height>
<height>311</height>
</rect>
</property>
<widget class="QWidget" name="tab">
@ -210,15 +210,18 @@
<string>2000</string>
</property>
</widget>
<widget class="QPushButton" name="getCurrent">
<widget class="QPushButton" name="getRCInputCurrent">
<property name="geometry">
<rect>
<x>190</x>
<y>210</y>
<y>240</y>
<width>93</width>
<height>27</height>
</rect>
</property>
<property name="toolTip">
<string>Retrieve settings from OpenPilot</string>
</property>
<property name="text">
<string>Get Current</string>
</property>
@ -350,15 +353,19 @@
<string/>
</property>
</widget>
<widget class="QPushButton" name="saveToSD">
<widget class="QPushButton" name="saveRCInputToSD">
<property name="geometry">
<rect>
<x>410</x>
<y>210</y>
<y>240</y>
<width>93</width>
<height>27</height>
</rect>
</property>
<property name="toolTip">
<string>Be sure to set the Neutral position on all sliders before sending!
Applies and Saves all settings to SD</string>
</property>
<property name="text">
<string>Save to SD</string>
</property>
@ -414,15 +421,19 @@
<enum>Qt::Vertical</enum>
</property>
</widget>
<widget class="QPushButton" name="saveToRAM">
<widget class="QPushButton" name="saveRCInputToRAM">
<property name="geometry">
<rect>
<x>300</x>
<y>210</y>
<y>240</y>
<width>93</width>
<height>27</height>
</rect>
</property>
<property name="toolTip">
<string>Send to OpenPilot but don't write in SD.
Be sure to set the Neutral position on all sliders before sending!</string>
</property>
<property name="text">
<string>Save to RAM</string>
</property>
@ -682,7 +693,7 @@
</rect>
</property>
<property name="maximum">
<number>0</number>
<number>99</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -860,6 +871,36 @@
</rect>
</property>
</widget>
<widget class="QCheckBox" name="doRCInputCalibration">
<property name="geometry">
<rect>
<x>10</x>
<y>210</y>
<width>131</width>
<height>22</height>
</rect>
</property>
<property name="toolTip">
<string>Start calibrating the RC Inputs.
Uncheck/Check to restart calibration.</string>
</property>
<property name="text">
<string>Run Calibration</string>
</property>
</widget>
<widget class="QLabel" name="RCInputConnected">
<property name="geometry">
<rect>
<x>320</x>
<y>210</y>
<width>181</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>RC Receiver Not Connected</string>
</property>
</widget>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
@ -869,5 +910,262 @@
</widget>
</widget>
<resources/>
<connections/>
<connections>
<connection>
<sender>ch2Slider</sender>
<signal>valueChanged(int)</signal>
<receiver>ch2Cur</receiver>
<slot>setNum(int)</slot>
<hints>
<hint type="sourcelabel">
<x>161</x>
<y>120</y>
</hint>
<hint type="destinationlabel">
<x>179</x>
<y>221</y>
</hint>
</hints>
</connection>
<connection>
<sender>ch0Slider</sender>
<signal>valueChanged(int)</signal>
<receiver>ch0Cur</receiver>
<slot>setNum(int)</slot>
<hints>
<hint type="sourcelabel">
<x>40</x>
<y>151</y>
</hint>
<hint type="destinationlabel">
<x>61</x>
<y>217</y>
</hint>
</hints>
</connection>
<connection>
<sender>ch1Slider</sender>
<signal>valueChanged(int)</signal>
<receiver>ch1Cur</receiver>
<slot>setNum(int)</slot>
<hints>
<hint type="sourcelabel">
<x>101</x>
<y>140</y>
</hint>
<hint type="destinationlabel">
<x>116</x>
<y>216</y>
</hint>
</hints>
</connection>
<connection>
<sender>ch3Slider</sender>
<signal>valueChanged(int)</signal>
<receiver>ch3Cur</receiver>
<slot>setNum(int)</slot>
<hints>
<hint type="sourcelabel">
<x>221</x>
<y>139</y>
</hint>
<hint type="destinationlabel">
<x>238</x>
<y>215</y>
</hint>
</hints>
</connection>
<connection>
<sender>ch4Slider</sender>
<signal>valueChanged(int)</signal>
<receiver>ch4Cur</receiver>
<slot>setNum(int)</slot>
<hints>
<hint type="sourcelabel">
<x>287</x>
<y>131</y>
</hint>
<hint type="destinationlabel">
<x>300</x>
<y>220</y>
</hint>
</hints>
</connection>
<connection>
<sender>ch5Slider</sender>
<signal>valueChanged(int)</signal>
<receiver>ch5Cur</receiver>
<slot>setNum(int)</slot>
<hints>
<hint type="sourcelabel">
<x>342</x>
<y>143</y>
</hint>
<hint type="destinationlabel">
<x>359</x>
<y>219</y>
</hint>
</hints>
</connection>
<connection>
<sender>ch6Slider</sender>
<signal>valueChanged(int)</signal>
<receiver>ch6Cur</receiver>
<slot>setNum(int)</slot>
<hints>
<hint type="sourcelabel">
<x>404</x>
<y>133</y>
</hint>
<hint type="destinationlabel">
<x>419</x>
<y>218</y>
</hint>
</hints>
</connection>
<connection>
<sender>ch7Slider</sender>
<signal>valueChanged(int)</signal>
<receiver>ch7Cur</receiver>
<slot>setNum(int)</slot>
<hints>
<hint type="sourcelabel">
<x>463</x>
<y>116</y>
</hint>
<hint type="destinationlabel">
<x>477</x>
<y>220</y>
</hint>
</hints>
</connection>
<connection>
<sender>doRCInputCalibration</sender>
<signal>toggled(bool)</signal>
<receiver>ch0Slider</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>31</x>
<y>272</y>
</hint>
<hint type="destinationlabel">
<x>38</x>
<y>170</y>
</hint>
</hints>
</connection>
<connection>
<sender>doRCInputCalibration</sender>
<signal>toggled(bool)</signal>
<receiver>ch1Slider</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>89</x>
<y>265</y>
</hint>
<hint type="destinationlabel">
<x>101</x>
<y>91</y>
</hint>
</hints>
</connection>
<connection>
<sender>doRCInputCalibration</sender>
<signal>toggled(bool)</signal>
<receiver>ch2Slider</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>104</x>
<y>275</y>
</hint>
<hint type="destinationlabel">
<x>166</x>
<y>106</y>
</hint>
</hints>
</connection>
<connection>
<sender>doRCInputCalibration</sender>
<signal>toggled(bool)</signal>
<receiver>ch3Slider</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>102</x>
<y>266</y>
</hint>
<hint type="destinationlabel">
<x>221</x>
<y>110</y>
</hint>
</hints>
</connection>
<connection>
<sender>doRCInputCalibration</sender>
<signal>toggled(bool)</signal>
<receiver>ch4Slider</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>74</x>
<y>262</y>
</hint>
<hint type="destinationlabel">
<x>280</x>
<y>89</y>
</hint>
</hints>
</connection>
<connection>
<sender>doRCInputCalibration</sender>
<signal>toggled(bool)</signal>
<receiver>ch5Slider</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>48</x>
<y>262</y>
</hint>
<hint type="destinationlabel">
<x>342</x>
<y>103</y>
</hint>
</hints>
</connection>
<connection>
<sender>doRCInputCalibration</sender>
<signal>toggled(bool)</signal>
<receiver>ch6Slider</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>72</x>
<y>269</y>
</hint>
<hint type="destinationlabel">
<x>400</x>
<y>90</y>
</hint>
</hints>
</connection>
<connection>
<sender>doRCInputCalibration</sender>
<signal>toggled(bool)</signal>
<receiver>ch7Slider</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>60</x>
<y>275</y>
</hint>
<hint type="destinationlabel">
<x>460</x>
<y>141</y>
</hint>
</hints>
</connection>
</connections>
</ui>