QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
ActuatorComponent.cc
Go to the documentation of this file.
1#include "ActuatorComponent.h"
2#include "MAVLinkLib.h"
3#include "QGCApplication.h"
4#include "GeometryImage.h"
6#include "Vehicle.h"
7
8#include <QtQml/QQmlApplicationEngine>
9
10static bool imageProviderAdded{false};
11
12ActuatorComponent::ActuatorComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent)
13 : VehicleComponent(vehicle, autopilot, AutoPilotPlugin::UnknownVehicleComponent, parent)
14 , _name(tr("Actuators"))
15 , _actuators(*vehicle->actuators())
16{
17 if (!imageProviderAdded) {
18 // TODO: qmlAppEngine should not be accessed inside app
19 qgcApp()->qmlAppEngine()->addImageProvider(QLatin1String("actuators"), GeometryImage::VehicleGeometryImageProvider::instance());
20 imageProviderAdded = true;
21 }
22
23 connect(&_actuators, &Actuators::hasUnsetRequiredFunctionsChanged, this, [this]() { _triggerUpdated({}); });
24}
25
26QString ActuatorComponent::name(void) const
27{
28 return _name;
29}
30
32{
33 return "";
34}
35
37{
38 return QStringLiteral("/qmlimages/MotorComponentIcon.svg");
39}
40
42{
43 return true;
44}
45
47{
48 return !_actuators.hasUnsetRequiredFunctions();
49}
50
52{
53 return QStringList();
54}
55
57{
58 return QUrl::fromUserInput(QStringLiteral("qrc:/qml/QGroundControl/AutoPilotPlugins/PX4/ActuatorComponent.qml"));
59}
60
62{
63 return QUrl();
64}
65
66QList<VehicleSummaryItem> ActuatorComponent::summaryItems() const
67{
68 if (!_actuators.isInitialized()) {
69 return {};
70 }
71
72 QList<VehicleSummaryItem> items;
73 Mixer::Mixers* const mixer = _actuators.mixer();
74 const QString geometry = mixer->title();
75 if (!geometry.isEmpty()) {
76 items.append({tr("Geometry"), geometry});
77 }
78 if (_actuators.hasUnsetRequiredFunctions()) {
79 items.append({tr("Required Outputs"), tr("Setup required"), VehicleSummaryItem::Attention});
80 }
81
82 const auto groupTitle = [mixer](int function) {
83 const Mixer::ActuatorTypes& actuatorTypes = mixer->actuatorTypes();
84 for (auto it = actuatorTypes.cbegin(); it != actuatorTypes.cend(); ++it) {
85 if (function < it->functionMin || function > it->functionMax) {
86 continue;
87 }
88 switch (ActuatorGeometry::typeFromStr(it.key())) {
90 return tr("Motors");
92 return tr("Servos");
93 default:
94 break;
95 }
96 break;
97 }
98
99 return tr("Other Outputs");
100 };
101
102 const QMap<int, QStringList> channels = _actuators.channelsByFunction();
103 for (auto it = channels.cbegin(); it != channels.cend(); ++it) {
104 const QString label = mixer->getSpecificLabelForFunction(it.key());
105 items.append({label.isEmpty() ? tr("Function %1").arg(it.key()) : label,
106 it.value().join(QStringLiteral(", ")), VehicleSummaryItem::Normal, groupTitle(it.key())});
107 }
108
109 return items;
110}
static bool imageProviderAdded
#define qgcApp()
QUrl summaryQmlSource(void) const final
virtual QUrl setupSource(void) const
QString description(void) const final
ActuatorComponent(Vehicle *vehicle, AutoPilotPlugin *autopilot, QObject *parent=nullptr)
QList< VehicleSummaryItem > summaryItems() const final
Values for this component's card on the Summary page. A component with none falls back to summaryQmlS...
QString name(void) const final
QStringList setupCompleteChangedTriggerList(void) const final
bool setupComplete(void) const final
QString iconResource(void) const final
bool requiresSetup(void) const final
void hasUnsetRequiredFunctionsChanged()
The AutoPilotPlugin class is an abstract base class which represents the methods and objects which ar...
static VehicleGeometryImageProvider * instance()
const ActuatorTypes & actuatorTypes() const
Definition Mixer.h:378
QString getSpecificLabelForFunction(int function) const
Definition Mixer.cc:545
QString title() const
Definition Mixer.cc:614
VehicleComponent(Vehicle *vehicle, AutoPilotPlugin *autopilot, AutoPilotPlugin::KnownVehicleComponent KnownVehicleComponent, QObject *parent=nullptr)
void _triggerUpdated(QVariant)
QMap< QString, ActuatorType > ActuatorTypes
key is the group name, where 'DEFAULT' is the default group
Definition Mixer.h:52
static Type typeFromStr(const QString &type)
Definition Common.cc:244