QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
ActuatorOutputs.cc
Go to the documentation of this file.
1#include "ActuatorOutputs.h"
2#include "MAVLinkLib.h"
3#include "ParameterManager.h"
5
6QGC_LOGGING_CATEGORY(ActuatorOutputsLog, "Vehicle.Actuators.ActuatorOutputs")
7
8using namespace ActuatorOutputs;
9
10void ChannelConfig::reevaluate()
11{
12 emit visibleChanged();
13}
14
15ActuatorOutputChannel::ActuatorOutputChannel(QObject *parent, const QString &label, int paramIndex,
16 QmlObjectListModel &channelConfigs, ParameterManager* parameterManager, std::function<void(Fact*)> factAddedCb) :
17 QObject(parent), _label(label), _paramIndex(paramIndex)
18{
19 for (int i = 0; i < channelConfigs.count(); ++i) {
20 auto channelConfig = channelConfigs.value<ChannelConfig*>(i);
21 QString param = channelConfig->parameter();
22 QString sparamIndex = QString::number(paramIndex + channelConfig->indexOffset());
23 param.replace("${i}", sparamIndex);
24
25 Fact* fact = nullptr;
26 if (parameterManager->parameterExists(ParameterManager::defaultComponentId, param)) {
27 fact = parameterManager->getParameter(ParameterManager::defaultComponentId, param);
28 if (channelConfig->displayOption() == Parameter::DisplayOption::Bitset) {
29 fact = new FactBitset(channelConfig, fact, paramIndex + channelConfig->indexOffset());
30 } else if (channelConfig->displayOption() == Parameter::DisplayOption::BoolTrueIfPositive) {
31 fact = new FactFloatAsBool(channelConfig, fact);
32 }
33 factAddedCb(fact);
34 } else {
35 qCDebug(ActuatorOutputsLog) << "ActuatorOutputChannel: Param does not exist:" << param;
36 }
37
38 ChannelConfigInstance *instance = new ChannelConfigInstance(this, fact, *channelConfig);
39 _configInstances->append(instance);
40 }
41}
42
44{
45 _channelConfigs->append(channelConfig);
47}
48
50{
51 _channels->append(channel);
52 emit channelsChanged();
53}
54
56{
58 delete _primaryParam;
59 _primaryParam = param;
60 } else {
61 _params->append(param);
62 }
63}
64
65ActuatorOutput::ActuatorOutput(QObject* parent, const QString& label, const Condition& groupVisibilityCondition)
66 : QObject(parent), _label(label), _groupVisibilityCondition(groupVisibilityCondition)
67{
68 if (_groupVisibilityCondition.fact()) {
69 connect(_groupVisibilityCondition.fact(), &Fact::rawValueChanged, this, &ActuatorOutput::groupsVisibleChanged);
70 }
71}
72
74{
75 _subgroups->append(subgroup);
76 emit subgroupsChanged();
77}
78
80{
82 delete _enableParam;
83 _enableParam = param;
84 } else {
85 _params->append(param);
86 }
87}
88
89void ActuatorOutput::getAllChannelFunctions(QList<Fact*> &allFunctions) const
90{
92 allFunctions.append(fact);
93 });
94}
95
97 bool hasExistingOutputFunction = false;
98 forEachOutputFunction([&hasExistingOutputFunction](
100 [[maybe_unused]] Fact *fact) { hasExistingOutputFunction = true; });
101 return hasExistingOutputFunction;
102}
103
105{
106 for (int subgroupIdx = 0; subgroupIdx < _subgroups->count(); subgroupIdx++) {
107 ActuatorOutputSubgroup *subgroup = qobject_cast<ActuatorOutputSubgroup*>(_subgroups->get(subgroupIdx));
108 for (int channelIdx = 0; channelIdx < subgroup->channels()->count(); channelIdx++) {
109 ActuatorOutputChannel *channel = qobject_cast<ActuatorOutputChannel*>(subgroup->channels()->get(channelIdx));
110 for (int configIdx = 0; configIdx < channel->configInstances()->count(); configIdx++) {
111 ChannelConfigInstance *configInstance = qobject_cast<ChannelConfigInstance*>(channel->configInstances()->get(configIdx));
112 Fact* fact = configInstance->fact();
113 if (configInstance->channelConfig()->function() == ChannelConfig::Function::OutputFunction && fact) {
114 callback(subgroup, configInstance, fact);
115 }
116 }
117 }
118 }
119}
#define QGC_LOGGING_CATEGORY(name, categoryStr)
ActuatorOutputChannel(QObject *parent, const QString &label, int paramIndex, QmlObjectListModel &channelConfigs, ParameterManager *parameterManager, std::function< void(Fact *)> factAddedCb)
void addConfigParam(ConfigParameter *param)
void addChannel(ActuatorOutputChannel *channel)
void addChannelConfig(ChannelConfig *channelConfig)
ActuatorOutput(QObject *parent, const QString &label, const Condition &groupVisibilityCondition)
void forEachOutputFunction(std::function< void(ActuatorOutputSubgroup *, ChannelConfigInstance *, Fact *)> callback) const
void getAllChannelFunctions(QList< Fact * > &allFunctions) const
void addConfigParam(ConfigParameter *param)
void addSubgroup(ActuatorOutputSubgroup *subgroup)
const QString & parameter() const
@ Primary
Primary parameter to configure the group of outputs.
@ Enable
Parameter to enable/disable the outputs.
Fact * fact() const
Definition Common.h:101
A Fact is used to hold a single value within the system.
Definition Fact.h:17
void rawValueChanged(const QVariant &value)
bool parameterExists(int componentId, const QString &paramName) const
Fact * getParameter(int componentId, const QString &paramName)
static constexpr int defaultComponentId
void append(QObject *object)
Caller maintains responsibility for object ownership and deletion.
T value(int index) const
Q_INVOKABLE QObject * get(int index)
int count() const override final
@ Bitset
integer displayed as boolean (checkbox), where the index defines the bit
@ BoolTrueIfPositive
Show checkbox for float/int value.