mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-29 14:52:12 +01:00
Merge branch 'thread/OP-1586_Test_Output' into rel-14.10
This commit is contained in:
commit
f36c2b31f3
@ -26,18 +26,18 @@
|
||||
*/
|
||||
|
||||
#include "outputcalibrationutil.h"
|
||||
#include "actuatorcommand.h"
|
||||
#include "uavobject.h"
|
||||
#include "uavobjectmanager.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include "vehicleconfigurationhelper.h"
|
||||
#include "manualcontrolsettings.h"
|
||||
|
||||
bool OutputCalibrationUtil::c_prepared = false;
|
||||
ActuatorCommand::Metadata OutputCalibrationUtil::c_savedActuatorCommandMetaData;
|
||||
|
||||
OutputCalibrationUtil::OutputCalibrationUtil(QObject *parent) :
|
||||
QObject(parent), m_outputChannel(-1), m_safeValue(1000)
|
||||
{
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
|
||||
m_uavObjectManager = pm->getObject<UAVObjectManager>();
|
||||
Q_ASSERT(m_uavObjectManager);
|
||||
}
|
||||
|
||||
OutputCalibrationUtil::~OutputCalibrationUtil()
|
||||
@ -45,22 +45,26 @@ OutputCalibrationUtil::~OutputCalibrationUtil()
|
||||
stopChannelOutput();
|
||||
}
|
||||
|
||||
void OutputCalibrationUtil::startChannelOutput(quint16 channel, quint16 safeValue)
|
||||
ActuatorCommand * OutputCalibrationUtil::getActuatorCommandObject()
|
||||
{
|
||||
if (m_outputChannel < 0 && channel < ActuatorCommand::CHANNEL_NUMELEM) {
|
||||
// Start output...
|
||||
m_outputChannel = channel;
|
||||
m_safeValue = safeValue;
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
Q_ASSERT(pm);
|
||||
|
||||
qDebug() << "Starting output for channel " << m_outputChannel + 1 << "...";
|
||||
UAVObjectManager *uavObjectManager = pm->getObject<UAVObjectManager>();
|
||||
Q_ASSERT(uavObjectManager);
|
||||
|
||||
ActuatorCommand *actuatorCommand = ActuatorCommand::GetInstance(m_uavObjectManager);
|
||||
Q_ASSERT(actuatorCommand);
|
||||
ActuatorCommand *actuatorCommand = ActuatorCommand::GetInstance(uavObjectManager);
|
||||
Q_ASSERT(actuatorCommand);
|
||||
|
||||
return actuatorCommand;
|
||||
}
|
||||
|
||||
void OutputCalibrationUtil::startOutputCalibration()
|
||||
{
|
||||
if (!c_prepared) {
|
||||
ActuatorCommand *actuatorCommand = getActuatorCommandObject();
|
||||
UAVObject::Metadata metaData = actuatorCommand->getMetadata();
|
||||
m_savedActuatorCommandMetadata = metaData;
|
||||
|
||||
// Store current data for later restore
|
||||
m_savedActuatorCommandData = actuatorCommand->getData();
|
||||
c_savedActuatorCommandMetaData = metaData;
|
||||
|
||||
// Enable actuator control from GCS...
|
||||
// Store current metadata for later restore
|
||||
@ -73,41 +77,65 @@ void OutputCalibrationUtil::startChannelOutput(quint16 channel, quint16 safeValu
|
||||
// Apply changes
|
||||
actuatorCommand->setMetadata(metaData);
|
||||
actuatorCommand->updated();
|
||||
c_prepared = true;
|
||||
qDebug() << "OutputCalibrationUtil started.";
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << "Output for channel " << m_outputChannel + 1 << " started.";
|
||||
void OutputCalibrationUtil::stopOutputCalibration()
|
||||
{
|
||||
if (c_prepared) {
|
||||
ActuatorCommand *actuatorCommand = getActuatorCommandObject();
|
||||
actuatorCommand->setMetadata(c_savedActuatorCommandMetaData);
|
||||
actuatorCommand->updated();
|
||||
c_prepared = false;
|
||||
qDebug() << "OutputCalibrationUtil stopped.";
|
||||
}
|
||||
}
|
||||
|
||||
void OutputCalibrationUtil::startChannelOutput(quint16 channel, quint16 safeValue)
|
||||
{
|
||||
if (c_prepared) {
|
||||
if (m_outputChannel < 0 && channel < ActuatorCommand::CHANNEL_NUMELEM) {
|
||||
// Start output...
|
||||
m_outputChannel = channel;
|
||||
m_safeValue = safeValue;
|
||||
qDebug() << "Output for channel " << m_outputChannel + 1 << " started.";
|
||||
}
|
||||
} else {
|
||||
qDebug() << "OutputCalibrationUtil not started.";
|
||||
}
|
||||
}
|
||||
|
||||
void OutputCalibrationUtil::stopChannelOutput()
|
||||
{
|
||||
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;
|
||||
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.";
|
||||
|
||||
// Restore metadata to what it was before
|
||||
ActuatorCommand *actuatorCommand = ActuatorCommand::GetInstance(m_uavObjectManager);
|
||||
Q_ASSERT(actuatorCommand);
|
||||
// actuatorCommand->setData(m_savedActuatorCommandData);
|
||||
actuatorCommand->setMetadata(m_savedActuatorCommandMetadata);
|
||||
actuatorCommand->updated();
|
||||
|
||||
qDebug() << "Output for channel " << m_outputChannel + 1 << " stopped.";
|
||||
|
||||
m_outputChannel = -1;
|
||||
m_outputChannel = -1;
|
||||
}
|
||||
} else {
|
||||
qDebug() << "OutputCalibrationUtil not started.";
|
||||
}
|
||||
}
|
||||
|
||||
void OutputCalibrationUtil::setChannelOutputValue(quint16 value)
|
||||
{
|
||||
if (m_outputChannel >= 0) {
|
||||
// Set output value
|
||||
qDebug() << "Setting output value for channel " << m_outputChannel << " to " << value << ".";
|
||||
ActuatorCommand *actuatorCommand = ActuatorCommand::GetInstance(m_uavObjectManager);
|
||||
Q_ASSERT(actuatorCommand);
|
||||
ActuatorCommand::DataFields data = actuatorCommand->getData();
|
||||
data.Channel[m_outputChannel] = value;
|
||||
actuatorCommand->setData(data);
|
||||
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;
|
||||
actuatorCommand->setData(data);
|
||||
} else {
|
||||
qDebug() << "OutputCalibrationUtil not started.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,10 +29,6 @@
|
||||
#define OUTPUTCALIBRATIONUTIL_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include "uavobject.h"
|
||||
#include "uavobjectmanager.h"
|
||||
#include "vehicleconfigurationsource.h"
|
||||
#include "actuatorcommand.h"
|
||||
|
||||
|
||||
@ -42,20 +38,20 @@ public:
|
||||
explicit OutputCalibrationUtil(QObject *parent = 0);
|
||||
~OutputCalibrationUtil();
|
||||
|
||||
signals:
|
||||
static void startOutputCalibration();
|
||||
static void stopOutputCalibration();
|
||||
static ActuatorCommand * getActuatorCommandObject();
|
||||
|
||||
public slots:
|
||||
void startChannelOutput(quint16 channel, quint16 safeValue);
|
||||
void stopChannelOutput();
|
||||
|
||||
void setChannelOutputValue(quint16 value);
|
||||
|
||||
private:
|
||||
static bool c_prepared;
|
||||
static ActuatorCommand::Metadata c_savedActuatorCommandMetaData;
|
||||
qint16 m_outputChannel;
|
||||
quint16 m_safeValue;
|
||||
UAVObject::Metadata m_savedActuatorCommandMetadata;
|
||||
ActuatorCommand::DataFields m_savedActuatorCommandData;
|
||||
UAVObjectManager *m_uavObjectManager;
|
||||
};
|
||||
|
||||
#endif // OUTPUTCALIBRATIONUTIL_H
|
||||
|
@ -102,6 +102,7 @@ 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);
|
||||
@ -145,6 +146,7 @@ void EscCalibrationPage::stopButtonClicked()
|
||||
output->stopChannelOutput();
|
||||
delete output;
|
||||
}
|
||||
OutputCalibrationUtil::stopOutputCalibration();
|
||||
ui->outputLevel->setText(QString(tr("%1 µs")).arg(OFF_PWM_OUTPUT_PULSE_LENGTH_MICROSECONDS));
|
||||
ui->outputHigh->setEnabled(false);
|
||||
ui->outputLow->setEnabled(true);
|
||||
|
@ -274,7 +274,6 @@ void OutputCalibrationPage::setupVehicleHighlightedPart()
|
||||
void OutputCalibrationPage::setWizardPage()
|
||||
{
|
||||
qDebug() << "Wizard index: " << m_currentWizardIndex;
|
||||
m_calibrationUtil->stopChannelOutput();
|
||||
|
||||
QApplication::processEvents();
|
||||
|
||||
@ -386,6 +385,7 @@ void OutputCalibrationPage::onStartButtonToggle(QAbstractButton *button, quint16
|
||||
if (checkAlarms()) {
|
||||
enableButtons(false);
|
||||
enableServoSliders(true);
|
||||
OutputCalibrationUtil::startOutputCalibration();
|
||||
m_calibrationUtil->startChannelOutput(channel, safeValue);
|
||||
slider->setValue(value);
|
||||
m_calibrationUtil->setChannelOutputValue(value);
|
||||
@ -394,6 +394,7 @@ void OutputCalibrationPage::onStartButtonToggle(QAbstractButton *button, quint16
|
||||
}
|
||||
} else {
|
||||
m_calibrationUtil->stopChannelOutput();
|
||||
OutputCalibrationUtil::stopOutputCalibration();
|
||||
enableServoSliders(false);
|
||||
enableButtons(true);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user