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

Merged in filnet/librepilot/LP-467_fix_old_regressions_in_vehicle_config (pull request #377)

LP-467 fix old regressions in vehicle config
This commit is contained in:
Lalanne Laurent 2017-01-27 20:20:23 +00:00
commit 82ae88e942
22 changed files with 708 additions and 604 deletions

View File

@ -69,7 +69,7 @@
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox">
<widget class="QComboBox" name="curve1SourceCombo">
<property name="enabled">
<bool>false</bool>
</property>

View File

@ -57,7 +57,7 @@ QStringList ConfigCcpmWidget::getChannelDescriptions()
QStringList channelDesc;
for (int i = 0; i < (int)ConfigCcpmWidget::CHANNEL_NUMELEM; i++) {
channelDesc.append(QString("-"));
channelDesc.append("-");
}
// get the gui config data
@ -65,64 +65,64 @@ QStringList ConfigCcpmWidget::getChannelDescriptions()
heliGUISettingsStruct heli = configData.heli;
if (heli.Throttle > 0) {
channelDesc[heli.Throttle - 1] = QString("Throttle");
channelDesc[heli.Throttle - 1] = "Throttle";
}
if (heli.Tail > 0) {
channelDesc[heli.Tail - 1] = QString("Tail");
channelDesc[heli.Tail - 1] = "Tail";
}
switch (heli.FirstServoIndex) {
case 0:
// front
if (heli.ServoIndexW > 0) {
channelDesc[heli.ServoIndexW - 1] = QString("Elevator");
channelDesc[heli.ServoIndexW - 1] = "Elevator";
}
if (heli.ServoIndexX > 0) {
channelDesc[heli.ServoIndexX - 1] = QString("Roll1");
channelDesc[heli.ServoIndexX - 1] = "Roll1";
}
if (heli.ServoIndexY > 0) {
channelDesc[heli.ServoIndexY - 1] = QString("Roll2");
channelDesc[heli.ServoIndexY - 1] = "Roll2";
}
break;
case 1:
// right
if (heli.ServoIndexW > 0) {
channelDesc[heli.ServoIndexW - 1] = QString("ServoW");
channelDesc[heli.ServoIndexW - 1] = "ServoW";
}
if (heli.ServoIndexX > 0) {
channelDesc[heli.ServoIndexX - 1] = QString("ServoX");
channelDesc[heli.ServoIndexX - 1] = "ServoX";
}
if (heli.ServoIndexY > 0) {
channelDesc[heli.ServoIndexY - 1] = QString("ServoY");
channelDesc[heli.ServoIndexY - 1] = "ServoY";
}
break;
case 2:
// rear
if (heli.ServoIndexW > 0) {
channelDesc[heli.ServoIndexW - 1] = QString("Elevator");
channelDesc[heli.ServoIndexW - 1] = "Elevator";
}
if (heli.ServoIndexX > 0) {
channelDesc[heli.ServoIndexX - 1] = QString("Roll1");
channelDesc[heli.ServoIndexX - 1] = "Roll1";
}
if (heli.ServoIndexY > 0) {
channelDesc[heli.ServoIndexY - 1] = QString("Roll2");
channelDesc[heli.ServoIndexY - 1] = "Roll2";
}
break;
case 3:
// left
if (heli.ServoIndexW > 0) {
channelDesc[heli.ServoIndexW - 1] = QString("ServoW");
channelDesc[heli.ServoIndexW - 1] = "ServoW";
}
if (heli.ServoIndexX > 0) {
channelDesc[heli.ServoIndexX - 1] = QString("ServoX");
channelDesc[heli.ServoIndexX - 1] = "ServoX";
}
if (heli.ServoIndexY > 0) {
channelDesc[heli.ServoIndexY - 1] = QString("ServoY");
channelDesc[heli.ServoIndexY - 1] = "ServoY";
}
break;
}
if (heli.ServoIndexZ > 0) {
channelDesc[heli.ServoIndexZ - 1] = QString("ServoZ");
channelDesc[heli.ServoIndexZ - 1] = "ServoZ";
}
return channelDesc;
}
@ -196,7 +196,7 @@ ConfigCcpmWidget::ConfigCcpmWidget(QWidget *parent) :
ServosText[i] = new QGraphicsTextItem();
ServosText[i]->setDefaultTextColor(Qt::yellow);
ServosText[i]->setPlainText(QString("-"));
ServosText[i]->setPlainText("-");
ServosText[i]->setFont(serifFont);
ServosText[i]->setZValue(31);
@ -237,16 +237,14 @@ ConfigCcpmWidget::ConfigCcpmWidget(QWidget *parent) :
m_aircraft->ccpmServoZChannel->setCurrentIndex(0);
QStringList Types;
Types << QString::fromUtf8("CCPM 2 Servo 90º") << QString::fromUtf8("CCPM 3 Servo 90º")
<< QString::fromUtf8("CCPM 4 Servo 90º") << QString::fromUtf8("CCPM 3 Servo 120º")
<< QString::fromUtf8("CCPM 3 Servo 140º") << QString::fromUtf8("FP 2 Servo 90º")
<< QString::fromUtf8("Coax 2 Servo 90º") << QString::fromUtf8("Custom - User Angles")
<< QString::fromUtf8("Custom - Advanced Settings");
Types << "CCPM 2 Servo 90º" << "CCPM 3 Servo 90º"
<< "CCPM 4 Servo 90º" << "CCPM 3 Servo 120º"
<< "CCPM 3 Servo 140º" << "FP 2 Servo 90º"
<< "Coax 2 Servo 90º" << "Custom - User Angles"
<< "Custom - Advanced Settings";
m_aircraft->ccpmType->addItems(Types);
m_aircraft->ccpmType->setCurrentIndex(m_aircraft->ccpmType->count() - 1);
// refreshWidgetsValues(QString("HeliCP"));
connect(m_aircraft->ccpmAngleW, SIGNAL(valueChanged(double)), this, SLOT(ccpmSwashplateUpdate()));
connect(m_aircraft->ccpmAngleX, SIGNAL(valueChanged(double)), this, SLOT(ccpmSwashplateUpdate()));
connect(m_aircraft->ccpmAngleY, SIGNAL(valueChanged(double)), this, SLOT(ccpmSwashplateUpdate()));
@ -284,6 +282,11 @@ ConfigCcpmWidget::~ConfigCcpmWidget()
delete m_aircraft;
}
QString ConfigCcpmWidget::getFrameType()
{
return "HeliCP";
}
void ConfigCcpmWidget::setupUI(QString frameType)
{
Q_UNUSED(frameType);
@ -320,10 +323,10 @@ void ConfigCcpmWidget::registerWidgets(ConfigTaskWidget &parent)
parent.addWidget(m_aircraft->ccpmRollScaleBox);
parent.addWidget(m_aircraft->SwashLvlPositionSlider);
parent.addWidget(m_aircraft->SwashLvlPositionSpinBox);
parent.addWidget(m_aircraft->ThrottleCurve->getCurveWidget());
parent.addWidget(m_aircraft->PitchCurve->getCurveWidget());
parent.addWidget(m_aircraft->PitchCurve);
parent.addWidget(m_aircraft->ThrottleCurve->getCurveWidget());
parent.addWidget(m_aircraft->PitchCurve);
parent.addWidget(m_aircraft->ThrottleCurve);
parent.addWidget(m_aircraft->ccpmAdvancedSettingsTable);
}
@ -337,11 +340,16 @@ void ConfigCcpmWidget::resetActuators(GUIConfigDataUnion *configData)
configData->heli.ServoIndexZ = 0;
}
void ConfigCcpmWidget::refreshWidgetsValues(QString frameType)
void ConfigCcpmWidget::enableControls(bool enable)
{
Q_UNUSED(frameType);
if (enable) {
SetUIComponentVisibilities();
}
}
setupUI(frameType);
void ConfigCcpmWidget::refreshWidgetsValuesImpl(UAVObject *obj)
{
Q_UNUSED(obj);
GUIConfigDataUnion config = getConfigData();
@ -383,13 +391,10 @@ void ConfigCcpmWidget::refreshWidgetsValues(QString frameType)
getMixer();
}
QString ConfigCcpmWidget::updateConfigObjectsFromWidgets()
void ConfigCcpmWidget::updateObjectsFromWidgetsImpl()
{
QString airframeType = updateConfigObjects();
updateConfigObjects();
setMixer();
return airframeType;
}
void ConfigCcpmWidget::UpdateType()
@ -406,85 +411,85 @@ void ConfigCcpmWidget::UpdateType()
NumServosDefined = 4;
// set values for pre defined heli types
if (typeText.compare(QString::fromUtf8("CCPM 2 Servo 90º"), Qt::CaseInsensitive) == 0) {
if (typeText.compare("CCPM 2 Servo 90º", Qt::CaseInsensitive) == 0) {
m_aircraft->ccpmAngleW->setValue(AdjustmentAngle + 0);
m_aircraft->ccpmAngleX->setValue(fmod(AdjustmentAngle + 90, 360));
m_aircraft->ccpmAngleY->setValue(0);
m_aircraft->ccpmAngleZ->setValue(0);
m_aircraft->ccpmAngleY->setEnabled(0);
m_aircraft->ccpmAngleZ->setEnabled(0);
m_aircraft->ccpmAngleY->setEnabled(false);
m_aircraft->ccpmAngleZ->setEnabled(false);
m_aircraft->ccpmServoYChannel->setCurrentIndex(0);
m_aircraft->ccpmServoZChannel->setCurrentIndex(0);
m_aircraft->ccpmServoYChannel->setEnabled(0);
m_aircraft->ccpmServoZChannel->setEnabled(0);
m_aircraft->ccpmServoYChannel->setEnabled(false);
m_aircraft->ccpmServoZChannel->setEnabled(false);
NumServosDefined = 2;
} else if (typeText.compare(QString::fromUtf8("CCPM 3 Servo 90º"), Qt::CaseInsensitive) == 0) {
} else if (typeText.compare("CCPM 3 Servo 90º", Qt::CaseInsensitive) == 0) {
m_aircraft->ccpmAngleW->setValue(AdjustmentAngle + 0);
m_aircraft->ccpmAngleX->setValue(fmod(AdjustmentAngle + 90, 360));
m_aircraft->ccpmAngleY->setValue(fmod(AdjustmentAngle + 180, 360));
m_aircraft->ccpmAngleZ->setValue(0);
m_aircraft->ccpmAngleZ->setEnabled(0);
m_aircraft->ccpmAngleZ->setEnabled(false);
m_aircraft->ccpmServoZChannel->setCurrentIndex(0);
m_aircraft->ccpmServoZChannel->setEnabled(0);
m_aircraft->ccpmServoZChannel->setEnabled(false);
NumServosDefined = 3;
} else if (typeText.compare(QString::fromUtf8("CCPM 4 Servo 90º"), Qt::CaseInsensitive) == 0) {
} else if (typeText.compare("CCPM 4 Servo 90º", Qt::CaseInsensitive) == 0) {
m_aircraft->ccpmAngleW->setValue(AdjustmentAngle + 0);
m_aircraft->ccpmAngleX->setValue(fmod(AdjustmentAngle + 90, 360));
m_aircraft->ccpmAngleY->setValue(fmod(AdjustmentAngle + 180, 360));
m_aircraft->ccpmAngleZ->setValue(fmod(AdjustmentAngle + 270, 360));
m_aircraft->ccpmSingleServo->setEnabled(0);
m_aircraft->ccpmSingleServo->setEnabled(false);
m_aircraft->ccpmSingleServo->setCurrentIndex(0);
NumServosDefined = 4;
} else if (typeText.compare(QString::fromUtf8("CCPM 3 Servo 120º"), Qt::CaseInsensitive) == 0) {
} else if (typeText.compare("CCPM 3 Servo 120º", Qt::CaseInsensitive) == 0) {
m_aircraft->ccpmAngleW->setValue(AdjustmentAngle + 0);
m_aircraft->ccpmAngleX->setValue(fmod(AdjustmentAngle + 120, 360));
m_aircraft->ccpmAngleY->setValue(fmod(AdjustmentAngle + 240, 360));
m_aircraft->ccpmAngleZ->setValue(0);
m_aircraft->ccpmAngleZ->setEnabled(0);
m_aircraft->ccpmAngleZ->setEnabled(false);
m_aircraft->ccpmServoZChannel->setCurrentIndex(0);
m_aircraft->ccpmServoZChannel->setEnabled(0);
m_aircraft->ccpmServoZChannel->setEnabled(false);
NumServosDefined = 3;
} else if (typeText.compare(QString::fromUtf8("CCPM 3 Servo 140º"), Qt::CaseInsensitive) == 0) {
} else if (typeText.compare("CCPM 3 Servo 140º", Qt::CaseInsensitive) == 0) {
m_aircraft->ccpmAngleW->setValue(AdjustmentAngle + 0);
m_aircraft->ccpmAngleX->setValue(fmod(AdjustmentAngle + 140, 360));
m_aircraft->ccpmAngleY->setValue(fmod(AdjustmentAngle + 220, 360));
m_aircraft->ccpmAngleZ->setValue(0);
m_aircraft->ccpmAngleZ->setEnabled(0);
m_aircraft->ccpmAngleZ->setEnabled(false);
m_aircraft->ccpmServoZChannel->setCurrentIndex(0);
m_aircraft->ccpmServoZChannel->setEnabled(0);
m_aircraft->ccpmServoZChannel->setEnabled(false);
NumServosDefined = 3;
} else if (typeText.compare(QString::fromUtf8("FP 2 Servo 90º"), Qt::CaseInsensitive) == 0) {
} else if (typeText.compare("FP 2 Servo 90º", Qt::CaseInsensitive) == 0) {
m_aircraft->ccpmAngleW->setValue(AdjustmentAngle + 0);
m_aircraft->ccpmAngleX->setValue(fmod(AdjustmentAngle + 90, 360));
m_aircraft->ccpmAngleY->setValue(0);
m_aircraft->ccpmAngleZ->setValue(0);
m_aircraft->ccpmAngleY->setEnabled(0);
m_aircraft->ccpmAngleZ->setEnabled(0);
m_aircraft->ccpmAngleY->setEnabled(false);
m_aircraft->ccpmAngleZ->setEnabled(false);
m_aircraft->ccpmServoYChannel->setCurrentIndex(0);
m_aircraft->ccpmServoZChannel->setCurrentIndex(0);
m_aircraft->ccpmServoYChannel->setEnabled(0);
m_aircraft->ccpmServoZChannel->setEnabled(0);
m_aircraft->ccpmServoYChannel->setEnabled(false);
m_aircraft->ccpmServoZChannel->setEnabled(false);
m_aircraft->ccpmCollectivespinBox->setEnabled(0);
m_aircraft->ccpmCollectiveSlider->setEnabled(0);
m_aircraft->ccpmCollectivespinBox->setEnabled(false);
m_aircraft->ccpmCollectiveSlider->setEnabled(false);
m_aircraft->ccpmCollectivespinBox->setValue(0);
m_aircraft->ccpmCollectiveSlider->setValue(0);
m_aircraft->PitchCurve->setVisible(0);
NumServosDefined = 2;
} else if (typeText.compare(QString::fromUtf8("Coax 2 Servo 90º"), Qt::CaseInsensitive) == 0) {
} else if (typeText.compare("Coax 2 Servo 90º", Qt::CaseInsensitive) == 0) {
m_aircraft->ccpmAngleW->setValue(AdjustmentAngle + 0);
m_aircraft->ccpmAngleX->setValue(fmod(AdjustmentAngle + 90, 360));
m_aircraft->ccpmAngleY->setValue(0);
m_aircraft->ccpmAngleZ->setValue(0);
m_aircraft->ccpmAngleY->setEnabled(0);
m_aircraft->ccpmAngleZ->setEnabled(0);
m_aircraft->ccpmAngleY->setEnabled(false);
m_aircraft->ccpmAngleZ->setEnabled(false);
m_aircraft->ccpmServoYChannel->setCurrentIndex(0);
m_aircraft->ccpmServoZChannel->setCurrentIndex(0);
m_aircraft->ccpmServoYChannel->setEnabled(0);
m_aircraft->ccpmServoZChannel->setEnabled(0);
m_aircraft->ccpmServoYChannel->setEnabled(false);
m_aircraft->ccpmServoZChannel->setEnabled(false);
m_aircraft->ccpmCollectivespinBox->setEnabled(0);
m_aircraft->ccpmCollectiveSlider->setEnabled(0);
m_aircraft->ccpmCollectivespinBox->setEnabled(false);
m_aircraft->ccpmCollectiveSlider->setEnabled(false);
m_aircraft->ccpmCollectivespinBox->setValue(0);
m_aircraft->ccpmCollectiveSlider->setValue(0);
m_aircraft->PitchCurve->setVisible(0);
@ -492,7 +497,7 @@ void ConfigCcpmWidget::UpdateType()
}
// Set the text of the motor boxes
if (typeText.compare(QString::fromUtf8("Coax 2 Servo 90º"), Qt::CaseInsensitive) == 0) {
if (typeText.compare("Coax 2 Servo 90º", Qt::CaseInsensitive) == 0) {
m_aircraft->ccpmEngineLabel->setText("CW motor");
m_aircraft->ccpmTailLabel->setText("CCW motor");
} else {
@ -719,7 +724,7 @@ void ConfigCcpmWidget::UpdateMixer()
table->item(i, 3)->setText(QString("%1").arg(0)); // Roll
table->item(i, 4)->setText(QString("%1").arg(0)); // Pitch
if (typeText.compare(QString::fromUtf8("Coax 2 Servo 90º"), Qt::CaseInsensitive) == 0) {
if (typeText.compare("Coax 2 Servo 90º", Qt::CaseInsensitive) == 0) {
// Yaw
table->item(i, 5)->setText(QString("%1").arg(-127));
} else {
@ -729,7 +734,7 @@ void ConfigCcpmWidget::UpdateMixer()
}
if (i == 1) {
// tailrotor --or-- counter-clockwise motor
if (typeText.compare(QString::fromUtf8("Coax 2 Servo 90º"), Qt::CaseInsensitive) == 0) {
if (typeText.compare("Coax 2 Servo 90º", Qt::CaseInsensitive) == 0) {
// ThrottleCurve1
table->item(i, 1)->setText(QString("%1").arg(127));
// Yaw
@ -766,13 +771,13 @@ void ConfigCcpmWidget::UpdateMixer()
}
} else {
for (int j = 0; j < 6; j++) {
table->item(i, j)->setText(QString("-"));
table->item(i, j)->setText("-");
}
}
}
} else {
// advanced settings
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("MixerSettings"));
Q_ASSERT(mixer);
// Populate custom mixer table from board values
@ -797,24 +802,18 @@ void ConfigCcpmWidget::UpdateMixer()
VehicleConfig::MIXERVECTOR_YAW)));
} else {
for (int j = 0; j < 6; j++) {
table->item(i, j)->setText(QString("-"));
table->item(i, j)->setText("-");
}
}
}
}
}
QString ConfigCcpmWidget::updateConfigObjects()
void ConfigCcpmWidget::updateConfigObjects()
{
QString airframeType = "HeliCP";
bool useCCPM;
bool useCyclic;
if (updatingFromHardware == true) {
return airframeType;
return;
}
updatingFromHardware = true;
// get the user options
@ -828,8 +827,8 @@ QString ConfigCcpmWidget::updateConfigObjects()
config.heli.ccpmCollectivePassthroughState = m_aircraft->ccpmCollectivePassthrough->isChecked();
config.heli.ccpmLinkCyclicState = m_aircraft->ccpmLinkCyclic->isChecked();
config.heli.ccpmLinkRollState = m_aircraft->ccpmLinkRoll->isChecked();
useCCPM = !(config.heli.ccpmCollectivePassthroughState || !config.heli.ccpmLinkCyclicState);
useCyclic = config.heli.ccpmLinkRollState;
bool useCCPM = !(config.heli.ccpmCollectivePassthroughState || !config.heli.ccpmLinkCyclicState);
bool useCyclic = config.heli.ccpmLinkRollState;
// correction angle
config.heli.CorrectionAngle = m_aircraft->ccpmCorrectionAngle->value();
@ -861,7 +860,6 @@ QString ConfigCcpmWidget::updateConfigObjects()
setConfigData(config);
updatingFromHardware = false;
return airframeType;
}
void ConfigCcpmWidget::SetUIComponentVisibilities()
@ -939,7 +937,7 @@ void ConfigCcpmWidget::getMixer()
updatingFromHardware = true;
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("MixerSettings"));
Q_ASSERT(mixer);
QList<double> curveValues;
@ -1025,7 +1023,7 @@ void ConfigCcpmWidget::setMixer()
for (i = 0; i < 6; i++) {
if ((MixerChannelData[i] > 0) && (MixerChannelData[i] < (int)ConfigCcpmWidget::CHANNEL_NUMELEM + 1)) {
// Set the mixer type. If Coax, then first two are motors. Otherwise, only first is motor
if (typeText.compare(QString::fromUtf8("Coax 2 Servo 90º"), Qt::CaseInsensitive) == 0) {
if (typeText.compare("Coax 2 Servo 90º", Qt::CaseInsensitive) == 0) {
*(mixerTypes[MixerChannelData[i] - 1]) = i > 1 ?
MixerSettings::MIXER1TYPE_SERVO :
MixerSettings::MIXER1TYPE_MOTOR;
@ -1141,12 +1139,12 @@ void ConfigCcpmWidget::SwashLvlStartButtonPressed()
// Get the channel assignements:
obj = dynamic_cast<UAVDataObject *>(objManager->getObject(QString("ActuatorSettings")));
obj = dynamic_cast<UAVDataObject *>(objManager->getObject("ActuatorSettings"));
Q_ASSERT(obj);
// obj->requestUpdate();
MinField = obj->getField(QString("ChannelMin"));
NeutralField = obj->getField(QString("ChannelNeutral"));
MaxField = obj->getField(QString("ChannelMax"));
MinField = obj->getField("ChannelMin");
NeutralField = obj->getField("ChannelNeutral");
MaxField = obj->getField("ChannelMax");
// channel assignments
oldSwashLvlConfiguration.ServoChannels[0] = m_aircraft->ccpmServoWChannel->currentIndex() - 1;
@ -1291,7 +1289,7 @@ void ConfigCcpmWidget::SwashLvlPrevNextButtonPressed()
m_aircraft->SwashLvlPrevButton->setEnabled(true);
m_aircraft->SwashLvlCancelButton->setEnabled(true);
m_aircraft->SwashLvlFinishButton->setEnabled(true);
break;
default:
// restore collective/cyclic setting
// restore pitch curve
@ -1324,12 +1322,12 @@ void ConfigCcpmWidget::SwashLvlCancelButtonPressed()
// restore old Actuator Settings
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject *obj = dynamic_cast<UAVDataObject *>(objManager->getObject(QString("ActuatorSettings")));
UAVDataObject *obj = dynamic_cast<UAVDataObject *>(objManager->getObject("ActuatorSettings"));
Q_ASSERT(obj);
// update settings to match our changes.
MinField = obj->getField(QString("ChannelMin"));
NeutralField = obj->getField(QString("ChannelNeutral"));
MaxField = obj->getField(QString("ChannelMax"));
MinField = obj->getField("ChannelMin");
NeutralField = obj->getField("ChannelNeutral");
MaxField = obj->getField("ChannelMax");
// min,neutral,max values for the servos
for (int i = 0; i < CCPM_MAX_SWASH_SERVOS; i++) {
@ -1365,13 +1363,13 @@ void ConfigCcpmWidget::SwashLvlFinishButtonPressed()
// save new Actuator Settings to memory and SD card
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject *obj = dynamic_cast<UAVDataObject *>(objManager->getObject(QString("ActuatorSettings")));
UAVDataObject *obj = dynamic_cast<UAVDataObject *>(objManager->getObject("ActuatorSettings"));
Q_ASSERT(obj);
// update settings to match our changes.
MinField = obj->getField(QString("ChannelMin"));
NeutralField = obj->getField(QString("ChannelNeutral"));
MaxField = obj->getField(QString("ChannelMax"));
MinField = obj->getField("ChannelMin");
NeutralField = obj->getField("ChannelNeutral");
MaxField = obj->getField("ChannelMax");
// min,neutral,max values for the servos
for (int i = 0; i < CCPM_MAX_SWASH_SERVOS; i++) {
@ -1467,7 +1465,7 @@ void ConfigCcpmWidget::enableSwashplateLevellingControl(bool state)
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject *obj = dynamic_cast<UAVDataObject *>(objManager->getObject(QString("ActuatorCommand")));
UAVDataObject *obj = dynamic_cast<UAVDataObject *>(objManager->getObject("ActuatorCommand"));
UAVObject::Metadata mdata = obj->getMetadata();
if (state) {
@ -1481,7 +1479,7 @@ void ConfigCcpmWidget::enableSwashplateLevellingControl(bool state)
m_aircraft->TabObject->setTabEnabled(0, 0);
m_aircraft->TabObject->setTabEnabled(2, 0);
m_aircraft->TabObject->setTabEnabled(3, 0);
m_aircraft->ccpmType->setEnabled(0);
m_aircraft->ccpmType->setEnabled(false);
} else {
// Restore metadata
mdata = SwashLvlaccInitialData;
@ -1490,7 +1488,7 @@ void ConfigCcpmWidget::enableSwashplateLevellingControl(bool state)
m_aircraft->TabObject->setTabEnabled(0, 1);
m_aircraft->TabObject->setTabEnabled(2, 1);
m_aircraft->TabObject->setTabEnabled(3, 1);
m_aircraft->ccpmType->setEnabled(1);
m_aircraft->ccpmType->setEnabled(true);
}
obj->setMetadata(mdata);
}

View File

@ -25,15 +25,11 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef CONFIGccpmWIDGET_H
#define CONFIGccpmWIDGET_H
#ifndef CONFIGCCPMWIDGET_H
#define CONFIGCCPMWIDGET_H
#include "cfg_vehicletypes/vehicleconfig.h"
#include "../uavobjectwidgetutils/configtaskwidget.h"
#include "uavobject.h"
class Ui_CcpmConfigWidget;
class QWidget;
@ -62,8 +58,7 @@ public:
ConfigCcpmWidget(QWidget *parent = 0);
~ConfigCcpmWidget();
virtual void refreshWidgetsValues(QString frameType);
virtual QString updateConfigObjectsFromWidgets();
virtual QString getFrameType();
public slots:
void getMixer();
@ -73,6 +68,13 @@ protected:
void showEvent(QShowEvent *event);
void resizeEvent(QResizeEvent *event);
virtual void enableControls(bool enable);
virtual void refreshWidgetsValuesImpl(UAVObject *obj);
virtual void updateObjectsFromWidgetsImpl();
virtual void registerWidgets(ConfigTaskWidget &parent);
virtual void setupUI(QString frameType);
private:
Ui_CcpmConfigWidget *m_aircraft;
@ -96,26 +98,20 @@ private:
int MixerChannelData[6];
virtual void registerWidgets(ConfigTaskWidget &parent);
virtual void resetActuators(GUIConfigDataUnion *configData);
void resetActuators(GUIConfigDataUnion *configData);
int ShowDisclaimer(int messageID);
virtual void enableControls(bool enable)
{
Q_UNUSED(enable)
}; // Not used by this widget
bool updatingFromHardware;
bool updatingToHardware;
QString updateConfigObjects();
void updateConfigObjects();
void saveObjectToSD(UAVObject *obj);
private slots:
virtual void setupUI(QString airframeType);
virtual bool throwConfigError(int typeInt);
bool throwConfigError(int typeInt);
private slots:
void ccpmSwashplateUpdate();
void ccpmSwashplateRedraw();
void UpdateMixer();
@ -128,15 +124,11 @@ private slots:
void SwashLvlCancelButtonPressed();
void SwashLvlFinishButtonPressed();
// void UpdateCCPMOptionsFromUI();
// void UpdateCCPMUIFromOptions();
void SetUIComponentVisibilities();
void enableSwashplateLevellingControl(bool state);
void setSwashplateLevel(int percent);
void SwashLvlSpinBoxChanged(int value);
virtual void refreshValues() {}; // Not used
};
#endif // CONFIGccpmWIDGET_H
#endif // CONFIGCCPMWIDGET_H

View File

@ -29,6 +29,8 @@
#include "ui_airframe_custom.h"
#include "uavobjectmanager.h"
#include "mixersettings.h"
#include <QDebug>
@ -47,103 +49,103 @@ QStringList ConfigCustomWidget::getChannelDescriptions()
QStringList channelDesc;
for (int i = 0; i < (int)VehicleConfig::CHANNEL_NUMELEM; i++) {
channelDesc.append(QString("-"));
channelDesc.append("-");
}
// get the gui config data
GUIConfigDataUnion configData = getConfigData();
customGUISettingsStruct custom = configData.custom;
if (custom.Motor1 > 0 && custom.Motor1 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.Motor1 - 1] = QString("Motor1");
channelDesc[custom.Motor1 - 1] = "Motor1";
}
if (custom.Motor2 > 0 && custom.Motor2 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.Motor2 - 1] = QString("Motor2");
channelDesc[custom.Motor2 - 1] = "Motor2";
}
if (custom.Motor3 > 0 && custom.Motor3 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.Motor3 - 1] = QString("Motor3");
channelDesc[custom.Motor3 - 1] = "Motor3";
}
if (custom.Motor4 > 0 && custom.Motor4 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.Motor4 - 1] = QString("Motor4");
channelDesc[custom.Motor4 - 1] = "Motor4";
}
if (custom.Motor5 > 0 && custom.Motor5 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.Motor5 - 1] = QString("Motor5");
channelDesc[custom.Motor5 - 1] = "Motor5";
}
if (custom.Motor6 > 0 && custom.Motor6 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.Motor6 - 1] = QString("Motor6");
channelDesc[custom.Motor6 - 1] = "Motor6";
}
if (custom.Motor7 > 0 && custom.Motor7 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.Motor7 - 1] = QString("Motor7");
channelDesc[custom.Motor7 - 1] = "Motor7";
}
if (custom.Motor8 > 0 && custom.Motor8 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.Motor8 - 1] = QString("Motor8");
channelDesc[custom.Motor8 - 1] = "Motor8";
}
if (custom.RevMotor1 > 0 && custom.RevMotor1 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.RevMotor1 - 1] = QString("RevMotor1");
channelDesc[custom.RevMotor1 - 1] = "RevMotor1";
}
if (custom.RevMotor2 > 0 && custom.RevMotor2 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.RevMotor2 - 1] = QString("RevMotor2");
channelDesc[custom.RevMotor2 - 1] = "RevMotor2";
}
if (custom.RevMotor3 > 0 && custom.RevMotor3 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.RevMotor3 - 1] = QString("RevMotor3");
channelDesc[custom.RevMotor3 - 1] = "RevMotor3";
}
if (custom.RevMotor4 > 0 && custom.RevMotor4 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.RevMotor4 - 1] = QString("RevMotor4");
channelDesc[custom.RevMotor4 - 1] = "RevMotor4";
}
if (custom.RevMotor5 > 0 && custom.RevMotor5 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.RevMotor5 - 1] = QString("RevMotor5");
channelDesc[custom.RevMotor5 - 1] = "RevMotor5";
}
if (custom.RevMotor6 > 0 && custom.RevMotor6 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.RevMotor6 - 1] = QString("RevMotor6");
channelDesc[custom.RevMotor6 - 1] = "RevMotor6";
}
if (custom.RevMotor7 > 0 && custom.RevMotor7 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.RevMotor7 - 1] = QString("RevMotor7");
channelDesc[custom.RevMotor7 - 1] = "RevMotor7";
}
if (custom.RevMotor8 > 0 && custom.RevMotor8 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.RevMotor8 - 1] = QString("RevMotor8");
channelDesc[custom.RevMotor8 - 1] = "RevMotor8";
}
if (custom.Servo1 > 0 && custom.Servo1 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.Servo1 - 1] = QString("Servo1");
channelDesc[custom.Servo1 - 1] = "Servo1";
}
if (custom.Servo2 > 0 && custom.Servo2 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.Servo2 - 1] = QString("Servo2");
channelDesc[custom.Servo2 - 1] = "Servo2";
}
if (custom.Servo3 > 0 && custom.Servo3 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.Servo3 - 1] = QString("Servo3");
channelDesc[custom.Servo3 - 1] = "Servo3";
}
if (custom.Servo4 > 0 && custom.Servo4 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.Servo4 - 1] = QString("Servo4");
channelDesc[custom.Servo4 - 1] = "Servo4";
}
if (custom.Servo5 > 0 && custom.Servo5 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.Servo5 - 1] = QString("Servo5");
channelDesc[custom.Servo5 - 1] = "Servo5";
}
if (custom.Servo6 > 0 && custom.Servo6 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.Servo6 - 1] = QString("Servo6");
channelDesc[custom.Servo6 - 1] = "Servo6";
}
if (custom.Servo7 > 0 && custom.Servo7 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.Servo7 - 1] = QString("Servo7");
channelDesc[custom.Servo7 - 1] = "Servo7";
}
if (custom.Servo8 > 0 && custom.Servo8 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.Servo8 - 1] = QString("Servo8");
channelDesc[custom.Servo8 - 1] = "Servo8";
}
if (custom.Accessory0 > 0 && custom.Accessory0 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.Accessory0 - 1] = QString("Accessory0");
channelDesc[custom.Accessory0 - 1] = "Accessory0";
}
if (custom.Accessory1 > 0 && custom.Accessory1 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.Accessory1 - 1] = QString("Accessory1");
channelDesc[custom.Accessory1 - 1] = "Accessory1";
}
if (custom.Accessory2 > 0 && custom.Accessory2 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.Accessory2 - 1] = QString("Accessory2");
channelDesc[custom.Accessory2 - 1] = "Accessory2";
}
if (custom.Accessory3 > 0 && custom.Accessory3 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.Accessory3 - 1] = QString("Accessory3");
channelDesc[custom.Accessory3 - 1] = "Accessory3";
}
if (custom.Accessory4 > 0 && custom.Accessory4 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.Accessory4 - 1] = QString("Accessory4");
channelDesc[custom.Accessory4 - 1] = "Accessory4";
}
if (custom.Accessory5 > 0 && custom.Accessory5 <= VehicleConfig::CHANNEL_NUMELEM) {
channelDesc[custom.Accessory5 - 1] = QString("Accessory5");
channelDesc[custom.Accessory5 - 1] = "Accessory5";
}
return channelDesc;
}
@ -157,10 +159,10 @@ ConfigCustomWidget::ConfigCustomWidget(QWidget *parent) :
m_aircraft->customMixerTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
// Put combo boxes in line one of the custom mixer table:
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("MixerSettings"));
Q_ASSERT(mixer);
UAVObjectField *field = mixer->getField(QString("Mixer1Type"));
UAVObjectField *field = mixer->getField("Mixer1Type");
QStringList list = field->getOptions();
for (int i = 0; i < (int)VehicleConfig::CHANNEL_NUMELEM; i++) {
QComboBox *qb = new QComboBox(m_aircraft->customMixerTable);
@ -179,6 +181,11 @@ ConfigCustomWidget::~ConfigCustomWidget()
delete m_aircraft;
}
QString ConfigCustomWidget::getFrameType()
{
return "Custom";
}
void ConfigCustomWidget::setupUI(QString frameType)
{
Q_UNUSED(frameType);
@ -190,11 +197,11 @@ void ConfigCustomWidget::registerWidgets(ConfigTaskWidget &parent)
parent.addWidget(m_aircraft->customMixerTable);
parent.addWidget(m_aircraft->customThrottle1Curve->getCurveWidget());
parent.addWidget(m_aircraft->customThrottle1Curve);
// There is no MixerSettings.Curve1Source (i.e. it is always Throttle)
// parent.addWidgetBinding("MixerSettings", "Curve1Source", m_aircraft->curve1SourceCombo);
parent.addWidget(m_aircraft->customThrottle2Curve->getCurveWidget());
parent.addWidget(m_aircraft->customThrottle2Curve);
// TODO why is curve2SourceCombo registered twice ?
parent.addWidgetBinding("MixerSettings", "Curve2Source", m_aircraft->curve2SourceCombo);
parent.addWidget(m_aircraft->curve2SourceCombo);
}
void ConfigCustomWidget::resetActuators(GUIConfigDataUnion *configData)
@ -234,15 +241,14 @@ void ConfigCustomWidget::resetActuators(GUIConfigDataUnion *configData)
/**
Helper function to refresh the UI widget values
*/
void ConfigCustomWidget::refreshWidgetsValues(QString frameType)
void ConfigCustomWidget::refreshWidgetsValuesImpl(UAVObject *obj)
{
Q_ASSERT(m_aircraft);
Q_UNUSED(obj);
setupUI(frameType);
UAVDataObject *system = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("SystemSettings")));
UAVDataObject *system = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("SystemSettings"));
Q_ASSERT(system);
QPointer<UAVObjectField> field = system->getField(QString("AirframeType"));
QPointer<UAVObjectField> field = system->getField("AirframeType");
// Do not allow table edit until AirframeType == Custom
// First save set AirframeType to 'Custom' and next modify.
@ -252,7 +258,7 @@ void ConfigCustomWidget::refreshWidgetsValues(QString frameType)
m_aircraft->customMixerTable->setEditTriggers(QAbstractItemView::AllEditTriggers);
}
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("MixerSettings"));
Q_ASSERT(mixer);
getChannelDescriptions();
@ -314,21 +320,18 @@ void ConfigCustomWidget::refreshWidgetsValues(QString frameType)
}
/**
Helper function to
*/
QString ConfigCustomWidget::updateConfigObjectsFromWidgets()
void ConfigCustomWidget::updateObjectsFromWidgetsImpl()
{
UAVDataObject *system = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("SystemSettings")));
UAVDataObject *system = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("SystemSettings"));
Q_ASSERT(system);
QPointer<UAVObjectField> field = system->getField(QString("AirframeType"));
QPointer<UAVObjectField> field = system->getField("AirframeType");
// Do not allow changes until AirframeType == Custom
// If user want to save custom mixer : first set AirframeType to 'Custom' without changes and next modify.
if (field->getValue().toString() == "Custom") {
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("MixerSettings"));
Q_ASSERT(mixer);
@ -438,7 +441,6 @@ QString ConfigCustomWidget::updateConfigObjectsFromWidgets()
}
setConfigData(configData);
}
return "Custom";
}
/**

View File

@ -29,17 +29,13 @@
#include "cfg_vehicletypes/vehicleconfig.h"
#include "../uavobjectwidgetutils/configtaskwidget.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavobject.h"
#include <QWidget>
#include <QList>
#include <QItemDelegate>
class Ui_CustomConfigWidget;
class QWidget;
class ConfigCustomWidget : public VehicleConfig {
Q_OBJECT
@ -49,22 +45,24 @@ public:
ConfigCustomWidget(QWidget *parent = 0);
~ConfigCustomWidget();
virtual void refreshWidgetsValues(QString frameType);
virtual QString updateConfigObjectsFromWidgets();
virtual QString getFrameType();
protected:
void showEvent(QShowEvent *event);
void resizeEvent(QResizeEvent *event);
virtual void refreshWidgetsValuesImpl(UAVObject *obj);
virtual void updateObjectsFromWidgetsImpl();
virtual void registerWidgets(ConfigTaskWidget &parent);
virtual void setupUI(QString frameType);
private:
Ui_CustomConfigWidget *m_aircraft;
virtual void registerWidgets(ConfigTaskWidget &parent);
virtual void resetActuators(GUIConfigDataUnion *configData);
void resetActuators(GUIConfigDataUnion *configData);
private slots:
virtual void setupUI(QString airframeType);
virtual bool throwConfigError(int numMotors);
bool throwConfigError(int numMotors);
};
class SpinBoxDelegate : public QItemDelegate {

View File

@ -29,6 +29,8 @@
#include "ui_airframe_fixedwing.h"
#include "uavobjectmanager.h"
#include "mixersettings.h"
#include "systemsettings.h"
#include "actuatorsettings.h"
@ -50,7 +52,7 @@ QStringList ConfigFixedWingWidget::getChannelDescriptions()
QStringList channelDesc;
for (int i = 0; i < (int)ConfigFixedWingWidget::CHANNEL_NUMELEM; i++) {
channelDesc.append(QString("-"));
channelDesc.append("-");
}
// get the gui config data
@ -58,51 +60,51 @@ QStringList ConfigFixedWingWidget::getChannelDescriptions()
fixedGUISettingsStruct fixedwing = configData.fixedwing;
if (configData.fixedwing.FixedWingPitch1 > 0) {
channelDesc[configData.fixedwing.FixedWingPitch1 - 1] = QString("FixedWingPitch1");
channelDesc[configData.fixedwing.FixedWingPitch1 - 1] = "FixedWingPitch1";
}
if (configData.fixedwing.FixedWingPitch2 > 0) {
channelDesc[configData.fixedwing.FixedWingPitch2 - 1] = QString("FixedWingPitch2");
channelDesc[configData.fixedwing.FixedWingPitch2 - 1] = "FixedWingPitch2";
}
if (configData.fixedwing.FixedWingRoll1 > 0) {
channelDesc[configData.fixedwing.FixedWingRoll1 - 1] = QString("FixedWingRoll1");
channelDesc[configData.fixedwing.FixedWingRoll1 - 1] = "FixedWingRoll1";
}
if (configData.fixedwing.FixedWingRoll2 > 0) {
channelDesc[configData.fixedwing.FixedWingRoll2 - 1] = QString("FixedWingRoll2");
channelDesc[configData.fixedwing.FixedWingRoll2 - 1] = "FixedWingRoll2";
}
if (configData.fixedwing.FixedWingYaw1 > 0) {
channelDesc[configData.fixedwing.FixedWingYaw1 - 1] = QString("FixedWingYaw1");
channelDesc[configData.fixedwing.FixedWingYaw1 - 1] = "FixedWingYaw1";
}
if (configData.fixedwing.FixedWingYaw2 > 0) {
channelDesc[configData.fixedwing.FixedWingYaw2 - 1] = QString("FixedWingYaw2");
channelDesc[configData.fixedwing.FixedWingYaw2 - 1] = "FixedWingYaw2";
}
if (configData.fixedwing.FixedWingThrottle > 0) {
channelDesc[configData.fixedwing.FixedWingThrottle - 1] = QString("FixedWingThrottle");
channelDesc[configData.fixedwing.FixedWingThrottle - 1] = "FixedWingThrottle";
}
if (fixedwing.Accessory0 > 0 && fixedwing.Accessory0 <= ConfigFixedWingWidget::CHANNEL_NUMELEM) {
channelDesc[fixedwing.Accessory0 - 1] = QString("Accessory0-1");
channelDesc[fixedwing.Accessory0 - 1] = "Accessory0-1";
}
if (fixedwing.Accessory1 > 0 && fixedwing.Accessory1 <= ConfigFixedWingWidget::CHANNEL_NUMELEM) {
channelDesc[fixedwing.Accessory1 - 1] = QString("Accessory1-1");
channelDesc[fixedwing.Accessory1 - 1] = "Accessory1-1";
}
if (fixedwing.Accessory2 > 0 && fixedwing.Accessory2 <= ConfigFixedWingWidget::CHANNEL_NUMELEM) {
channelDesc[fixedwing.Accessory2 - 1] = QString("Accessory2-1");
channelDesc[fixedwing.Accessory2 - 1] = "Accessory2-1";
}
if (fixedwing.Accessory3 > 0 && fixedwing.Accessory3 <= ConfigFixedWingWidget::CHANNEL_NUMELEM) {
channelDesc[fixedwing.Accessory3 - 1] = QString("Accessory3-1");
channelDesc[fixedwing.Accessory3 - 1] = "Accessory3-1";
}
if (fixedwing.Accessory0_2 > 0 && fixedwing.Accessory0_2 <= ConfigFixedWingWidget::CHANNEL_NUMELEM) {
channelDesc[fixedwing.Accessory0_2 - 1] = QString("Accessory0-2");
channelDesc[fixedwing.Accessory0_2 - 1] = "Accessory0-2";
}
if (fixedwing.Accessory1_2 > 0 && fixedwing.Accessory1_2 <= ConfigFixedWingWidget::CHANNEL_NUMELEM) {
channelDesc[fixedwing.Accessory1_2 - 1] = QString("Accessory1-2");
channelDesc[fixedwing.Accessory1_2 - 1] = "Accessory1-2";
}
if (fixedwing.Accessory2_2 > 0 && fixedwing.Accessory2_2 <= ConfigFixedWingWidget::CHANNEL_NUMELEM) {
channelDesc[fixedwing.Accessory2_2 - 1] = QString("Accessory2-2");
channelDesc[fixedwing.Accessory2_2 - 1] = "Accessory2-2";
}
if (fixedwing.Accessory3_2 > 0 && fixedwing.Accessory3_2 <= ConfigFixedWingWidget::CHANNEL_NUMELEM) {
channelDesc[fixedwing.Accessory3_2 - 1] = QString("Accessory3-2");
channelDesc[fixedwing.Accessory3_2 - 1] = "Accessory3-2";
}
return channelDesc;
@ -131,7 +133,7 @@ ConfigFixedWingWidget::ConfigFixedWingWidget(QWidget *parent) :
m_aircraft->planeShape->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
// Set default model to "Aileron"
connect(m_aircraft->fixedWingType, SIGNAL(currentIndexChanged(QString)), this, SLOT(setupUI(QString)));
connect(m_aircraft->fixedWingType, SIGNAL(currentIndexChanged(QString)), this, SLOT(frameTypeChanged(QString)));
m_aircraft->fixedWingType->setCurrentIndex(m_aircraft->fixedWingType->findText("Aileron"));
setupUI(m_aircraft->fixedWingType->currentText());
}
@ -141,6 +143,21 @@ ConfigFixedWingWidget::~ConfigFixedWingWidget()
delete m_aircraft;
}
QString ConfigFixedWingWidget::getFrameType()
{
QString frameType = "FixedWing";
// All airframe types must start with "FixedWing"
if (m_aircraft->fixedWingType->currentText() == "Aileron") {
frameType = "FixedWing";
} else if (m_aircraft->fixedWingType->currentText() == "Elevon") {
frameType = "FixedWingElevon";
} else { // "Vtail"
frameType = "FixedWingVtail";
}
return frameType;
}
/**
Virtual function to setup the UI
*/
@ -152,11 +169,11 @@ void ConfigFixedWingWidget::setupUI(QString frameType)
planeimg = new QGraphicsSvgItem();
planeimg->setSharedRenderer(renderer);
UAVDataObject *system = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("SystemSettings")));
UAVDataObject *system = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("SystemSettings"));
Q_ASSERT(system);
QPointer<UAVObjectField> field = system->getField(QString("AirframeType"));
QPointer<UAVObjectField> field = system->getField("AirframeType");
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("MixerSettings"));
Q_ASSERT(mixer);
if (frameType == "FixedWing" || frameType == "Aileron") {
@ -317,7 +334,7 @@ void ConfigFixedWingWidget::resetRcOutputs(GUIConfigDataUnion *configData)
void ConfigFixedWingWidget::updateRcCurvesUsed()
{
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("MixerSettings"));
Q_ASSERT(mixer);
@ -343,13 +360,11 @@ void ConfigFixedWingWidget::updateRcCurvesUsed()
/**
Virtual function to refresh the UI widget values
*/
void ConfigFixedWingWidget::refreshWidgetsValues(QString frameType)
void ConfigFixedWingWidget::refreshWidgetsValuesImpl(UAVObject *obj)
{
Q_ASSERT(m_aircraft);
Q_UNUSED(obj);
setupUI(frameType);
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("MixerSettings"));
Q_ASSERT(mixer);
QList<double> curveValues;
@ -390,6 +405,7 @@ void ConfigFixedWingWidget::refreshWidgetsValues(QString frameType)
// Get mixing values for GUI sliders (values stored onboard)
m_aircraft->elevonSlider3->setValue(getMixerValue(mixer, "RollDifferential"));
QString frameType = getFrameType();
if (frameType == "FixedWingElevon" || frameType == "Elevon") {
m_aircraft->elevonSlider1->setValue(getMixerValue(mixer, "MixerValueRoll"));
m_aircraft->elevonSlider2->setValue(getMixerValue(mixer, "MixerValuePitch"));
@ -402,12 +418,10 @@ void ConfigFixedWingWidget::refreshWidgetsValues(QString frameType)
/**
Virtual function to update the UI widget objects
*/
QString ConfigFixedWingWidget::updateConfigObjectsFromWidgets()
void ConfigFixedWingWidget::updateObjectsFromWidgetsImpl()
{
QString airframeType = "FixedWing";
// Save the curve (common to all Fixed wing frames)
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("MixerSettings"));
Q_ASSERT(mixer);
@ -421,19 +435,14 @@ QString ConfigFixedWingWidget::updateConfigObjectsFromWidgets()
// Set the throttle curve
setThrottleCurve(mixer, VehicleConfig::MIXER_THROTTLECURVE1, m_aircraft->fixedWingThrottle->getCurve());
// All airframe types must start with "FixedWing"
QString frameType = getFrameType();
if (m_aircraft->fixedWingType->currentText() == "Aileron") {
airframeType = "FixedWing";
setupFrameFixedWing(airframeType);
setupFrameFixedWing(frameType);
} else if (m_aircraft->fixedWingType->currentText() == "Elevon") {
airframeType = "FixedWingElevon";
setupFrameElevon(airframeType);
setupFrameElevon(frameType);
} else { // "Vtail"
airframeType = "FixedWingVtail";
setupFrameVtail(airframeType);
setupFrameVtail(frameType);
}
return airframeType;
}
/**
@ -443,11 +452,11 @@ QString ConfigFixedWingWidget::updateConfigObjectsFromWidgets()
Returns False if impossible to create the mixer.
*/
bool ConfigFixedWingWidget::setupFrameFixedWing(QString airframeType)
bool ConfigFixedWingWidget::setupFrameFixedWing(QString frameType)
{
// Check coherence:
// Show any config errors in GUI
if (throwConfigError(airframeType)) {
if (throwConfigError(frameType)) {
return false;
}
@ -465,7 +474,7 @@ bool ConfigFixedWingWidget::setupFrameFixedWing(QString airframeType)
setConfigData(config);
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("MixerSettings"));
Q_ASSERT(mixer);
resetMotorAndServoMixers(mixer);
@ -519,11 +528,11 @@ bool ConfigFixedWingWidget::setupFrameFixedWing(QString airframeType)
/**
Setup Elevon
*/
bool ConfigFixedWingWidget::setupFrameElevon(QString airframeType)
bool ConfigFixedWingWidget::setupFrameElevon(QString frameType)
{
// Check coherence:
// Show any config errors in GUI
if (throwConfigError(airframeType)) {
if (throwConfigError(frameType)) {
return false;
}
@ -538,7 +547,7 @@ bool ConfigFixedWingWidget::setupFrameElevon(QString airframeType)
setConfigData(config);
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("MixerSettings"));
Q_ASSERT(mixer);
resetMotorAndServoMixers(mixer);
@ -602,11 +611,11 @@ bool ConfigFixedWingWidget::setupFrameElevon(QString airframeType)
/**
Setup VTail
*/
bool ConfigFixedWingWidget::setupFrameVtail(QString airframeType)
bool ConfigFixedWingWidget::setupFrameVtail(QString frameType)
{
// Check coherence:
// Show any config errors in GUI
if (throwConfigError(airframeType)) {
if (throwConfigError(frameType)) {
return false;
}
@ -621,7 +630,7 @@ bool ConfigFixedWingWidget::setupFrameVtail(QString airframeType)
setConfigData(config);
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("MixerSettings"));
Q_ASSERT(mixer);
resetMotorAndServoMixers(mixer);
@ -802,8 +811,6 @@ void ConfigFixedWingWidget::setupRcOutputs(QList<QString> rcOutputList)
void ConfigFixedWingWidget::enableControls(bool enable)
{
ConfigTaskWidget::enableControls(enable);
if (enable) {
setupUI(m_aircraft->fixedWingType->currentText());
}
@ -812,7 +819,7 @@ void ConfigFixedWingWidget::enableControls(bool enable)
/**
This function displays text and color formatting in order to help the user understand what channels have not yet been configured.
*/
bool ConfigFixedWingWidget::throwConfigError(QString airframeType)
bool ConfigFixedWingWidget::throwConfigError(QString frameType)
{
// Initialize configuration error flag
bool error = false;
@ -830,15 +837,15 @@ bool ConfigFixedWingWidget::throwConfigError(QString airframeType)
if (combobox->currentText() == "None") {
int size = combobox->style()->pixelMetric(QStyle::PM_SmallIconSize);
QPixmap pixmap(size, size);
if ((airframeType == "FixedWingElevon") && (i > 2)) {
if ((frameType == "FixedWingElevon") && (i > 2)) {
pixmap.fill(QColor("green"));
// Rudders are optional for elevon frame
combobox->setToolTip(tr("Rudders are optional for Elevon frame"));
} else if (((airframeType == "FixedWing") || (airframeType == "FixedWingVtail")) && (i == 2)) {
} else if (((frameType == "FixedWing") || (frameType == "FixedWingVtail")) && (i == 2)) {
pixmap.fill(QColor("green"));
// Second aileron servo is optional for FixedWing frame
combobox->setToolTip(tr("Second aileron servo is optional"));
} else if ((airframeType == "FixedWing") && (i > 3)) {
} else if ((frameType == "FixedWing") && (i > 3)) {
pixmap.fill(QColor("green"));
// Second elevator and rudders are optional for FixedWing frame
combobox->setToolTip(tr("Second elevator servo is optional"));

View File

@ -29,11 +29,6 @@
#include "cfg_vehicletypes/vehicleconfig.h"
#include "../uavobjectwidgetutils/configtaskwidget.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavobject.h"
#include <QList>
class Ui_FixedWingConfigWidget;
@ -50,31 +45,33 @@ public:
ConfigFixedWingWidget(QWidget *parent = 0);
~ConfigFixedWingWidget();
virtual void refreshWidgetsValues(QString frameType);
virtual QString updateConfigObjectsFromWidgets();
virtual QString getFrameType();
protected:
void resizeEvent(QResizeEvent *);
void showEvent(QShowEvent *);
virtual void enableControls(bool enable);
virtual void refreshWidgetsValuesImpl(UAVObject *obj);
virtual void updateObjectsFromWidgetsImpl();
virtual void registerWidgets(ConfigTaskWidget &parent);
virtual void setupUI(QString frameType);
private:
Ui_FixedWingConfigWidget *m_aircraft;
QGraphicsSvgItem *planeimg;
virtual void registerWidgets(ConfigTaskWidget &parent);
virtual void resetActuators(GUIConfigDataUnion *configData);
virtual void resetRcOutputs(GUIConfigDataUnion *configData);
void resetActuators(GUIConfigDataUnion *configData);
void resetRcOutputs(GUIConfigDataUnion *configData);
bool setupFrameFixedWing(QString airframeType);
bool setupFrameElevon(QString airframeType);
bool setupFrameVtail(QString airframeType);
bool setupFrameFixedWing(QString frameType);
bool setupFrameElevon(QString frameType);
bool setupFrameVtail(QString frameType);
void setupRcOutputs(QList<QString> rcOutputList);
void updateRcCurvesUsed();
protected:
void enableControls(bool enable);
void resizeEvent(QResizeEvent *);
void showEvent(QShowEvent *);
private slots:
virtual void setupUI(QString airframeType);
virtual bool throwConfigError(QString airframeType);
bool throwConfigError(QString frameType);
};
#endif // CONFIGFIXEDWINGWIDGET_H

View File

@ -29,6 +29,8 @@
#include "ui_airframe_ground.h"
#include "uavobjectmanager.h"
#include "mixersettings.h"
#include "systemsettings.h"
#include "actuatorsettings.h"
@ -51,23 +53,23 @@ QStringList ConfigGroundVehicleWidget::getChannelDescriptions()
QStringList channelDesc;
for (int i = 0; i < (int)ConfigGroundVehicleWidget::CHANNEL_NUMELEM; i++) {
channelDesc.append(QString("-"));
channelDesc.append("-");
}
// get the gui config data
GUIConfigDataUnion configData = getConfigData();
if (configData.ground.GroundVehicleSteering1 > 0) {
channelDesc[configData.ground.GroundVehicleSteering1 - 1] = QString("GroundSteering1");
channelDesc[configData.ground.GroundVehicleSteering1 - 1] = "GroundSteering1";
}
if (configData.ground.GroundVehicleSteering2 > 0) {
channelDesc[configData.ground.GroundVehicleSteering2 - 1] = QString("GroundSteering2");
channelDesc[configData.ground.GroundVehicleSteering2 - 1] = "GroundSteering2";
}
if (configData.ground.GroundVehicleThrottle1 > 0) {
channelDesc[configData.ground.GroundVehicleThrottle1 - 1] = QString("GroundMotor1");
channelDesc[configData.ground.GroundVehicleThrottle1 - 1] = "GroundMotor1";
}
if (configData.ground.GroundVehicleThrottle2 > 0) {
channelDesc[configData.ground.GroundVehicleThrottle2 - 1] = QString("GroundMotor2");
channelDesc[configData.ground.GroundVehicleThrottle2 - 1] = "GroundMotor2";
}
return channelDesc;
}
@ -88,8 +90,10 @@ ConfigGroundVehicleWidget::ConfigGroundVehicleWidget(QWidget *parent) :
m_aircraft->groundShape->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
// Set default model to "Car (Turnable)"
connect(m_aircraft->groundVehicleType, SIGNAL(currentIndexChanged(QString)), this, SLOT(setupUI(QString)));
m_aircraft->groundVehicleType->setCurrentIndex(m_aircraft->groundVehicleType->findText("Car (Turnable)"));
connect(m_aircraft->groundVehicleType, SIGNAL(currentIndexChanged(QString)), this, SLOT(frameTypeChanged(QString)));
setupUI(m_aircraft->groundVehicleType->currentText());
}
@ -98,6 +102,25 @@ ConfigGroundVehicleWidget::~ConfigGroundVehicleWidget()
delete m_aircraft;
}
QString ConfigGroundVehicleWidget::getFrameType()
{
QString frameType = "GroundVehicleCar";
// All frame types must start with "GroundVehicle"
if (m_aircraft->groundVehicleType->currentText() == "Boat (Differential)") {
frameType = "GroundVehicleDifferentialBoat";
} else if (m_aircraft->groundVehicleType->currentText() == "Boat (Turnable)") {
frameType = "GroundVehicleBoat";
} else if (m_aircraft->groundVehicleType->currentText() == "Car (Turnable)") {
frameType = "GroundVehicleCar";
} else if (m_aircraft->groundVehicleType->currentText() == "Tank (Differential)") {
frameType = "GroundVehicleDifferential";
} else {
frameType = "GroundVehicleMotorcycle";
}
return frameType;
}
/**
Virtual function to setup the UI
*/
@ -111,9 +134,9 @@ void ConfigGroundVehicleWidget::setupUI(QString frameType)
m_vehicleImg = new QGraphicsSvgItem();
m_vehicleImg->setSharedRenderer(renderer);
UAVDataObject *system = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("SystemSettings")));
UAVDataObject *system = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("SystemSettings"));
Q_ASSERT(system);
QPointer<UAVObjectField> frameTypeSaved = system->getField(QString("AirframeType"));
QPointer<UAVObjectField> frameTypeSaved = system->getField("AirframeType");
m_aircraft->differentialSteeringSlider1->setEnabled(false);
m_aircraft->differentialSteeringSlider2->setEnabled(false);
@ -129,7 +152,6 @@ void ConfigGroundVehicleWidget::setupUI(QString frameType)
if (frameType == "GroundVehicleBoat" || frameType == "Boat (Turnable)") {
// Boat
m_vehicleImg->setElementId("boat");
setComboCurrentIndex(m_aircraft->groundVehicleType, m_aircraft->groundVehicleType->findText("Boat (Turnable)"));
m_aircraft->gvMotor1ChannelBox->setEnabled(true);
m_aircraft->gvMotor2ChannelBox->setEnabled(true);
@ -160,20 +182,16 @@ void ConfigGroundVehicleWidget::setupUI(QString frameType)
}
} else if ((frameType == "GroundVehicleDifferential") || (frameType == "Tank (Differential)") ||
(frameType == "GroundVehicleDifferentialBoat") || (frameType == "Boat (Differential)")) {
bool is_Boat = frameType.contains("Boat");
bool isBoat = frameType.contains("Boat");
if (is_Boat) {
if (isBoat) {
// Boat differential
m_vehicleImg->setElementId("boat_diff");
setComboCurrentIndex(m_aircraft->groundVehicleType,
m_aircraft->groundVehicleType->findText("Boat (Differential)"));
m_aircraft->gvSteering1Label->setText("First rudder");
m_aircraft->gvSteering2Label->setText("Second rudder");
} else {
// Tank
m_vehicleImg->setElementId("tank");
setComboCurrentIndex(m_aircraft->groundVehicleType,
m_aircraft->groundVehicleType->findText("Tank (Differential)"));
m_aircraft->gvSteering1Label->setText("Front steering");
m_aircraft->gvSteering2Label->setText("Rear steering");
}
@ -181,7 +199,6 @@ void ConfigGroundVehicleWidget::setupUI(QString frameType)
m_aircraft->gvMotor1ChannelBox->setEnabled(true);
m_aircraft->gvMotor2ChannelBox->setEnabled(true);
m_aircraft->gvMotor1Label->setText("Left motor");
m_aircraft->gvMotor2Label->setText("Right motor");
@ -202,8 +219,8 @@ void ConfigGroundVehicleWidget::setupUI(QString frameType)
initMixerCurves(frameType);
// If new setup, set sliders to defaults and set curves values
if ((!is_Boat && (frameTypeSaved->getValue().toString() != "GroundVehicleDifferential")) ||
(is_Boat && (frameTypeSaved->getValue().toString() != "GroundVehicleDifferentialBoat"))) {
if ((!isBoat && (frameTypeSaved->getValue().toString() != "GroundVehicleDifferential")) ||
(isBoat && (frameTypeSaved->getValue().toString() != "GroundVehicleDifferentialBoat"))) {
m_aircraft->differentialSteeringSlider1->setValue(100);
m_aircraft->differentialSteeringSlider2->setValue(100);
m_aircraft->groundVehicleThrottle1->initLinearCurve(5, 0.8, 0.0);
@ -212,7 +229,6 @@ void ConfigGroundVehicleWidget::setupUI(QString frameType)
} else if (frameType == "GroundVehicleMotorcycle" || frameType == "Motorcycle") {
// Motorcycle
m_vehicleImg->setElementId("motorbike");
setComboCurrentIndex(m_aircraft->groundVehicleType, m_aircraft->groundVehicleType->findText("Motorcycle"));
m_aircraft->gvMotor1ChannelBox->setEnabled(false);
m_aircraft->gvMotor2ChannelBox->setEnabled(true);
@ -244,7 +260,6 @@ void ConfigGroundVehicleWidget::setupUI(QString frameType)
} else {
// Car
m_vehicleImg->setElementId("car");
setComboCurrentIndex(m_aircraft->groundVehicleType, m_aircraft->groundVehicleType->findText("Car (Turnable)"));
m_aircraft->gvMotor1ChannelBox->setEnabled(true);
m_aircraft->gvMotor2ChannelBox->setEnabled(true);
@ -284,8 +299,6 @@ void ConfigGroundVehicleWidget::setupUI(QString frameType)
void ConfigGroundVehicleWidget::enableControls(bool enable)
{
ConfigTaskWidget::enableControls(enable);
if (enable) {
setupUI(m_aircraft->groundVehicleType->currentText());
}
@ -315,13 +328,15 @@ void ConfigGroundVehicleWidget::resetActuators(GUIConfigDataUnion *configData)
/**
Virtual function to refresh the UI widget values
*/
void ConfigGroundVehicleWidget::refreshWidgetsValues(QString frameType)
void ConfigGroundVehicleWidget::refreshWidgetsValuesImpl(UAVObject *obj)
{
setupUI(frameType);
Q_UNUSED(obj);
QString frameType = getFrameType();
initMixerCurves(frameType);
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("MixerSettings"));
Q_ASSERT(mixer);
GUIConfigDataUnion config = getConfigData();
@ -354,7 +369,7 @@ void ConfigGroundVehicleWidget::refreshWidgetsValues(QString frameType)
*/
void ConfigGroundVehicleWidget::initMixerCurves(QString frameType)
{
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("MixerSettings"));
Q_ASSERT(mixer);
@ -376,7 +391,7 @@ void ConfigGroundVehicleWidget::initMixerCurves(QString frameType)
}
}
// Setup all Throttle2 curves for all types of airframes
// Setup all Throttle2 curves for all types of frames
getThrottleCurve(mixer, VehicleConfig::MIXER_THROTTLECURVE2, &curveValues);
if (isValidThrottleCurve(&curveValues)) {
@ -396,36 +411,27 @@ void ConfigGroundVehicleWidget::initMixerCurves(QString frameType)
/**
Virtual function to update the UI widget objects
*/
QString ConfigGroundVehicleWidget::updateConfigObjectsFromWidgets()
void ConfigGroundVehicleWidget::updateObjectsFromWidgetsImpl()
{
QString airframeType = "GroundVehicleCar";
// Save the curve (common to all ground vehicle frames)
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("MixerSettings"));
// set the throttle curves
setThrottleCurve(mixer, VehicleConfig::MIXER_THROTTLECURVE1, m_aircraft->groundVehicleThrottle1->getCurve());
setThrottleCurve(mixer, VehicleConfig::MIXER_THROTTLECURVE2, m_aircraft->groundVehicleThrottle2->getCurve());
// All airframe types must start with "GroundVehicle"
QString frameType = getFrameType();
if (m_aircraft->groundVehicleType->currentText() == "Boat (Differential)") {
airframeType = "GroundVehicleDifferentialBoat";
setupGroundVehicleDifferential(airframeType);
setupGroundVehicleDifferential(frameType);
} else if (m_aircraft->groundVehicleType->currentText() == "Boat (Turnable)") {
airframeType = "GroundVehicleBoat";
setupGroundVehicleTurnable(airframeType);
setupGroundVehicleTurnable(frameType);
} else if (m_aircraft->groundVehicleType->currentText() == "Car (Turnable)") {
airframeType = "GroundVehicleCar";
setupGroundVehicleTurnable(airframeType);
setupGroundVehicleTurnable(frameType);
} else if (m_aircraft->groundVehicleType->currentText() == "Tank (Differential)") {
airframeType = "GroundVehicleDifferential";
setupGroundVehicleDifferential(airframeType);
setupGroundVehicleDifferential(frameType);
} else {
airframeType = "GroundVehicleMotorcycle";
setupGroundVehicleMotorcycle(airframeType);
setupGroundVehicleMotorcycle(frameType);
}
return airframeType;
}
/**
@ -433,11 +439,11 @@ QString ConfigGroundVehicleWidget::updateConfigObjectsFromWidgets()
Returns False if impossible to create the mixer.
*/
bool ConfigGroundVehicleWidget::setupGroundVehicleMotorcycle(QString airframeType)
bool ConfigGroundVehicleWidget::setupGroundVehicleMotorcycle(QString frameType)
{
// Check coherence:
// Show any config errors in GUI
if (throwConfigError(airframeType)) {
if (throwConfigError(frameType)) {
return false;
}
@ -451,7 +457,7 @@ bool ConfigGroundVehicleWidget::setupGroundVehicleMotorcycle(QString airframeTyp
setConfigData(config);
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("MixerSettings"));
Q_ASSERT(mixer);
resetMotorAndServoMixers(mixer);
@ -483,12 +489,12 @@ bool ConfigGroundVehicleWidget::setupGroundVehicleMotorcycle(QString airframeTyp
Returns False if impossible to create the mixer.
*/
bool ConfigGroundVehicleWidget::setupGroundVehicleDifferential(QString airframeType)
bool ConfigGroundVehicleWidget::setupGroundVehicleDifferential(QString frameType)
{
// Check coherence:
// Show any config errors in GUI
if (throwConfigError(airframeType)) {
if (throwConfigError(frameType)) {
return false;
}
@ -501,7 +507,7 @@ bool ConfigGroundVehicleWidget::setupGroundVehicleDifferential(QString airframeT
setConfigData(config);
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("MixerSettings"));
Q_ASSERT(mixer);
resetMotorAndServoMixers(mixer);
@ -531,11 +537,11 @@ bool ConfigGroundVehicleWidget::setupGroundVehicleDifferential(QString airframeT
Returns False if impossible to create the mixer.
*/
bool ConfigGroundVehicleWidget::setupGroundVehicleTurnable(QString airframeType)
bool ConfigGroundVehicleWidget::setupGroundVehicleTurnable(QString frameType)
{
// Check coherence:
// Show any config errors in GUI
if (throwConfigError(airframeType)) {
if (throwConfigError(frameType)) {
return false;
}
@ -550,7 +556,7 @@ bool ConfigGroundVehicleWidget::setupGroundVehicleTurnable(QString airframeType)
setConfigData(config);
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("MixerSettings"));
Q_ASSERT(mixer);
resetMotorAndServoMixers(mixer);
@ -568,7 +574,7 @@ bool ConfigGroundVehicleWidget::setupGroundVehicleTurnable(QString airframeType)
channel = m_aircraft->gvMotor2ChannelBox->currentIndex() - 1;
setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_REVERSABLEMOTOR);
if (airframeType == "GroundVehicleCar") {
if (frameType == "GroundVehicleCar") {
// Car: Throttle2 curve for 2nd motor
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_THROTTLECURVE2, 127);
} else {
@ -584,7 +590,7 @@ bool ConfigGroundVehicleWidget::setupGroundVehicleTurnable(QString airframeType)
/**
This function displays text and color formatting in order to help the user understand what channels have not yet been configured.
*/
bool ConfigGroundVehicleWidget::throwConfigError(QString airframeType)
bool ConfigGroundVehicleWidget::throwConfigError(QString frameType)
{
// Initialize configuration error flag
bool error = false;
@ -595,7 +601,7 @@ bool ConfigGroundVehicleWidget::throwConfigError(QString airframeType)
pixmap.fill(QColor("red"));
if ((airframeType == "GroundVehicleCar") || (airframeType == "GroundVehicleBoat")) { // Car
if ((frameType == "GroundVehicleCar") || (frameType == "GroundVehicleBoat")) { // Car
if (m_aircraft->gvMotor1ChannelBox->currentText() == "None"
&& m_aircraft->gvMotor2ChannelBox->currentText() == "None") {
m_aircraft->gvMotor1ChannelBox->setItemData(0, pixmap, Qt::DecorationRole); // Set color palettes
@ -615,7 +621,7 @@ bool ConfigGroundVehicleWidget::throwConfigError(QString airframeType)
m_aircraft->gvSteering1ChannelBox->setItemData(0, 0, Qt::DecorationRole); // Reset color palettes
m_aircraft->gvSteering2ChannelBox->setItemData(0, 0, Qt::DecorationRole); // Reset color palettes
}
} else if (airframeType.contains("GroundVehicleDifferential")) { // differential Tank and Boat
} else if (frameType.contains("GroundVehicleDifferential")) { // differential Tank and Boat
if (m_aircraft->gvMotor1ChannelBox->currentText() == "None"
|| m_aircraft->gvMotor2ChannelBox->currentText() == "None") {
m_aircraft->gvMotor1ChannelBox->setItemData(0, pixmap, Qt::DecorationRole); // Set color palettes
@ -629,7 +635,7 @@ bool ConfigGroundVehicleWidget::throwConfigError(QString airframeType)
// Always reset
m_aircraft->gvSteering1ChannelBox->setItemData(0, 0, Qt::DecorationRole); // Reset color palettes
m_aircraft->gvSteering2ChannelBox->setItemData(0, 0, Qt::DecorationRole); // Reset color palettes
} else if (airframeType == "GroundVehicleMotorcycle") { // Motorcycle
} else if (frameType == "GroundVehicleMotorcycle") { // Motorcycle
if (m_aircraft->gvMotor2ChannelBox->currentText() == "None") {
m_aircraft->gvMotor2ChannelBox->setItemData(0, pixmap, Qt::DecorationRole); // Set color palettes
error = true;
@ -651,7 +657,7 @@ bool ConfigGroundVehicleWidget::throwConfigError(QString airframeType)
}
if (error) {
m_aircraft->gvStatusLabel->setText(QString("<font color='red'>ERROR: Assign all necessary channels</font>"));
m_aircraft->gvStatusLabel->setText("<font color='red'>ERROR: Assign all necessary channels</font>");
}
return error;
}

View File

@ -30,11 +30,6 @@
#include "cfg_vehicletypes/vehicleconfig.h"
#include "../uavobjectwidgetutils/configtaskwidget.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavobject.h"
class Ui_GroundConfigWidget;
class QWidget;
@ -49,29 +44,32 @@ public:
ConfigGroundVehicleWidget(QWidget *parent = 0);
~ConfigGroundVehicleWidget();
virtual void refreshWidgetsValues(QString frameType);
virtual QString getFrameType();
virtual void initMixerCurves(QString frameType);
virtual QString updateConfigObjectsFromWidgets();
protected:
void enableControls(bool enable);
void resizeEvent(QResizeEvent *);
void showEvent(QShowEvent *);
virtual void enableControls(bool enable);
virtual void refreshWidgetsValuesImpl(UAVObject *obj);
virtual void updateObjectsFromWidgetsImpl();
virtual void registerWidgets(ConfigTaskWidget &parent);
virtual void setupUI(QString frameType);
private:
Ui_GroundConfigWidget *m_aircraft;
QGraphicsSvgItem *m_vehicleImg;
virtual void registerWidgets(ConfigTaskWidget &parent);
virtual void resetActuators(GUIConfigDataUnion *configData);
void resetActuators(GUIConfigDataUnion *configData);
bool setupGroundVehicleTurnable(QString airframeType);
bool setupGroundVehicleDifferential(QString airframeType);
bool setupGroundVehicleMotorcycle(QString airframeType);
bool setupGroundVehicleTurnable(QString frameType);
bool setupGroundVehicleDifferential(QString frameType);
bool setupGroundVehicleMotorcycle(QString frameType);
private slots:
virtual void setupUI(QString airframeType);
virtual bool throwConfigError(QString airframeType);
bool throwConfigError(QString frameType);
};
#endif // CONFIGGROUNDVEHICLEWIDGET_H

View File

@ -29,6 +29,8 @@
#include "ui_airframe_multirotor.h"
#include "uavobjectmanager.h"
#include "mixersettings.h"
#include "systemsettings.h"
#include "actuatorsettings.h"
@ -45,7 +47,7 @@
#include <math.h>
#include <QMessageBox>
const QString ConfigMultiRotorWidget::CHANNELBOXNAME = QString("multiMotorChannelBox");
const QString ConfigMultiRotorWidget::CHANNELBOXNAME = "multiMotorChannelBox";
QStringList ConfigMultiRotorWidget::getChannelDescriptions()
{
@ -53,7 +55,7 @@ QStringList ConfigMultiRotorWidget::getChannelDescriptions()
QStringList channelDesc;
for (int i = 0; i < (int)ConfigMultiRotorWidget::CHANNEL_NUMELEM; i++) {
channelDesc.append(QString("-"));
channelDesc.append("-");
}
// get the gui config data
@ -62,70 +64,70 @@ QStringList ConfigMultiRotorWidget::getChannelDescriptions()
// Octocopter X motor definition
if (multi.VTOLMotorNNE > 0 && multi.VTOLMotorNNE <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) {
channelDesc[multi.VTOLMotorNNE - 1] = QString("VTOLMotorNNE");
channelDesc[multi.VTOLMotorNNE - 1] = "VTOLMotorNNE";
}
if (multi.VTOLMotorENE > 0 && multi.VTOLMotorENE <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) {
channelDesc[multi.VTOLMotorENE - 1] = QString("VTOLMotorENE");
channelDesc[multi.VTOLMotorENE - 1] = "VTOLMotorENE";
}
if (multi.VTOLMotorESE > 0 && multi.VTOLMotorESE <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) {
channelDesc[multi.VTOLMotorESE - 1] = QString("VTOLMotorESE");
channelDesc[multi.VTOLMotorESE - 1] = "VTOLMotorESE";
}
if (multi.VTOLMotorSSE > 0 && multi.VTOLMotorSSE <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) {
channelDesc[multi.VTOLMotorSSE - 1] = QString("VTOLMotorSSE");
channelDesc[multi.VTOLMotorSSE - 1] = "VTOLMotorSSE";
}
if (multi.VTOLMotorSSW > 0 && multi.VTOLMotorSSW <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) {
channelDesc[multi.VTOLMotorSSW - 1] = QString("VTOLMotorSSW");
channelDesc[multi.VTOLMotorSSW - 1] = "VTOLMotorSSW";
}
if (multi.VTOLMotorWSW > 0 && multi.VTOLMotorWSW <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) {
channelDesc[multi.VTOLMotorWSW - 1] = QString("VTOLMotorWSW");
channelDesc[multi.VTOLMotorWSW - 1] = "VTOLMotorWSW";
}
if (multi.VTOLMotorWNW > 0 && multi.VTOLMotorWNW <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) {
channelDesc[multi.VTOLMotorWNW - 1] = QString("VTOLMotorWNW");
channelDesc[multi.VTOLMotorWNW - 1] = "VTOLMotorWNW";
}
if (multi.VTOLMotorNNW > 0 && multi.VTOLMotorNNW <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) {
channelDesc[multi.VTOLMotorNNW - 1] = QString("VTOLMotorNNW");
channelDesc[multi.VTOLMotorNNW - 1] = "VTOLMotorNNW";
}
// End OctocopterX
if (multi.VTOLMotorN > 0 && multi.VTOLMotorN <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) {
channelDesc[multi.VTOLMotorN - 1] = QString("VTOLMotorN");
channelDesc[multi.VTOLMotorN - 1] = "VTOLMotorN";
}
if (multi.VTOLMotorNE > 0 && multi.VTOLMotorNE <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) {
channelDesc[multi.VTOLMotorNE - 1] = QString("VTOLMotorNE");
channelDesc[multi.VTOLMotorNE - 1] = "VTOLMotorNE";
}
if (multi.VTOLMotorNW > 0 && multi.VTOLMotorNW <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) {
channelDesc[multi.VTOLMotorNW - 1] = QString("VTOLMotorNW");
channelDesc[multi.VTOLMotorNW - 1] = "VTOLMotorNW";
}
if (multi.VTOLMotorS > 0 && multi.VTOLMotorS <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) {
channelDesc[multi.VTOLMotorS - 1] = QString("VTOLMotorS");
channelDesc[multi.VTOLMotorS - 1] = "VTOLMotorS";
}
if (multi.VTOLMotorSE > 0 && multi.VTOLMotorSE <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) {
channelDesc[multi.VTOLMotorSE - 1] = QString("VTOLMotorSE");
channelDesc[multi.VTOLMotorSE - 1] = "VTOLMotorSE";
}
if (multi.VTOLMotorSW > 0 && multi.VTOLMotorSW <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) {
channelDesc[multi.VTOLMotorSW - 1] = QString("VTOLMotorSW");
channelDesc[multi.VTOLMotorSW - 1] = "VTOLMotorSW";
}
if (multi.VTOLMotorW > 0 && multi.VTOLMotorW <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) {
channelDesc[multi.VTOLMotorW - 1] = QString("VTOLMotorW");
channelDesc[multi.VTOLMotorW - 1] = "VTOLMotorW";
}
if (multi.VTOLMotorE > 0 && multi.VTOLMotorE <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) {
channelDesc[multi.VTOLMotorE - 1] = QString("VTOLMotorE");
channelDesc[multi.VTOLMotorE - 1] = "VTOLMotorE";
}
if (multi.TRIYaw > 0 && multi.TRIYaw <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) {
channelDesc[multi.TRIYaw - 1] = QString("Tri-Yaw");
channelDesc[multi.TRIYaw - 1] = "Tri-Yaw";
}
if (multi.Accessory0 > 0 && multi.Accessory0 <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) {
channelDesc[multi.Accessory0 - 1] = QString("Accessory0");
channelDesc[multi.Accessory0 - 1] = "Accessory0";
}
if (multi.Accessory1 > 0 && multi.Accessory1 <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) {
channelDesc[multi.Accessory1 - 1] = QString("Accessory1");
channelDesc[multi.Accessory1 - 1] = "Accessory1";
}
if (multi.Accessory2 > 0 && multi.Accessory2 <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) {
channelDesc[multi.Accessory2 - 1] = QString("Accessory2");
channelDesc[multi.Accessory2 - 1] = "Accessory2";
}
if (multi.Accessory3 > 0 && multi.Accessory3 <= ConfigMultiRotorWidget::CHANNEL_NUMELEM) {
channelDesc[multi.Accessory3 - 1] = QString("Accessory3");
channelDesc[multi.Accessory3 - 1] = "Accessory3";
}
return channelDesc;
@ -170,7 +172,7 @@ ConfigMultiRotorWidget::ConfigMultiRotorWidget(QWidget *parent) :
// Set default model to "Quad X"
m_aircraft->multirotorFrameType->setCurrentIndex(m_aircraft->multirotorFrameType->findText("Quad X"));
connect(m_aircraft->multirotorFrameType, SIGNAL(currentIndexChanged(QString)), this, SLOT(setupUI(QString)));
connect(m_aircraft->multirotorFrameType, SIGNAL(currentIndexChanged(QString)), this, SLOT(frameTypeChanged(QString)));
// Connect the multirotor motor reverse checkbox
connect(m_aircraft->MultirotorRevMixerCheckBox, SIGNAL(clicked(bool)), this, SLOT(reverseMultirotorMotor()));
@ -184,6 +186,38 @@ ConfigMultiRotorWidget::~ConfigMultiRotorWidget()
delete m_aircraft;
}
QString ConfigMultiRotorWidget::getFrameType()
{
QString frameType = "QuadX";
if (m_aircraft->multirotorFrameType->currentText() == "Quad +") {
frameType = "QuadP";
} else if (m_aircraft->multirotorFrameType->currentText() == "Quad X") {
frameType = "QuadX";
} else if (m_aircraft->multirotorFrameType->currentText() == "Hexacopter") {
frameType = "Hexa";
} else if (m_aircraft->multirotorFrameType->currentText() == "Hexacopter X") {
frameType = "HexaX";
} else if (m_aircraft->multirotorFrameType->currentText() == "Hexacopter H") {
frameType = "HexaH";
} else if (m_aircraft->multirotorFrameType->currentText() == "Hexacopter Y6") {
frameType = "HexaCoax";
} else if (m_aircraft->multirotorFrameType->currentText() == "Octocopter") {
frameType = "Octo";
} else if (m_aircraft->multirotorFrameType->currentText() == "Octocopter X") {
frameType = "OctoX";
} else if (m_aircraft->multirotorFrameType->currentText() == "Octocopter V") {
frameType = "OctoV";
} else if (m_aircraft->multirotorFrameType->currentText() == "Octo Coax +") {
frameType = "OctoCoaxP";
} else if (m_aircraft->multirotorFrameType->currentText() == "Octo Coax X") {
frameType = "OctoCoaxX";
} else if (m_aircraft->multirotorFrameType->currentText() == "Tricopter Y") {
frameType = "Tri";
}
return frameType;
}
void ConfigMultiRotorWidget::setupUI(QString frameType)
{
Q_ASSERT(m_aircraft);
@ -407,7 +441,7 @@ void ConfigMultiRotorWidget::resetRcOutputs(GUIConfigDataUnion *configData)
void ConfigMultiRotorWidget::updateRcCurvesUsed()
{
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("MixerSettings"));
Q_ASSERT(mixer);
@ -433,13 +467,11 @@ void ConfigMultiRotorWidget::updateRcCurvesUsed()
/**
Helper function to refresh the UI widget values
*/
void ConfigMultiRotorWidget::refreshWidgetsValues(QString frameType)
void ConfigMultiRotorWidget::refreshWidgetsValuesImpl(UAVObject *obj)
{
Q_ASSERT(m_aircraft);
Q_UNUSED(obj);
setupUI(frameType);
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("MixerSettings"));
Q_ASSERT(mixer);
QList<double> curveValues;
@ -457,6 +489,7 @@ void ConfigMultiRotorWidget::refreshWidgetsValues(QString frameType)
GUIConfigDataUnion config = getConfigData();
multiGUISettingsStruct multi = config.multi;
QString frameType = getFrameType();
if (frameType == "QuadP") {
// Motors 1/2/3/4 are: N / E / S / W
setComboCurrentIndex(m_aircraft->multiMotorChannelBox1, multi.VTOLMotorN);
@ -583,11 +616,11 @@ void ConfigMultiRotorWidget::updateMotorsPositionLabels(QStringList motorLabels)
}
/**
Helper function to update the UI widget objects
Function to update the UI widget objects
*/
QString ConfigMultiRotorWidget::updateConfigObjectsFromWidgets()
void ConfigMultiRotorWidget::updateObjectsFromWidgetsImpl()
{
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("MixerSettings"));
Q_ASSERT(mixer);
@ -601,26 +634,19 @@ QString ConfigMultiRotorWidget::updateConfigObjectsFromWidgets()
// Curve is also common to all quads:
setThrottleCurve(mixer, VehicleConfig::MIXER_THROTTLECURVE1, m_aircraft->multiThrottleCurve->getCurve());
QString airframeType;
QList<QString> motorList;
if (m_aircraft->multirotorFrameType->currentText() == "Quad +") {
airframeType = "QuadP";
setupQuad(true);
} else if (m_aircraft->multirotorFrameType->currentText() == "Quad X") {
airframeType = "QuadX";
setupQuad(false);
} else if (m_aircraft->multirotorFrameType->currentText() == "Hexacopter") {
airframeType = "Hexa";
setupHexa(true);
} else if (m_aircraft->multirotorFrameType->currentText() == "Hexacopter X") {
airframeType = "HexaX";
setupHexa(false);
} else if (m_aircraft->multirotorFrameType->currentText() == "Hexacopter H") {
airframeType = "HexaH";
// Show any config errors in GUI
if (throwConfigError(6)) {
return airframeType;
return;
}
motorList << "VTOLMotorNE" << "VTOLMotorE" << "VTOLMotorSE" << "VTOLMotorSW" << "VTOLMotorW" << "VTOLMotorNW";
setupMotors(motorList);
@ -647,11 +673,9 @@ QString ConfigMultiRotorWidget::updateConfigObjectsFromWidgets()
setupMultiRotorMixer(hMixer);
m_aircraft->mrStatusLabel->setText(tr("Configuration OK"));
} else if (m_aircraft->multirotorFrameType->currentText() == "Hexacopter Y6") {
airframeType = "HexaCoax";
// Show any config errors in GUI
if (throwConfigError(6)) {
return airframeType;
return;
}
motorList << "VTOLMotorNW" << "VTOLMotorW" << "VTOLMotorNE" << "VTOLMotorE" << "VTOLMotorS" << "VTOLMotorSE";
setupMotors(motorList);
@ -671,11 +695,9 @@ QString ConfigMultiRotorWidget::updateConfigObjectsFromWidgets()
setupMultiRotorMixer(mixerMatrix);
m_aircraft->mrStatusLabel->setText(tr("Configuration OK"));
} else if (m_aircraft->multirotorFrameType->currentText() == "Octocopter") {
airframeType = "Octo";
// Show any config errors in GUI
if (throwConfigError(8)) {
return airframeType;
return;
}
motorList << "VTOLMotorN" << "VTOLMotorNE" << "VTOLMotorE" << "VTOLMotorSE" << "VTOLMotorS" << "VTOLMotorSW"
<< "VTOLMotorW" << "VTOLMotorNW";
@ -702,11 +724,9 @@ QString ConfigMultiRotorWidget::updateConfigObjectsFromWidgets()
setupMultiRotorMixer(mixerMatrix);
m_aircraft->mrStatusLabel->setText(tr("Configuration OK"));
} else if (m_aircraft->multirotorFrameType->currentText() == "Octocopter X") {
airframeType = "OctoX";
// Show any config errors in GUI
if (throwConfigError(8)) {
return airframeType;
return;
}
motorList << "VTOLMotorNNE" << "VTOLMotorENE" << "VTOLMotorESE" << "VTOLMotorSSE" << "VTOLMotorSSW" << "VTOLMotorWSW"
<< "VTOLMotorWNW" << "VTOLMotorNNW";
@ -733,11 +753,9 @@ QString ConfigMultiRotorWidget::updateConfigObjectsFromWidgets()
setupMultiRotorMixer(mixerMatrix);
m_aircraft->mrStatusLabel->setText(tr("Configuration OK"));
} else if (m_aircraft->multirotorFrameType->currentText() == "Octocopter V") {
airframeType = "OctoV";
// Show any config errors in GUI
if (throwConfigError(8)) {
return airframeType;
return;
}
motorList << "VTOLMotorN" << "VTOLMotorNE" << "VTOLMotorE" << "VTOLMotorSE" << "VTOLMotorS" << "VTOLMotorSW"
<< "VTOLMotorW" << "VTOLMotorNW";
@ -758,11 +776,9 @@ QString ConfigMultiRotorWidget::updateConfigObjectsFromWidgets()
setupMultiRotorMixer(mixerMatrix);
m_aircraft->mrStatusLabel->setText(tr("Configuration OK"));
} else if (m_aircraft->multirotorFrameType->currentText() == "Octo Coax +") {
airframeType = "OctoCoaxP";
// Show any config errors in GUI
if (throwConfigError(8)) {
return airframeType;
return;
}
motorList << "VTOLMotorN" << "VTOLMotorNE" << "VTOLMotorE" << "VTOLMotorSE" << "VTOLMotorS" << "VTOLMotorSW"
<< "VTOLMotorW" << "VTOLMotorNW";
@ -782,11 +798,9 @@ QString ConfigMultiRotorWidget::updateConfigObjectsFromWidgets()
setupMultiRotorMixer(mixerMatrix);
m_aircraft->mrStatusLabel->setText(tr("Configuration OK"));
} else if (m_aircraft->multirotorFrameType->currentText() == "Octo Coax X") {
airframeType = "OctoCoaxX";
// Show any config errors in GUI
if (throwConfigError(8)) {
return airframeType;
return;
}
motorList << "VTOLMotorNW" << "VTOLMotorN" << "VTOLMotorNE" << "VTOLMotorE" << "VTOLMotorSE" << "VTOLMotorS"
<< "VTOLMotorSW" << "VTOLMotorW";
@ -806,15 +820,13 @@ QString ConfigMultiRotorWidget::updateConfigObjectsFromWidgets()
setupMultiRotorMixer(mixerMatrix);
m_aircraft->mrStatusLabel->setText(tr("Configuration OK"));
} else if (m_aircraft->multirotorFrameType->currentText() == "Tricopter Y") {
airframeType = "Tri";
// Show any config errors in GUI
if (throwConfigError(3)) {
return airframeType;
return;
}
if (m_aircraft->triYawChannelBox->currentText() == "None") {
m_aircraft->mrStatusLabel->setText(tr("<font color='red'>ERROR: Assign a Yaw channel</font>"));
return airframeType;
return;
}
motorList << "VTOLMotorNW" << "VTOLMotorNE" << "VTOLMotorS";
setupMotors(motorList);
@ -850,7 +862,6 @@ QString ConfigMultiRotorWidget::updateConfigObjectsFromWidgets()
m_aircraft->mrStatusLabel->setText(tr("Configuration OK"));
}
return airframeType;
}
void ConfigMultiRotorWidget::setYawMixLevel(int value)
@ -920,7 +931,7 @@ void ConfigMultiRotorWidget::updateAirframe(QString frameType)
*/
void ConfigMultiRotorWidget::setupQuadMotor(int channel, double pitch, double roll, double yaw)
{
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("MixerSettings"));
Q_ASSERT(mixer);
@ -945,7 +956,7 @@ void ConfigMultiRotorWidget::setupRcOutputs(QList<QString> rcOutputList)
GUIConfigDataUnion configData = getConfigData();
resetRcOutputs(&configData);
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("MixerSettings"));
Q_ASSERT(mixer);
int curveAccessory0 = m_aircraft->rcOutputCurveBox1->currentIndex();
@ -956,7 +967,7 @@ void ConfigMultiRotorWidget::setupRcOutputs(QList<QString> rcOutputList)
foreach(QString rc_output, rcOutputList) {
int index = rcList.takeFirst()->currentIndex();
if (rc_output == QString("Accessory0")) {
if (rc_output == "Accessory0") {
configData.multi.Accessory0 = index;
if (index) {
setMixerType(mixer, index - 1, VehicleConfig::MIXERTYPE_ACCESSORY0);
@ -966,7 +977,7 @@ void ConfigMultiRotorWidget::setupRcOutputs(QList<QString> rcOutputList)
setMixerVectorValue(mixer, index - 1, VehicleConfig::MIXERVECTOR_THROTTLECURVE1, 127);
}
}
} else if (rc_output == QString("Accessory1")) {
} else if (rc_output == "Accessory1") {
configData.multi.Accessory1 = index;
if (index) {
setMixerType(mixer, index - 1, VehicleConfig::MIXERTYPE_ACCESSORY1);
@ -976,7 +987,7 @@ void ConfigMultiRotorWidget::setupRcOutputs(QList<QString> rcOutputList)
setMixerVectorValue(mixer, index - 1, VehicleConfig::MIXERVECTOR_THROTTLECURVE1, 127);
}
}
} else if (rc_output == QString("Accessory2")) {
} else if (rc_output == "Accessory2") {
configData.multi.Accessory2 = index;
if (index) {
setMixerType(mixer, index - 1, VehicleConfig::MIXERTYPE_ACCESSORY2);
@ -986,7 +997,7 @@ void ConfigMultiRotorWidget::setupRcOutputs(QList<QString> rcOutputList)
setMixerVectorValue(mixer, index - 1, VehicleConfig::MIXERVECTOR_THROTTLECURVE1, 127);
}
}
} else if (rc_output == QString("Accessory3")) {
} else if (rc_output == "Accessory3") {
configData.multi.Accessory3 = index;
if (index) {
setMixerType(mixer, index - 1, VehicleConfig::MIXERTYPE_ACCESSORY3);
@ -1018,38 +1029,38 @@ void ConfigMultiRotorWidget::setupMotors(QList<QString> motorList)
foreach(QString motor, motorList) {
int index = mmList.takeFirst()->currentIndex();
if (motor == QString("VTOLMotorN")) {
if (motor == "VTOLMotorN") {
configData.multi.VTOLMotorN = index;
} else if (motor == QString("VTOLMotorNE")) {
} else if (motor == "VTOLMotorNE") {
configData.multi.VTOLMotorNE = index;
} else if (motor == QString("VTOLMotorE")) {
} else if (motor == "VTOLMotorE") {
configData.multi.VTOLMotorE = index;
} else if (motor == QString("VTOLMotorSE")) {
} else if (motor == "VTOLMotorSE") {
configData.multi.VTOLMotorSE = index;
} else if (motor == QString("VTOLMotorS")) {
} else if (motor == "VTOLMotorS") {
configData.multi.VTOLMotorS = index;
} else if (motor == QString("VTOLMotorSW")) {
} else if (motor == "VTOLMotorSW") {
configData.multi.VTOLMotorSW = index;
} else if (motor == QString("VTOLMotorW")) {
} else if (motor == "VTOLMotorW") {
configData.multi.VTOLMotorW = index;
} else if (motor == QString("VTOLMotorNW")) {
} else if (motor == "VTOLMotorNW") {
configData.multi.VTOLMotorNW = index;
// OctoX
} else if (motor == QString("VTOLMotorNNE")) {
} else if (motor == "VTOLMotorNNE") {
configData.multi.VTOLMotorNNE = index;
} else if (motor == QString("VTOLMotorENE")) {
} else if (motor == "VTOLMotorENE") {
configData.multi.VTOLMotorENE = index;
} else if (motor == QString("VTOLMotorESE")) {
} else if (motor == "VTOLMotorESE") {
configData.multi.VTOLMotorESE = index;
} else if (motor == QString("VTOLMotorSSE")) {
} else if (motor == "VTOLMotorSSE") {
configData.multi.VTOLMotorSSE = index;
} else if (motor == QString("VTOLMotorSSW")) {
} else if (motor == "VTOLMotorSSW") {
configData.multi.VTOLMotorSSW = index;
} else if (motor == QString("VTOLMotorWSW")) {
} else if (motor == "VTOLMotorWSW") {
configData.multi.VTOLMotorWSW = index;
} else if (motor == QString("VTOLMotorWNW")) {
} else if (motor == "VTOLMotorWNW") {
configData.multi.VTOLMotorWNW = index;
} else if (motor == QString("VTOLMotorNNW")) {
} else if (motor == "VTOLMotorNNW") {
configData.multi.VTOLMotorNNW = index;
}
}
@ -1196,7 +1207,7 @@ bool ConfigMultiRotorWidget::setupHexa(bool pLayout)
*/
bool ConfigMultiRotorWidget::setupMultiRotorMixer(double mixerFactors[8][3])
{
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("MixerSettings"));
Q_ASSERT(mixer);
resetMotorAndServoMixers(mixer);
@ -1289,7 +1300,7 @@ bool ConfigMultiRotorWidget::throwConfigError(int numMotors)
if (error) {
m_aircraft->mrStatusLabel->setText(
QString(tr("<font color='red'>ERROR: Assign all %1 motor channels</font>")).arg(numMotors));
tr("<font color='red'>ERROR: Assign all %1 motor channels</font>").arg(numMotors));
}
return error;
}
@ -1317,8 +1328,6 @@ void ConfigMultiRotorWidget::resizeEvent(QResizeEvent *event)
void ConfigMultiRotorWidget::enableControls(bool enable)
{
ConfigTaskWidget::enableControls(enable);
if (enable) {
setupEnabledControls(m_aircraft->multirotorFrameType->currentText());
}

View File

@ -29,11 +29,6 @@
#include "cfg_vehicletypes/vehicleconfig.h"
#include "../uavobjectwidgetutils/configtaskwidget.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavobject.h"
#include <QList>
class Ui_MultiRotorConfigWidget;
@ -51,22 +46,26 @@ public:
ConfigMultiRotorWidget(QWidget *parent = 0);
~ConfigMultiRotorWidget();
virtual void refreshWidgetsValues(QString frameType);
virtual QString updateConfigObjectsFromWidgets();
virtual QString getFrameType();
protected:
void showEvent(QShowEvent *event);
void resizeEvent(QResizeEvent *event);
void enableControls(bool enable);
virtual void enableControls(bool enable);
virtual void refreshWidgetsValuesImpl(UAVObject *obj);
virtual void updateObjectsFromWidgetsImpl();
virtual void registerWidgets(ConfigTaskWidget &parent);
virtual void setupUI(QString frameType);
private:
Ui_MultiRotorConfigWidget *m_aircraft;
QGraphicsSvgItem *quad;
bool invertMotors;
virtual void registerWidgets(ConfigTaskWidget &parent);
virtual void resetActuators(GUIConfigDataUnion *configData);
virtual void resetRcOutputs(GUIConfigDataUnion *configData);
void resetActuators(GUIConfigDataUnion *configData);
void resetRcOutputs(GUIConfigDataUnion *configData);
bool setupQuad(bool pLayout);
bool setupHexa(bool pLayout);
@ -82,10 +81,9 @@ private:
void updateMotorsPositionLabels(QStringList motorLabels);
void setupEnabledControls(QString multiRotorType);
private slots:
virtual void setupUI(QString airframeType);
virtual bool throwConfigError(int numMotors);
bool throwConfigError(int numMotors);
private slots:
void reverseMultirotorMotor();
};

View File

@ -38,7 +38,7 @@
#include <QPushButton>
#include <QPointer>
VehicleConfig::VehicleConfig(QWidget *parent) : ConfigTaskWidget(parent)
VehicleConfig::VehicleConfig(QWidget *parent) : ConfigTaskWidget(parent, Child)
{
// Generate lists of mixerTypeNames, mixerVectorNames, channelNames
channelNames << "None";
@ -105,19 +105,21 @@ void VehicleConfig::setConfigData(GUIConfigDataUnion configData)
}
}
void VehicleConfig::setupUI(QString frameType)
QString VehicleConfig::getFrameType()
{
Q_UNUSED(frameType);
return "None";
}
void VehicleConfig::refreshWidgetsValues(QString frameType)
void VehicleConfig::frameTypeChanged(QString frameType)
{
Q_UNUSED(frameType);
setupUI(frameType);
}
QString VehicleConfig::updateConfigObjectsFromWidgets()
void VehicleConfig::enableControls(bool enable)
{
return NULL;
Q_UNUSED(enable);
// do nothing. no need to call parent.
}
void VehicleConfig::refreshWidgetsValuesImpl(UAVObject *obj)
@ -128,17 +130,16 @@ void VehicleConfig::refreshWidgetsValuesImpl(UAVObject *obj)
void VehicleConfig::updateObjectsFromWidgetsImpl()
{}
void VehicleConfig::resetActuators(GUIConfigDataUnion *configData)
{
Q_UNUSED(configData);
}
void VehicleConfig::registerWidgets(ConfigTaskWidget &parent)
{
Q_UNUSED(parent);
}
void VehicleConfig::setupUI(QString frameType)
{
Q_UNUSED(frameType);
}
// NEW STYLE: Loop through the widgets looking for all widgets that have "ChannelBox" in their name
// The upshot of this is that ALL new ComboBox widgets for selecting the output channel must have "ChannelBox" in their name
// FOR WHATEVER REASON, THIS DOES NOT WORK WITH ChannelBox. ChannelBo is sufficiently accurate

View File

@ -29,11 +29,11 @@
#define VEHICLECONFIG_H
#include "../uavobjectwidgetutils/configtaskwidget.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavobject.h"
#include "actuatorcommand.h"
class UAVDataObject;
typedef struct {
uint VTOLMotorN : 4;
uint VTOLMotorS : 4;
@ -157,22 +157,22 @@ typedef union {
customGUISettingsStruct custom;
} GUIConfigDataUnion;
class ConfigTaskWidget;
class ConfigVehicleTypeWidget;
/*
* This class handles vehicle specific configuration UI and associated logic.
*
* VehicleConfig derives from ConfigTaskWidget but is not a top level ConfigTaskWidget.
* VehicleConfig objects are nested within the ConfigVehicleConfigWidget and have particularities:
* VehicleConfig objects are nested within the ConfigVehicleTypeWidget and have particularities:
* - bindings are added to the parent (i.e. ConfigVehicleConfigWidget)
* - auto bindings are not supported
* - as a consequence things like dirty state management are bypassed and delegated to the parent class.
*
* It does not use the "dirty" state management directly and registers its relevant widgets with ConfigTaskWidget to do so.
*/
class VehicleConfig : public ConfigTaskWidget {
Q_OBJECT
friend ConfigVehicleTypeWidget;
public:
/* Enumeration options for ThrottleCurves */
@ -220,10 +220,7 @@ public:
VehicleConfig(QWidget *parent = 0);
~VehicleConfig();
virtual void registerWidgets(ConfigTaskWidget &parent);
virtual void refreshWidgetsValues(QString frameType);
virtual QString updateConfigObjectsFromWidgets();
virtual QString getFrameType();
double getMixerValue(UAVDataObject *mixer, QString elementName);
void setMixerValue(UAVDataObject *mixer, QString elementName, double value);
@ -249,16 +246,18 @@ protected:
double getCurveMin(QList<double> *curve);
double getCurveMax(QList<double> *curve);
virtual void enableControls(bool enable);
virtual void refreshWidgetsValuesImpl(UAVObject *obj);
virtual void updateObjectsFromWidgetsImpl();
virtual void registerWidgets(ConfigTaskWidget &parent);
virtual void setupUI(QString frameType);
protected slots:
void frameTypeChanged(QString frameType);
private:
static UAVObjectManager *getUAVObjectManager();
virtual void resetActuators(GUIConfigDataUnion *configData);
private slots:
virtual void setupUI(QString airframeType);
};
#endif // VEHICLECONFIG_H

View File

@ -283,7 +283,7 @@ void ConfigGadgetWidget::tabAboutToChange(int index, bool *proceed)
if (ans == QMessageBox::No) {
*proceed = false;
} else {
wid->setDirty(false);
wid->clearDirty();
}
}
}

View File

@ -43,7 +43,7 @@ static const int MAX_CHANNEL_NUM = 250;
static const int MIN_CHANNEL_RANGE = 10;
static const float FREQUENCY_STEP = 0.040;
ConfigOPLinkWidget::ConfigOPLinkWidget(QWidget *parent) : ConfigTaskWidget(parent, false), statusUpdated(false)
ConfigOPLinkWidget::ConfigOPLinkWidget(QWidget *parent) : ConfigTaskWidget(parent, OPLink), statusUpdated(false)
{
m_oplink = new Ui_OPLinkWidget();
m_oplink->setupUi(this);

View File

@ -30,6 +30,7 @@
#include "ui_airframe.h"
#include "configgadgetfactory.h"
#include "uavobjectmanager.h"
#include <extensionsystem/pluginmanager.h>
#include "systemsettings.h"
@ -144,10 +145,9 @@ ConfigVehicleTypeWidget::ConfigVehicleTypeWidget(QWidget *parent) : ConfigTaskWi
m_aircraft->aircraftType->addTab(tr("Helicopter"));
m_aircraft->aircraftType->addTab(tr("Ground"));
m_aircraft->aircraftType->addTab(tr("Custom"));
// switchAirframeType(0);
// Connect aircraft type selection dropbox to callback function
connect(m_aircraft->aircraftType, SIGNAL(currentChanged(int)), this, SLOT(switchAirframeType(int)));
connect(m_aircraft->aircraftType, SIGNAL(currentChanged(int)), this, SLOT(frameTypeChanged(int)));
}
/**
@ -158,10 +158,32 @@ ConfigVehicleTypeWidget::~ConfigVehicleTypeWidget()
// Do nothing
}
void ConfigVehicleTypeWidget::switchAirframeType(int index)
void ConfigVehicleTypeWidget::frameTypeChanged(int index)
{
m_aircraft->airframesWidget->setCurrentWidget(getVehicleConfigWidget(index));
VehicleConfig *vehicleConfig = getVehicleConfigWidget(index);
if (vehicleConfig) {
// switch tab
m_aircraft->airframesWidget->setCurrentWidget(vehicleConfig);
// enable controls
enableControls(isConnected());
// flag vehicle config as dirty (frame type was changed...)
setDirty(true);
}
}
void ConfigVehicleTypeWidget::enableControls(bool enable)
{
ConfigTaskWidget::enableControls(enable);
// forward call to selected vehicle config
VehicleConfig *vehicleConfig = (VehicleConfig *)m_aircraft->airframesWidget->currentWidget();
if (vehicleConfig) {
vehicleConfig->enableControls(enable);
}
}
/**
@ -173,54 +195,33 @@ void ConfigVehicleTypeWidget::refreshWidgetsValuesImpl(UAVObject *obj)
{
Q_UNUSED(obj);
if (!allObjectsUpdated()) {
if (obj) {
// single object was updated, skip...
return;
}
// Get the Airframe type from the system settings:
UAVDataObject *system = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("SystemSettings")));
Q_ASSERT(system);
UAVObjectField *field = system->getField(QString("AirframeType"));
Q_ASSERT(field);
// At this stage, we will need to have some hardcoded settings in this code
QString frameType = field->getValue().toString();
// Always update custom tab from others airframe settings : debug/learn hardcoded mixers
int category = frameCategory("Custom");
// update current vehicle tab
QString ft = frameType();
int category = frameCategory(ft);
m_aircraft->aircraftType->setCurrentIndex(category);
VehicleConfig *vehicleConfig = getVehicleConfigWidget(category);
if (vehicleConfig) {
vehicleConfig->refreshWidgetsValues("Custom");
vehicleConfig->setupUI(ft);
vehicleConfig->refreshWidgetsValuesImpl(obj);
}
// Switch to Airframe currently used
category = frameCategory(frameType);
if (frameType != "Custom") {
m_aircraft->aircraftType->setCurrentIndex(category);
VehicleConfig *vehicleConfig = getVehicleConfigWidget(category);
// update custom tab from others frame settings (to debug/learn hard coded mixers)
if (ft != "Custom") {
int customCategory = frameCategory("Custom");
VehicleConfig *vehicleConfig = getVehicleConfigWidget(customCategory);
if (vehicleConfig) {
vehicleConfig->refreshWidgetsValues(frameType);
vehicleConfig->setupUI("Custom");
vehicleConfig->refreshWidgetsValuesImpl(obj);
}
}
field = system->getField(QString("VehicleName"));
Q_ASSERT(field);
QString name;
for (uint i = 0; i < field->getNumElements(); ++i) {
QChar chr = field->getValue(i).toChar();
if (chr != 0) {
name.append(chr);
} else {
break;
}
}
// update vehicle name
QString name = vehicleName();
m_aircraft->nameEdit->setText(name);
}
@ -233,27 +234,90 @@ void ConfigVehicleTypeWidget::refreshWidgetsValuesImpl(UAVObject *obj)
*/
void ConfigVehicleTypeWidget::updateObjectsFromWidgetsImpl()
{
// Airframe type defaults to Custom
QString airframeType = "Custom";
VehicleConfig *vehicleConfig = (VehicleConfig *)m_aircraft->airframesWidget->currentWidget();
// frame type defaults to Custom
QString ft = "Custom";
if (vehicleConfig) {
airframeType = vehicleConfig->updateConfigObjectsFromWidgets();
vehicleConfig->updateObjectsFromWidgetsImpl();
ft = vehicleConfig->getFrameType();
}
// set the airframe type
UAVDataObject *system = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("SystemSettings")));
// save frame type
setFrameType(ft);
// save vehicle name
QString name = m_aircraft->nameEdit->text();
setVehicleName(name);
// update custom tab from others frame settings (to debug/learn hard coded mixers)
if (ft != "Custom") {
int customCategory = frameCategory("Custom");
VehicleConfig *vehicleConfig = getVehicleConfigWidget(customCategory);
if (vehicleConfig) {
vehicleConfig->setupUI("Custom");
vehicleConfig->refreshWidgetsValuesImpl(NULL);
}
}
}
QString ConfigVehicleTypeWidget::frameType()
{
UAVDataObject *system = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("SystemSettings"));
Q_ASSERT(system);
UAVObjectField *field = system->getField(QString("AirframeType"));
if (field) {
field->setValue(airframeType);
}
field = system->getField(QString("VehicleName"));
UAVObjectField *field = system->getField("AirframeType");
Q_ASSERT(field);
QString name = m_aircraft->nameEdit->text();
return field->getValue().toString();
}
void ConfigVehicleTypeWidget::setFrameType(QString frameType)
{
UAVDataObject *system = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("SystemSettings"));
Q_ASSERT(system);
UAVObjectField *field = system->getField("AirframeType");
Q_ASSERT(field);
if (field) {
field->setValue(frameType);
}
}
QString ConfigVehicleTypeWidget::vehicleName()
{
UAVDataObject *system = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("SystemSettings"));
Q_ASSERT(system);
UAVObjectField *field = system->getField("VehicleName");
Q_ASSERT(field);
QString name;
for (uint i = 0; i < field->getNumElements(); ++i) {
QChar chr = field->getValue(i).toChar();
if (chr != 0) {
name.append(chr);
} else {
break;
}
}
return name;
}
void ConfigVehicleTypeWidget::setVehicleName(QString name)
{
UAVDataObject *system = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject("SystemSettings"));
Q_ASSERT(system);
UAVObjectField *field = system->getField("VehicleName");
Q_ASSERT(field);
for (uint i = 0; i < field->getNumElements(); ++i) {
if (i < (uint)name.length()) {
field->setValue(name.at(i).toLatin1(), i);
@ -261,10 +325,6 @@ void ConfigVehicleTypeWidget::updateObjectsFromWidgetsImpl()
field->setValue(0, i);
}
}
// call refreshWidgetsValues() to reflect actual saved values
// TODO is this needed ?
refreshWidgetsValues();
}
int ConfigVehicleTypeWidget::frameCategory(QString frameType)
@ -302,13 +362,6 @@ VehicleConfig *ConfigVehicleTypeWidget::getVehicleConfigWidget(int frameCategory
if (!m_vehicleIndexMap.contains(frameCategory)) {
// create config widget
vehicleConfig = createVehicleConfigWidget(frameCategory);
// add config widget to UI
int index = m_aircraft->airframesWidget->insertWidget(m_aircraft->airframesWidget->count(), vehicleConfig);
m_vehicleIndexMap[frameCategory] = index;
// and enable controls (needed?)
updateEnableControls();
}
int index = m_vehicleIndexMap.value(frameCategory);
vehicleConfig = (VehicleConfig *)m_aircraft->airframesWidget->widget(index);
@ -340,9 +393,13 @@ VehicleConfig *ConfigVehicleTypeWidget::createVehicleConfigWidget(int frameCateg
break;
}
if (vehicleConfig) {
// bind config widget "field" to this ConfigTaskWodget
// bind config widget "field" to this ConfigTaskWidget
// this is necessary to get "dirty" state management
vehicleConfig->registerWidgets(*this);
// add config widget to UI
int index = m_aircraft->airframesWidget->insertWidget(m_aircraft->airframesWidget->count(), vehicleConfig);
m_vehicleIndexMap[frameCategory] = index;
}
return vehicleConfig;
}

View File

@ -61,6 +61,7 @@ public:
~ConfigVehicleTypeWidget();
protected:
virtual void enableControls(bool enable);
virtual void refreshWidgetsValuesImpl(UAVObject *obj);
virtual void updateObjectsFromWidgetsImpl();
@ -72,14 +73,19 @@ private:
// Maps a frame category to its index in the m_aircraft->airframesWidget QStackedWidget
QMap<int, int> m_vehicleIndexMap;
QString frameType();
void setFrameType(QString frameType);
int frameCategory(QString frameType);
QString vehicleName();
void setVehicleName(QString name);
static int frameCategory(QString frameType);
VehicleConfig *getVehicleConfigWidget(int frameCategory);
VehicleConfig *createVehicleConfigWidget(int frameCategory);
private slots:
void switchAirframeType(int index);
void frameTypeChanged(int index);
};
#endif // CONFIGVEHICLETYPEWIDGET_H

View File

@ -27,8 +27,12 @@
*/
#include "outputcalibrationpage.h"
#include "ui_outputcalibrationpage.h"
#include "systemalarms.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
const QString OutputCalibrationPage::MULTI_SVG_FILE = QString(":/setupwizard/resources/multirotor-shapes.svg");

View File

@ -49,34 +49,48 @@
#include <QUrl>
#include <QWidget>
ConfigTaskWidget::ConfigTaskWidget(QWidget *parent, bool autopilot) : QWidget(parent),
ConfigTaskWidget::ConfigTaskWidget(QWidget *parent, ConfigTaskType configType) : QWidget(parent),
m_currentBoardId(-1), m_isConnected(false), m_isWidgetUpdatesAllowed(true), m_isDirty(false), m_refreshing(false),
m_wikiURL("Welcome"), m_saveButton(NULL), m_outOfLimitsStyle("background-color: rgb(255, 0, 0);"), m_realtimeUpdateTimer(NULL)
{
m_autopilot = autopilot;
m_configType = configType;
m_pluginManager = ExtensionSystem::PluginManager::instance();
m_objectUtilManager = m_pluginManager->getObject<UAVObjectUtilManager>();
if (m_configType != Child) {
UAVSettingsImportExportFactory *importexportplugin = m_pluginManager->getObject<UAVSettingsImportExportFactory>();
connect(importexportplugin, SIGNAL(importAboutToBegin()), this, SLOT(invalidateObjects()));
m_saveButton = new SmartSaveButton(this);
connect(m_saveButton, SIGNAL(preProcessOperations()), this, SLOT(updateObjectsFromWidgets()));
connect(m_saveButton, SIGNAL(saveSuccessfull()), this, SLOT(clearDirty()));
connect(m_saveButton, SIGNAL(beginOp()), this, SLOT(disableObjectUpdates()));
connect(m_saveButton, SIGNAL(preProcessOperations()), this, SLOT(updateObjectsFromWidgets()));
connect(m_saveButton, SIGNAL(endOp()), this, SLOT(enableObjectUpdates()));
connect(m_saveButton, SIGNAL(saveSuccessful()), this, SLOT(saveSuccessful()));
}
if (m_autopilot) {
switch (m_configType) {
case AutoPilot:
{
// connect to telemetry manager
TelemetryManager *tm = m_pluginManager->getObject<TelemetryManager>();
connect(tm, SIGNAL(connected()), this, SLOT(onConnect()));
connect(tm, SIGNAL(disconnected()), this, SLOT(onDisconnect()));
} else {
break;
}
case OPLink:
{
// connect to oplink manager
OPLinkManager *om = m_pluginManager->getObject<OPLinkManager>();
connect(om, SIGNAL(connected()), this, SLOT(onConnect()));
connect(om, SIGNAL(disconnected()), this, SLOT(onDisconnect()));
break;
}
case Child:
default:
// do nothing
break;
}
}
@ -239,6 +253,7 @@ void ConfigTaskWidget::setWidgetBindingObjectEnabled(QString objectName, bool en
Q_ASSERT(object);
bool isRefreshing = m_refreshing;
m_refreshing = true;
foreach(WidgetBinding * binding, m_widgetBindingsPerObject.values(object)) {
@ -252,7 +267,7 @@ void ConfigTaskWidget::setWidgetBindingObjectEnabled(QString objectName, bool en
}
}
m_refreshing = true;
m_refreshing = isRefreshing;
}
bool ConfigTaskWidget::isComboboxOptionSelected(QComboBox *combo, int optionValue)
@ -305,13 +320,25 @@ bool ConfigTaskWidget::isConnected() const
{
bool connected = false;
if (m_autopilot) {
switch (m_configType) {
case AutoPilot:
{
TelemetryManager *tm = m_pluginManager->getObject<TelemetryManager>();
connected = tm->isConnected();
} else {
break;
}
case OPLink:
{
OPLinkManager *om = m_pluginManager->getObject<OPLinkManager>();
connected = om->isConnected();
break;
}
case Child:
default:
// do nothing
break;
}
return connected;
}
@ -328,7 +355,7 @@ void ConfigTaskWidget::bind()
void ConfigTaskWidget::onConnect()
{
if (m_autopilot) {
if (m_configType == AutoPilot) {
m_currentBoardId = m_objectUtilManager->getBoardModel();
}
@ -343,7 +370,7 @@ void ConfigTaskWidget::onConnect()
refreshWidgetsValues();
setDirty(false);
clearDirty();
}
void ConfigTaskWidget::onDisconnect()
@ -365,6 +392,7 @@ void ConfigTaskWidget::refreshWidgetsValues(UAVObject *obj)
return;
}
bool isRefreshing = m_refreshing;
m_refreshing = true;
QList<WidgetBinding *> bindings = obj == NULL ? m_widgetBindingsPerObject.values() : m_widgetBindingsPerObject.values(obj);
@ -381,7 +409,7 @@ void ConfigTaskWidget::refreshWidgetsValues(UAVObject *obj)
// call specific implementation
refreshWidgetsValuesImpl(obj);
m_refreshing = false;
m_refreshing = isRefreshing;
}
void ConfigTaskWidget::updateObjectsFromWidgets()
@ -396,6 +424,14 @@ void ConfigTaskWidget::updateObjectsFromWidgets()
updateObjectsFromWidgetsImpl();
}
void ConfigTaskWidget::saveSuccessful()
{
// refresh values to reflect saved values
refreshWidgetsValues(NULL);
clearDirty();
// in case of failure to save we do nothing, config stays "dirty" (unsaved changes are kept)
}
void ConfigTaskWidget::helpButtonPressed()
{
QString url = m_helpButtons.value((QPushButton *)sender(), QString());
@ -407,8 +443,8 @@ void ConfigTaskWidget::helpButtonPressed()
void ConfigTaskWidget::addApplyButton(QPushButton *button)
{
m_saveButton->addApplyButton(button);
button->setVisible(expertMode());
m_saveButton->addApplyButton(button);
}
void ConfigTaskWidget::addSaveButton(QPushButton *button)
@ -444,7 +480,6 @@ bool ConfigTaskWidget::shouldObjectBeSaved(UAVObject *object)
return true;
}
void ConfigTaskWidget::widgetsContentsChanged()
{
QWidget *emitter = ((QWidget *)sender());
@ -499,9 +534,9 @@ void ConfigTaskWidget::widgetsContentsChanged()
setDirty(true);
}
void ConfigTaskWidget::clearDirty()
bool ConfigTaskWidget::isDirty()
{
setDirty(false);
return m_isConnected ? m_isDirty : false;
}
void ConfigTaskWidget::setDirty(bool value)
@ -512,13 +547,9 @@ void ConfigTaskWidget::setDirty(bool value)
m_isDirty = value;
}
bool ConfigTaskWidget::isDirty()
void ConfigTaskWidget::clearDirty()
{
if (m_isConnected) {
return m_isDirty;
} else {
return false;
}
m_isDirty = false;
}
void ConfigTaskWidget::disableObjectUpdates()
@ -624,8 +655,8 @@ void ConfigTaskWidget::addAutoBindings()
QVariant info = widget->property("objrelation");
if (info.isValid()) {
bindingStruct uiRelation;
uiRelation.buttonType = none;
BindingStruct uiRelation;
uiRelation.buttonType = None;
uiRelation.scale = 1;
uiRelation.index = -1;
uiRelation.elementName = QString();
@ -656,15 +687,15 @@ void ConfigTaskWidget::addAutoBindings()
}
} else if (prop == "button") {
if (value == "save") {
uiRelation.buttonType = save_button;
uiRelation.buttonType = SaveButton;
} else if (value == "apply") {
uiRelation.buttonType = apply_button;
uiRelation.buttonType = ApplyButton;
} else if (value == "reload") {
uiRelation.buttonType = reload_button;
uiRelation.buttonType = ReloadButton;
} else if (value == "default") {
uiRelation.buttonType = default_button;
uiRelation.buttonType = DefaultButton;
} else if (value == "help") {
uiRelation.buttonType = help_button;
uiRelation.buttonType = HelpButton;
}
} else if (prop == "buttongroup") {
foreach(QString s, value.split(",")) {
@ -674,34 +705,34 @@ void ConfigTaskWidget::addAutoBindings()
uiRelation.url = str.mid(str.indexOf(":") + 1);
}
}
if (uiRelation.buttonType != none) {
if (uiRelation.buttonType != None) {
QPushButton *button = NULL;
switch (uiRelation.buttonType) {
case save_button:
case SaveButton:
button = qobject_cast<QPushButton *>(widget);
if (button) {
addSaveButton(button);
}
break;
case apply_button:
case ApplyButton:
button = qobject_cast<QPushButton *>(widget);
if (button) {
addApplyButton(button);
}
break;
case default_button:
case DefaultButton:
button = qobject_cast<QPushButton *>(widget);
if (button) {
addDefaultButton(button, uiRelation.buttonGroup.at(0));
}
break;
case reload_button:
case ReloadButton:
button = qobject_cast<QPushButton *>(widget);
if (button) {
addReloadButton(button, uiRelation.buttonGroup.at(0));
}
break;
case help_button:
case HelpButton:
button = qobject_cast<QPushButton *>(widget);
if (button) {
addHelpButton(button, WIKI_URL_ROOT + m_wikiURL);
@ -816,10 +847,10 @@ void ConfigTaskWidget::reloadButtonClicked()
connect(m_realtimeUpdateTimer, SIGNAL(timeout()), eventLoop, SLOT(quit()));
connect(objper, SIGNAL(objectUpdated(UAVObject *)), eventLoop, SLOT(quit()));
QList<objectComparator> temp;
QList<ObjectComparator> temp;
foreach(WidgetBinding * binding, bindings) {
if (binding->isEnabled() && binding->object()) {
objectComparator value;
ObjectComparator value;
value.objid = binding->object()->getObjID();
value.objinstid = binding->object()->getInstID();
if (temp.contains(value)) {

View File

@ -100,13 +100,16 @@ class UAVOBJECTWIDGETUTILS_EXPORT ConfigTaskWidget : public QWidget {
Q_OBJECT
public:
ConfigTaskWidget(QWidget *parent = 0, bool autopilot = true);
enum ConfigTaskType { AutoPilot, OPLink, Child };
ConfigTaskWidget(QWidget *parent = 0, ConfigTaskType configType = AutoPilot);
virtual ~ConfigTaskWidget();
void bind();
bool isDirty();
void setDirty(bool value);
void clearDirty();
virtual bool shouldObjectBeSaved(UAVObject *object);
@ -176,23 +179,21 @@ protected:
return m_currentBoardId;
}
bool expertMode() const;
virtual void enableControls(bool enable);
virtual QString mapObjectName(const QString objectName);
virtual UAVObject *getObject(const QString name, quint32 instId = 0);
virtual void buildOptionComboBox(QComboBox *combo, UAVObjectField *field, int index, bool applyLimits);
void updateEnableControls();
bool isConnected() const;
virtual void enableControls(bool enable);
virtual void refreshWidgetsValuesImpl(UAVObject *) {};
virtual void updateObjectsFromWidgetsImpl() {};
bool isConnected() const;
void updateEnableControls();
protected slots:
void setWidgetBindingObjectEnabled(QString objectName, bool enabled);
void clearDirty();
virtual void widgetsContentsChanged();
// void populateWidgets();
void refreshWidgetsValues(UAVObject *obj = NULL);
void updateObjectsFromWidgets();
@ -205,36 +206,38 @@ private slots:
void objectUpdated(UAVObject *object);
void invalidateObjects();
void saveSuccessful();
void defaultButtonClicked();
void reloadButtonClicked();
void helpButtonPressed();
private:
struct objectComparator {
struct ObjectComparator {
quint32 objid;
quint32 objinstid;
bool operator==(const objectComparator & lhs)
bool operator==(const ObjectComparator & lhs)
{
return lhs.objid == this->objid && lhs.objinstid == this->objinstid;
}
};
enum buttonTypeEnum { none, save_button, apply_button, reload_button, default_button, help_button };
struct bindingStruct {
enum ButtonTypeEnum { None, SaveButton, ApplyButton, ReloadButton, DefaultButton, HelpButton };
struct BindingStruct {
QString objectName;
QString fieldName;
QString elementName;
int index;
QString url;
buttonTypeEnum buttonType;
ButtonTypeEnum buttonType;
QList<int> buttonGroup;
double scale;
bool haslimits;
};
// indicates if this is an "autopilot" widget (CC3D, Revolution, ...) or an OPLink widget
// indicates if this is an "autopilot" widget (CC3D, Revolution, ...), an OPLink widget or a Child widget (for vehicle config)
// TODO the logic that this flag controls should be moved to derived classes
bool m_autopilot;
ConfigTaskType m_configType;
// only valid for "autopilot" widgets
int m_currentBoardId;

View File

@ -139,20 +139,18 @@ void SmartSaveButton::processOperation(QPushButton *button, bool save)
}
}
}
emit endOp();
if (!error) {
emit saveSuccessful();
}
if (button) {
button->setEnabled(true);
}
if (!error) {
if (button) {
button->setIcon(QIcon(":/uploader/images/dialog-apply.svg"));
}
emit saveSuccessfull();
} else {
if (button) {
button->setIcon(QIcon(":/uploader/images/process-stop.svg"));
}
}
emit endOp();
}
void SmartSaveButton::setObjects(QList<UAVDataObject *> list)

View File

@ -57,7 +57,7 @@ public:
signals:
void preProcessOperations();
void saveSuccessfull();
void saveSuccessful();
void beginOp();
void endOp();