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

OP-522: When you unchecked Run Calibration it forces the Throttle neutral to 5%

of the range and the FlightMode to 50%.

Sorry there's also some indentation changes mixed into this patch.
This commit is contained in:
James Cotton 2011-06-08 12:21:43 -05:00
parent 5aa8224181
commit 3a3c88cefa

View File

@ -534,35 +534,34 @@ void ConfigInputWidget::updateChannels(UAVObject* controlCommand)
if (m_config->doRCInputCalibration->isChecked()) { if (m_config->doRCInputCalibration->isChecked()) {
if (firstUpdate) { if (firstUpdate) {
// Increase the data rate from the board so that the sliders // Increase the data rate from the board so that the sliders
// move faster // move faster
UAVObject::Metadata mdata = controlCommand->getMetadata(); UAVObject::Metadata mdata = controlCommand->getMetadata();
mdata.flightTelemetryUpdateMode = UAVObject::UPDATEMODE_PERIODIC; mdata.flightTelemetryUpdateMode = UAVObject::UPDATEMODE_PERIODIC;
mccDataRate = mdata.flightTelemetryUpdatePeriod; mccDataRate = mdata.flightTelemetryUpdatePeriod;
mdata.flightTelemetryUpdatePeriod = 150; mdata.flightTelemetryUpdatePeriod = 150;
controlCommand->setMetadata(mdata); controlCommand->setMetadata(mdata);
// Also protect the user by setting all values to zero
// and making the ActuatorCommand object readonly
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("ActuatorCommand")));
mdata = obj->getMetadata();
mdata.flightAccess = UAVObject::ACCESS_READONLY;
obj->setMetadata(mdata);
UAVObjectField *field = obj->getField("Channel");
for (uint i=0; i< field->getNumElements(); i++) {
field->setValue(0,i);
}
obj->updated();
// Also protect the user by setting all values to zero
// and making the ActuatorCommand object readonly
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(getObjectManager()->getObject(QString("ActuatorCommand")));
mdata = obj->getMetadata();
mdata.flightAccess = UAVObject::ACCESS_READONLY;
obj->setMetadata(mdata);
UAVObjectField *field = obj->getField("Channel");
for (uint i=0; i< field->getNumElements(); i++) {
field->setValue(0,i);
} }
obj->updated();
}
field = controlCommand->getField(QString("Channel")); field = controlCommand->getField(QString("Channel"));
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
updateChannelInSlider(inSliders[i], inMinLabels[i], inMaxLabels[i], field->getValue(i).toInt(),inRevCheckboxes[i]->isChecked()); updateChannelInSlider(inSliders[i], inMinLabels[i], inMaxLabels[i], field->getValue(i).toInt(),inRevCheckboxes[i]->isChecked());
firstUpdate = false; firstUpdate = false;
} }
else { else {
if (!firstUpdate) { if (!firstUpdate) {
// Restore original data rate from the board: // Restore original data rate from the board:
UAVObject::Metadata mdata = controlCommand->getMetadata(); UAVObject::Metadata mdata = controlCommand->getMetadata();
mdata.flightTelemetryUpdateMode = UAVObject::UPDATEMODE_PERIODIC; mdata.flightTelemetryUpdateMode = UAVObject::UPDATEMODE_PERIODIC;
@ -573,6 +572,22 @@ void ConfigInputWidget::updateChannels(UAVObject* controlCommand)
mdata = obj->getMetadata(); mdata = obj->getMetadata();
mdata.flightAccess = UAVObject::ACCESS_READWRITE; mdata.flightAccess = UAVObject::ACCESS_READWRITE;
obj->setMetadata(mdata); obj->setMetadata(mdata);
// Set some slider values to better defaults
ManualControlSettings * manualSettings = ManualControlSettings::GetInstance(getObjectManager());
ManualControlSettings::DataFields manualSettingsData = manualSettings->getData();
uint throttleIndex = manualSettingsData.Throttle;
uint flightModeIndex = manualSettingsData.FlightMode;
if(throttleIndex < manualSettings->THROTTLE_NONE) {
// Throttle neutral defaults to 5% of range
manualSettingsData.ChannelNeutral[throttleIndex] = 0.05 * (manualSettingsData.ChannelMax[throttleIndex] - manualSettingsData.ChannelMin[throttleIndex]) + manualSettingsData.ChannelMin[throttleIndex];
qDebug() << manualSettingsData.ChannelNeutral[throttleIndex];
}
if(flightModeIndex < manualSettings->FLIGHTMODE_NONE) {
// Flight mode neutral defaults to 50% of range
manualSettingsData.ChannelNeutral[flightModeIndex] = 0.5 * (manualSettingsData.ChannelMax[flightModeIndex] - manualSettingsData.ChannelMin[flightModeIndex]) + manualSettingsData.ChannelMin[flightModeIndex];
}
manualSettings->setData(manualSettingsData);
} }
firstUpdate = true; firstUpdate = true;
} }
@ -591,17 +606,17 @@ void ConfigInputWidget::updateChannels(UAVObject* controlCommand)
int value = controlCommand->getField("Channel")->getValue(chIndex).toInt(); int value = controlCommand->getField("Channel")->getValue(chIndex).toInt();
if ((chMax > chMin && value >= chNeutral) || (chMin > chMax && value <= chNeutral)) if ((chMax > chMin && value >= chNeutral) || (chMin > chMax && value <= chNeutral))
{ {
if (chMax != chNeutral) if (chMax != chNeutral)
valueScaled = (float)(value - chNeutral) / (float)(chMax - chNeutral); valueScaled = (float)(value - chNeutral) / (float)(chMax - chNeutral);
else else
valueScaled = 0; valueScaled = 0;
} }
else else
{ {
if (chMin != chNeutral) if (chMin != chNeutral)
valueScaled = (float)(value - chNeutral) / (float)(chNeutral - chMin); valueScaled = (float)(value - chNeutral) / (float)(chNeutral - chMin);
else else
valueScaled = 0; valueScaled = 0;
} }
if(valueScaled < -(1.0 / 3.0)) if(valueScaled < -(1.0 / 3.0))
@ -611,7 +626,7 @@ void ConfigInputWidget::updateChannels(UAVObject* controlCommand)
else else
m_config->fmsSlider->setValue(0); m_config->fmsSlider->setValue(0);
} }
} }
void ConfigInputWidget::updateChannelInSlider(QSlider *slider, QLabel *min, QLabel *max, int value, bool reversed) void ConfigInputWidget::updateChannelInSlider(QSlider *slider, QLabel *min, QLabel *max, int value, bool reversed)