1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-09 20:46:07 +01:00
LibrePilot/ground/openpilotgcs/src/plugins/setupwizard/outputcalibrationutil.cpp
Kevin Finisterre 4ebaa6f205 set all the min and max values to 554 and 2400 per the Arduino servo library
fix some cosmetic errors on the debug output
fix the Vtail mixer setting that caused channel 4 to go crazy due to being undefined. Servo would sit and shake for no reason.
2014-05-25 16:05:13 -04:00

114 lines
4.2 KiB
C++

/**
******************************************************************************
*
* @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"
#include "actuatorcommand.h"
#include "extensionsystem/pluginmanager.h"
#include "vehicleconfigurationhelper.h"
#include "manualcontrolsettings.h"
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()
{
stopChannelOutput();
}
void OutputCalibrationUtil::startChannelOutput(quint16 channel, quint16 safeValue)
{
if (m_outputChannel < 0 && channel < ActuatorCommand::CHANNEL_NUMELEM) {
// Start output...
m_outputChannel = channel;
m_safeValue = safeValue;
qDebug() << "Starting output for channel " << m_outputChannel+1 << "...";
ActuatorCommand *actuatorCommand = ActuatorCommand::GetInstance(m_uavObjectManager);
Q_ASSERT(actuatorCommand);
UAVObject::Metadata metaData = actuatorCommand->getMetadata();
m_savedActuatorCommandMetadata = metaData;
// Store current data for later restore
m_savedActuatorCommandData = actuatorCommand->getData();
// Enable actuator control from GCS...
// Store current metadata for later restore
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;
// Apply changes
actuatorCommand->setMetadata(metaData);
actuatorCommand->updated();
qDebug() << "Output for channel " << m_outputChannel+1 << " 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;
// 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;
}
}
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);
}
}