1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-20 10:54:14 +01:00

OP-138 Persistent (to SD) saves of all mixer settings working now (was missing two objects earlier).

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1814 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
edouard 2010-10-01 07:18:11 +00:00 committed by edouard
parent 712725f3d3
commit b32da232cb
3 changed files with 109 additions and 69 deletions

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>720</width>
<width>730</width>
<height>508</height>
</rect>
</property>
@ -67,9 +67,9 @@
</widget>
</item>
<item>
<widget class="QStackedWidget" name="stackedWidget">
<widget class="QStackedWidget" name="airframesWidget">
<property name="currentIndex">
<number>3</number>
<number>0</number>
</property>
<widget class="QWidget" name="fixedWing">
<property name="enabled">
@ -357,11 +357,22 @@
<item>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QLabel" name="label_13">
<property name="text">
<string>Throttle Curve</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_15">
<item>
<widget class="QLabel" name="label_13">
<property name="text">
<string>Throttle Curve</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="fwThrottleReset">
<property name="text">
<string>Reset</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="MixerCurveWidget" name="fixedWingThrottle" native="true">
@ -579,12 +590,50 @@
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_12">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<widget class="QLabel" name="label_24">
<property name="text">
<string>Throttle Curve</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="QLabel" name="label_24">
<property name="text">
<string>Throttle Curve</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="resetMultiThrottleon_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Reset</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="MixerCurveWidget" name="multiThrottleCurve" native="true">
@ -1238,22 +1287,6 @@
</customwidgets>
<resources/>
<connections>
<connection>
<sender>aircraftType</sender>
<signal>currentIndexChanged(int)</signal>
<receiver>stackedWidget</receiver>
<slot>setCurrentIndex(int)</slot>
<hints>
<hint type="sourcelabel">
<x>152</x>
<y>38</y>
</hint>
<hint type="destinationlabel">
<x>187</x>
<y>112</y>
</hint>
</hints>
</connection>
<connection>
<sender>elevonSlider2</sender>
<signal>valueChanged(int)</signal>

View File

@ -93,12 +93,14 @@ ConfigAirframeWidget::ConfigAirframeWidget(QWidget *parent) : ConfigTaskWidget(p
m_aircraft->quadShape->setScene(scene);
requestAircraftUpdate();
connect(m_aircraft->saveAircraftToSD, SIGNAL(clicked()), this, SLOT(saveAircraftUpdate()));
connect(m_aircraft->saveAircraftToRAM, SIGNAL(clicked()), this, SLOT(sendAircraftUpdate()));
connect(m_aircraft->getAircraftCurrent, SIGNAL(clicked()), this, SLOT(requestAircraftUpdate()));
connect(m_aircraft->fixedWingType, SIGNAL(currentIndexChanged(QString)), this, SLOT(setupAirframeUI(QString)));
connect(m_aircraft->multirotorFrameType, SIGNAL(currentIndexChanged(QString)), this, SLOT(setupAirframeUI(QString)));
connect(m_aircraft->aircraftType, SIGNAL(currentIndexChanged(int)), this, SLOT(switchAirframeType(int)));
requestAircraftUpdate();
// connect(m_aircraft->fwAileron1Channel, SIGNAL(currentIndexChanged(int)), this, SLOT(toggleAileron2(int)));
// connect(m_aircraft->fwElevator1Channel, SIGNAL(currentIndexChanged(int)), this, SLOT(toggleElevator2(int)));
@ -111,6 +113,19 @@ ConfigAirframeWidget::~ConfigAirframeWidget()
// Do nothing
}
/**
Slot for switching the airframe type. We do it explicitely
rather than a signal in the UI, because we want to force a fitInView of the quad shapes.
This is because this method (fitinview) only works when the widget is shown.
*/
void ConfigAirframeWidget::switchAirframeType(int index){
m_aircraft->airframesWidget->setCurrentIndex(index);
m_aircraft->quadShape->setSceneRect(quad->boundingRect());
m_aircraft->quadShape->fitInView(quad, Qt::KeepAspectRatio);
}
void ConfigAirframeWidget::showEvent(QShowEvent *event)
{
Q_UNUSED(event)
@ -124,6 +139,7 @@ void ConfigAirframeWidget::resizeEvent(QResizeEvent* event)
{
Q_UNUSED(event);
m_aircraft->quadShape->fitInView(quad, Qt::KeepAspectRatio);
}
@ -171,27 +187,30 @@ void ConfigAirframeWidget::requestAircraftUpdate()
QString frameType = field->getValue().toString();
setupAirframeUI(frameType);
obj = dynamic_cast<UAVDataObject*>(objManager->getObject(QString("MixerSettings")));
Q_ASSERT(obj);
obj->requestUpdate();
field = obj->getField(QString("ThrottleCurve1"));
Q_ASSERT(field);
QList<double> curveValues;
// If the 1st element of the curve is <= -10, then the curve
// is a straight line (that's how the mixer works on the mainboard):
if (field->getValue(0).toInt() <= -10) {
for (double i=0; i<field->getNumElements(); i++) {
curveValues.append(-1.0 + 2*i/(field->getNumElements()-1));
}
} else {
for (unsigned int i=0; i < field->getNumElements(); i++) {
curveValues.append(field->getValue(i).toDouble());
}
}
// Setup all Throttle1 curves for all types of airframes
m_aircraft->fixedWingThrottle->initCurve(curveValues);
m_aircraft->multiThrottleCurve->initCurve(curveValues);
// Load the Settings for fixed wing frames:
if (frameType.startsWith("FixedWing")) {
obj = dynamic_cast<UAVDataObject*>(objManager->getObject(QString("MixerSettings")));
Q_ASSERT(obj);
obj->requestUpdate();
field = obj->getField(QString("ThrottleCurve1"));
Q_ASSERT(field);
QList<double> curveValues;
// If the 1st element of the curve is <= -10, then the curve
// is a straight line (that's how the mixer works on the mainboard):
if (field->getValue(0).toInt() <= -10) {
for (double i=0; i<field->getNumElements(); i++) {
curveValues.append(-1.0 + 2*i/(field->getNumElements()-1));
}
} else {
for (unsigned int i=0; i < field->getNumElements(); i++) {
curveValues.append(field->getValue(i).toDouble());
}
}
m_aircraft->fixedWingThrottle->initCurve(curveValues);
// Then retrieve how channels are setup
// Then retrieve how channels are setup
obj = dynamic_cast<UAVDataObject*>(objManager->getObject(QString("ActuatorSettings")));
Q_ASSERT(obj);
field = obj->getField(QString("FixedWingThrottle"));
@ -239,31 +258,13 @@ void ConfigAirframeWidget::requestAircraftUpdate()
m_aircraft->elevonSlider2->setValue(field->getDouble(ti)*100);
}
}
} else if (frameType == "QuadX" || frameType == "QuadP" ||
frameType == "Hexa" || frameType == "Octo" ) {
//////////////////////////////////////////////////////////////////
// Retrieve Multirotor settings
//////////////////////////////////////////////////////////////////
// First of all, curve settings:
obj = dynamic_cast<UAVDataObject*>(objManager->getObject(QString("MixerSettings")));
Q_ASSERT(obj);
obj->requestUpdate();
field = obj->getField(QString("ThrottleCurve1"));
Q_ASSERT(field);
QList<double> curveValues;
// If the 1st element of the curve is <= -10, then the curve
// is a straight line (that's how the mixer works on the mainboard):
if (field->getValue(0).toInt() <= -10) {
for (double i=0; i<field->getNumElements(); i++) {
curveValues.append(-1.0 + 2*i/(field->getNumElements()-1));
}
} else {
for (unsigned int i=0; i < field->getNumElements(); i++) {
curveValues.append(field->getValue(i).toDouble());
}
}
m_aircraft->multiThrottleCurve->initCurve(curveValues);
obj = dynamic_cast<UAVDataObject*>(objManager->getObject(QString("ActuatorSettings")));
Q_ASSERT(obj);
if (frameType == "QuadP") {
@ -1025,6 +1026,11 @@ void ConfigAirframeWidget::saveAircraftUpdate()
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(objManager->getObject(QString("SystemSettings")));
Q_ASSERT(obj);
updateObjectPersistance(ObjectPersistence::OPERATION_SAVE, obj);
saveObjectToSD(obj);
obj = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("MixerSettings")));
saveObjectToSD(obj);
obj = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("ActuatorSettings")));
saveObjectToSD(obj);
}

View File

@ -68,6 +68,7 @@ private slots:
void setupAirframeUI(QString type);
void toggleAileron2(int index);
void toggleElevator2(int index);
void switchAirframeType(int index);
protected:
void showEvent(QShowEvent *event);