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

OP-138 Standard Fixed wing mixer implemented. I have not flown with it yet, take your responsibilities :)

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1738 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
edouard 2010-09-24 21:24:42 +00:00 committed by edouard
parent eedf85a5ac
commit 918770f4a2
3 changed files with 130 additions and 10 deletions

View File

@ -69,7 +69,7 @@
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>3</number>
<number>0</number>
</property>
<widget class="QWidget" name="fixedWing">
<property name="enabled">
@ -112,6 +112,19 @@
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="fwStatusLabel">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Mixer OK</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
@ -150,6 +163,9 @@
</item>
<item row="2" column="0">
<widget class="QLabel" name="fwAileron2Label">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Aileron 2</string>
</property>
@ -176,17 +192,28 @@
<widget class="QComboBox" name="fwRudderChannel"/>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="fwAileron2Channel"/>
<widget class="QComboBox" name="fwAileron2Channel">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="fwElevator2Label">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Elevator 2</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="fwElevator2Channel"/>
<widget class="QComboBox" name="fwElevator2Channel">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>

View File

@ -81,6 +81,8 @@ ConfigAirframeWidget::ConfigAirframeWidget(QWidget *parent) : ConfigTaskWidget(p
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->fwAileron1Channel, SIGNAL(currentIndexChanged(int)), this, SLOT(toggleAileron2(int)));
connect(m_aircraft->fwElevator1Channel, SIGNAL(currentIndexChanged(int)), this, SLOT(toggleElevator2(int)));
connect(parent, SIGNAL(autopilotConnected()),this, SLOT(requestAircraftUpdate()));
@ -91,6 +93,27 @@ ConfigAirframeWidget::~ConfigAirframeWidget()
// Do nothing
}
void ConfigAirframeWidget::toggleAileron2(int index)
{
if (index) {
m_aircraft->fwAileron2Channel->setEnabled(true);
m_aircraft->fwAileron2Label->setEnabled(true);
} else {
m_aircraft->fwAileron2Channel->setEnabled(false);
m_aircraft->fwAileron2Label->setEnabled(false);
}
}
void ConfigAirframeWidget::toggleElevator2(int index)
{
if (index) {
m_aircraft->fwElevator2Channel->setEnabled(true);
m_aircraft->fwElevator2Label->setEnabled(true);
} else {
m_aircraft->fwElevator2Channel->setEnabled(false);
m_aircraft->fwElevator2Label->setEnabled(false);
}
}
/**************************
* Aircraft settings
@ -175,8 +198,8 @@ void ConfigAirframeWidget::setupAirframeUI(QString frameType)
m_aircraft->fwRudderLabel->setEnabled(true);
m_aircraft->fwElevator1Channel->setEnabled(true);
m_aircraft->fwElevator1Label->setEnabled(true);
m_aircraft->fwElevator2Channel->setEnabled(true);
m_aircraft->fwElevator2Label->setEnabled(true);
//m_aircraft->fwElevator2Channel->setEnabled(true);
//m_aircraft->fwElevator2Label->setEnabled(true);
} else if (frameType == "FixedWingElevon" || frameType == "Elevon") {
m_aircraft->aircraftType->setCurrentIndex(m_aircraft->aircraftType->findText("Fixed Wing"));
@ -195,8 +218,19 @@ void ConfigAirframeWidget::setupAirframeUI(QString frameType)
m_aircraft->fwRudderLabel->setEnabled(false);
m_aircraft->fwElevator1Channel->setEnabled(true);
m_aircraft->fwElevator1Label->setEnabled(true);
m_aircraft->fwElevator2Channel->setEnabled(true);
m_aircraft->fwElevator2Label->setEnabled(true);
//m_aircraft->fwElevator2Channel->setEnabled(true);
//m_aircraft->fwElevator2Label->setEnabled(true);
}
}
/**
Reset the contents of a field
*/
void ConfigAirframeWidget::resetField(UAVObjectField * field)
{
for (unsigned int i=0;i<field->getNumElements();i++) {
field->setValue(0,i);
}
}
@ -216,12 +250,14 @@ bool ConfigAirframeWidget::setupFrameFixedWing()
((m_aircraft->fwAileron1Channel->currentText() == "None") &&
(m_aircraft->fwRudderChannel->currentText() == "None"))) {
// TODO: explain the problem in the UI
m_aircraft->fwStatusLabel->setText("WARNING: check channel assignment");
return false;
}
// Now setup the channels:
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("ActuatorSettings")));
Q_ASSERT(obj);
QList<UAVObjectField*> fieldList = obj->getFields();
// Reset all assignements first:
foreach (UAVObjectField* field, fieldList) {
// NOTE: we assume that all options in ActuatorSettings are a channel assignement
// except for the options called "ChannelXXX"
@ -287,13 +323,67 @@ bool ConfigAirframeWidget::setupFrameFixedWing()
field->setValue("Motor");
field = obj->getField(mixerVectors.at(eng));
// First of all reset the vector
for (int i=0;i<field->getNumElements();i++) {
field->setValue(0,i);
}
resetField(field);
int ti = field->getElementNames().indexOf("ThrottleCurve1");
field->setValue(1, ti);
// Rudder
eng = m_aircraft->fwRudderChannel->currentIndex()-1;
// eng will be -1 if rudder is set to "None"
if (eng > -1) {
field = obj->getField(mixerTypes.at(eng));
field->setValue("Servo");
field = obj->getField(mixerVectors.at(eng));
resetField(field);
ti = field->getElementNames().indexOf("Yaw");
field->setValue(1, ti);
} // Else: we have no rudder, only ailerons, we're fine with it.
// Ailerons
eng = m_aircraft->fwAileron1Channel->currentIndex()-1;
if (eng > -1) {
field = obj->getField(mixerTypes.at(eng));
field->setValue("Servo");
field = obj->getField(mixerVectors.at(eng));
resetField(field);
ti = field->getElementNames().indexOf("Roll");
field->setValue(1, ti);
// Only set Aileron 2 if Aileron 1 is defined
eng = m_aircraft->fwAileron2Channel->currentIndex()-1;
if (eng > -1) {
field = obj->getField(mixerTypes.at(eng));
field->setValue("Servo");
field = obj->getField(mixerVectors.at(eng));
resetField(field);
ti = field->getElementNames().indexOf("Roll");
field->setValue(1, ti);
}
}
// Elevator
eng = m_aircraft->fwElevator1Channel->currentIndex()-1;
if (eng > -1) {
field = obj->getField(mixerTypes.at(eng));
field->setValue("Servo");
field = obj->getField(mixerVectors.at(eng));
resetField(field);
ti = field->getElementNames().indexOf("Pitch");
field->setValue(1, ti);
// Only set Elevator 2 if Aileron 1 is defined
eng = m_aircraft->fwElevator2Channel->currentIndex()-1;
if (eng > -1) {
field = obj->getField(mixerTypes.at(eng));
field->setValue("Servo");
field = obj->getField(mixerVectors.at(eng));
resetField(field);
ti = field->getElementNames().indexOf("Pitch");
field->setValue(1, ti);
}
}
obj->updated();
m_aircraft->fwStatusLabel->setText("Mixer generated");
return true;
}

View File

@ -48,6 +48,7 @@ public:
private:
Ui_AircraftWidget *m_aircraft;
bool setupFrameFixedWing();
void resetField(UAVObjectField * field);
private slots:
@ -55,6 +56,8 @@ private slots:
void sendAircraftUpdate();
void saveAircraftUpdate();
void setupAirframeUI(QString type);
void toggleAileron2(int index);
void toggleElevator2(int index);
};