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

OP-907 step 3: vehicle config code formatting cleanups

This commit is contained in:
Philippe Renon 2013-04-13 17:37:34 +02:00
parent 3520a7c055
commit 80b658cebf
7 changed files with 706 additions and 872 deletions

View File

@ -44,12 +44,9 @@
QStringList ConfigCcpmWidget::getChannelDescriptions()
{
int i;
QStringList channelDesc;
// init a channel_numelem list of channel desc defaults
for (i=0; i < (int)(ConfigCcpmWidget::CHANNEL_NUMELEM); i++)
{
QStringList channelDesc;
for (int i = 0; i < (int) ConfigCcpmWidget::CHANNEL_NUMELEM; i++) {
channelDesc.append(QString("-"));
}
@ -57,87 +54,94 @@ QStringList ConfigCcpmWidget::getChannelDescriptions()
GUIConfigDataUnion configData = GetConfigData();
heliGUISettingsStruct heli = configData.heli;
if (heli.Throttle > 0)
if (heli.Throttle > 0) {
channelDesc[heli.Throttle - 1] = QString("Throttle");
if (heli.Tail > 0)
channelDesc[heli.Tail - 1] = QString("Tail");
switch(heli.FirstServoIndex)
{
case 0: //front
if (heli.ServoIndexW > 0)
channelDesc[heli.ServoIndexW - 1] = QString("Elevator");
if (heli.ServoIndexX > 0)
channelDesc[heli.ServoIndexX - 1] = QString("Roll1");
if (heli.ServoIndexY > 0)
channelDesc[heli.ServoIndexY - 1] = QString("Roll2");
break;
case 1: //right
if (heli.ServoIndexW > 0)
channelDesc[heli.ServoIndexW - 1] = QString("ServoW");
if (heli.ServoIndexX > 0)
channelDesc[heli.ServoIndexX - 1] = QString("ServoX");
if (heli.ServoIndexY > 0)
channelDesc[heli.ServoIndexY - 1] = QString("ServoY");
break;
case 2: //rear
if (heli.ServoIndexW > 0)
channelDesc[heli.ServoIndexW - 1] = QString("Elevator");
if (heli.ServoIndexX > 0)
channelDesc[heli.ServoIndexX - 1] = QString("Roll1");
if (heli.ServoIndexY > 0)
channelDesc[heli.ServoIndexY - 1] = QString("Roll2");
break;
case 3: //left
if (heli.ServoIndexW > 0)
channelDesc[heli.ServoIndexW - 1] = QString("ServoW");
if (heli.ServoIndexX > 0)
channelDesc[heli.ServoIndexX - 1] = QString("ServoX");
if (heli.ServoIndexY > 0)
channelDesc[heli.ServoIndexY - 1] = QString("ServoY");
break;
}
if (heli.ServoIndexZ > 0)
channelDesc[heli.ServoIndexZ - 1] = QString("ServoZ");
if (heli.Tail > 0) {
channelDesc[heli.Tail - 1] = QString("Tail");
}
switch (heli.FirstServoIndex) {
case 0:
// front
if (heli.ServoIndexW > 0) {
channelDesc[heli.ServoIndexW - 1] = QString("Elevator");
}
if (heli.ServoIndexX > 0) {
channelDesc[heli.ServoIndexX - 1] = QString("Roll1");
}
if (heli.ServoIndexY > 0) {
channelDesc[heli.ServoIndexY - 1] = QString("Roll2");
}
break;
case 1:
// right
if (heli.ServoIndexW > 0) {
channelDesc[heli.ServoIndexW - 1] = QString("ServoW");
}
if (heli.ServoIndexX > 0) {
channelDesc[heli.ServoIndexX - 1] = QString("ServoX");
}
if (heli.ServoIndexY > 0) {
channelDesc[heli.ServoIndexY - 1] = QString("ServoY");
}
break;
case 2:
// rear
if (heli.ServoIndexW > 0) {
channelDesc[heli.ServoIndexW - 1] = QString("Elevator");
}
if (heli.ServoIndexX > 0) {
channelDesc[heli.ServoIndexX - 1] = QString("Roll1");
}
if (heli.ServoIndexY > 0) {
channelDesc[heli.ServoIndexY - 1] = QString("Roll2");
}
break;
case 3:
// left
if (heli.ServoIndexW > 0) {
channelDesc[heli.ServoIndexW - 1] = QString("ServoW");
}
if (heli.ServoIndexX > 0) {
channelDesc[heli.ServoIndexX - 1] = QString("ServoX");
}
if (heli.ServoIndexY > 0) {
channelDesc[heli.ServoIndexY - 1] = QString("ServoY");
}
break;
}
if (heli.ServoIndexZ > 0) {
channelDesc[heli.ServoIndexZ - 1] = QString("ServoZ");
}
return channelDesc;
}
ConfigCcpmWidget::ConfigCcpmWidget(QWidget *parent) :
VehicleConfig(parent), m_aircraft(new Ui_CcpmConfigWidget())
VehicleConfig(parent), m_aircraft(new Ui_CcpmConfigWidget())
{
m_aircraft->setupUi(this);
//Ui_CcpmConfigWidget *m_aircraft = m_aircraft;
SwashLvlConfigurationInProgress = 0;
SwashLvlState = 0;
SwashLvlServoInterlock = 0;
updatingFromHardware = FALSE;
updatingToHardware = FALSE;
//m_aircraft = new Ui_ccpmWidget();
//m_aircraft->setupUi(this);
// Initialization of the swashplaye widget
m_aircraft->SwashplateImage->setScene(new QGraphicsScene(this));
m_aircraft->SwashLvlSwashplateImage->setScene(m_aircraft->SwashplateImage->scene());
m_aircraft->SwashLvlSwashplateImage->setSceneRect(-50,-50,500,500);
m_aircraft->SwashLvlSwashplateImage->setSceneRect(-50, -50, 500, 500);
//m_aircraft->SwashLvlSwashplateImage->scale(.85,.85);
//m_aircraft->SwashplateImage->setSceneRect(SwashplateImg->boundingRect());
m_aircraft->SwashplateImage->setSceneRect(-50,-30,500,500);
m_aircraft->SwashplateImage->setSceneRect(-50, -30, 500, 500);
//m_aircraft->SwashplateImage->scale(.85,.85);
QSvgRenderer *renderer = new QSvgRenderer();
renderer->load(QString(":/configgadget/images/ccpm_setup.svg"));
SwashplateImg = new QGraphicsSvgItem();
SwashplateImg->setSharedRenderer(renderer);
SwashplateImg->setElementId("Swashplate");
@ -146,7 +150,8 @@ ConfigCcpmWidget::ConfigCcpmWidget(QWidget *parent) :
m_aircraft->SwashplateImage->scene()->addItem(SwashplateImg);
QFont serifFont("Times", 24, QFont::Bold);
QPen pen; // creates a default pen
// creates a default pen
QPen pen;
pen.setStyle(Qt::DotLine);
pen.setWidth(2);
@ -154,24 +159,23 @@ ConfigCcpmWidget::ConfigCcpmWidget(QWidget *parent) :
pen.setCapStyle(Qt::RoundCap);
pen.setJoinStyle(Qt::RoundJoin);
QBrush brush(Qt::darkBlue);
QPen pen2; // creates a default pen
// creates a default pen
QPen pen2;
//pen2.setStyle(Qt::DotLine);
pen2.setWidth(1);
pen2.setBrush(Qt::blue);
//pen2.setCapStyle(Qt::RoundCap);
//pen2.setJoinStyle(Qt::RoundJoin);
//brush.setStyle(Qt::RadialGradientPattern);
//brush.setStyle(Qt::RadialGradientPattern);
QList<QString> ServoNames;
ServoNames << "ServoW" << "ServoX" << "ServoY" << "ServoZ" ;
ServoNames << "ServoW" << "ServoX" << "ServoY" << "ServoZ";
for (int i = 0; i < CCPM_MAX_SWASH_SERVOS; i++) {
ServoLines[i] = m_aircraft->SwashLvlSwashplateImage->scene()->addLine(0,0,100*i,i*i*100,pen);
ServoLines[i] = m_aircraft->SwashLvlSwashplateImage->scene()->addLine(0, 0, 100 * i, i * i * 100, pen);
Servos[i] = new QGraphicsSvgItem();
Servos[i]->setSharedRenderer(renderer);
@ -182,14 +186,12 @@ ConfigCcpmWidget::ConfigCcpmWidget(QWidget *parent) :
ServosText[i]->setDefaultTextColor(Qt::yellow);
ServosText[i]->setPlainText(QString("-"));
ServosText[i]->setFont(serifFont);
ServosTextCircles[i] = new QGraphicsEllipseItem(1,1,30,30);
ServosTextCircles[i] = new QGraphicsEllipseItem(1, 1, 30, 30);
ServosTextCircles[i]->setBrush(brush);
ServosTextCircles[i]->setPen(pen2);
m_aircraft->SwashplateImage->scene()->addItem(ServosTextCircles[i]);
m_aircraft->SwashplateImage->scene()->addItem(ServosText[i]);
SwashLvlSpinBoxes[i] = new QSpinBox(m_aircraft->SwashLvlSwashplateImage); // use QGraphicsView
m_aircraft->SwashLvlSwashplateImage->scene()->addWidget(SwashLvlSpinBoxes[i]);
@ -199,7 +201,7 @@ ConfigCcpmWidget::ConfigCcpmWidget(QWidget *parent) :
}
//initialize our two mixer curves
// initialize our two mixer curves
// mixercurve defaults to mixercurve_throttle
m_aircraft->ThrottleCurve->initLinearCurve(5, 1.0, 0.0);
@ -207,7 +209,7 @@ ConfigCcpmWidget::ConfigCcpmWidget(QWidget *parent) :
m_aircraft->PitchCurve->setMixerType(MixerCurve::MIXERCURVE_PITCH);
m_aircraft->PitchCurve->initLinearCurve(5, 1.0, -1.0);
//initialize channel names
// initialize channel names
m_aircraft->ccpmEngineChannel->addItems(channelNames);
m_aircraft->ccpmEngineChannel->setCurrentIndex(0);
m_aircraft->ccpmTailChannel->addItems(channelNames);
@ -222,11 +224,11 @@ 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 << 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");
m_aircraft->ccpmType->addItems(Types);
m_aircraft->ccpmType->setCurrentIndex(m_aircraft->ccpmType->count() - 1);
@ -258,10 +260,10 @@ ConfigCcpmWidget::ConfigCcpmWidget(QWidget *parent) :
connect(m_aircraft->SwashLvlCancelButton, SIGNAL(clicked()), this, SLOT(SwashLvlCancelButtonPressed()));
connect(m_aircraft->SwashLvlFinishButton, SIGNAL(clicked()), this, SLOT(SwashLvlFinishButtonPressed()));
connect(m_aircraft->ccpmCollectivePassthrough, SIGNAL(clicked()),this, SLOT(SetUIComponentVisibilities()));
connect(m_aircraft->ccpmCollectivePassthrough, SIGNAL(clicked()), this, SLOT(SetUIComponentVisibilities()));
connect(m_aircraft->ccpmLinkCyclic, SIGNAL(clicked()), this, SLOT(SetUIComponentVisibilities()));
connect(m_aircraft->ccpmLinkRoll, SIGNAL(clicked()), this, SLOT(SetUIComponentVisibilities()));
ccpmSwashplateRedraw();
}
@ -293,19 +295,19 @@ void ConfigCcpmWidget::refreshWidgetsValues(QString frameType)
GUIConfigDataUnion config = GetConfigData();
//swashplate config
// swashplate config
setComboCurrentIndex( m_aircraft->ccpmType, m_aircraft->ccpmType->count() - (config.heli.SwashplateType +1));
setComboCurrentIndex(m_aircraft->ccpmSingleServo, config.heli.FirstServoIndex);
//ccpm mixing options
// ccpm mixing options
m_aircraft->ccpmCollectivePassthrough->setChecked(config.heli.ccpmCollectivePassthroughState);
m_aircraft->ccpmLinkCyclic->setChecked(config.heli.ccpmLinkCyclicState);
m_aircraft->ccpmLinkRoll->setChecked(config.heli.ccpmLinkRollState);
//correction angle
// correction angle
m_aircraft->ccpmCorrectionAngle->setValue(config.heli.CorrectionAngle);
//update sliders
// update sliders
m_aircraft->ccpmCollectiveScale->setValue(config.heli.SliderValue0);
m_aircraft->ccpmCollectiveScaleBox->setValue(config.heli.SliderValue0);
m_aircraft->ccpmCyclicScale->setValue(config.heli.SliderValue1);
@ -317,15 +319,15 @@ void ConfigCcpmWidget::refreshWidgetsValues(QString frameType)
m_aircraft->ccpmCollectiveSlider->setValue(config.heli.SliderValue0);
m_aircraft->ccpmCollectivespinBox->setValue(config.heli.SliderValue0);
//servo assignments
// servo assignments
setComboCurrentIndex(m_aircraft->ccpmServoWChannel, config.heli.ServoIndexW);
setComboCurrentIndex( m_aircraft->ccpmServoXChannel,config.heli.ServoIndexX);
setComboCurrentIndex( m_aircraft->ccpmServoYChannel,config.heli.ServoIndexY);
setComboCurrentIndex( m_aircraft->ccpmServoZChannel,config.heli.ServoIndexZ);
//throttle
// throttle
setComboCurrentIndex( m_aircraft->ccpmEngineChannel, config.heli.Throttle);
//tail
// tail
setComboCurrentIndex( m_aircraft->ccpmTailChannel, config.heli.Tail);
getMixer();

View File

@ -41,7 +41,7 @@
QStringList ConfigCustomWidget::getChannelDescriptions()
{
QStringList channelDesc;
for (int i = 0; i < (int) (VehicleConfig::CHANNEL_NUMELEM); i++) {
for (int i = 0; i < (int) VehicleConfig::CHANNEL_NUMELEM; i++) {
channelDesc.append(QString("-"));
}
return channelDesc;
@ -58,14 +58,14 @@ ConfigCustomWidget::ConfigCustomWidget(QWidget *parent) :
UAVObjectField* field = mixer->getField(QString("Mixer1Type"));
QStringList list = field->getOptions();
for (int i = 0; i < (int) (VehicleConfig::CHANNEL_NUMELEM); i++) {
for (int i = 0; i < (int) VehicleConfig::CHANNEL_NUMELEM; i++) {
QComboBox* qb = new QComboBox(m_aircraft->customMixerTable);
qb->addItems(list);
m_aircraft->customMixerTable->setCellWidget(0, i, qb);
}
SpinBoxDelegate *sbd = new SpinBoxDelegate();
for (int i = 1; i < (int) (VehicleConfig::CHANNEL_NUMELEM); i++) {
for (int i = 1; i < (int) VehicleConfig::CHANNEL_NUMELEM; i++) {
m_aircraft->customMixerTable->setItemDelegateForRow(i, sbd);
}
}
@ -164,7 +164,7 @@ QString ConfigCustomWidget::updateConfigObjectsFromWidgets()
setThrottleCurve(mixer, VehicleConfig::MIXER_THROTTLECURVE2, m_aircraft->customThrottle2Curve->getCurve());
// Update the table:
for (int channel = 0; channel < (int) (VehicleConfig::CHANNEL_NUMELEM); channel++) {
for (int channel = 0; channel < (int) VehicleConfig::CHANNEL_NUMELEM; channel++) {
QComboBox* q = (QComboBox*) m_aircraft->customMixerTable->cellWidget(0, channel);
if (q->currentText() == "Disabled") {
setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_DISABLED);

View File

@ -44,7 +44,7 @@ QStringList ConfigFixedWingWidget::getChannelDescriptions()
{
// init a channel_numelem list of channel desc defaults
QStringList channelDesc;
for (int i = 0; i < (int) (ConfigFixedWingWidget::CHANNEL_NUMELEM); i++) {
for (int i = 0; i < (int) ConfigFixedWingWidget::CHANNEL_NUMELEM; i++) {
channelDesc.append(QString("-"));
}
@ -105,7 +105,6 @@ void ConfigFixedWingWidget::setupUI(QString frameType)
Q_ASSERT(m_aircraft);
if (frameType == "FixedWing" || frameType == "Elevator aileron rudder") {
//setComboCurrentIndex(m_aircraft->aircraftType, m_aircraft->aircraftType->findText("Fixed Wing"));
setComboCurrentIndex(m_aircraft->fixedWingType, m_aircraft->fixedWingType->findText("Elevator aileron rudder"));
m_aircraft->fwRudder1ChannelBox->setEnabled(true);
m_aircraft->fwRudder1Label->setEnabled(true);
@ -127,7 +126,6 @@ void ConfigFixedWingWidget::setupUI(QString frameType)
m_aircraft->elevonMixBox->setHidden(true);
} else if (frameType == "FixedWingElevon" || frameType == "Elevon") {
//setComboCurrentIndex(m_aircraft->aircraftType, m_aircraft->aircraftType->findText("Fixed Wing"));
setComboCurrentIndex(m_aircraft->fixedWingType, m_aircraft->fixedWingType->findText("Elevon"));
m_aircraft->fwAileron1Label->setText("Elevon 1");
m_aircraft->fwAileron2Label->setText("Elevon 2");
@ -146,7 +144,6 @@ void ConfigFixedWingWidget::setupUI(QString frameType)
m_aircraft->elevonLabel2->setText("Pitch");
} else if (frameType == "FixedWingVtail" || frameType == "Vtail") {
//setComboCurrentIndex(m_aircraft->aircraftType, m_aircraft->aircraftType->findText("Fixed Wing"));
setComboCurrentIndex(m_aircraft->fixedWingType, m_aircraft->fixedWingType->findText("Vtail"));
m_aircraft->fwRudder1ChannelBox->setEnabled(false);
m_aircraft->fwRudder1Label->setEnabled(false);
@ -177,38 +174,6 @@ void ConfigFixedWingWidget::resetActuators(GUIConfigDataUnion *configData)
configData->fixedwing.FixedWingThrottle = 0;
}
/**
Virtual function to update the UI widget objects
*/
QString ConfigFixedWingWidget::updateConfigObjectsFromWidgets()
{
QString airframeType = "FixedWing";
// Save the curve (common to all Fixed wing frames)
UAVDataObject* mixer = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("MixerSettings")));
Q_ASSERT(mixer);
// Remove Feed Forward, it is pointless on a plane:
setMixerValue(mixer, "FeedForward", 0.0);
// Set the throttle curve
setThrottleCurve(mixer,VehicleConfig::MIXER_THROTTLECURVE1, m_aircraft->fixedWingThrottle->getCurve());
//All airframe types must start with "FixedWing"
if (m_aircraft->fixedWingType->currentText() == "Elevator aileron rudder" ) {
airframeType = "FixedWing";
setupFrameFixedWing( airframeType );
} else if (m_aircraft->fixedWingType->currentText() == "Elevon") {
airframeType = "FixedWingElevon";
setupFrameElevon( airframeType );
} else { // "Vtail"
airframeType = "FixedWingVtail";
setupFrameVtail( airframeType );
}
return airframeType;
}
/**
Virtual function to refresh the UI widget values
*/
@ -234,14 +199,6 @@ void ConfigFixedWingWidget::refreshWidgetsValues(QString frameType)
m_aircraft->fixedWingThrottle->initLinearCurve(curveValues.count(), 1.0);
}
GUIConfigDataUnion config = GetConfigData();
fixedGUISettingsStruct fixed = config.fixedwing;
@ -254,14 +211,10 @@ void ConfigFixedWingWidget::refreshWidgetsValues(QString frameType)
setComboCurrentIndex(m_aircraft->fwRudder1ChannelBox, fixed.FixedWingYaw1);
setComboCurrentIndex(m_aircraft->fwRudder2ChannelBox, fixed.FixedWingYaw2);
//UAVDataObject* mixer= dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("MixerSettings")));
//Q_ASSERT(mixer);
int channel;
if (frameType == "FixedWingElevon") {
// If the airframe is elevon, restore the slider setting
// Find the channel number for Elevon1 (FixedWingRoll1)
channel = m_aircraft->fwAileron1ChannelBox->currentIndex() - 1;
int channel = m_aircraft->fwAileron1ChannelBox->currentIndex() - 1;
if (channel > -1) {
// If for some reason the actuators were incoherent, we might fail here, hence the check.
m_aircraft->elevonSlider1->setValue(
@ -271,7 +224,7 @@ void ConfigFixedWingWidget::refreshWidgetsValues(QString frameType)
}
}
else if (frameType == "FixedWingVtail") {
channel = m_aircraft->fwElevator1ChannelBox->currentIndex() - 1;
int channel = m_aircraft->fwElevator1ChannelBox->currentIndex() - 1;
if (channel > -1) {
// If for some reason the actuators were incoherent, we might fail here, hence the check.
m_aircraft->elevonSlider1->setValue(
@ -282,7 +235,37 @@ void ConfigFixedWingWidget::refreshWidgetsValues(QString frameType)
}
}
/**
Virtual function to update the UI widget objects
*/
QString ConfigFixedWingWidget::updateConfigObjectsFromWidgets()
{
QString airframeType = "FixedWing";
// Save the curve (common to all Fixed wing frames)
UAVDataObject* mixer = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("MixerSettings")));
Q_ASSERT(mixer);
// Remove Feed Forward, it is pointless on a plane:
setMixerValue(mixer, "FeedForward", 0.0);
// Set the throttle curve
setThrottleCurve(mixer,VehicleConfig::MIXER_THROTTLECURVE1, m_aircraft->fixedWingThrottle->getCurve());
// All airframe types must start with "FixedWing"
if (m_aircraft->fixedWingType->currentText() == "Elevator aileron rudder" ) {
airframeType = "FixedWing";
setupFrameFixedWing( airframeType );
} else if (m_aircraft->fixedWingType->currentText() == "Elevon") {
airframeType = "FixedWingElevon";
setupFrameElevon( airframeType );
} else { // "Vtail"
airframeType = "FixedWingVtail";
setupFrameVtail( airframeType );
}
return airframeType;
}
/**
Setup Elevator/Aileron/Rudder airframe.
@ -294,13 +277,12 @@ void ConfigFixedWingWidget::refreshWidgetsValues(QString frameType)
bool ConfigFixedWingWidget::setupFrameFixedWing(QString airframeType)
{
// Check coherence:
//Show any config errors in GUI
// Show any config errors in GUI
if (throwConfigError(airframeType)) {
return false;
}
return false;
}
// Now setup the channels:
GUIConfigDataUnion config = GetConfigData();
resetActuators(&config);
@ -312,7 +294,7 @@ bool ConfigFixedWingWidget::setupFrameFixedWing(QString airframeType)
config.fixedwing.FixedWingThrottle = m_aircraft->fwEngineChannelBox->currentIndex();
SetConfigData(config);
UAVDataObject* mixer = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("MixerSettings")));
Q_ASSERT(mixer);
resetMotorAndServoMixers(mixer);
@ -323,56 +305,54 @@ bool ConfigFixedWingWidget::setupFrameFixedWing(QString airframeType)
// 1. Assign the servo/motor/none for each channel
//motor
int channel = m_aircraft->fwEngineChannelBox->currentIndex()-1;
setMixerType(mixer,channel,VehicleConfig::MIXERTYPE_MOTOR);
setMixerVectorValue(mixer,channel,VehicleConfig::MIXERVECTOR_THROTTLECURVE1, 127);
// motor
int channel = m_aircraft->fwEngineChannelBox->currentIndex() - 1;
setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_MOTOR);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_THROTTLECURVE1, 127);
//rudder
channel = m_aircraft->fwRudder1ChannelBox->currentIndex()-1;
setMixerType(mixer,channel,VehicleConfig::MIXERTYPE_SERVO);
// rudder
channel = m_aircraft->fwRudder1ChannelBox->currentIndex() - 1;
setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_SERVO);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW, 127);
//ailerons
channel = m_aircraft->fwAileron1ChannelBox->currentIndex()-1;
// ailerons
channel = m_aircraft->fwAileron1ChannelBox->currentIndex() - 1;
if (channel > -1) {
setMixerType(mixer,channel,VehicleConfig::MIXERTYPE_SERVO);
setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_SERVO);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL, 127);
channel = m_aircraft->fwAileron2ChannelBox->currentIndex()-1;
setMixerType(mixer,channel,VehicleConfig::MIXERTYPE_SERVO);
channel = m_aircraft->fwAileron2ChannelBox->currentIndex() - 1;
setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_SERVO);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL, 127);
}
//elevators
channel = m_aircraft->fwElevator1ChannelBox->currentIndex()-1;
// elevators
channel = m_aircraft->fwElevator1ChannelBox->currentIndex() - 1;
if (channel > -1) {
setMixerType(mixer,channel,VehicleConfig::MIXERTYPE_SERVO);
setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_SERVO);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH, 127);
channel = m_aircraft->fwElevator2ChannelBox->currentIndex()-1;
setMixerType(mixer,channel,VehicleConfig::MIXERTYPE_SERVO);
channel = m_aircraft->fwElevator2ChannelBox->currentIndex() - 1;
setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_SERVO);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH, 127);
}
m_aircraft->fwStatusLabel->setText("Mixer generated");
return true;
}
/**
Setup Elevon
*/
bool ConfigFixedWingWidget::setupFrameElevon(QString airframeType)
{
// Check coherence:
//Show any config errors in GUI
// Show any config errors in GUI
if (throwConfigError(airframeType)) {
return false;
}
GUIConfigDataUnion config = GetConfigData();
resetActuators(&config);
@ -383,7 +363,7 @@ bool ConfigFixedWingWidget::setupFrameElevon(QString airframeType)
config.fixedwing.FixedWingThrottle = m_aircraft->fwEngineChannelBox->currentIndex();
SetConfigData(config);
UAVDataObject* mixer = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("MixerSettings")));
Q_ASSERT(mixer);
resetMotorAndServoMixers(mixer);
@ -397,34 +377,34 @@ bool ConfigFixedWingWidget::setupFrameElevon(QString airframeType)
double value;
//motor
int channel = m_aircraft->fwEngineChannelBox->currentIndex()-1;
setMixerType(mixer,channel,VehicleConfig::MIXERTYPE_MOTOR);
setMixerVectorValue(mixer,channel,VehicleConfig::MIXERVECTOR_THROTTLECURVE1, 127);
// motor
int channel = m_aircraft->fwEngineChannelBox->currentIndex() - 1;
setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_MOTOR);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_THROTTLECURVE1, 127);
//rudders
channel = m_aircraft->fwRudder1ChannelBox->currentIndex()-1;
setMixerType(mixer,channel,VehicleConfig::MIXERTYPE_SERVO);
// rudders
channel = m_aircraft->fwRudder1ChannelBox->currentIndex() - 1;
setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_SERVO);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW, 127);
channel = m_aircraft->fwRudder2ChannelBox->currentIndex()-1;
setMixerType(mixer,channel,VehicleConfig::MIXERTYPE_SERVO);
channel = m_aircraft->fwRudder2ChannelBox->currentIndex() - 1;
setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_SERVO);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW, -127);
//ailerons
channel = m_aircraft->fwAileron1ChannelBox->currentIndex()-1;
// ailerons
channel = m_aircraft->fwAileron1ChannelBox->currentIndex() - 1;
if (channel > -1) {
setMixerType(mixer,channel,VehicleConfig::MIXERTYPE_SERVO);
value = (double)(m_aircraft->elevonSlider2->value()*1.27);
setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_SERVO);
value = (double) (m_aircraft->elevonSlider2->value() * 1.27);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH, value);
value = (double)(m_aircraft->elevonSlider1->value()*1.27);
value = (double) (m_aircraft->elevonSlider1->value() * 1.27);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL, value);
channel = m_aircraft->fwAileron2ChannelBox->currentIndex()-1;
setMixerType(mixer,channel,VehicleConfig::MIXERTYPE_SERVO);
value = (double)(m_aircraft->elevonSlider2->value()*1.27);
channel = m_aircraft->fwAileron2ChannelBox->currentIndex() - 1;
setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_SERVO);
value = (double) (m_aircraft->elevonSlider2->value() * 1.27);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH, value);
value = (double)(m_aircraft->elevonSlider1->value()*1.27);
value = (double) (m_aircraft->elevonSlider1->value() * 1.27);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL, -value);
}
@ -432,15 +412,13 @@ bool ConfigFixedWingWidget::setupFrameElevon(QString airframeType)
return true;
}
/**
Setup VTail
*/
bool ConfigFixedWingWidget::setupFrameVtail(QString airframeType)
{
// Check coherence:
//Show any config errors in GUI
// Show any config errors in GUI
if (throwConfigError(airframeType)) {
return false;
}
@ -467,14 +445,12 @@ bool ConfigFixedWingWidget::setupFrameVtail(QString airframeType)
// 1. Assign the servo/motor/none for each channel
double value;
//motor
// motor
int channel = m_aircraft->fwEngineChannelBox->currentIndex()-1;
setMixerType(mixer,channel,VehicleConfig::MIXERTYPE_MOTOR);
setMixerVectorValue(mixer,channel,VehicleConfig::MIXERVECTOR_THROTTLECURVE1, 127);
//rudders
// rudders
channel = m_aircraft->fwRudder1ChannelBox->currentIndex()-1;
setMixerType(mixer,channel,VehicleConfig::MIXERTYPE_SERVO);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW, 127);
@ -483,7 +459,7 @@ bool ConfigFixedWingWidget::setupFrameVtail(QString airframeType)
setMixerType(mixer,channel,VehicleConfig::MIXERTYPE_SERVO);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW, -127);
//ailerons
// ailerons
channel = m_aircraft->fwAileron1ChannelBox->currentIndex()-1;
if (channel > -1) {
setMixerType(mixer,channel,VehicleConfig::MIXERTYPE_SERVO);
@ -494,11 +470,11 @@ bool ConfigFixedWingWidget::setupFrameVtail(QString airframeType)
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL, -127);
}
//vtail
// vtail
channel = m_aircraft->fwElevator1ChannelBox->currentIndex()-1;
if (channel > -1) {
setMixerType(mixer,channel,VehicleConfig::MIXERTYPE_SERVO);
value = (double)(m_aircraft->elevonSlider2->value()*1.27);
double value = (double)(m_aircraft->elevonSlider2->value()*1.27);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH, value);
value = (double)(m_aircraft->elevonSlider1->value()*1.27);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW, value);
@ -520,96 +496,88 @@ bool ConfigFixedWingWidget::setupFrameVtail(QString airframeType)
*/
bool ConfigFixedWingWidget::throwConfigError(QString airframeType)
{
//Initialize configuration error flag
bool error=false;
//Create a red block. All combo boxes are the same size, so any one should do as a model
int size = m_aircraft->fwEngineChannelBox->style()->pixelMetric(QStyle::PM_SmallIconSize);
QPixmap pixmap(size,size);
pixmap.fill(QColor("red"));
if (airframeType == "FixedWing" ) {
if (m_aircraft->fwEngineChannelBox->currentText() == "None"){
m_aircraft->fwEngineChannelBox->setItemData(0, pixmap, Qt::DecorationRole);//Set color palettes
error=true;
}
else{
m_aircraft->fwEngineChannelBox->setItemData(0, 0, Qt::DecorationRole);//Reset color palettes
}
if (m_aircraft->fwElevator1ChannelBox->currentText() == "None"){
m_aircraft->fwElevator1ChannelBox->setItemData(0, pixmap, Qt::DecorationRole);//Set color palettes
error=true;
}
else{
m_aircraft->fwElevator1ChannelBox->setItemData(0, 0, Qt::DecorationRole);//Reset color palettes
}
if ((m_aircraft->fwAileron1ChannelBox->currentText() == "None") && (m_aircraft->fwRudder1ChannelBox->currentText() == "None")) {
pixmap.fill(QColor("green"));
m_aircraft->fwAileron1ChannelBox->setItemData(0, pixmap, Qt::DecorationRole);//Set color palettes
m_aircraft->fwRudder1ChannelBox->setItemData(0, pixmap, Qt::DecorationRole);//Set color palettes
error=true;
}
else{
m_aircraft->fwAileron1ChannelBox->setItemData(0, 0, Qt::DecorationRole);//Reset color palettes
m_aircraft->fwRudder1ChannelBox->setItemData(0, 0, Qt::DecorationRole);//Reset color palettes
}
} else if (airframeType == "FixedWingElevon"){
if (m_aircraft->fwEngineChannelBox->currentText() == "None"){
m_aircraft->fwEngineChannelBox->setItemData(0, pixmap, Qt::DecorationRole);//Set color palettes
error=true;
}
else{
m_aircraft->fwEngineChannelBox->setItemData(0, 0, Qt::DecorationRole);//Reset color palettes
}
if(m_aircraft->fwAileron1ChannelBox->currentText() == "None"){
m_aircraft->fwAileron1ChannelBox->setItemData(0, pixmap, Qt::DecorationRole);//Set color palettes
error=true;
}
else{
m_aircraft->fwAileron1ChannelBox->setItemData(0, 0, Qt::DecorationRole);//Reset color palettes
}
if (m_aircraft->fwAileron2ChannelBox->currentText() == "None"){
m_aircraft->fwAileron2ChannelBox->setItemData(0, pixmap, Qt::DecorationRole);//Set color palettes
error=true;
}
else{
m_aircraft->fwAileron2ChannelBox->setItemData(0, 0, Qt::DecorationRole);//Reset color palettes
}
} else if ( airframeType == "FixedWingVtail"){
if (m_aircraft->fwEngineChannelBox->currentText() == "None"){
m_aircraft->fwEngineChannelBox->setItemData(0, pixmap, Qt::DecorationRole);//Set color palettes
error=true;
}
else{
m_aircraft->fwEngineChannelBox->setItemData(0, 0, Qt::DecorationRole);//Reset color palettes
}
if(m_aircraft->fwElevator1ChannelBox->currentText() == "None"){
m_aircraft->fwElevator1ChannelBox->setItemData(0, pixmap, Qt::DecorationRole);//Set color palettes
error=true;
}
else{
m_aircraft->fwElevator1ChannelBox->setItemData(0, 0, Qt::DecorationRole);//Reset color palettes
}
if(m_aircraft->fwElevator2ChannelBox->currentText() == "None"){
m_aircraft->fwElevator2ChannelBox->setItemData(0, pixmap, Qt::DecorationRole);//Set color palettes
error=true;
}
else{
m_aircraft->fwElevator2ChannelBox->setItemData(0, 0, Qt::DecorationRole);//Reset color palettes
}
}
if (error){
m_aircraft->fwStatusLabel->setText(QString("<font color='red'>ERROR: Assign all necessary channels</font>"));
}
// Initialize configuration error flag
bool error = false;
// Create a red block. All combo boxes are the same size, so any one should do as a model
int size = m_aircraft->fwEngineChannelBox->style()->pixelMetric(QStyle::PM_SmallIconSize);
QPixmap pixmap(size, size);
pixmap.fill(QColor("red"));
if (airframeType == "FixedWing") {
if (m_aircraft->fwEngineChannelBox->currentText() == "None") {
m_aircraft->fwEngineChannelBox->setItemData(0, pixmap, Qt::DecorationRole); //Set color palettes
error = true;
} else {
m_aircraft->fwEngineChannelBox->setItemData(0, 0, Qt::DecorationRole); //Reset color palettes
}
if (m_aircraft->fwElevator1ChannelBox->currentText() == "None") {
m_aircraft->fwElevator1ChannelBox->setItemData(0, pixmap, Qt::DecorationRole); //Set color palettes
error = true;
} else {
m_aircraft->fwElevator1ChannelBox->setItemData(0, 0, Qt::DecorationRole); //Reset color palettes
}
if ((m_aircraft->fwAileron1ChannelBox->currentText() == "None")
&& (m_aircraft->fwRudder1ChannelBox->currentText() == "None")) {
pixmap.fill(QColor("green"));
m_aircraft->fwAileron1ChannelBox->setItemData(0, pixmap, Qt::DecorationRole); //Set color palettes
m_aircraft->fwRudder1ChannelBox->setItemData(0, pixmap, Qt::DecorationRole); //Set color palettes
error = true;
} else {
m_aircraft->fwAileron1ChannelBox->setItemData(0, 0, Qt::DecorationRole); //Reset color palettes
m_aircraft->fwRudder1ChannelBox->setItemData(0, 0, Qt::DecorationRole); //Reset color palettes
}
} else if (airframeType == "FixedWingElevon") {
if (m_aircraft->fwEngineChannelBox->currentText() == "None") {
m_aircraft->fwEngineChannelBox->setItemData(0, pixmap, Qt::DecorationRole); //Set color palettes
error = true;
} else {
m_aircraft->fwEngineChannelBox->setItemData(0, 0, Qt::DecorationRole); //Reset color palettes
}
if (m_aircraft->fwAileron1ChannelBox->currentText() == "None") {
m_aircraft->fwAileron1ChannelBox->setItemData(0, pixmap, Qt::DecorationRole); //Set color palettes
error = true;
} else {
m_aircraft->fwAileron1ChannelBox->setItemData(0, 0, Qt::DecorationRole); //Reset color palettes
}
if (m_aircraft->fwAileron2ChannelBox->currentText() == "None") {
m_aircraft->fwAileron2ChannelBox->setItemData(0, pixmap, Qt::DecorationRole); //Set color palettes
error = true;
} else {
m_aircraft->fwAileron2ChannelBox->setItemData(0, 0, Qt::DecorationRole); //Reset color palettes
}
} else if (airframeType == "FixedWingVtail") {
if (m_aircraft->fwEngineChannelBox->currentText() == "None") {
m_aircraft->fwEngineChannelBox->setItemData(0, pixmap, Qt::DecorationRole); //Set color palettes
error = true;
} else {
m_aircraft->fwEngineChannelBox->setItemData(0, 0, Qt::DecorationRole); //Reset color palettes
}
if (m_aircraft->fwElevator1ChannelBox->currentText() == "None") {
m_aircraft->fwElevator1ChannelBox->setItemData(0, pixmap, Qt::DecorationRole); //Set color palettes
error = true;
} else {
m_aircraft->fwElevator1ChannelBox->setItemData(0, 0, Qt::DecorationRole); //Reset color palettes
}
if (m_aircraft->fwElevator2ChannelBox->currentText() == "None") {
m_aircraft->fwElevator2ChannelBox->setItemData(0, pixmap, Qt::DecorationRole); //Set color palettes
error = true;
} else {
m_aircraft->fwElevator2ChannelBox->setItemData(0, 0, Qt::DecorationRole); //Reset color palettes
}
}
if (error) {
m_aircraft->fwStatusLabel->setText(QString("<font color='red'>ERROR: Assign all necessary channels</font>"));
}
return error;
}

View File

@ -25,7 +25,6 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "configgroundvehiclewidget.h"
//#include "configvehicletypewidget.h"
#include "mixersettings.h"
#include "systemsettings.h"
#include "actuatorsettings.h"
@ -38,14 +37,15 @@
#include <QtGui/QVBoxLayout>
#include <QtGui/QPushButton>
#include <QBrush>
#include <math.h>
#include <QMessageBox>
#include <math.h>
QStringList ConfigGroundVehicleWidget::getChannelDescriptions()
{
// init a channel_numelem list of channel desc defaults
QStringList channelDesc;
for (int i = 0; i < (int) (ConfigGroundVehicleWidget::CHANNEL_NUMELEM); i++) {
for (int i = 0; i < (int) ConfigGroundVehicleWidget::CHANNEL_NUMELEM; i++) {
channelDesc.append(QString("-"));
}
@ -91,100 +91,97 @@ ConfigGroundVehicleWidget::~ConfigGroundVehicleWidget()
/**
Virtual function to setup the UI
TODO move to constructor or make private
*/
void ConfigGroundVehicleWidget::setupUI(QString frameType)
{
m_aircraft->differentialSteeringMixBox->setHidden(true);
//STILL NEEDS WORK
m_aircraft->differentialSteeringMixBox->setHidden(true);
//STILL NEEDS WORK
// Setup the UI
//setComboCurrentIndex(m_aircraft->aircraftType, m_aircraft->aircraftType->findText("Ground"));
m_aircraft->gvEngineChannelBox->setEnabled(false);
m_aircraft->gvEngineLabel->setEnabled(false);
m_aircraft->gvAileron1ChannelBox->setEnabled(false);
m_aircraft->gvAileron1Label->setEnabled(false);
m_aircraft->gvAileron2ChannelBox->setEnabled(false);
m_aircraft->gvAileron2Label->setEnabled(false);
if (frameType == "GroundVehicleDifferential" || frameType == "Differential (tank)") {
// Tank
setComboCurrentIndex(m_aircraft->groundVehicleType, m_aircraft->groundVehicleType->findText("Differential (tank)"));
m_aircraft->gvMotor1ChannelBox->setEnabled(true);
m_aircraft->gvMotor1Label->setEnabled(true);
m_aircraft->gvMotor2ChannelBox->setEnabled(true);
m_aircraft->gvMotor2Label->setEnabled(true);
// Setup the UI
m_aircraft->gvMotor1Label->setText("Left motor");
m_aircraft->gvMotor2Label->setText("Right motor");
m_aircraft->gvEngineChannelBox->setEnabled(false);
m_aircraft->gvEngineLabel->setEnabled(false);
m_aircraft->gvSteering1ChannelBox->setEnabled(false);
m_aircraft->gvSteering1Label->setEnabled(false);
m_aircraft->gvSteering2ChannelBox->setEnabled(false);
m_aircraft->gvSteering2Label->setEnabled(false);
m_aircraft->gvAileron1ChannelBox->setEnabled(false);
m_aircraft->gvAileron1Label->setEnabled(false);
m_aircraft->gvSteering2Label->setText("Rear steering");
m_aircraft->gvAileron2ChannelBox->setEnabled(false);
m_aircraft->gvAileron2Label->setEnabled(false);
m_aircraft->differentialSteeringMixBox->setHidden(false);
if (frameType == "GroundVehicleDifferential" || frameType == "Differential (tank)") {
// Tank
setComboCurrentIndex(m_aircraft->groundVehicleType,
m_aircraft->groundVehicleType->findText("Differential (tank)"));
m_aircraft->gvMotor1ChannelBox->setEnabled(true);
m_aircraft->gvMotor1Label->setEnabled(true);
m_aircraft->gvThrottleCurve1GroupBox->setTitle("Left throttle curve");
m_aircraft->gvThrottleCurve2GroupBox->setTitle("Right throttle curve");
m_aircraft->gvMotor2ChannelBox->setEnabled(true);
m_aircraft->gvMotor2Label->setEnabled(true);
}
else if (frameType == "GroundVehicleMotorcycle" || frameType == "Motorcycle") {
// Motorcycle
m_aircraft->gvMotor1Label->setText("Left motor");
m_aircraft->gvMotor2Label->setText("Right motor");
m_aircraft->gvSteering1ChannelBox->setEnabled(false);
m_aircraft->gvSteering1Label->setEnabled(false);
m_aircraft->gvSteering2ChannelBox->setEnabled(false);
m_aircraft->gvSteering2Label->setEnabled(false);
m_aircraft->gvSteering2Label->setText("Rear steering");
m_aircraft->differentialSteeringMixBox->setHidden(false);
m_aircraft->gvThrottleCurve1GroupBox->setTitle("Left throttle curve");
m_aircraft->gvThrottleCurve2GroupBox->setTitle("Right throttle curve");
} else if (frameType == "GroundVehicleMotorcycle" || frameType == "Motorcycle") {
// Motorcycle
setComboCurrentIndex(m_aircraft->groundVehicleType, m_aircraft->groundVehicleType->findText("Motorcycle"));
m_aircraft->gvMotor1ChannelBox->setEnabled(false);
m_aircraft->gvMotor1Label->setEnabled(false);
m_aircraft->gvMotor1ChannelBox->setEnabled(false);
m_aircraft->gvMotor1Label->setEnabled(false);
m_aircraft->gvMotor2ChannelBox->setEnabled(true);
m_aircraft->gvMotor2Label->setEnabled(true);
m_aircraft->gvMotor2ChannelBox->setEnabled(true);
m_aircraft->gvMotor2Label->setEnabled(true);
m_aircraft->gvMotor1Label->setText("Front motor");
m_aircraft->gvMotor2Label->setText("Rear motor");
m_aircraft->gvMotor1Label->setText("Front motor");
m_aircraft->gvMotor2Label->setText("Rear motor");
m_aircraft->gvSteering1ChannelBox->setEnabled(true);
m_aircraft->gvSteering1Label->setEnabled(true);
m_aircraft->gvSteering2ChannelBox->setEnabled(true);
m_aircraft->gvSteering2Label->setEnabled(true);
m_aircraft->gvSteering1ChannelBox->setEnabled(true);
m_aircraft->gvSteering1Label->setEnabled(true);
m_aircraft->gvSteering2Label->setText("Balancing");
m_aircraft->gvSteering2ChannelBox->setEnabled(true);
m_aircraft->gvSteering2Label->setEnabled(true);
m_aircraft->differentialSteeringMixBox->setHidden(true);
m_aircraft->gvThrottleCurve1GroupBox->setTitle("Front throttle curve");
m_aircraft->gvThrottleCurve2GroupBox->setTitle("Rear throttle curve");
}
else {
// Car
m_aircraft->gvSteering2Label->setText("Balancing");
m_aircraft->differentialSteeringMixBox->setHidden(true);
m_aircraft->gvThrottleCurve1GroupBox->setTitle("Front throttle curve");
m_aircraft->gvThrottleCurve2GroupBox->setTitle("Rear throttle curve");
} else {
// Car
setComboCurrentIndex(m_aircraft->groundVehicleType, m_aircraft->groundVehicleType->findText("Turnable (car)"));
m_aircraft->gvMotor1ChannelBox->setEnabled(true);
m_aircraft->gvMotor1Label->setEnabled(true);
m_aircraft->gvMotor2ChannelBox->setEnabled(true);
m_aircraft->gvMotor2Label->setEnabled(true);
m_aircraft->gvMotor1Label->setText("Front motor");
m_aircraft->gvMotor2Label->setText("Rear motor");
m_aircraft->gvSteering1ChannelBox->setEnabled(true);
m_aircraft->gvSteering1Label->setEnabled(true);
m_aircraft->gvSteering2ChannelBox->setEnabled(true);
m_aircraft->gvSteering2Label->setEnabled(true);
m_aircraft->differentialSteeringMixBox->setHidden(true);
m_aircraft->gvThrottleCurve1GroupBox->setTitle("Front throttle curve");
m_aircraft->gvThrottleCurve2GroupBox->setTitle("Rear throttle curve");
}
m_aircraft->gvMotor1ChannelBox->setEnabled(true);
m_aircraft->gvMotor1Label->setEnabled(true);
m_aircraft->gvMotor2ChannelBox->setEnabled(true);
m_aircraft->gvMotor2Label->setEnabled(true);
m_aircraft->gvMotor1Label->setText("Front motor");
m_aircraft->gvMotor2Label->setText("Rear motor");
m_aircraft->gvSteering1ChannelBox->setEnabled(true);
m_aircraft->gvSteering1Label->setEnabled(true);
m_aircraft->gvSteering2ChannelBox->setEnabled(true);
m_aircraft->gvSteering2Label->setEnabled(true);
m_aircraft->differentialSteeringMixBox->setHidden(true);
m_aircraft->gvThrottleCurve1GroupBox->setTitle("Front throttle curve");
m_aircraft->gvThrottleCurve2GroupBox->setTitle("Rear throttle curve");
}
}
void ConfigGroundVehicleWidget::resetActuators(GUIConfigDataUnion *configData)
@ -214,8 +211,7 @@ void ConfigGroundVehicleWidget::refreshWidgetsValues(QString frameType)
if (isValidThrottleCurve(&curveValues)) {
// yes, use the curve we just read from mixersettings
m_aircraft->groundVehicleThrottle1->initCurve(&curveValues);
}
else {
} else {
// no, init a straight curve
m_aircraft->groundVehicleThrottle1->initLinearCurve(curveValues.count(), 1.0);
}
@ -225,26 +221,12 @@ void ConfigGroundVehicleWidget::refreshWidgetsValues(QString frameType)
if (isValidThrottleCurve(&curveValues)) {
m_aircraft->groundVehicleThrottle2->initCurve(&curveValues);
}
else {
} else {
m_aircraft->groundVehicleThrottle2->initLinearCurve(curveValues.count(), 1.0);
}
//UAVDataObject *obj;
//UAVObjectField *field;
GUIConfigDataUnion config = GetConfigData();
//THIS SECTION STILL NEEDS WORK. FOR THE MOMENT, USE THE FIXED-WING ONBOARD SETTING IN ORDER TO MINIMIZE CHANCES OF BOLLOXING REAL CODE
// THIS SECTION STILL NEEDS WORK. FOR THE MOMENT, USE THE FIXED-WING ONBOARD SETTING IN ORDER TO MINIMIZE CHANCES OF BOLLOXING REAL CODE
// Retrieve channel setup values
setComboCurrentIndex(m_aircraft->gvMotor1ChannelBox, config.ground.GroundVehicleThrottle1);
setComboCurrentIndex(m_aircraft->gvMotor2ChannelBox, config.ground.GroundVehicleThrottle2);
@ -266,9 +248,8 @@ void ConfigGroundVehicleWidget::refreshWidgetsValues(QString frameType)
m_aircraft->differentialSteeringSlider2->setValue(
getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH) * 100);
}
}
else if (frameType == "GroundVehicleMotorcycle") {
//CURRENTLY BROKEN UNTIL WE DECIDE HOW MOTORCYCLE SHOULD BEHAVE
} else if (frameType == "GroundVehicleMotorcycle") {
// CURRENTLY BROKEN UNTIL WE DECIDE HOW MOTORCYCLE SHOULD BEHAVE
// obj = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("MixerSettings")));
// Q_ASSERT(obj);
// int chMixerNumber = m_aircraft->gvMotor1ChannelBox->currentIndex()-1;
@ -288,12 +269,12 @@ void ConfigGroundVehicleWidget::refreshWidgetsValues(QString frameType)
*/
QString ConfigGroundVehicleWidget::updateConfigObjectsFromWidgets()
{
QString airframeType = "GroundVehicleCar";
QString airframeType = "GroundVehicleCar";
// Save the curve (common to all ground vehicle frames)
// Save the curve (common to all ground vehicle frames)
UAVDataObject *mixer = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("MixerSettings")));
// Remove Feed Forward, it is pointless on a ground vehicle:
// Remove Feed Forward, it is pointless on a ground vehicle:
setMixerValue(mixer, "FeedForward", 0.0);
// set the throttle curves
@ -312,7 +293,7 @@ QString ConfigGroundVehicleWidget::updateConfigObjectsFromWidgets()
setupGroundVehicleMotorcycle(airframeType);
}
return airframeType;
return airframeType;
}
/**
@ -320,14 +301,15 @@ QString ConfigGroundVehicleWidget::updateConfigObjectsFromWidgets()
Returns False if impossible to create the mixer.
*/
bool ConfigGroundVehicleWidget::setupGroundVehicleMotorcycle(QString airframeType){
// Check coherence:
//Show any config errors in GUI
bool ConfigGroundVehicleWidget::setupGroundVehicleMotorcycle(QString airframeType)
{
// Check coherence:
// Show any config errors in GUI
if (throwConfigError(airframeType)) {
return false;
}
return false;
}
// Now setup the channels:
// Now setup the channels:
GUIConfigDataUnion config = GetConfigData();
resetActuators(&config);
@ -335,31 +317,31 @@ bool ConfigGroundVehicleWidget::setupGroundVehicleMotorcycle(QString airframeTyp
config.ground.GroundVehicleThrottle2 = m_aircraft->gvMotor2ChannelBox->currentIndex();
SetConfigData(config);
UAVDataObject* mixer = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("MixerSettings")));
Q_ASSERT(mixer);
resetMotorAndServoMixers(mixer);
//motor
int channel = m_aircraft->gvMotor2ChannelBox->currentIndex()-1;
// motor
int channel = m_aircraft->gvMotor2ChannelBox->currentIndex() - 1;
setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_SERVO);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_THROTTLECURVE1, 127);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW, 127);
//steering
channel = m_aircraft->gvSteering1ChannelBox->currentIndex()-1;
// steering
channel = m_aircraft->gvSteering1ChannelBox->currentIndex() - 1;
setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_SERVO);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW, -127);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL, -127);
//balance
channel = m_aircraft->gvSteering2ChannelBox->currentIndex()-1;
// balance
channel = m_aircraft->gvSteering2ChannelBox->currentIndex() - 1;
setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_SERVO);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW, 127);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL, 127);
m_aircraft->gvStatusLabel->setText("Mixer generated");
m_aircraft->gvStatusLabel->setText("Mixer generated");
return true;
}
@ -368,42 +350,43 @@ bool ConfigGroundVehicleWidget::setupGroundVehicleMotorcycle(QString airframeTyp
Returns False if impossible to create the mixer.
*/
bool ConfigGroundVehicleWidget::setupGroundVehicleDifferential(QString airframeType){
// Check coherence:
//Show any config errors in GUI
bool ConfigGroundVehicleWidget::setupGroundVehicleDifferential(QString airframeType)
{
// Check coherence:
// Show any config errors in GUI
if (throwConfigError(airframeType)) {
return false;
}
return false;
}
// Now setup the channels:
GUIConfigDataUnion config = GetConfigData();
resetActuators(&config);
config.ground.GroundVehicleThrottle1 = m_aircraft->gvMotor1ChannelBox->currentIndex();
config.ground.GroundVehicleThrottle2 = m_aircraft->gvMotor2ChannelBox->currentIndex();
SetConfigData((config));
UAVDataObject *mixer = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("MixerSettings")));
Q_ASSERT(mixer);
resetMotorAndServoMixers(mixer);
//left motor
int channel = m_aircraft->gvMotor1ChannelBox->currentIndex()-1;
// left motor
int channel = m_aircraft->gvMotor1ChannelBox->currentIndex() - 1;
setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_SERVO);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_THROTTLECURVE1, 127);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW, 127);
//right motor
channel = m_aircraft->gvMotor2ChannelBox->currentIndex()-1;
// right motor
channel = m_aircraft->gvMotor2ChannelBox->currentIndex() - 1;
setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_SERVO);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_THROTTLECURVE2, 127);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW, -127);
//Output success message
m_aircraft->gvStatusLabel->setText("Mixer generated");
// Output success message
m_aircraft->gvStatusLabel->setText("Mixer generated");
return true;
}
@ -415,15 +398,15 @@ bool ConfigGroundVehicleWidget::setupGroundVehicleDifferential(QString airframeT
bool ConfigGroundVehicleWidget::setupGroundVehicleCar(QString airframeType)
{
// Check coherence:
//Show any config errors in GUI
// Show any config errors in GUI
if (throwConfigError(airframeType)) {
return false;
}
return false;
}
// Now setup the channels:
GUIConfigDataUnion config = GetConfigData();
resetActuators(&config);
config.ground.GroundVehicleThrottle1 = m_aircraft->gvMotor1ChannelBox->currentIndex();
config.ground.GroundVehicleThrottle2 = m_aircraft->gvMotor2ChannelBox->currentIndex();
config.ground.GroundVehicleSteering1 = m_aircraft->gvSteering1ChannelBox->currentIndex();
@ -435,25 +418,25 @@ bool ConfigGroundVehicleWidget::setupGroundVehicleCar(QString airframeType)
Q_ASSERT(mixer);
resetMotorAndServoMixers(mixer);
int channel = m_aircraft->gvSteering1ChannelBox->currentIndex()-1;
setMixerType(mixer,channel, VehicleConfig::MIXERTYPE_SERVO);
int channel = m_aircraft->gvSteering1ChannelBox->currentIndex() - 1;
setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_SERVO);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW, 127);
channel = m_aircraft->gvSteering2ChannelBox->currentIndex()-1;
setMixerType(mixer,channel, VehicleConfig::MIXERTYPE_SERVO);
channel = m_aircraft->gvSteering2ChannelBox->currentIndex() - 1;
setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_SERVO);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW, -127);
channel = m_aircraft->gvMotor1ChannelBox->currentIndex()-1;
setMixerType(mixer,channel, VehicleConfig::MIXERTYPE_SERVO);
channel = m_aircraft->gvMotor1ChannelBox->currentIndex() - 1;
setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_SERVO);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_THROTTLECURVE1, 127);
channel = m_aircraft->gvMotor2ChannelBox->currentIndex()-1;
setMixerType(mixer,channel, VehicleConfig::MIXERTYPE_SERVO);
channel = m_aircraft->gvMotor2ChannelBox->currentIndex() - 1;
setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_SERVO);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_THROTTLECURVE2, 127);
//Output success message
// Output success message
m_aircraft->gvStatusLabel->setText("Mixer generated");
return true;
}
@ -462,93 +445,91 @@ bool ConfigGroundVehicleWidget::setupGroundVehicleCar(QString airframeType)
*/
bool ConfigGroundVehicleWidget::throwConfigError(QString airframeType)
{
//Initialize configuration error flag
bool error=false;
// Initialize configuration error flag
bool error = false;
//Create a red block. All combo boxes are the same size, so any one should do as a model
int size = m_aircraft->gvEngineChannelBox->style()->pixelMetric(QStyle::PM_SmallIconSize);
QPixmap pixmap(size,size);
pixmap.fill(QColor("red"));
if (airframeType == "GroundVehicleCar" ) { //Car
if(m_aircraft->gvMotor1ChannelBox->currentText() == "None" && m_aircraft->gvMotor2ChannelBox->currentText() == "None"){
pixmap.fill(QColor("green"));
m_aircraft->gvMotor1ChannelBox->setItemData(0, pixmap, Qt::DecorationRole);//Set color palettes
m_aircraft->gvMotor2ChannelBox->setItemData(0, pixmap, Qt::DecorationRole);//Set color palettes
// m_aircraft->gvMotor1Label->setText("<font color='red'>" + m_aircraft->gvMotor1Label->text() + "</font>");
// m_aircraft->gvMotor2Label->setText("<font color='red'>" + m_aircraft->gvMotor2Label->text() + "</font>");
error=true;
// Create a red block. All combo boxes are the same size, so any one should do as a model
int size = m_aircraft->gvEngineChannelBox->style()->pixelMetric(QStyle::PM_SmallIconSize);
QPixmap pixmap(size, size);
pixmap.fill(QColor("red"));
}
else{
m_aircraft->gvMotor1ChannelBox->setItemData(0, 0, Qt::DecorationRole);//Reset color palettes
m_aircraft->gvMotor2ChannelBox->setItemData(0, 0, Qt::DecorationRole);//Reset color palettes
// QTextEdit* htmlText=new QTextEdit(m_aircraft->gvMotor1Label->text()); // HtmlText is any QString with html tags.
// m_aircraft->gvMotor1Label->setText(htmlText->toPlainText());
// delete htmlText;
//
// htmlText=new QTextEdit(m_aircraft->gvMotor2Label->text()); // HtmlText is any QString with html tags.
// m_aircraft->gvMotor2Label->setText(htmlText->toPlainText());
}
if (m_aircraft->gvSteering1ChannelBox->currentText() == "None" && m_aircraft->gvSteering2ChannelBox->currentText() == "None") {
m_aircraft->gvSteering1ChannelBox->setItemData(0, pixmap, Qt::DecorationRole);//Set color palettes
m_aircraft->gvSteering2ChannelBox->setItemData(0, pixmap, Qt::DecorationRole);//Set color palettes
// m_aircraft->gvStatusLabel->setText("<font color='red'>ERROR: check steering channel assignment</font>");
// m_aircraft->gvSteering1Label->setText("<font color='red'>" + m_aircraft->gvSteering1Label->text() + "</font>");
// m_aircraft->gvSteering2Label->setText("<font color='red'>" + m_aircraft->gvSteering2Label->text() + "</font>");
error=true;
}
else{
m_aircraft->gvSteering1ChannelBox->setItemData(0, 0, Qt::DecorationRole);//Reset color palettes
m_aircraft->gvSteering2ChannelBox->setItemData(0, 0, Qt::DecorationRole);//Reset color palettes
// QTextEdit* htmlText=new QTextEdit(m_aircraft->gvSteering1Label->text()); // HtmlText is any QString with html tags.
// m_aircraft->gvSteering1Label->setText(htmlText->toPlainText());
// delete htmlText;
//
// htmlText=new QTextEdit(m_aircraft->gvSteering2Label->text()); // HtmlText is any QString with html tags.
// m_aircraft->gvSteering2Label->setText(htmlText->toPlainText());
}
} else if (airframeType == "GroundVehicleDifferential"){ //Tank
if(m_aircraft->gvMotor1ChannelBox->currentText() == "None" || m_aircraft->gvMotor2ChannelBox->currentText() == "None"){
m_aircraft->gvMotor1ChannelBox->setItemData(0, pixmap, Qt::DecorationRole);//Set color palettes
m_aircraft->gvMotor2ChannelBox->setItemData(0, pixmap, Qt::DecorationRole);//Set color palettes
error=true;
}
else{
m_aircraft->gvMotor1ChannelBox->setItemData(0, 0, Qt::DecorationRole);//Reset color palettes
m_aircraft->gvMotor2ChannelBox->setItemData(0, 0, Qt::DecorationRole);//Reset color palettes
}
//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
if(m_aircraft->gvMotor1ChannelBox->currentText() == "None" && m_aircraft->gvMotor2ChannelBox->currentText() == "None"){
m_aircraft->gvMotor2ChannelBox->setItemData(0, pixmap, Qt::DecorationRole);//Set color palettes
error=true;
}
else{
m_aircraft->gvMotor2ChannelBox->setItemData(0, 0, Qt::DecorationRole);//Reset color palettes
}
if (m_aircraft->gvSteering1ChannelBox->currentText() == "None" && m_aircraft->gvSteering2ChannelBox->currentText() == "None") {
m_aircraft->gvSteering1ChannelBox->setItemData(0, pixmap, Qt::DecorationRole);//Set color palettes
error=true;
}
else{
m_aircraft->gvSteering1ChannelBox->setItemData(0, 0, Qt::DecorationRole);//Reset color palettes
}
//Always reset
m_aircraft->gvMotor1ChannelBox->setItemData(0, 0, Qt::DecorationRole);//Reset color palettes
m_aircraft->gvSteering2ChannelBox->setItemData(0, 0, Qt::DecorationRole);//Reset color palettes
}
if (error){
m_aircraft->gvStatusLabel->setText(QString("<font color='red'>ERROR: Assign all necessary channels</font>"));
}
if (airframeType == "GroundVehicleCar") { //Car
if (m_aircraft->gvMotor1ChannelBox->currentText() == "None"
&& m_aircraft->gvMotor2ChannelBox->currentText() == "None") {
pixmap.fill(QColor("green"));
m_aircraft->gvMotor1ChannelBox->setItemData(0, pixmap, Qt::DecorationRole); //Set color palettes
m_aircraft->gvMotor2ChannelBox->setItemData(0, pixmap, Qt::DecorationRole); //Set color palettes
//m_aircraft->gvMotor1Label->setText("<font color='red'>" + m_aircraft->gvMotor1Label->text() + "</font>");
//m_aircraft->gvMotor2Label->setText("<font color='red'>" + m_aircraft->gvMotor2Label->text() + "</font>");
error = true;
} else {
m_aircraft->gvMotor1ChannelBox->setItemData(0, 0, Qt::DecorationRole); //Reset color palettes
m_aircraft->gvMotor2ChannelBox->setItemData(0, 0, Qt::DecorationRole); //Reset color palettes
//QTextEdit* htmlText=new QTextEdit(m_aircraft->gvMotor1Label->text()); // HtmlText is any QString with html tags.
//m_aircraft->gvMotor1Label->setText(htmlText->toPlainText());
//delete htmlText;
//htmlText=new QTextEdit(m_aircraft->gvMotor2Label->text()); // HtmlText is any QString with html tags.
//m_aircraft->gvMotor2Label->setText(htmlText->toPlainText());
}
if (m_aircraft->gvSteering1ChannelBox->currentText() == "None"
&& m_aircraft->gvSteering2ChannelBox->currentText() == "None") {
m_aircraft->gvSteering1ChannelBox->setItemData(0, pixmap, Qt::DecorationRole); //Set color palettes
m_aircraft->gvSteering2ChannelBox->setItemData(0, pixmap, Qt::DecorationRole); //Set color palettes
//m_aircraft->gvStatusLabel->setText("<font color='red'>ERROR: check steering channel assignment</font>");
//m_aircraft->gvSteering1Label->setText("<font color='red'>" + m_aircraft->gvSteering1Label->text() + "</font>");
//m_aircraft->gvSteering2Label->setText("<font color='red'>" + m_aircraft->gvSteering2Label->text() + "</font>");
error = true;
} else {
m_aircraft->gvSteering1ChannelBox->setItemData(0, 0, Qt::DecorationRole); //Reset color palettes
m_aircraft->gvSteering2ChannelBox->setItemData(0, 0, Qt::DecorationRole); //Reset color palettes
//QTextEdit* htmlText=new QTextEdit(m_aircraft->gvSteering1Label->text()); // HtmlText is any QString with html tags.
//m_aircraft->gvSteering1Label->setText(htmlText->toPlainText());
//delete htmlText;
//htmlText=new QTextEdit(m_aircraft->gvSteering2Label->text()); // HtmlText is any QString with html tags.
//m_aircraft->gvSteering2Label->setText(htmlText->toPlainText());
}
} else if (airframeType == "GroundVehicleDifferential") { //Tank
if (m_aircraft->gvMotor1ChannelBox->currentText() == "None"
|| m_aircraft->gvMotor2ChannelBox->currentText() == "None") {
m_aircraft->gvMotor1ChannelBox->setItemData(0, pixmap, Qt::DecorationRole); //Set color palettes
m_aircraft->gvMotor2ChannelBox->setItemData(0, pixmap, Qt::DecorationRole); //Set color palettes
error = true;
} else {
m_aircraft->gvMotor1ChannelBox->setItemData(0, 0, Qt::DecorationRole); //Reset color palettes
m_aircraft->gvMotor2ChannelBox->setItemData(0, 0, Qt::DecorationRole); //Reset color palettes
}
// 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
if (m_aircraft->gvMotor1ChannelBox->currentText() == "None"
&& m_aircraft->gvMotor2ChannelBox->currentText() == "None") {
m_aircraft->gvMotor2ChannelBox->setItemData(0, pixmap, Qt::DecorationRole); //Set color palettes
error = true;
} else {
m_aircraft->gvMotor2ChannelBox->setItemData(0, 0, Qt::DecorationRole); //Reset color palettes
}
if (m_aircraft->gvSteering1ChannelBox->currentText() == "None"
&& m_aircraft->gvSteering2ChannelBox->currentText() == "None") {
m_aircraft->gvSteering1ChannelBox->setItemData(0, pixmap, Qt::DecorationRole); //Set color palettes
error = true;
} else {
m_aircraft->gvSteering1ChannelBox->setItemData(0, 0, Qt::DecorationRole); //Reset color palettes
}
// Always reset
m_aircraft->gvMotor1ChannelBox->setItemData(0, 0, Qt::DecorationRole); //Reset color palettes
m_aircraft->gvSteering2ChannelBox->setItemData(0, 0, Qt::DecorationRole); //Reset color palettes
}
if (error) {
m_aircraft->gvStatusLabel->setText(QString("<font color='red'>ERROR: Assign all necessary channels</font>"));
}
return error;
}

View File

@ -43,12 +43,11 @@
const QString ConfigMultiRotorWidget::CHANNELBOXNAME = QString("multiMotorChannelBox");
QStringList ConfigMultiRotorWidget::getChannelDescriptions()
{
// init a channel_numelem list of channel desc defaults
QStringList channelDesc;
for (int i = 0; i < (int) (ConfigMultiRotorWidget::CHANNEL_NUMELEM); i++) {
for (int i = 0; i < (int) ConfigMultiRotorWidget::CHANNEL_NUMELEM; i++) {
channelDesc.append(QString("-"));
}
@ -86,7 +85,6 @@ QStringList ConfigMultiRotorWidget::getChannelDescriptions()
return channelDesc;
}
ConfigMultiRotorWidget::ConfigMultiRotorWidget(QWidget *parent) :
VehicleConfig(parent), m_aircraft(new Ui_MultiRotorConfigWidget()), invertMotors(1)
{
@ -107,14 +105,9 @@ ConfigMultiRotorWidget::ConfigMultiRotorWidget(QWidget *parent) :
scene->setSceneRect(quad->boundingRect());
m_aircraft->quadShape->setScene(scene);
//m_multirotor = new ConfigMultiRotorWidget(m_aircraft);
//m_multirotor->quad = quad;
//setupUI(m_aircraft->multirotorFrameType->currentText());
QStringList multiRotorTypes;
multiRotorTypes << "Tricopter Y" << "Quad +" << "Quad X" <<
"Hexacopter" << "Hexacopter X" << "Hexacopter Y6" <<
"Octocopter" << "Octocopter V" << "Octo Coax +" << "Octo Coax X" ;
multiRotorTypes << "Tricopter Y" << "Quad +" << "Quad X" << "Hexacopter" << "Hexacopter X" << "Hexacopter Y6"
<< "Octocopter" << "Octocopter V" << "Octo Coax +" << "Octo Coax X";
m_aircraft->multirotorFrameType->addItems(multiRotorTypes);
// Set default model to "Quad X"
@ -140,9 +133,6 @@ void ConfigMultiRotorWidget::setupUI(QString frameType)
qDebug() << "ConfigMultiRotorWidget::setupUI - frame type" << frameType;
// set aircraftType to Multirotor
//setComboCurrentIndex(m_aircraft->aircraftType, m_aircraft->aircraftType->findText("Multirotor"));
// disable triyaw channel
m_aircraft->triYawChannelBox->setEnabled(false);
@ -167,8 +157,7 @@ void ConfigMultiRotorWidget::setupUI(QString frameType)
setYawMixLevel(50);
m_aircraft->triYawChannelBox->setEnabled(true);
}
else if (frameType == "QuadX" || frameType == "Quad X") {
} else if (frameType == "QuadX" || frameType == "Quad X") {
setComboCurrentIndex(m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findText("Quad X"));
// Enable all necessary motor channel boxes...
@ -178,8 +167,7 @@ void ConfigMultiRotorWidget::setupUI(QString frameType)
m_aircraft->mrRollMixLevel->setValue(50);
m_aircraft->mrPitchMixLevel->setValue(50);
setYawMixLevel(50);
}
else if (frameType == "QuadP" || frameType == "Quad +") {
} else if (frameType == "QuadP" || frameType == "Quad +") {
setComboCurrentIndex(m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findText("Quad +"));
// Enable all necessary motor channel boxes...
@ -188,8 +176,7 @@ void ConfigMultiRotorWidget::setupUI(QString frameType)
m_aircraft->mrRollMixLevel->setValue(100);
m_aircraft->mrPitchMixLevel->setValue(100);
setYawMixLevel(50);
}
else if (frameType == "Hexa" || frameType == "Hexacopter") {
} else if (frameType == "Hexa" || frameType == "Hexacopter") {
setComboCurrentIndex(m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findText("Hexacopter"));
// Enable all necessary motor channel boxes...
@ -198,8 +185,7 @@ void ConfigMultiRotorWidget::setupUI(QString frameType)
m_aircraft->mrRollMixLevel->setValue(50);
m_aircraft->mrPitchMixLevel->setValue(33);
setYawMixLevel(33);
}
else if (frameType == "HexaX" || frameType == "Hexacopter X" ) {
} else if (frameType == "HexaX" || frameType == "Hexacopter X") {
setComboCurrentIndex(m_aircraft->multirotorFrameType,
m_aircraft->multirotorFrameType->findText("Hexacopter X"));
@ -209,8 +195,7 @@ void ConfigMultiRotorWidget::setupUI(QString frameType)
m_aircraft->mrRollMixLevel->setValue(33);
m_aircraft->mrPitchMixLevel->setValue(50);
setYawMixLevel(33);
}
else if (frameType == "HexaCoax" || frameType == "Hexacopter Y6") {
} else if (frameType == "HexaCoax" || frameType == "Hexacopter Y6") {
setComboCurrentIndex(m_aircraft->multirotorFrameType,
m_aircraft->multirotorFrameType->findText("Hexacopter Y6"));
@ -220,8 +205,7 @@ void ConfigMultiRotorWidget::setupUI(QString frameType)
m_aircraft->mrRollMixLevel->setValue(100);
m_aircraft->mrPitchMixLevel->setValue(50);
setYawMixLevel(66);
}
else if (frameType == "Octo" || frameType == "Octocopter") {
} else if (frameType == "Octo" || frameType == "Octocopter") {
setComboCurrentIndex(m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findText("Octocopter"));
// Enable all necessary motor channel boxes
@ -230,8 +214,7 @@ void ConfigMultiRotorWidget::setupUI(QString frameType)
m_aircraft->mrRollMixLevel->setValue(33);
m_aircraft->mrPitchMixLevel->setValue(33);
setYawMixLevel(25);
}
else if (frameType == "OctoV" || frameType == "Octocopter V") {
} else if (frameType == "OctoV" || frameType == "Octocopter V") {
setComboCurrentIndex(m_aircraft->multirotorFrameType,
m_aircraft->multirotorFrameType->findText("Octocopter V"));
@ -241,8 +224,7 @@ void ConfigMultiRotorWidget::setupUI(QString frameType)
m_aircraft->mrRollMixLevel->setValue(25);
m_aircraft->mrPitchMixLevel->setValue(25);
setYawMixLevel(25);
}
else if (frameType == "OctoCoaxP" || frameType == "Octo Coax +") {
} else if (frameType == "OctoCoaxP" || frameType == "Octo Coax +") {
setComboCurrentIndex(m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findText("Octo Coax +"));
// Enable all necessary motor channel boxes
@ -251,8 +233,7 @@ void ConfigMultiRotorWidget::setupUI(QString frameType)
m_aircraft->mrRollMixLevel->setValue(100);
m_aircraft->mrPitchMixLevel->setValue(100);
setYawMixLevel(50);
}
else if (frameType == "OctoCoaxX" || frameType == "Octo Coax X") {
} else if (frameType == "OctoCoaxX" || frameType == "Octo Coax X") {
setComboCurrentIndex(m_aircraft->multirotorFrameType, m_aircraft->multirotorFrameType->findText("Octo Coax X"));
// Enable all necessary motor channel boxes
@ -262,9 +243,8 @@ void ConfigMultiRotorWidget::setupUI(QString frameType)
m_aircraft->mrPitchMixLevel->setValue(50);
setYawMixLevel(50);
}
// Draw the appropriate airframe
// drawAirframe(frameType);
//drawAirframe(frameType);
}
void ConfigMultiRotorWidget::resetActuators(GUIConfigDataUnion *configData)
@ -299,272 +279,223 @@ void ConfigMultiRotorWidget::refreshWidgetsValues(QString frameType)
if (isValidThrottleCurve(&curveValues)) {
// yes, use the curve we just read from mixersettings
m_aircraft->multiThrottleCurve->initCurve(&curveValues);
}
else {
} else {
// no, init a straight curve
m_aircraft->multiThrottleCurve->initLinearCurve(curveValues.count(), 0.9);
}
int channel;
double value;
GUIConfigDataUnion config = GetConfigData();
multiGUISettingsStruct multi = config.multi;
// UAVDataObject* mixer = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("MixerSettings")));
// Q_ASSERT(mixer);
if (frameType == "QuadP")
{
if (frameType == "QuadP") {
// Motors 1/2/3/4 are: N / E / S / W
setComboCurrentIndex(m_aircraft->multiMotorChannelBox1,multi.VTOLMotorN);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox2,multi.VTOLMotorE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox3,multi.VTOLMotorS);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox4,multi.VTOLMotorW);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox1, multi.VTOLMotorN);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox2, multi.VTOLMotorE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox3, multi.VTOLMotorS);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox4, multi.VTOLMotorW);
// Now, read the 1st mixer R/P/Y levels and initialize the mix sliders.
// This assumes that all vectors are identical - if not, the user should use the
// "custom" setting.
// This assumes that all vectors are identical - if not, the user should use the "custom" setting.
channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1;
if (channel > -1)
{
value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH);
m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) );
int channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1;
if (channel > -1) {
double value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH);
m_aircraft->mrPitchMixLevel->setValue(qRound(value / 1.27));
value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW);
setYawMixLevel( -qRound(value/1.27) );
setYawMixLevel(-qRound(value / 1.27));
channel = m_aircraft->multiMotorChannelBox2->currentIndex() - 1;
value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL);
m_aircraft->mrRollMixLevel->setValue( -qRound(value/1.27));
m_aircraft->mrRollMixLevel->setValue(-qRound(value / 1.27));
}
}
else if (frameType == "QuadX")
{
} else if (frameType == "QuadX") {
// Motors 1/2/3/4 are: NW / NE / SE / SW
setComboCurrentIndex(m_aircraft->multiMotorChannelBox1,multi.VTOLMotorNW);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox2,multi.VTOLMotorNE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox3,multi.VTOLMotorSE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox4,multi.VTOLMotorSW);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox1, multi.VTOLMotorNW);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox2, multi.VTOLMotorNE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox3, multi.VTOLMotorSE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox4, multi.VTOLMotorSW);
// Now, read the 1st mixer R/P/Y levels and initialize the mix sliders.
// This assumes that all vectors are identical - if not, the user should use the
// "custom" setting.
channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1;
if (channel > -1)
{
value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH);
m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) );
int channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1;
if (channel > -1) {
double value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH);
m_aircraft->mrPitchMixLevel->setValue(qRound(value / 1.27));
value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW);
setYawMixLevel( -qRound(value/1.27) );
setYawMixLevel(-qRound(value / 1.27));
value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL);
m_aircraft->mrRollMixLevel->setValue( qRound(value/1.27));
m_aircraft->mrRollMixLevel->setValue(qRound(value / 1.27));
}
}
else if (frameType == "Hexa")
{
} else if (frameType == "Hexa") {
// Motors 1/2/3 4/5/6 are: N / NE / SE / S / SW / NW
setComboCurrentIndex(m_aircraft->multiMotorChannelBox1,multi.VTOLMotorN);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox2,multi.VTOLMotorNE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox3,multi.VTOLMotorSE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox4,multi.VTOLMotorS);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox5,multi.VTOLMotorSW);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox6,multi.VTOLMotorNW);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox1, multi.VTOLMotorN);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox2, multi.VTOLMotorNE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox3, multi.VTOLMotorSE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox4, multi.VTOLMotorS);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox5, multi.VTOLMotorSW);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox6, multi.VTOLMotorNW);
// Now, read the 1st mixer R/P/Y levels and initialize the mix sliders.
// This assumes that all vectors are identical - if not, the user should use the
// "custom" setting.
channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1;
if (channel > -1)
{
value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH);
m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) );
int channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1;
if (channel > -1) {
double value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH);
m_aircraft->mrPitchMixLevel->setValue(qRound(value / 1.27));
value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW);
setYawMixLevel( -qRound(value/1.27) );
setYawMixLevel(-qRound(value / 1.27));
//change channels
channel = m_aircraft->multiMotorChannelBox2->currentIndex() - 1;
value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL);
m_aircraft->mrRollMixLevel->setValue( -qRound(value/1.27) );
m_aircraft->mrRollMixLevel->setValue(-qRound(value / 1.27));
}
}
else if (frameType == "HexaX")
{
} else if (frameType == "HexaX") {
// Motors 1/2/3 4/5/6 are: NE / E / SE / SW / W / NW
setComboCurrentIndex(m_aircraft->multiMotorChannelBox1,multi.VTOLMotorNE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox2,multi.VTOLMotorE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox3,multi.VTOLMotorSE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox4,multi.VTOLMotorSW);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox5,multi.VTOLMotorW);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox6,multi.VTOLMotorNW);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox1, multi.VTOLMotorNE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox2, multi.VTOLMotorE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox3, multi.VTOLMotorSE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox4, multi.VTOLMotorSW);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox5, multi.VTOLMotorW);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox6, multi.VTOLMotorNW);
// Now, read the 1st mixer R/P/Y levels and initialize the mix sliders.
// This assumes that all vectors are identical - if not, the user should use the
// "custom" setting.
channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1;
if (channel > -1)
{
value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH);
m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) );
int channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1;
if (channel > -1) {
double value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH);
m_aircraft->mrPitchMixLevel->setValue(qRound(value / 1.27));
value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW);
setYawMixLevel( -qRound(value/1.27) );
setYawMixLevel(-qRound(value / 1.27));
channel = m_aircraft->multiMotorChannelBox2->currentIndex() - 1;
value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL);
m_aircraft->mrRollMixLevel->setValue( -qRound(value/1.27) );
m_aircraft->mrRollMixLevel->setValue(-qRound(value / 1.27));
}
}
else if (frameType == "HexaCoax")
{
} else if (frameType == "HexaCoax") {
// Motors 1/2/3 4/5/6 are: NW/W NE/E S/SE
setComboCurrentIndex(m_aircraft->multiMotorChannelBox1,multi.VTOLMotorNW);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox2,multi.VTOLMotorW);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox3,multi.VTOLMotorNE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox4,multi.VTOLMotorE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox5,multi.VTOLMotorS);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox6,multi.VTOLMotorSE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox1, multi.VTOLMotorNW);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox2, multi.VTOLMotorW);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox3, multi.VTOLMotorNE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox4, multi.VTOLMotorE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox5, multi.VTOLMotorS);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox6, multi.VTOLMotorSE);
// Now, read the 1st mixer R/P/Y levels and initialize the mix sliders.
// This assumes that all vectors are identical - if not, the user should use the
// "custom" setting.
channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1;
if (channel > -1)
{
value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH);
m_aircraft->mrPitchMixLevel->setValue( qRound(2*value/1.27) );
int channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1;
if (channel > -1) {
double value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH);
m_aircraft->mrPitchMixLevel->setValue(qRound(2 * value / 1.27));
channel = m_aircraft->multiMotorChannelBox2->currentIndex() - 1;
value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW);
setYawMixLevel( qRound(value/1.27) );
setYawMixLevel(qRound(value / 1.27));
value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL);
m_aircraft->mrRollMixLevel->setValue( qRound(value/1.27) );
m_aircraft->mrRollMixLevel->setValue(qRound(value / 1.27));
}
}
else if (frameType == "Octo" || frameType == "OctoV" || frameType == "OctoCoaxP")
{
} else if (frameType == "Octo" || frameType == "OctoV" || frameType == "OctoCoaxP") {
// Motors 1 to 8 are N / NE / E / etc
setComboCurrentIndex(m_aircraft->multiMotorChannelBox1,multi.VTOLMotorN);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox2,multi.VTOLMotorNE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox3,multi.VTOLMotorE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox4,multi.VTOLMotorSE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox5,multi.VTOLMotorS);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox6,multi.VTOLMotorSW);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox7,multi.VTOLMotorW);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox8,multi.VTOLMotorNW);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox1, multi.VTOLMotorN);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox2, multi.VTOLMotorNE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox3, multi.VTOLMotorE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox4, multi.VTOLMotorSE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox5, multi.VTOLMotorS);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox6, multi.VTOLMotorSW);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox7, multi.VTOLMotorW);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox8, multi.VTOLMotorNW);
// Now, read the 1st mixer R/P/Y levels and initialize the mix sliders.
// This assumes that all vectors are identical - if not, the user should use the
// "custom" setting.
channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1;
if (channel > -1)
{
int channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1;
if (channel > -1) {
if (frameType == "Octo") {
value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH);
m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) );
double value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH);
m_aircraft->mrPitchMixLevel->setValue(qRound(value / 1.27));
value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW);
setYawMixLevel( -qRound(value/1.27) );
setYawMixLevel(-qRound(value / 1.27));
//change channels
channel = m_aircraft->multiMotorChannelBox2->currentIndex() - 1;
value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL);
m_aircraft->mrRollMixLevel->setValue( -qRound(value/1.27) );
}
else if (frameType == "OctoV") {
value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH);
m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) );
m_aircraft->mrRollMixLevel->setValue(-qRound(value / 1.27));
} else if (frameType == "OctoV") {
double value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH);
m_aircraft->mrPitchMixLevel->setValue(qRound(value / 1.27));
value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW);
setYawMixLevel( -qRound(value/1.27) );
setYawMixLevel(-qRound(value / 1.27));
//change channels
channel = m_aircraft->multiMotorChannelBox2->currentIndex() - 1;
value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL);
m_aircraft->mrRollMixLevel->setValue( -qRound(value/1.27) );
}
else if (frameType == "OctoCoaxP") {
value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH);
m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) );
m_aircraft->mrRollMixLevel->setValue(-qRound(value / 1.27));
} else if (frameType == "OctoCoaxP") {
double value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH);
m_aircraft->mrPitchMixLevel->setValue(qRound(value / 1.27));
value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW);
setYawMixLevel( -qRound(value/1.27) );
setYawMixLevel(-qRound(value / 1.27));
//change channels
channel = m_aircraft->multiMotorChannelBox3->currentIndex() - 1;
value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL);
m_aircraft->mrRollMixLevel->setValue( -qRound(value/1.27) );
m_aircraft->mrRollMixLevel->setValue(-qRound(value / 1.27));
}
}
}
else if (frameType == "OctoCoaxX")
{
} else if (frameType == "OctoCoaxX") {
// Motors 1 to 8 are N / NE / E / etc
setComboCurrentIndex(m_aircraft->multiMotorChannelBox1,multi.VTOLMotorNW);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox2,multi.VTOLMotorN);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox3,multi.VTOLMotorNE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox4,multi.VTOLMotorE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox5,multi.VTOLMotorSE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox6,multi.VTOLMotorS);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox7,multi.VTOLMotorSW);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox8,multi.VTOLMotorW);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox1, multi.VTOLMotorNW);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox2, multi.VTOLMotorN);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox3, multi.VTOLMotorNE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox4, multi.VTOLMotorE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox5, multi.VTOLMotorSE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox6, multi.VTOLMotorS);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox7, multi.VTOLMotorSW);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox8, multi.VTOLMotorW);
// Now, read the 1st mixer R/P/Y levels and initialize the mix sliders.
// This assumes that all vectors are identical - if not, the user should use the
// "custom" setting.
channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1;
if (channel > -1)
{
value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH);
m_aircraft->mrPitchMixLevel->setValue( qRound(value/1.27) );
int channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1;
if (channel > -1) {
double value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH);
m_aircraft->mrPitchMixLevel->setValue(qRound(value / 1.27));
value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW);
setYawMixLevel( -qRound(value/1.27) );
setYawMixLevel(-qRound(value / 1.27));
value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL);
m_aircraft->mrRollMixLevel->setValue( qRound(value/1.27) );
m_aircraft->mrRollMixLevel->setValue(qRound(value / 1.27));
}
}
else if (frameType == "Tri")
{
} else if (frameType == "Tri") {
// Motors 1 to 8 are N / NE / E / etc
setComboCurrentIndex(m_aircraft->multiMotorChannelBox1, multi.VTOLMotorNW);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox2, multi.VTOLMotorNE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox3, multi.VTOLMotorS);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox4, multi.VTOLMotorS);
setComboCurrentIndex(m_aircraft->triYawChannelBox, multi.TRIYaw);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox1,multi.VTOLMotorNW);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox2,multi.VTOLMotorNE);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox3,multi.VTOLMotorS);
setComboCurrentIndex(m_aircraft->multiMotorChannelBox4,multi.VTOLMotorS);
setComboCurrentIndex(m_aircraft->triYawChannelBox,multi.TRIYaw);
channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1;
if (channel > -1)
{
value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH);
m_aircraft->mrPitchMixLevel->setValue( qRound(2*value/1.27) );
int channel = m_aircraft->multiMotorChannelBox1->currentIndex() - 1;
if (channel > -1) {
double value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH);
m_aircraft->mrPitchMixLevel->setValue(qRound(2 * value / 1.27));
value = getMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL);
m_aircraft->mrRollMixLevel->setValue( qRound(value/1.27) );
m_aircraft->mrRollMixLevel->setValue(qRound(value / 1.27));
}
}
@ -577,15 +508,14 @@ void ConfigMultiRotorWidget::refreshWidgetsValues(QString frameType)
*/
QString ConfigMultiRotorWidget::updateConfigObjectsFromWidgets()
{
QString airframeType;
QList<QString> motorList;
UAVDataObject *mixer = dynamic_cast<UAVDataObject *>(getObjectManager()->getObject(QString("MixerSettings")));
Q_ASSERT(mixer);
// 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);
@ -601,12 +531,11 @@ QString ConfigMultiRotorWidget::updateConfigObjectsFromWidgets()
} else if (m_aircraft->multirotorFrameType->currentText() == "Hexacopter Y6") {
airframeType = "HexaCoax";
//Show any config errors in GUI
// Show any config errors in GUI
if (throwConfigError(6)) {
return airframeType;
}
motorList << "VTOLMotorNW" << "VTOLMotorW" << "VTOLMotorNE" << "VTOLMotorE"
<< "VTOLMotorS" << "VTOLMotorSE";
motorList << "VTOLMotorNW" << "VTOLMotorW" << "VTOLMotorNE" << "VTOLMotorE" << "VTOLMotorS" << "VTOLMotorSE";
setupMotors(motorList);
// Motor 1 to 6, Y6 Layout:
@ -627,13 +556,13 @@ QString ConfigMultiRotorWidget::updateConfigObjectsFromWidgets()
} else if (m_aircraft->multirotorFrameType->currentText() == "Octocopter") {
airframeType = "Octo";
//Show any config errors in GUI
// Show any config errors in GUI
if (throwConfigError(8)) {
return airframeType;
}
motorList << "VTOLMotorN" << "VTOLMotorNE" << "VTOLMotorE" << "VTOLMotorSE"
<< "VTOLMotorS" << "VTOLMotorSW" << "VTOLMotorW" << "VTOLMotorNW";
motorList << "VTOLMotorN" << "VTOLMotorNE" << "VTOLMotorE" << "VTOLMotorSE" << "VTOLMotorS" << "VTOLMotorSW"
<< "VTOLMotorW" << "VTOLMotorNW";
setupMotors(motorList);
// Motor 1 to 8:
// pitch roll yaw
@ -653,12 +582,12 @@ QString ConfigMultiRotorWidget::updateConfigObjectsFromWidgets()
} else if (m_aircraft->multirotorFrameType->currentText() == "Octocopter V") {
airframeType = "OctoV";
//Show any config errors in GUI
// Show any config errors in GUI
if (throwConfigError(8)) {
return airframeType;
}
motorList << "VTOLMotorN" << "VTOLMotorNE" << "VTOLMotorE" << "VTOLMotorSE"
<< "VTOLMotorS" << "VTOLMotorSW" << "VTOLMotorW" << "VTOLMotorNW";
motorList << "VTOLMotorN" << "VTOLMotorNE" << "VTOLMotorE" << "VTOLMotorSE" << "VTOLMotorS" << "VTOLMotorSW"
<< "VTOLMotorW" << "VTOLMotorNW";
setupMotors(motorList);
// Motor 1 to 8:
// IMPORTANT: Assumes evenly spaced engines
@ -679,12 +608,12 @@ QString ConfigMultiRotorWidget::updateConfigObjectsFromWidgets()
} else if (m_aircraft->multirotorFrameType->currentText() == "Octo Coax +") {
airframeType = "OctoCoaxP";
//Show any config errors in GUI
// Show any config errors in GUI
if (throwConfigError(8)) {
return airframeType;
}
motorList << "VTOLMotorN" << "VTOLMotorNE" << "VTOLMotorE" << "VTOLMotorSE"
<< "VTOLMotorS" << "VTOLMotorSW" << "VTOLMotorW" << "VTOLMotorNW";
motorList << "VTOLMotorN" << "VTOLMotorNE" << "VTOLMotorE" << "VTOLMotorSE" << "VTOLMotorS" << "VTOLMotorSW"
<< "VTOLMotorW" << "VTOLMotorNW";
setupMotors(motorList);
// Motor 1 to 8:
// pitch roll yaw
@ -704,12 +633,12 @@ QString ConfigMultiRotorWidget::updateConfigObjectsFromWidgets()
} else if (m_aircraft->multirotorFrameType->currentText() == "Octo Coax X") {
airframeType = "OctoCoaxX";
//Show any config errors in GUI
// Show any config errors in GUI
if (throwConfigError(8)) {
return airframeType;
}
motorList << "VTOLMotorNW" << "VTOLMotorN" << "VTOLMotorNE" << "VTOLMotorE"
<< "VTOLMotorSE" << "VTOLMotorS" << "VTOLMotorSW" << "VTOLMotorW";
motorList << "VTOLMotorNW" << "VTOLMotorN" << "VTOLMotorNE" << "VTOLMotorE" << "VTOLMotorSE" << "VTOLMotorS"
<< "VTOLMotorSW" << "VTOLMotorW";
setupMotors(motorList);
// Motor 1 to 8:
// pitch roll yaw
@ -729,7 +658,7 @@ QString ConfigMultiRotorWidget::updateConfigObjectsFromWidgets()
} else if (m_aircraft->multirotorFrameType->currentText() == "Tricopter Y") {
airframeType = "Tri";
//Show any config errors in GUI
// Show any config errors in GUI
if (throwConfigError(3)) {
return airframeType;
@ -745,7 +674,6 @@ QString ConfigMultiRotorWidget::updateConfigObjectsFromWidgets()
config.multi.TRIYaw = m_aircraft->triYawChannelBox->currentIndex();
SetConfigData(config);
// Motor 1 to 6, Y6 Layout:
// pitch roll yaw
double mixerMatrix[8][3] = {
@ -843,54 +771,49 @@ void ConfigMultiRotorWidget::setupQuadMotor(int channel, double pitch, double ro
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_THROTTLECURVE1, 127);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_THROTTLECURVE2, 0);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL, roll*127);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH, pitch*127);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW, yaw*127);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_ROLL, roll * 127);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_PITCH, pitch * 127);
setMixerVectorValue(mixer, channel, VehicleConfig::MIXERVECTOR_YAW, yaw * 127);
}
/**
Helper function: setup motors. Takes a list of channel names in input.
*/
void ConfigMultiRotorWidget::setupMotors(QList<QString> motorList)
{
QList<QComboBox*> mmList;
mmList << m_aircraft->multiMotorChannelBox1 << m_aircraft->multiMotorChannelBox2 << m_aircraft->multiMotorChannelBox3
<< m_aircraft->multiMotorChannelBox4 << m_aircraft->multiMotorChannelBox5 << m_aircraft->multiMotorChannelBox6
<< m_aircraft->multiMotorChannelBox7 << m_aircraft->multiMotorChannelBox8;
mmList << m_aircraft->multiMotorChannelBox1 << m_aircraft->multiMotorChannelBox2
<< m_aircraft->multiMotorChannelBox3 << m_aircraft->multiMotorChannelBox4
<< m_aircraft->multiMotorChannelBox5 << m_aircraft->multiMotorChannelBox6
<< m_aircraft->multiMotorChannelBox7 << m_aircraft->multiMotorChannelBox8;
GUIConfigDataUnion configData = GetConfigData();
resetActuators(&configData);
int index;
foreach (QString motor, motorList) {
index = mmList.takeFirst()->currentIndex();
if (motor == QString("VTOLMotorN"))
foreach (QString motor, motorList)
{
int index = mmList.takeFirst()->currentIndex();
if (motor == QString("VTOLMotorN")) {
configData.multi.VTOLMotorN = index;
else if (motor == QString("VTOLMotorNE"))
} else if (motor == QString("VTOLMotorNE")) {
configData.multi.VTOLMotorNE = index;
else if (motor == QString("VTOLMotorE"))
} else if (motor == QString("VTOLMotorE")) {
configData.multi.VTOLMotorE = index;
else if (motor == QString("VTOLMotorSE"))
} else if (motor == QString("VTOLMotorSE")) {
configData.multi.VTOLMotorSE = index;
else if (motor == QString( "VTOLMotorS"))
} else if (motor == QString("VTOLMotorS")) {
configData.multi.VTOLMotorS = index;
else if (motor == QString( "VTOLMotorSW"))
} else if (motor == QString("VTOLMotorSW")) {
configData.multi.VTOLMotorSW = index;
else if (motor == QString( "VTOLMotorW"))
} else if (motor == QString("VTOLMotorW")) {
configData.multi.VTOLMotorW = index;
else if (motor == QString( "VTOLMotorNW"))
} else if (motor == QString("VTOLMotorNW")) {
configData.multi.VTOLMotorNW = index;
}
}
SetConfigData(configData);
}
/**
Set up a Quad-X or Quad-P mixer
*/
@ -898,19 +821,16 @@ bool ConfigMultiRotorWidget::setupQuad(bool pLayout)
{
// Check coherence:
//Show any config errors in GUI
// Show any config errors in GUI
if (throwConfigError(4)) {
return false;
}
QList<QString> motorList;
if (pLayout) {
motorList << "VTOLMotorN" << "VTOLMotorE" << "VTOLMotorS"
<< "VTOLMotorW";
motorList << "VTOLMotorN" << "VTOLMotorE" << "VTOLMotorS" << "VTOLMotorW";
} else {
motorList << "VTOLMotorNW" << "VTOLMotorNE" << "VTOLMotorSE"
<< "VTOLMotorSW";
motorList << "VTOLMotorNW" << "VTOLMotorNE" << "VTOLMotorSE" << "VTOLMotorSW";
}
setupMotors(motorList);
@ -931,7 +851,7 @@ bool ConfigMultiRotorWidget::setupQuad(bool pLayout)
{ 0, 0, 0},
{ 0, 0, 0}
};
//
// Motor 1 to 4, P Layout:
// pitch roll yaw
// {1 ,0 ,-0.5 //Front motor (CW)
@ -958,25 +878,22 @@ bool ConfigMultiRotorWidget::setupQuad(bool pLayout)
return true;
}
/**
Set up a Hexa-X or Hexa-P mixer
*/
bool ConfigMultiRotorWidget::setupHexa(bool pLayout)
{
// Check coherence:
//Show any config errors in GUI
if (throwConfigError(6))
// Show any config errors in GUI
if (throwConfigError(6)) {
return false;
}
QList<QString> motorList;
if (pLayout) {
motorList << "VTOLMotorN" << "VTOLMotorNE" << "VTOLMotorSE"
<< "VTOLMotorS" << "VTOLMotorSW" << "VTOLMotorNW";
motorList << "VTOLMotorN" << "VTOLMotorNE" << "VTOLMotorSE" << "VTOLMotorS" << "VTOLMotorSW" << "VTOLMotorNW";
} else {
motorList << "VTOLMotorNE" << "VTOLMotorE" << "VTOLMotorSE"
<< "VTOLMotorSW" << "VTOLMotorW" << "VTOLMotorNW";
motorList << "VTOLMotorNE" << "VTOLMotorE" << "VTOLMotorSE" << "VTOLMotorSW" << "VTOLMotorW" << "VTOLMotorNW";
}
setupMotors(motorList);
@ -990,7 +907,6 @@ bool ConfigMultiRotorWidget::setupHexa(bool pLayout)
// 4 {-0.3 , 0 , 0.3 // S CCW
// 5 {-0.3 , 0.5 ,-0.3 // SW CW
// 6 { 0.3 , 0.5 , 0.3 // NW CCW
double pMixer [8][3] = {
{ 1, 0, -1},
{ 1, -1, 1},
@ -1002,7 +918,6 @@ bool ConfigMultiRotorWidget::setupHexa(bool pLayout)
{ 0, 0, 0}
};
//
// Motor 1 to 6, X Layout:
// 1 [ 0.5, -0.3, -0.3 ] NE
// 2 [ 0 , -0.3, 0.3 ] E
@ -1037,61 +952,59 @@ bool ConfigMultiRotorWidget::setupHexa(bool pLayout)
bool ConfigMultiRotorWidget::setupMultiRotorMixer(double mixerFactors[8][3])
{
QList<QComboBox*> mmList;
mmList << m_aircraft->multiMotorChannelBox1 << m_aircraft->multiMotorChannelBox2 << m_aircraft->multiMotorChannelBox3
<< m_aircraft->multiMotorChannelBox4 << m_aircraft->multiMotorChannelBox5 << m_aircraft->multiMotorChannelBox6
<< m_aircraft->multiMotorChannelBox7 << m_aircraft->multiMotorChannelBox8;
mmList << m_aircraft->multiMotorChannelBox1 << m_aircraft->multiMotorChannelBox2
<< m_aircraft->multiMotorChannelBox3 << m_aircraft->multiMotorChannelBox4
<< m_aircraft->multiMotorChannelBox5 << m_aircraft->multiMotorChannelBox6
<< m_aircraft->multiMotorChannelBox7 << m_aircraft->multiMotorChannelBox8;
UAVDataObject* mixer = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("MixerSettings")));
Q_ASSERT(mixer);
resetMotorAndServoMixers(mixer);
// and enable only the relevant channels:
double pFactor = (double)m_aircraft->mrPitchMixLevel->value()/100;
double rFactor = (double)m_aircraft->mrRollMixLevel->value()/100;
invertMotors = m_aircraft->MultirotorRevMixerCheckBox->isChecked() ? -1:1;
double yFactor =invertMotors * (double)m_aircraft->mrYawMixLevel->value()/100;
for (int i=0 ; i<8; i++) {
if(mmList.at(i)->isEnabled())
{
int channel = mmList.at(i)->currentIndex()-1;
double pFactor = (double) m_aircraft->mrPitchMixLevel->value() / 100;
double rFactor = (double) m_aircraft->mrRollMixLevel->value() / 100;
invertMotors = m_aircraft->MultirotorRevMixerCheckBox->isChecked() ? -1 : 1;
double yFactor = invertMotors * (double) m_aircraft->mrYawMixLevel->value() / 100;
for (int i = 0; i < 8; i++) {
if (mmList.at(i)->isEnabled()) {
int channel = mmList.at(i)->currentIndex() - 1;
if (channel > -1)
setupQuadMotor(channel, mixerFactors[i][0]*pFactor,
rFactor*mixerFactors[i][1], yFactor*mixerFactors[i][2]);
setupQuadMotor(channel, mixerFactors[i][0] * pFactor, rFactor * mixerFactors[i][1],
yFactor * mixerFactors[i][2]);
}
}
return true;
}
/**
This function displays text and color formatting in order to help the user understand what channels have not yet been configured.
*/
bool ConfigMultiRotorWidget::throwConfigError(int numMotors)
{
//Initialize configuration error flag
bool error=false;
{
// Initialize configuration error flag
bool error = false;
//Iterate through all instances of multiMotorChannelBox
for (int i=0; i<numMotors; i++) {
// Iterate through all instances of multiMotorChannelBox
for (int i = 0; i < numMotors; i++) {
//Fine widgets with text "multiMotorChannelBox.x", where x is an integer
QComboBox *combobox = qFindChild<QComboBox*>(this, "multiMotorChannelBox" + QString::number(i+1));
if (combobox){
QComboBox *combobox = qFindChild<QComboBox*>(this, "multiMotorChannelBox" + QString::number(i + 1));
if (combobox) {
if (combobox->currentText() == "None") {
int size = combobox->style()->pixelMetric(QStyle::PM_SmallIconSize);
QPixmap pixmap(size,size);
QPixmap pixmap(size, size);
pixmap.fill(QColor("red"));
combobox->setItemData(0, pixmap, Qt::DecorationRole);//Set color palettes
error=true;
}
else {
combobox->setItemData(0, 0, Qt::DecorationRole);//Reset color palettes
combobox->setItemData(0, pixmap, Qt::DecorationRole); //Set color palettes
error = true;
} else {
combobox->setItemData(0, 0, Qt::DecorationRole); //Reset color palettes
}
}
}
if (error){
m_aircraft->mrStatusLabel->setText(QString("<font color='red'>ERROR: Assign all %1 motor channels</font>").arg(numMotors));
if (error) {
m_aircraft->mrStatusLabel->setText(
QString("<font color='red'>ERROR: Assign all %1 motor channels</font>").arg(numMotors));
}
return error;
}

View File

@ -37,7 +37,7 @@ VehicleConfig::VehicleConfig(QWidget *parent) : ConfigTaskWidget(parent)
{
// Generate lists of mixerTypeNames, mixerVectorNames, channelNames
channelNames << "None";
for (int i = 0; i < (int)(VehicleConfig::CHANNEL_NUMELEM); i++) {
for (int i = 0; i < (int) VehicleConfig::CHANNEL_NUMELEM; i++) {
mixerTypes << QString("Mixer%1Type").arg(i+1);
mixerVectors << QString("Mixer%1Vector").arg(i+1);
channelNames << QString("Channel%1").arg(i+1);
@ -60,8 +60,8 @@ VehicleConfig::~VehicleConfig()
// Do nothing
}
GUIConfigDataUnion VehicleConfig::GetConfigData() {
GUIConfigDataUnion VehicleConfig::GetConfigData()
{
int i;
GUIConfigDataUnion configData;
@ -81,13 +81,10 @@ GUIConfigDataUnion VehicleConfig::GetConfigData() {
return configData;
}
void VehicleConfig::SetConfigData(GUIConfigDataUnion configData) {
int i;
void VehicleConfig::SetConfigData(GUIConfigDataUnion configData)
{
// sanity check
Q_ASSERT(SystemSettings::GUICONFIGDATA_NUMELEM ==
(sizeof(configData.UAVObject) / sizeof(configData.UAVObject[0])));
Q_ASSERT(SystemSettings::GUICONFIGDATA_NUMELEM == (sizeof(configData.UAVObject) / sizeof(configData.UAVObject[0])));
// get an instance of systemsettings
SystemSettings * systemSettings = SystemSettings::GetInstance(getUAVObjectManager());
@ -96,15 +93,16 @@ void VehicleConfig::SetConfigData(GUIConfigDataUnion configData) {
UAVObjectField* guiConfig = systemSettings->getField("GUIConfigData");
Q_ASSERT(guiConfig);
if(!guiConfig)
if (!guiConfig) {
return;
}
// copy parameter configData -> systemsettings
for (i = 0; i < (int)(SystemSettings::GUICONFIGDATA_NUMELEM); i++)
for (int i = 0; i < (int) (SystemSettings::GUICONFIGDATA_NUMELEM); i++) {
guiConfig->setValue(configData.UAVObject[i], i);
}
}
void VehicleConfig::setupUI(QString frameType)
{
}
@ -154,20 +152,22 @@ QString VehicleConfig::getMixerType(UAVDataObject *mixer, int channel)
{
Q_ASSERT(mixer);
QString mixerType = mixerTypeDescriptions[0]; //default to disabled
// default to disabled
QString mixerType = mixerTypeDescriptions[0];
if (channel >= 0 && channel < mixerTypes.count()) {
UAVObjectField *field = mixer->getField(mixerTypes.at(channel));
Q_ASSERT(field);
if (field)
mixerType = field->getValue().toString();
if (field) {
mixerType = field->getValue().toString();
}
}
return mixerType;
}
void VehicleConfig::setMixerType(UAVDataObject* mixer, int channel, MixerTypeElem mixerType)
void VehicleConfig::setMixerType(UAVDataObject *mixer, int channel, MixerTypeElem mixerType)
{
Q_ASSERT(mixer);
@ -176,15 +176,14 @@ void VehicleConfig::setMixerType(UAVDataObject* mixer, int channel, MixerTypeEle
Q_ASSERT(field);
if (field) {
if (mixerType >= 0 && mixerType < mixerTypeDescriptions.count())
{
if (mixerType >= 0 && mixerType < mixerTypeDescriptions.count()) {
field->setValue(mixerTypeDescriptions[mixerType]);
}
}
}
}
void VehicleConfig::resetMixerVector(UAVDataObject* mixer, int channel)
void VehicleConfig::resetMixerVector(UAVDataObject *mixer, int channel)
{
Q_ASSERT(mixer);
@ -200,7 +199,7 @@ void VehicleConfig::resetMixerVector(UAVDataObject* mixer, int channel)
// Disable all servo/motor mixers (but keep camera and accessory ones)
void VehicleConfig::resetMotorAndServoMixers(UAVDataObject *mixer)
{
for (int channel = 0; channel < (int)VehicleConfig::CHANNEL_NUMELEM; channel++) {
for (int channel = 0; channel < (int) VehicleConfig::CHANNEL_NUMELEM; channel++) {
QString type = getMixerType(mixer, channel);
if ((type == "Disabled") || (type == "Motor") || (type == "Servo")) {
setMixerType(mixer, channel, VehicleConfig::MIXERTYPE_DISABLED);
@ -209,12 +208,10 @@ void VehicleConfig::resetMotorAndServoMixers(UAVDataObject *mixer)
}
}
double VehicleConfig::getMixerVectorValue(UAVDataObject* mixer, int channel, MixerVectorElem elementName)
double VehicleConfig::getMixerVectorValue(UAVDataObject *mixer, int channel, MixerVectorElem elementName)
{
Q_ASSERT(mixer);
double value = 0;
if (channel >= 0 && channel < mixerVectors.count()) {
UAVObjectField *field = mixer->getField(mixerVectors.at(channel));
Q_ASSERT(field);
@ -226,7 +223,7 @@ double VehicleConfig::getMixerVectorValue(UAVDataObject* mixer, int channel, Mix
return value;
}
void VehicleConfig::setMixerVectorValue(UAVDataObject* mixer, int channel, MixerVectorElem elementName, double value)
void VehicleConfig::setMixerVectorValue(UAVDataObject *mixer, int channel, MixerVectorElem elementName, double value)
{
Q_ASSERT(mixer);
@ -240,7 +237,7 @@ void VehicleConfig::setMixerVectorValue(UAVDataObject* mixer, int channel, Mixer
}
}
double VehicleConfig::getMixerValue(UAVDataObject* mixer, QString elementName)
double VehicleConfig::getMixerValue(UAVDataObject *mixer, QString elementName)
{
Q_ASSERT(mixer);
@ -253,7 +250,7 @@ double VehicleConfig::getMixerValue(UAVDataObject* mixer, QString elementName)
return value;
}
void VehicleConfig::setMixerValue(UAVDataObject* mixer, QString elementName, double value)
void VehicleConfig::setMixerValue(UAVDataObject *mixer, QString elementName, double value)
{
Q_ASSERT(mixer);
@ -283,7 +280,7 @@ void VehicleConfig::setThrottleCurve(UAVDataObject *mixer, MixerThrottleCurveEle
}
}
void VehicleConfig::getThrottleCurve(UAVDataObject* mixer, MixerThrottleCurveElem curveType, QList<double>* curve)
void VehicleConfig::getThrottleCurve(UAVDataObject *mixer, MixerThrottleCurveElem curveType, QList<double> *curve)
{
Q_ASSERT(mixer);
Q_ASSERT(curve);
@ -307,7 +304,7 @@ void VehicleConfig::getThrottleCurve(UAVDataObject* mixer, MixerThrottleCurveEle
}
}
bool VehicleConfig::isValidThrottleCurve(QList<double>* curve)
bool VehicleConfig::isValidThrottleCurve(QList<double> *curve)
{
Q_ASSERT(curve);
@ -322,6 +319,7 @@ bool VehicleConfig::isValidThrottleCurve(QList<double>* curve)
double VehicleConfig::getCurveMin(QList<double> *curve)
{
// TODO initialize to max double
double min = 0;
for (int i = 0; i < curve->count(); i++) {
min = std::min(min, curve->at(i));
@ -331,6 +329,7 @@ double VehicleConfig::getCurveMin(QList<double> *curve)
double VehicleConfig::getCurveMax(QList<double> *curve)
{
// TODO initialize to min double
double max = 0;
for (int i = 0; i < curve->count(); i++) {
max = std::max(max, curve->at(i));
@ -352,9 +351,10 @@ void VehicleConfig::resetField(UAVObjectField * field)
* Util function to get a pointer to the object manager
* @return pointer to the UAVObjectManager
*/
UAVObjectManager *VehicleConfig::getUAVObjectManager() {
UAVObjectManager *VehicleConfig::getUAVObjectManager()
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager * objMngr = pm->getObject<UAVObjectManager>();
UAVObjectManager *objMngr = pm->getObject<UAVObjectManager>();
Q_ASSERT(objMngr);
return objMngr;
}

View File

@ -206,35 +206,6 @@ ConfigVehicleTypeWidget::~ConfigVehicleTypeWidget()
// m_aircraft->airframesWidget->setCurrentIndex(index);
//}
/**
\brief Sets up the mixer depending on Airframe type. Accepts either system settings or
combo box entry from airframe type, as those do not overlap.
*/
//void ConfigVehicleTypeWidget::setupAirframeUI(QString frameType)
//{
// qDebug() << "ConfigVehicleTypeWidget::setupAirframeUI - begin";
// qDebug() << "ConfigVehicleTypeWidget::setupAirframeUI - frame type" << frameType;
//
// bool dirty = isDirty();
//
// QString category = frameCategory2(frameType);
// if (category == "FixedWing") {
// m_fixedwing->setupUI(frameType);
// } else if (category == "Multirotor") {
// m_multirotor->setupUI(frameType);
// } else if (category == "Helicopter") {
// m_heli->setupUI(frameType);
// } else if (category == "Ground") {
// m_groundvehicle->setupUI(frameType);
// } else if (category == "Custom") {
// m_custom->setupUI(frameType);
// }
//
// setDirty(dirty);
//
// qDebug() << "ConfigVehicleTypeWidget::setupAirframeUI - end";
//}
/**
Refreshes the current value of the SystemSettings which holds the aircraft type
*/
@ -462,7 +433,6 @@ void ConfigVehicleTypeWidget::enableFFTest()
Note: does NOT ask for an object refresh itself!
*/
// TODO rename to FF
void ConfigVehicleTypeWidget::updateFeedForwardUI()
{
UAVDataObject* mixer = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("MixerSettings")));
@ -471,10 +441,10 @@ void ConfigVehicleTypeWidget::updateFeedForwardUI()
QPointer<VehicleConfig> vconfig = new VehicleConfig();
// Update feed forward settings
m_aircraft->feedForwardSlider->setValue(vconfig->getMixerValue(mixer,"FeedForward") * 100);
m_aircraft->accelTime->setValue(vconfig->getMixerValue(mixer,"AccelTime"));
m_aircraft->decelTime->setValue(vconfig->getMixerValue(mixer,"DecelTime"));
m_aircraft->maxAccelSlider->setValue(vconfig->getMixerValue(mixer,"MaxAccel"));
m_aircraft->feedForwardSlider->setValue(vconfig->getMixerValue(mixer, "FeedForward") * 100);
m_aircraft->accelTime->setValue(vconfig->getMixerValue(mixer, "AccelTime"));
m_aircraft->decelTime->setValue(vconfig->getMixerValue(mixer, "DecelTime"));
m_aircraft->maxAccelSlider->setValue(vconfig->getMixerValue(mixer, "MaxAccel"));
}
/**