1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

VehicleConfig/mixer bugfix: keep the ui in synch when 'Save'ing from uavbrowser;

spruce up vehicleconfig with a couple more helpers;
This commit is contained in:
Mike LaBranche 2012-06-20 12:46:07 -07:00
parent 02cdc6feff
commit 5edd952ed6
4 changed files with 88 additions and 90 deletions

View File

@ -287,6 +287,36 @@ void VehicleConfig::getThrottleCurve(UAVDataObject* mixer, MixerThrottleCurveEle
}
}
bool VehicleConfig::isValidThrottleCurve(QList<double>* curve)
{
Q_ASSERT(curve);
if (curve) {
for (int i=0; i < curve->count(); i++) {
if (curve->at(i) != 0)
return true;
}
}
return false;
}
double VehicleConfig::getCurveMin(QList<double>* curve)
{
double min = 0;
for (int i=0; i<curve->count(); i++)
min = std::min(min, curve->at(i));
return min;
}
double VehicleConfig::getCurveMax(QList<double>* curve)
{
double max = 0;
for (int i=0; i<curve->count(); i++)
max = std::max(max, curve->at(i));
return max;
}
/**
Reset the contents of a field
*/

View File

@ -132,7 +132,9 @@ class VehicleConfig: public ConfigTaskWidget
void setMixerType(UAVDataObject* mixer, int channel, MixerTypeElem mixerType);
void setThrottleCurve(UAVDataObject* mixer, MixerThrottleCurveElem curveType, QList<double> curve);
void getThrottleCurve(UAVDataObject* mixer, MixerThrottleCurveElem curveType, QList<double>* curve);
bool isValidThrottleCurve(QList<double>* curve);
double getCurveMin(QList<double>* curve);
double getCurveMax(QList<double>* curve);
virtual void ResetActuators(GUIConfigDataUnion* configData);
virtual QStringList getChannelDescriptions();

View File

@ -614,82 +614,53 @@ void ConfigVehicleTypeWidget::refreshWidgetsValues(UAVObject * o)
{
Q_UNUSED(o);
if(!allObjectsUpdated())
return;
//if(!allObjectsUpdated())
// return;
//WHAT DOES THIS DO?
bool dirty=isDirty(); //WHY IS THIS CALLED HERE AND THEN AGAIN SEVERAL LINES LATER IN setupAirframeUI()
// Get the Airframe type from the system settings:
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("SystemSettings")));
Q_ASSERT(obj);
UAVObjectField *field = obj->getField(QString("AirframeType"));
UAVDataObject* system = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("SystemSettings")));
Q_ASSERT(system);
UAVObjectField *field = system->getField(QString("AirframeType"));
Q_ASSERT(field);
// At this stage, we will need to have some hardcoded settings in this code, this
// is not ideal, but here you go.
QString frameType = field->getValue().toString();
setupAirframeUI(frameType);
obj = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("MixerSettings")));
Q_ASSERT(obj);
field = obj->getField(QString("ThrottleCurve1"));
Q_ASSERT(field);
UAVDataObject* mixer = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("MixerSettings")));
Q_ASSERT(mixer);
QPointer<VehicleConfig> vconfig = new VehicleConfig();
QList<double> curveValues;
// If the 1st element of the curve is <= -10, then the curve
// is a straight line (that's how the mixer works on the mainboard):
if (field->getValue(0).toInt() <= -10) {
m_aircraft->multiThrottleCurve->initLinearCurve(field->getNumElements(),(double)1);
m_aircraft->fixedWingThrottle->initLinearCurve(field->getNumElements(),(double)1);
m_aircraft->groundVehicleThrottle1->initLinearCurve(field->getNumElements(),(double)1);
vconfig->getThrottleCurve(mixer, VehicleConfig::MIXER_THROTTLECURVE1, &curveValues);
// is at least one of the curve values != 0?
if (vconfig->isValidThrottleCurve(&curveValues)) {
// yes, use the curve we just read from mixersettings
m_aircraft->multiThrottleCurve->initCurve(curveValues);
m_aircraft->fixedWingThrottle->initCurve(curveValues);
m_aircraft->groundVehicleThrottle1->initCurve(curveValues);
}
else {
double temp=0;
double value;
for (unsigned int i=0; i < field->getNumElements(); i++) {
value=field->getValue(i).toDouble();
temp+=value;
curveValues.append(value);
}
if(temp==0)
{
m_aircraft->multiThrottleCurve->initLinearCurve(field->getNumElements(),0.9);
m_aircraft->fixedWingThrottle->initLinearCurve(field->getNumElements(),(double)1);
m_aircraft->groundVehicleThrottle1->initLinearCurve(field->getNumElements(),(double)1);
}
else
{
m_aircraft->multiThrottleCurve->initCurve(curveValues);
m_aircraft->fixedWingThrottle->initCurve(curveValues);
m_aircraft->groundVehicleThrottle1->initCurve(curveValues);
}
// no, init a straight curve
m_aircraft->multiThrottleCurve->initLinearCurve(curveValues.count(),0.9);
m_aircraft->fixedWingThrottle->initLinearCurve(curveValues.count(),(double)1);
m_aircraft->groundVehicleThrottle1->initLinearCurve(curveValues.count(),(double)1);
}
// Setup all Throttle2 curves for all types of airframes //AT THIS MOMENT, THAT MEANS ONLY GROUND VEHICLES
Q_ASSERT(obj);
field = obj->getField(QString("ThrottleCurve2"));
Q_ASSERT(field);
curveValues.clear();
// If the 1st element of the curve is <= -10, then the curve
// is a straight line (that's how the mixer works on the mainboard):
if (field->getValue(0).toInt() <= -10) {
m_aircraft->groundVehicleThrottle2->initLinearCurve(field->getNumElements(),(double)1);
vconfig->getThrottleCurve(mixer, VehicleConfig::MIXER_THROTTLECURVE2, &curveValues);
if (vconfig->isValidThrottleCurve(&curveValues)) {
m_aircraft->groundVehicleThrottle2->initCurve(curveValues);
}
else {
double temp=0;
double value;
for (unsigned int i=0; i < field->getNumElements(); i++) {
value=field->getValue(i).toDouble();
temp+=value;
curveValues.append(value);
}
if(temp==0)
{
m_aircraft->groundVehicleThrottle2->initLinearCurve(field->getNumElements(),(double)1);
}
else
{
m_aircraft->groundVehicleThrottle2->initCurve(curveValues);
}
m_aircraft->groundVehicleThrottle2->initLinearCurve(curveValues.count(),(double)1);
}
// Load the Settings for fixed wing frames:
@ -718,7 +689,6 @@ void ConfigVehicleTypeWidget::refreshWidgetsValues(UAVObject * o)
setComboCurrentIndex(m_aircraft->aircraftType, m_aircraft->aircraftType->findText("Custom"));
}
updateCustomAirframeUI();
setDirty(dirty);
}
@ -786,38 +756,34 @@ void ConfigVehicleTypeWidget::updateCustomAirframeUI()
UAVDataObject* mixer = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("MixerSettings")));
Q_ASSERT(mixer);
VehicleConfig* vconfig = new VehicleConfig();
QPointer<VehicleConfig> vconfig = new VehicleConfig();
QList<double> curveValues;
vconfig->getThrottleCurve(mixer, VehicleConfig::MIXER_THROTTLECURVE1, &curveValues);
// setup throttlecurve 1
vconfig->getThrottleCurve(mixer,VehicleConfig::MIXER_THROTTLECURVE1,&curveValues);
int total = 0;
for (int i=0; i<curveValues.length(); i++)
total += curveValues.at(i);
if (curveValues.at(0) <= -10 || total == 0) {
m_aircraft->customThrottle1Curve->initLinearCurve(curveValues.length(),(double)1);
}
else {
// is at least one of the curve values != 0?
if (vconfig->isValidThrottleCurve(&curveValues)) {
// yes, use the curve we just read from mixersettings
m_aircraft->customThrottle1Curve->setMin(vconfig->getCurveMin(&curveValues));
m_aircraft->customThrottle1Curve->setMax(vconfig->getCurveMax(&curveValues));
m_aircraft->customThrottle1Curve->initCurve(curveValues);
}
// setup throttlecurve 2
vconfig->getThrottleCurve(mixer,VehicleConfig::MIXER_THROTTLECURVE2,&curveValues);
total = 0;
for (int i=0; i<curveValues.length(); i++)
total += curveValues.at(i);
if (curveValues.at(0) <= -10 || total == 0) {
m_aircraft->customThrottle2Curve->initLinearCurve(curveValues.length(),(double)1);
}
else {
// no, init a straight curve
m_aircraft->customThrottle1Curve->initLinearCurve(curveValues.count(),(double)1);
}
// Setup all Throttle2 curves for all types of airframes //AT THIS MOMENT, THAT MEANS ONLY GROUND VEHICLES
vconfig->getThrottleCurve(mixer, VehicleConfig::MIXER_THROTTLECURVE2, &curveValues);
if (vconfig->isValidThrottleCurve(&curveValues)) {
m_aircraft->customThrottle2Curve->setMin(vconfig->getCurveMin(&curveValues));
m_aircraft->customThrottle2Curve->setMax(vconfig->getCurveMax(&curveValues));
m_aircraft->customThrottle2Curve->initCurve(curveValues);
}
else {
m_aircraft->customThrottle2Curve->initLinearCurve(curveValues.count(),(double)1);
}
// Update the mixer table:
for (int channel=0; channel<8; channel++) {

View File

@ -77,11 +77,11 @@ MixerCurveWidget::MixerCurveWidget(QWidget *parent) : QGraphicsView(parent)
MixerCurveWidget::~MixerCurveWidget()
{
for (int i=0; i<nodePool.count(); i++)
delete nodePool.at(i);
while (!nodePool.isEmpty())
delete nodePool.takeFirst();
for (int i=0; i<edgePool.count(); i++)
delete edgePool.at(i);
while (!edgePool.isEmpty())
delete edgePool.takeFirst();
}
Node* MixerCurveWidget::getNode(int index)