1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-17 02:52:12 +01:00

Fix 'smart' throttle/flight mode channel assignment, it works now. Someone please test & report.

OP-522
This commit is contained in:
elafargue 2011-06-08 22:15:10 +02:00
parent 3a3c88cefa
commit 1ac92643b7
3 changed files with 188 additions and 101 deletions

View File

@ -70,15 +70,6 @@ ConfigInputWidget::ConfigInputWidget(QWidget *parent) : ConfigTaskWidget(parent)
<< m_config->ch6Min
<< m_config->ch7Min;
inNeuLabels << m_config->ch0Cur
<< m_config->ch1Cur
<< m_config->ch2Cur
<< m_config->ch3Cur
<< m_config->ch4Cur
<< m_config->ch5Cur
<< m_config->ch6Cur
<< m_config->ch7Cur;
inSliders << m_config->inSlider0
<< m_config->inSlider1
<< m_config->inSlider2
@ -97,6 +88,14 @@ ConfigInputWidget::ConfigInputWidget(QWidget *parent) : ConfigTaskWidget(parent)
<< m_config->ch6Rev
<< m_config->ch7Rev;
inChannelAssign << m_config->ch0Assign
<< m_config->ch1Assign
<< m_config->ch2Assign
<< m_config->ch3Assign
<< m_config->ch4Assign
<< m_config->ch5Assign
<< m_config->ch6Assign
<< m_config->ch7Assign;
// Now connect the widget to the ManualControlCommand / Channel UAVObject
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(objManager->getObject(QString("ManualControlCommand")));
@ -166,15 +165,6 @@ ConfigInputWidget::ConfigInputWidget(QWidget *parent) : ConfigTaskWidget(parent)
connect(parent, SIGNAL(autopilotConnected()),this, SLOT(onAutopilotConnect()));
connect(parent, SIGNAL(autopilotDisconnected()), this, SLOT(onAutopilotDisconnect()));
connect(m_config->inSlider0, SIGNAL(valueChanged(int)),this, SLOT(onInSliderValueChanged0(int)));
connect(m_config->inSlider1, SIGNAL(valueChanged(int)),this, SLOT(onInSliderValueChanged1(int)));
connect(m_config->inSlider2, SIGNAL(valueChanged(int)),this, SLOT(onInSliderValueChanged2(int)));
connect(m_config->inSlider3, SIGNAL(valueChanged(int)),this, SLOT(onInSliderValueChanged3(int)));
connect(m_config->inSlider4, SIGNAL(valueChanged(int)),this, SLOT(onInSliderValueChanged4(int)));
connect(m_config->inSlider5, SIGNAL(valueChanged(int)),this, SLOT(onInSliderValueChanged5(int)));
connect(m_config->inSlider6, SIGNAL(valueChanged(int)),this, SLOT(onInSliderValueChanged6(int)));
connect(m_config->inSlider7, SIGNAL(valueChanged(int)),this, SLOT(onInSliderValueChanged7(int)));
connect(m_config->ch0Rev, SIGNAL(toggled(bool)), this, SLOT(reverseCheckboxClicked(bool)));
connect(m_config->ch1Rev, SIGNAL(toggled(bool)), this, SLOT(reverseCheckboxClicked(bool)));
connect(m_config->ch2Rev, SIGNAL(toggled(bool)), this, SLOT(reverseCheckboxClicked(bool)));
@ -213,49 +203,6 @@ void ConfigInputWidget::reverseCheckboxClicked(bool state)
}
}
// ************************************
// slider value changed signals
void ConfigInputWidget::onInSliderValueChanged0(int value)
{
inNeuLabels[0]->setText(QString::number(value));
}
void ConfigInputWidget::onInSliderValueChanged1(int value)
{
inNeuLabels[1]->setText(QString::number(value));
}
void ConfigInputWidget::onInSliderValueChanged2(int value)
{
inNeuLabels[2]->setText(QString::number(value));
}
void ConfigInputWidget::onInSliderValueChanged3(int value)
{
inNeuLabels[3]->setText(QString::number(value));
}
void ConfigInputWidget::onInSliderValueChanged4(int value)
{
inNeuLabels[4]->setText(QString::number(value));
}
void ConfigInputWidget::onInSliderValueChanged5(int value)
{
inNeuLabels[5]->setText(QString::number(value));
}
void ConfigInputWidget::onInSliderValueChanged6(int value)
{
inNeuLabels[6]->setText(QString::number(value));
}
void ConfigInputWidget::onInSliderValueChanged7(int value)
{
inNeuLabels[7]->setText(QString::number(value));
}
// ************************************
@ -269,8 +216,6 @@ void ConfigInputWidget::enableControls(bool enable)
//m_config->saveRCInputToRAM->setEnabled(enable);
m_config->saveRCInputToSD->setEnabled(enable);
m_config->doRCInputCalibration->setEnabled(enable);
m_config->doRCInputCalibration->setChecked(false);
}
@ -319,14 +264,9 @@ void ConfigInputWidget::refreshValues()
m_config->receiverType->setCurrentIndex(m_config->receiverType->findText(field->getValue().toString()));
// Reset all channel assignement dropdowns:
m_config->ch0Assign->setCurrentIndex(0);
m_config->ch1Assign->setCurrentIndex(0);
m_config->ch2Assign->setCurrentIndex(0);
m_config->ch3Assign->setCurrentIndex(0);
m_config->ch4Assign->setCurrentIndex(0);
m_config->ch5Assign->setCurrentIndex(0);
m_config->ch6Assign->setCurrentIndex(0);
m_config->ch7Assign->setCurrentIndex(0);
foreach (QComboBox *combo, inChannelAssign) {
combo->setCurrentIndex(0);
}
// Update all channels assignements
QList<UAVObjectField *> fieldList = obj->getFields();
@ -553,6 +493,10 @@ void ConfigInputWidget::updateChannels(UAVObject* controlCommand)
field->setValue(0,i);
}
obj->updated();
// Last, make sure the user won't apply/save during calibration
m_config->saveRCInputToRAM->setEnabled(false);
m_config->saveRCInputToSD->setEnabled(false);
}
field = controlCommand->getField(QString("Channel"));
@ -574,20 +518,42 @@ void ConfigInputWidget::updateChannels(UAVObject* controlCommand)
obj->setMetadata(mdata);
// Set some slider values to better defaults
ManualControlSettings * manualSettings = ManualControlSettings::GetInstance(getObjectManager());
ManualControlSettings::DataFields manualSettingsData = manualSettings->getData();
uint throttleIndex = manualSettingsData.Throttle;
uint flightModeIndex = manualSettingsData.FlightMode;
if(throttleIndex < manualSettings->THROTTLE_NONE) {
// Throttle neutral defaults to 5% of range
manualSettingsData.ChannelNeutral[throttleIndex] = 0.05 * (manualSettingsData.ChannelMax[throttleIndex] - manualSettingsData.ChannelMin[throttleIndex]) + manualSettingsData.ChannelMin[throttleIndex];
qDebug() << manualSettingsData.ChannelNeutral[throttleIndex];
// Find what channel we used for throttle, set it 5% about min:
int throttleChannel = -1;
int fmChannel = -1;
for (int i=0; i < inChannelAssign.length(); i++) {
if (inChannelAssign.at(i)->currentText() == "Throttle") {
// TODO: this is very ugly, because this relies on the name of the
// channel input, everywhere else in the gadget we don't rely on the
// naming...
throttleChannel = i;
}
if (inChannelAssign.at(i)->currentText() == "FlightMode") {
// TODO: this is very ugly, because this relies on the name of the
// channel input, everywhere else in the gadget we don't rely on the
// naming...
fmChannel = i;
}
}
if(flightModeIndex < manualSettings->FLIGHTMODE_NONE) {
// Flight mode neutral defaults to 50% of range
manualSettingsData.ChannelNeutral[flightModeIndex] = 0.5 * (manualSettingsData.ChannelMax[flightModeIndex] - manualSettingsData.ChannelMin[flightModeIndex]) + manualSettingsData.ChannelMin[flightModeIndex];
// Throttle neutral defaults to 2% of range
if (throttleChannel > -1) {
inSliders.at(throttleChannel)->setValue(
inSliders.at(throttleChannel)->minimum() +
(inSliders.at(throttleChannel)->maximum()-
inSliders.at(throttleChannel)->minimum())*0.02);
}
manualSettings->setData(manualSettingsData);
// Flight mode at 50% of range:
if (fmChannel > -1) {
inSliders.at(fmChannel)->setValue(
inSliders.at(fmChannel)->minimum()+
(inSliders.at(fmChannel)->maximum()-
inSliders.at(fmChannel)->minimum())*0.5);
}
m_config->saveRCInputToRAM->setEnabled(true);
m_config->saveRCInputToSD->setEnabled(true);
}
firstUpdate = true;
}

View File

@ -47,15 +47,6 @@ public:
public slots:
void onInSliderValueChanged0(int value);
void onInSliderValueChanged1(int value);
void onInSliderValueChanged2(int value);
void onInSliderValueChanged3(int value);
void onInSliderValueChanged4(int value);
void onInSliderValueChanged5(int value);
void onInSliderValueChanged6(int value);
void onInSliderValueChanged7(int value);
private:
Ui_InputWidget *m_config;
@ -75,6 +66,7 @@ private:
QList<QLabel*> inMinLabels;
QList<QLabel*> inNeuLabels;
QList<QCheckBox*> inRevCheckboxes;
QList<QComboBox*> inChannelAssign;
bool firstUpdate;

View File

@ -52,7 +52,7 @@ p, li { white-space: pre-wrap; }
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:9pt;&quot;&gt;Current channel value.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>1000</string>
<string>1500</string>
</property>
</widget>
</item>
@ -160,7 +160,7 @@ p, li { white-space: pre-wrap; }
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:9pt;&quot;&gt;Current channel value.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>1000</string>
<string>1500</string>
</property>
</widget>
</item>
@ -268,7 +268,7 @@ p, li { white-space: pre-wrap; }
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:9pt;&quot;&gt;Current channel value.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>1000</string>
<string>1500</string>
</property>
</widget>
</item>
@ -376,7 +376,7 @@ p, li { white-space: pre-wrap; }
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:9pt;&quot;&gt;Current channel value.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>1000</string>
<string>1500</string>
</property>
</widget>
</item>
@ -484,7 +484,7 @@ p, li { white-space: pre-wrap; }
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:9pt;&quot;&gt;Current channel value.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>1000</string>
<string>1500</string>
</property>
</widget>
</item>
@ -592,7 +592,7 @@ p, li { white-space: pre-wrap; }
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:9pt;&quot;&gt;Current channel value.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>1000</string>
<string>1500</string>
</property>
</widget>
</item>
@ -700,7 +700,7 @@ p, li { white-space: pre-wrap; }
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:9pt;&quot;&gt;Current channel value.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>1000</string>
<string>1500</string>
</property>
</widget>
</item>
@ -912,7 +912,7 @@ p, li { white-space: pre-wrap; }
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:9pt;&quot;&gt;Current channel value.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>1000</string>
<string>1500</string>
</property>
</widget>
</item>
@ -1460,5 +1460,134 @@ Applies and Saves all settings to SD</string>
<resources>
<include location="../coreplugin/core.qrc"/>
</resources>
<connections/>
<connections>
<connection>
<sender>inSlider0</sender>
<signal>valueChanged(int)</signal>
<receiver>ch0Cur</receiver>
<slot>setNum(int)</slot>
<hints>
<hint type="sourcelabel">
<x>291</x>
<y>93</y>
</hint>
<hint type="destinationlabel">
<x>150</x>
<y>104</y>
</hint>
</hints>
</connection>
<connection>
<sender>inSlider1</sender>
<signal>valueChanged(int)</signal>
<receiver>ch1Cur</receiver>
<slot>setNum(int)</slot>
<hints>
<hint type="sourcelabel">
<x>283</x>
<y>137</y>
</hint>
<hint type="destinationlabel">
<x>160</x>
<y>138</y>
</hint>
</hints>
</connection>
<connection>
<sender>inSlider2</sender>
<signal>valueChanged(int)</signal>
<receiver>ch2Cur</receiver>
<slot>setNum(int)</slot>
<hints>
<hint type="sourcelabel">
<x>341</x>
<y>163</y>
</hint>
<hint type="destinationlabel">
<x>156</x>
<y>167</y>
</hint>
</hints>
</connection>
<connection>
<sender>inSlider3</sender>
<signal>valueChanged(int)</signal>
<receiver>ch3Cur</receiver>
<slot>setNum(int)</slot>
<hints>
<hint type="sourcelabel">
<x>283</x>
<y>211</y>
</hint>
<hint type="destinationlabel">
<x>159</x>
<y>210</y>
</hint>
</hints>
</connection>
<connection>
<sender>inSlider4</sender>
<signal>valueChanged(int)</signal>
<receiver>ch4Cur</receiver>
<slot>setNum(int)</slot>
<hints>
<hint type="sourcelabel">
<x>287</x>
<y>239</y>
</hint>
<hint type="destinationlabel">
<x>156</x>
<y>242</y>
</hint>
</hints>
</connection>
<connection>
<sender>inSlider5</sender>
<signal>valueChanged(int)</signal>
<receiver>ch5Cur</receiver>
<slot>setNum(int)</slot>
<hints>
<hint type="sourcelabel">
<x>309</x>
<y>272</y>
</hint>
<hint type="destinationlabel">
<x>164</x>
<y>276</y>
</hint>
</hints>
</connection>
<connection>
<sender>inSlider6</sender>
<signal>valueChanged(int)</signal>
<receiver>ch6Cur</receiver>
<slot>setNum(int)</slot>
<hints>
<hint type="sourcelabel">
<x>282</x>
<y>300</y>
</hint>
<hint type="destinationlabel">
<x>144</x>
<y>311</y>
</hint>
</hints>
</connection>
<connection>
<sender>inSlider7</sender>
<signal>valueChanged(int)</signal>
<receiver>ch7Cur</receiver>
<slot>setNum(int)</slot>
<hints>
<hint type="sourcelabel">
<x>278</x>
<y>339</y>
</hint>
<hint type="destinationlabel">
<x>168</x>
<y>340</y>
</hint>
</hints>
</connection>
</connections>
</ui>