2012-09-03 01:01:57 +02:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file outputcalibrationutil.cpp
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
|
|
|
|
* @addtogroup
|
|
|
|
* @{
|
|
|
|
* @addtogroup OutputCalibrationUtil
|
|
|
|
* @{
|
|
|
|
* @brief
|
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "outputcalibrationutil.h"
|
2014-10-31 11:50:00 +01:00
|
|
|
#include "uavobject.h"
|
|
|
|
#include "uavobjectmanager.h"
|
2012-09-03 01:01:57 +02:00
|
|
|
#include "extensionsystem/pluginmanager.h"
|
2012-09-04 01:28:28 +02:00
|
|
|
#include "vehicleconfigurationhelper.h"
|
2012-09-07 07:35:43 +02:00
|
|
|
#include "manualcontrolsettings.h"
|
2012-09-04 01:28:28 +02:00
|
|
|
|
2014-10-30 10:56:00 +01:00
|
|
|
bool OutputCalibrationUtil::c_prepared = false;
|
|
|
|
ActuatorCommand::Metadata OutputCalibrationUtil::c_savedActuatorCommandMetaData;
|
|
|
|
|
2012-09-03 01:01:57 +02:00
|
|
|
OutputCalibrationUtil::OutputCalibrationUtil(QObject *parent) :
|
2014-11-06 22:32:21 +01:00
|
|
|
QObject(parent), m_safeValue(1000)
|
2014-11-03 23:09:26 +01:00
|
|
|
{}
|
2012-09-03 01:01:57 +02:00
|
|
|
|
2012-09-05 00:58:53 +02:00
|
|
|
OutputCalibrationUtil::~OutputCalibrationUtil()
|
2012-09-03 01:01:57 +02:00
|
|
|
{
|
2012-09-05 00:58:53 +02:00
|
|
|
stopChannelOutput();
|
|
|
|
}
|
|
|
|
|
2014-11-03 23:09:26 +01:00
|
|
|
ActuatorCommand *OutputCalibrationUtil::getActuatorCommandObject()
|
2014-10-31 11:50:00 +01:00
|
|
|
{
|
|
|
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
2014-11-03 23:09:26 +01:00
|
|
|
|
2014-10-31 11:50:00 +01:00
|
|
|
Q_ASSERT(pm);
|
|
|
|
|
|
|
|
UAVObjectManager *uavObjectManager = pm->getObject<UAVObjectManager>();
|
|
|
|
Q_ASSERT(uavObjectManager);
|
|
|
|
|
2014-11-03 23:09:26 +01:00
|
|
|
ActuatorCommand *actuatorCommand = ActuatorCommand::GetInstance(uavObjectManager);
|
2014-10-31 11:50:00 +01:00
|
|
|
Q_ASSERT(actuatorCommand);
|
|
|
|
|
|
|
|
return actuatorCommand;
|
|
|
|
}
|
|
|
|
|
2014-10-30 10:56:00 +01:00
|
|
|
void OutputCalibrationUtil::startOutputCalibration()
|
2012-09-05 00:58:53 +02:00
|
|
|
{
|
2014-10-30 10:56:00 +01:00
|
|
|
if (!c_prepared) {
|
2014-10-31 11:50:00 +01:00
|
|
|
ActuatorCommand *actuatorCommand = getActuatorCommandObject();
|
2013-05-19 16:37:30 +02:00
|
|
|
UAVObject::Metadata metaData = actuatorCommand->getMetadata();
|
2014-10-30 10:56:00 +01:00
|
|
|
c_savedActuatorCommandMetaData = metaData;
|
2012-09-05 00:58:53 +02:00
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
// Enable actuator control from GCS...
|
|
|
|
// Store current metadata for later restore
|
2012-09-03 01:01:57 +02:00
|
|
|
UAVObject::SetFlightAccess(metaData, UAVObject::ACCESS_READONLY);
|
|
|
|
UAVObject::SetFlightTelemetryUpdateMode(metaData, UAVObject::UPDATEMODE_ONCHANGE);
|
|
|
|
UAVObject::SetGcsTelemetryAcked(metaData, false);
|
|
|
|
UAVObject::SetGcsTelemetryUpdateMode(metaData, UAVObject::UPDATEMODE_ONCHANGE);
|
|
|
|
metaData.gcsTelemetryUpdatePeriod = 100;
|
2012-09-05 00:58:53 +02:00
|
|
|
|
2013-05-19 16:37:30 +02:00
|
|
|
// Apply changes
|
2012-09-03 01:01:57 +02:00
|
|
|
actuatorCommand->setMetadata(metaData);
|
|
|
|
actuatorCommand->updated();
|
2014-10-30 10:56:00 +01:00
|
|
|
c_prepared = true;
|
|
|
|
qDebug() << "OutputCalibrationUtil started.";
|
2012-09-03 01:01:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-30 10:56:00 +01:00
|
|
|
void OutputCalibrationUtil::stopOutputCalibration()
|
2012-09-03 01:01:57 +02:00
|
|
|
{
|
2014-10-30 10:56:00 +01:00
|
|
|
if (c_prepared) {
|
2014-10-31 11:50:00 +01:00
|
|
|
ActuatorCommand *actuatorCommand = getActuatorCommandObject();
|
2014-10-30 10:56:00 +01:00
|
|
|
actuatorCommand->setMetadata(c_savedActuatorCommandMetaData);
|
2012-09-03 01:01:57 +02:00
|
|
|
actuatorCommand->updated();
|
2014-10-30 10:56:00 +01:00
|
|
|
c_prepared = false;
|
|
|
|
qDebug() << "OutputCalibrationUtil stopped.";
|
|
|
|
}
|
|
|
|
}
|
2012-09-03 01:01:57 +02:00
|
|
|
|
2014-11-14 01:05:54 +01:00
|
|
|
void OutputCalibrationUtil::startChannelOutput(quint16 channel, quint16 safeValue)
|
|
|
|
{
|
2014-11-06 22:32:21 +01:00
|
|
|
QList<quint16> channels;
|
|
|
|
channels.append(channel);
|
|
|
|
startChannelOutput(channels, safeValue);
|
|
|
|
}
|
|
|
|
|
2015-03-01 22:48:35 +01:00
|
|
|
void OutputCalibrationUtil::startChannelOutput(QList<quint16> &channels, quint16 safeValue)
|
2014-10-30 10:56:00 +01:00
|
|
|
{
|
|
|
|
if (c_prepared) {
|
2014-11-06 22:32:21 +01:00
|
|
|
m_outputChannels = channels;
|
|
|
|
m_safeValue = safeValue;
|
2014-10-30 10:56:00 +01:00
|
|
|
} else {
|
|
|
|
qDebug() << "OutputCalibrationUtil not started.";
|
|
|
|
}
|
|
|
|
}
|
2012-09-04 01:28:28 +02:00
|
|
|
|
2014-10-30 10:56:00 +01:00
|
|
|
void OutputCalibrationUtil::stopChannelOutput()
|
|
|
|
{
|
|
|
|
if (c_prepared) {
|
2014-11-06 22:32:21 +01:00
|
|
|
setChannelOutputValue(m_safeValue);
|
|
|
|
m_outputChannels.clear();
|
|
|
|
qDebug() << "OutputCalibrationUtil output stopped.";
|
2014-10-30 10:56:00 +01:00
|
|
|
} else {
|
|
|
|
qDebug() << "OutputCalibrationUtil not started.";
|
2012-09-03 01:01:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OutputCalibrationUtil::setChannelOutputValue(quint16 value)
|
|
|
|
{
|
2014-10-30 10:56:00 +01:00
|
|
|
if (c_prepared) {
|
2014-11-06 22:32:21 +01:00
|
|
|
ActuatorCommand *actuatorCommand = getActuatorCommandObject();
|
|
|
|
ActuatorCommand::DataFields data = actuatorCommand->getData();
|
2014-11-14 01:05:54 +01:00
|
|
|
foreach(quint32 channel, m_outputChannels) {
|
2014-10-30 10:56:00 +01:00
|
|
|
// Set output value
|
2014-11-14 01:05:54 +01:00
|
|
|
if (channel <= ActuatorCommand::CHANNEL_NUMELEM) {
|
2014-11-06 22:32:21 +01:00
|
|
|
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 << ".";
|
|
|
|
}
|
2014-10-30 10:56:00 +01:00
|
|
|
}
|
2014-11-06 22:32:21 +01:00
|
|
|
actuatorCommand->setData(data);
|
|
|
|
} else {
|
|
|
|
qDebug() << "OutputCalibrationUtil not started.";
|
2012-09-03 01:01:57 +02:00
|
|
|
}
|
|
|
|
}
|