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

Merge branch 'rel-14.10' of ssh://git.openpilot.org/OpenPilot into rel-14.10

This commit is contained in:
m_thread 2014-11-07 15:43:20 +01:00
commit 247f08239c
4 changed files with 41 additions and 43 deletions

View File

@ -36,7 +36,7 @@ bool OutputCalibrationUtil::c_prepared = false;
ActuatorCommand::Metadata OutputCalibrationUtil::c_savedActuatorCommandMetaData;
OutputCalibrationUtil::OutputCalibrationUtil(QObject *parent) :
QObject(parent), m_outputChannel(-1), m_safeValue(1000)
QObject(parent), m_safeValue(1000)
{}
OutputCalibrationUtil::~OutputCalibrationUtil()
@ -93,15 +93,17 @@ void OutputCalibrationUtil::stopOutputCalibration()
}
}
void OutputCalibrationUtil::startChannelOutput(quint16 channel, quint16 safeValue)
void OutputCalibrationUtil::startChannelOutput(quint16 channel, quint16 safeValue) {
QList<quint16> channels;
channels.append(channel);
startChannelOutput(channels, safeValue);
}
void OutputCalibrationUtil::startChannelOutput(QList<quint16> channels, quint16 safeValue)
{
if (c_prepared) {
if (m_outputChannel < 0 && channel < ActuatorCommand::CHANNEL_NUMELEM) {
// Start output...
m_outputChannel = channel;
m_outputChannels = channels;
m_safeValue = safeValue;
qDebug() << "Output for channel " << m_outputChannel + 1 << " started.";
}
} else {
qDebug() << "OutputCalibrationUtil not started.";
}
@ -110,15 +112,9 @@ void OutputCalibrationUtil::startChannelOutput(quint16 channel, quint16 safeValu
void OutputCalibrationUtil::stopChannelOutput()
{
if (c_prepared) {
if (m_outputChannel >= 0) {
qDebug() << "Stopping output for channel " << m_outputChannel + 1 << "...";
// Stop output...
setChannelOutputValue(m_safeValue);
qDebug() << "Settings output for channel " << m_outputChannel + 1 << " to " << m_safeValue;
qDebug() << "Output for channel " << m_outputChannel + 1 << " stopped.";
m_outputChannel = -1;
}
m_outputChannels.clear();
qDebug() << "OutputCalibrationUtil output stopped.";
} else {
qDebug() << "OutputCalibrationUtil not started.";
}
@ -127,15 +123,20 @@ void OutputCalibrationUtil::stopChannelOutput()
void OutputCalibrationUtil::setChannelOutputValue(quint16 value)
{
if (c_prepared) {
if (m_outputChannel >= 0) {
// Set output value
qDebug() << "Setting output value for channel " << m_outputChannel << " to " << value << ".";
ActuatorCommand *actuatorCommand = getActuatorCommandObject();
ActuatorCommand::DataFields data = actuatorCommand->getData();
data.Channel[m_outputChannel] = value;
foreach (quint32 channel, m_outputChannels) {
// Set output value
if (channel <= ActuatorCommand::CHANNEL_NUMELEM){
qDebug() << "OutputCalibrationUtil setting output value for channel " << channel << " to " << value << ".";
data.Channel[channel] = value;
} else {
qDebug() << "OutputCalibrationUtil could not set output value for channel " << channel
<< " to " << value << "." << "Channel out of bounds" << channel << ".";
}
}
actuatorCommand->setData(data);
} else {
qDebug() << "OutputCalibrationUtil not started.";
}
}
}

View File

@ -44,13 +44,14 @@ public:
public slots:
void startChannelOutput(quint16 channel, quint16 safeValue);
void startChannelOutput(QList<quint16> channels, quint16 safeValue);
void stopChannelOutput();
void setChannelOutputValue(quint16 value);
private:
static bool c_prepared;
static ActuatorCommand::Metadata c_savedActuatorCommandMetaData;
qint16 m_outputChannel;
QList<quint16> m_outputChannels;
quint16 m_safeValue;
};

View File

@ -102,17 +102,19 @@ void EscCalibrationPage::startButtonClicked()
MixerSettings *mSettings = MixerSettings::GetInstance(uavoManager);
Q_ASSERT(mSettings);
QString mixerTypePattern = "Mixer%1Type";
OutputCalibrationUtil::startOutputCalibration();
for (quint32 i = 0; i < ActuatorSettings::CHANNELADDR_NUMELEM; i++) {
UAVObjectField *field = mSettings->getField(mixerTypePattern.arg(i + 1));
Q_ASSERT(field);
if (field->getValue().toString() == field->getOptions().at(VehicleConfigurationHelper::MIXER_TYPE_MOTOR)) {
OutputCalibrationUtil *output = new OutputCalibrationUtil();
output->startChannelOutput(i, OFF_PWM_OUTPUT_PULSE_LENGTH_MICROSECONDS);
output->setChannelOutputValue(HIGH_PWM_OUTPUT_PULSE_LENGTH_MICROSECONDS);
m_outputs << output;
m_outputChannels << i;
}
}
m_outputUtil.startChannelOutput(m_outputChannels, OFF_PWM_OUTPUT_PULSE_LENGTH_MICROSECONDS);
QThread::msleep(100);
m_outputUtil.setChannelOutputValue(HIGH_PWM_OUTPUT_PULSE_LENGTH_MICROSECONDS);
ui->stopButton->setEnabled(true);
}
}
@ -124,35 +126,29 @@ void EscCalibrationPage::stopButtonClicked()
ui->outputHigh->setEnabled(false);
// Set to low pwm out
foreach(OutputCalibrationUtil * output, m_outputs) {
output->setChannelOutputValue(LOW_PWM_OUTPUT_PULSE_LENGTH_MICROSECONDS);
}
m_outputUtil.setChannelOutputValue(LOW_PWM_OUTPUT_PULSE_LENGTH_MICROSECONDS);
ui->outputLevel->setText(QString(tr("%1 µs")).arg(LOW_PWM_OUTPUT_PULSE_LENGTH_MICROSECONDS));
QApplication::processEvents();
QThread::msleep(2000);
// Ramp down to off pwm out
for (int i = LOW_PWM_OUTPUT_PULSE_LENGTH_MICROSECONDS; i >= OFF_PWM_OUTPUT_PULSE_LENGTH_MICROSECONDS; i -= 10) {
foreach(OutputCalibrationUtil * output, m_outputs) {
output->setChannelOutputValue(i);
}
m_outputUtil.setChannelOutputValue(i);
ui->outputLevel->setText(QString(tr("%1 µs")).arg(i));
QApplication::processEvents();
QThread::msleep(200);
}
// Stop output
foreach(OutputCalibrationUtil * output, m_outputs) {
output->stopChannelOutput();
delete output;
}
m_outputUtil.stopChannelOutput();
OutputCalibrationUtil::stopOutputCalibration();
ui->outputLevel->setText(QString(tr("%1 µs")).arg(OFF_PWM_OUTPUT_PULSE_LENGTH_MICROSECONDS));
ui->outputHigh->setEnabled(false);
ui->outputLow->setEnabled(true);
ui->nonconnectedLabel->setEnabled(true);
ui->connectedLabel->setEnabled(false);
m_outputs.clear();
m_outputChannels.clear();
m_isCalibrating = false;
resetAllSecurityCheckboxes();
enableButtons(true);

View File

@ -58,8 +58,8 @@ private:
static const int HIGH_PWM_OUTPUT_PULSE_LENGTH_MICROSECONDS = 1900;
Ui::EscCalibrationPage *ui;
bool m_isCalibrating;
QList<OutputCalibrationUtil *> m_outputs;
OutputCalibrationUtil m_outputUtil;
QList<quint16> m_outputChannels;
};
#endif // ESCCALIBRATIONPAGE_H