dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
outputcalibrationutil.cpp
Go to the documentation of this file.
1 
13 /*
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  * for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  */
27 
28 #include "outputcalibrationutil.h"
29 #include "actuatorcommand.h"
32 #include "manualcontrolsettings.h"
33 
34 #include <QDebug>
35 
37  : QObject(parent)
38  , m_outputChannel(-1)
39  , m_safeValue(1000)
40 {
41  ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
42 
43  m_uavObjectManager = pm->getObject<UAVObjectManager>();
44  Q_ASSERT(m_uavObjectManager);
45 }
46 
48 {
50 }
51 
52 void OutputCalibrationUtil::startChannelOutput(quint16 channel, quint16 safeValue)
53 {
54  if (m_outputChannel < 0 && channel < ActuatorCommand::CHANNEL_NUMELEM) {
55  // Start output...
56  m_outputChannel = channel;
57  m_safeValue = safeValue;
58 
59  qDebug() << "Starting output for channel " << m_outputChannel << "...";
60 
61  ActuatorCommand *actuatorCommand = ActuatorCommand::GetInstance(m_uavObjectManager);
62  Q_ASSERT(actuatorCommand);
63  UAVObject::Metadata metaData = actuatorCommand->getMetadata();
64  m_savedActuatorCommandMetadata = metaData;
65 
66  // Store current data for later restore
67  m_savedActuatorCommandData = actuatorCommand->getData();
68 
69  // Enable actuator control from GCS...
70  // Store current metadata for later restore
73  UAVObject::SetGcsTelemetryAcked(metaData, false);
75  metaData.gcsTelemetryUpdatePeriod = 100;
76 
77  // Apply changes
78  actuatorCommand->setMetadata(metaData);
79  actuatorCommand->updated();
80 
81  qDebug() << "Output for channel " << m_outputChannel << " started.";
82  }
83 }
84 
86 {
87  if (m_outputChannel >= 0) {
88  qDebug() << "Stopping output for channel " << m_outputChannel << "...";
89  // Stop output...
90  setChannelOutputValue(m_safeValue);
91  qDebug() << "Settings output for channel " << m_outputChannel << " to " << m_safeValue;
92 
93  // Restore metadata to what it was before
94  ActuatorCommand *actuatorCommand = ActuatorCommand::GetInstance(m_uavObjectManager);
95  Q_ASSERT(actuatorCommand);
96  // actuatorCommand->setData(m_savedActuatorCommandData);
97  actuatorCommand->setMetadata(m_savedActuatorCommandMetadata);
98  actuatorCommand->updated();
99 
100  qDebug() << "Output for channel " << m_outputChannel << " stopped.";
101 
102  m_outputChannel = -1;
103  }
104 }
105 
107 {
108  if (m_outputChannel >= 0) {
109  // Set output value
110  qDebug() << "Setting output value for channel " << m_outputChannel << " to " << value
111  << ".";
112  ActuatorCommand *actuatorCommand = ActuatorCommand::GetInstance(m_uavObjectManager);
113  Q_ASSERT(actuatorCommand);
114  ActuatorCommand::DataFields data = actuatorCommand->getData();
115  data.Channel[m_outputChannel] = value;
116  actuatorCommand->setData(data);
117  }
118 }
static void SetFlightAccess(Metadata &meta, AccessMode mode)
Definition: uavobject.cpp:387
Core plugin system that manages the plugins, their life cycle and their registered objects...
Definition: pluginmanager.h:53
static void SetGcsTelemetryAcked(Metadata &meta, quint8 val)
Definition: uavobject.cpp:447
DataFields data
static void SetFlightTelemetryUpdateMode(Metadata &meta, UpdateMode val)
Definition: uavobject.cpp:468
void setChannelOutputValue(quint16 value)
void startChannelOutput(quint16 channel, quint16 safeValue)
OutputCalibrationUtil(QObject *parent=nullptr)
static void SetGcsTelemetryUpdateMode(Metadata &meta, UpdateMode val)
Definition: uavobject.cpp:490