QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
PX4AutoPilotPlugin.cc
Go to the documentation of this file.
2#include "PX4AirframeLoader.h"
3#include "AppMessages.h"
5#include "PX4RadioComponent.h"
7#include "PowerComponent.h"
8#include "SafetyComponent.h"
9#include "SensorsComponent.h"
10#include "ParameterManager.h"
11#include "Vehicle.h"
12#include "Actuators.h"
13#include "ActuatorComponent.h"
14#include "QGCLoggingCategory.h"
15
16#include <algorithm>
17
18QGC_LOGGING_CATEGORY(PX4AutoPilotPluginLog, "Vehicle.Actuators.PX4AutoPilotPlugin")
19
21 : AutoPilotPlugin(vehicle, parent)
22 , _incorrectParameterVersion(false)
23 , _airframeComponent(nullptr)
24 , _radioComponent(nullptr)
25 , _esp8266Component(nullptr)
26 , _flightModesComponent(nullptr)
27 , _sensorsComponent(nullptr)
28 , _safetyComponent(nullptr)
29 , _powerComponent(nullptr)
30 , _motorComponent(nullptr)
31 , _actuatorComponent(nullptr)
32 , _tuningComponent(nullptr)
33 , _flightBehavior(nullptr)
34 , _syslinkComponent(nullptr)
35 , _joystickComponent(nullptr)
36{
37 if (!vehicle) {
38 qWarning() << "Internal error";
39 return;
40 }
41
42 _airframeFacts = new PX4AirframeLoader(this, this);
43 Q_CHECK_PTR(_airframeFacts);
44
46}
47
52
54{
55 if (_components.count() == 0 && !_incorrectParameterVersion) {
56 if (_vehicle) {
60 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_airframeComponent)));
61
62 if (!_vehicle->hilMode()) {
65 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_sensorsComponent)));
66 }
67
70 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_radioComponent)));
71
74 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_flightModesComponent)));
75
76 _powerComponent = new PowerComponent(_vehicle, this, this);
78 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_powerComponent)));
79
80 if (_vehicle->actuators()) {
81 _vehicle->actuators()->init(); // At this point params are loaded, so we can init the actuators
82 }
83
84 // Decide between new Actuators page or legacy Motor page
85 bool showActuatorsPage = false;
86 if (!_vehicle->actuators()) {
87 qCDebug(PX4AutoPilotPluginLog) << "Actuators page will NOT show because:";
88 qCDebug(PX4AutoPilotPluginLog) << " - Vehicle did not provide actuators metadata via component information";
89 } else if (!_vehicle->actuators()->showUi()) {
90 qCDebug(PX4AutoPilotPluginLog) << "Actuators page will NOT show because:";
91 if (!_vehicle->actuators()->isInitialized()) {
92 qCDebug(PX4AutoPilotPluginLog) << " - Actuators initialization failed:" << _vehicle->actuators()->initializationError();
93 } else {
94 qCDebug(PX4AutoPilotPluginLog) << " - Condition 'show-ui-if' evaluated to false";
95 qCDebug(PX4AutoPilotPluginLog) << " (see 'Evaluating [show-ui-if]' log above for details)";
96 }
97 } else {
98 showActuatorsPage = true;
99 qCDebug(PX4AutoPilotPluginLog) << "Actuators page WILL show (all conditions passed)";
100 }
101
102 if (showActuatorsPage) {
105 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_actuatorComponent)));
106 } else {
107 qCDebug(PX4AutoPilotPluginLog) << " → Using legacy Motor page instead";
108 _motorComponent = new MotorComponent(_vehicle, this, this);
110 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_motorComponent)));
111 }
112
113 _safetyComponent = new SafetyComponent(_vehicle, this, this);
115 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_safetyComponent)));
116
119 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_tuningComponent)));
120
121 if(_vehicle->parameterManager()->parameterExists(_vehicle->compId(), "SYS_VEHICLE_RESP")) {
122 _flightBehavior = new PX4FlightBehavior(_vehicle, this, this);
124 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_flightBehavior)));
125 }
126
127 //-- Is there an ESP8266 Connected?
128 if(_vehicle->parameterManager()->parameterExists(MAV_COMP_ID_UDP_BRIDGE, "SW_VER")) {
131 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_esp8266Component)));
132 }
133
136 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_joystickComponent)));
137
138 } else {
139 qWarning() << "Call to vehicleCompenents prior to parametersReady";
140 }
141
142 if(_vehicle->parameterManager()->parameterExists(_vehicle->compId(), "SLNK_RADIO_CHAN")) {
145 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_syslinkComponent)));
146 }
147 } else {
148 qWarning() << "Internal error";
149 }
150
151 std::sort(_components.begin(), _components.end(), [](const QVariant &a, const QVariant &b) {
152 return a.value<VehicleComponent*>()->name().toLower() < b.value<VehicleComponent*>()->name().toLower();
153 });
154 }
155
156 return _components;
157}
158
160{
161 // Base class must be called
163
164 QString hitlParam("SYS_HITL");
167 QGC::showAppMessage(tr("Warning: Hardware In The Loop (HITL) simulation is enabled for this vehicle."));
168 }
169}
170
172{
173 bool requiresAirframeCheck = false;
174
175 if (qobject_cast<const FlightModesComponent*>(component)) {
176 if (_vehicle->parameterManager()->getParameter(-1, "COM_RC_IN_MODE")->rawValue().toInt() == 1) {
177 // No RC input
178 return QString();
179 } else {
181 return _airframeComponent->name();
183 return _radioComponent->name();
184 }
185 }
186 } else if (qobject_cast<const PX4RadioComponent*>(component)) {
187 if (_vehicle->parameterManager()->getParameter(-1, "COM_RC_IN_MODE")->rawValue().toInt() != 1) {
188 //requiresAirframeCheck = true;
189 }
190 } else if (qobject_cast<const PX4TuningComponent*>(component)) {
191 requiresAirframeCheck = true;
192 } else if (qobject_cast<const PowerComponent*>(component)) {
193 requiresAirframeCheck = true;
194 } else if (qobject_cast<const SafetyComponent*>(component)) {
195 requiresAirframeCheck = true;
196 } else if (qobject_cast<const SensorsComponent*>(component)) {
197 requiresAirframeCheck = true;
198 }
199
200 if (requiresAirframeCheck) {
202 return _airframeComponent->name();
203 }
204 }
205
206 return QString();
207}
#define QGC_LOGGING_CATEGORY(name, categoryStr)
bool showUi() const
Definition Actuators.cc:777
const QString & initializationError() const
Definition Actuators.h:63
bool isInitialized() const
Definition Actuators.h:62
void init()
Definition Actuators.cc:139
virtual QString name(void) const
virtual bool setupComplete(void) const
The AutoPilotPlugin class is an abstract base class which represents the methods and objects which ar...
virtual void parametersReadyPreChecks()
QVariant rawValue() const
Value after translation.
Definition Fact.h:85
Collection of Parameter Facts for PX4 AutoPilot.
static void loadAirframeMetaData(void)
SafetyComponent * _safetyComponent
PX4RadioComponent * _radioComponent
bool _incorrectParameterVersion
true: parameter version incorrect, setup not allowed
QString prerequisiteSetup(VehicleComponent *component) const override
Returns the name of the vehicle component which must complete setup prior to this one....
AirframeComponent * _airframeComponent
PowerComponent * _powerComponent
PX4TuningComponent * _tuningComponent
const QVariantList & vehicleComponents(void) override
void parametersReadyPreChecks(void) override
JoystickComponent * _joystickComponent
SyslinkComponent * _syslinkComponent
PX4FlightBehavior * _flightBehavior
ActuatorComponent * _actuatorComponent
ESP8266Component * _esp8266Component
PX4AirframeLoader * _airframeFacts
SensorsComponent * _sensorsComponent
MotorComponent * _motorComponent
FlightModesComponent * _flightModesComponent
virtual QString name(void) const
virtual bool setupComplete(void) const
bool parameterExists(int componentId, const QString &paramName) const
Fact * getParameter(int componentId, const QString &paramName)
bool parametersReady() const
static constexpr int defaultComponentId
A vehicle component is an object which abstracts the physical portion of a vehicle into a set of conf...
virtual void setupTriggerSignals()
bool hilMode() const
Definition Vehicle.h:536
Actuators * actuators() const
Definition Vehicle.h:537
int compId() const
Definition Vehicle.h:426
ParameterManager * parameterManager()
Definition Vehicle.h:573
void showAppMessage(const QString &message, const QString &title)
Modal application message. Queued if the UI isn't ready yet.
Definition AppMessages.cc:9