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 "QGCApplication.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
16 : AutoPilotPlugin(vehicle, parent)
17 , _incorrectParameterVersion(false)
18 , _airframeComponent(nullptr)
19 , _radioComponent(nullptr)
20 , _esp8266Component(nullptr)
21 , _flightModesComponent(nullptr)
22 , _sensorsComponent(nullptr)
23 , _safetyComponent(nullptr)
24 , _powerComponent(nullptr)
25 , _motorComponent(nullptr)
26 , _actuatorComponent(nullptr)
27 , _tuningComponent(nullptr)
28 , _flightBehavior(nullptr)
29 , _syslinkComponent(nullptr)
30 , _joystickComponent(nullptr)
31{
32 if (!vehicle) {
33 qWarning() << "Internal error";
34 return;
35 }
36
37 _airframeFacts = new PX4AirframeLoader(this, this);
38 Q_CHECK_PTR(_airframeFacts);
39
41}
42
47
49{
50 if (_components.count() == 0 && !_incorrectParameterVersion) {
51 if (_vehicle) {
54 _airframeComponent->setupTriggerSignals();
55 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_airframeComponent)));
56
57 if (!_vehicle->hilMode()) {
59 _sensorsComponent->setupTriggerSignals();
60 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_sensorsComponent)));
61 }
62
64 _radioComponent->setupTriggerSignals();
65 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_radioComponent)));
66
68 _flightModesComponent->setupTriggerSignals();
69 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_flightModesComponent)));
70
71 _powerComponent = new PowerComponent(_vehicle, this, this);
72 _powerComponent->setupTriggerSignals();
73 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_powerComponent)));
74
75 if (_vehicle->actuators()) {
76 _vehicle->actuators()->init(); // At this point params are loaded, so we can init the actuators
77 }
78
79 // Decide between new Actuators page or legacy Motor page
80 bool showActuatorsPage = false;
81 if (!_vehicle->actuators()) {
82 qCDebug(ActuatorsConfigLog) << "Actuators page will NOT show because:";
83 qCDebug(ActuatorsConfigLog) << " - Vehicle did not provide actuators metadata via component information";
84 } else if (!_vehicle->actuators()->showUi()) {
85 qCDebug(ActuatorsConfigLog) << "Actuators page will NOT show because:";
86 if (!_vehicle->actuators()->isInitialized()) {
87 qCDebug(ActuatorsConfigLog) << " - Actuators initialization failed:" << _vehicle->actuators()->initializationError();
88 } else {
89 qCDebug(ActuatorsConfigLog) << " - Condition 'show-ui-if' evaluated to false";
90 qCDebug(ActuatorsConfigLog) << " (see 'Evaluating [show-ui-if]' log above for details)";
91 }
92 } else {
93 showActuatorsPage = true;
94 qCDebug(ActuatorsConfigLog) << "Actuators page WILL show (all conditions passed)";
95 }
96
97 if (showActuatorsPage) {
99 _actuatorComponent->setupTriggerSignals();
100 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_actuatorComponent)));
101 } else {
102 qCDebug(ActuatorsConfigLog) << " → Using legacy Motor page instead";
103 _motorComponent = new MotorComponent(_vehicle, this, this);
104 _motorComponent->setupTriggerSignals();
105 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_motorComponent)));
106 }
107
108 _safetyComponent = new SafetyComponent(_vehicle, this, this);
109 _safetyComponent->setupTriggerSignals();
110 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_safetyComponent)));
111
113 _tuningComponent->setupTriggerSignals();
114 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_tuningComponent)));
115
116 if(_vehicle->parameterManager()->parameterExists(_vehicle->compId(), "SYS_VEHICLE_RESP")) {
117 _flightBehavior = new PX4FlightBehavior(_vehicle, this, this);
118 _flightBehavior->setupTriggerSignals();
119 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_flightBehavior)));
120 }
121
122 //-- Is there an ESP8266 Connected?
123 if(_vehicle->parameterManager()->parameterExists(MAV_COMP_ID_UDP_BRIDGE, "SW_VER")) {
125 _esp8266Component->setupTriggerSignals();
126 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_esp8266Component)));
127 }
128
130 _joystickComponent->setupTriggerSignals();
131 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_joystickComponent)));
132
133 } else {
134 qWarning() << "Call to vehicleCompenents prior to parametersReady";
135 }
136
137 if(_vehicle->parameterManager()->parameterExists(_vehicle->compId(), "SLNK_RADIO_CHAN")) {
139 _syslinkComponent->setupTriggerSignals();
140 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_syslinkComponent)));
141 }
142 } else {
143 qWarning() << "Internal error";
144 }
145 }
146
147 return _components;
148}
149
151{
152 // Base class must be called
153 AutoPilotPlugin::parametersReadyPreChecks();
154
155 QString hitlParam("SYS_HITL");
157 _vehicle->parameterManager()->getParameter(ParameterManager::defaultComponentId, hitlParam)->rawValue().toBool()) {
158 qgcApp()->showAppMessage(tr("Warning: Hardware In The Loop (HITL) simulation is enabled for this vehicle."));
159 }
160}
161
163{
164 bool requiresAirframeCheck = false;
165
166 if (qobject_cast<const FlightModesComponent*>(component)) {
167 if (_vehicle->parameterManager()->getParameter(-1, "COM_RC_IN_MODE")->rawValue().toInt() == 1) {
168 // No RC input
169 return QString();
170 } else {
172 return _airframeComponent->name();
174 return _radioComponent->name();
175 }
176 }
177 } else if (qobject_cast<const PX4RadioComponent*>(component)) {
178 if (_vehicle->parameterManager()->getParameter(-1, "COM_RC_IN_MODE")->rawValue().toInt() != 1) {
179 //requiresAirframeCheck = true;
180 }
181 } else if (qobject_cast<const PX4TuningComponent*>(component)) {
182 requiresAirframeCheck = true;
183 } else if (qobject_cast<const PowerComponent*>(component)) {
184 requiresAirframeCheck = true;
185 } else if (qobject_cast<const SafetyComponent*>(component)) {
186 requiresAirframeCheck = true;
187 } else if (qobject_cast<const SensorsComponent*>(component)) {
188 requiresAirframeCheck = true;
189 }
190
191 if (requiresAirframeCheck) {
193 return _airframeComponent->name();
194 }
195 }
196
197 return QString();
198}
#define qgcApp()
bool showUi() const
Definition Actuators.cc:773
const QString & initializationError() const
Definition Actuators.h:63
bool isInitialized() const
Definition Actuators.h:62
void init()
Definition Actuators.cc:135
virtual QString name(void) const
virtual bool setupComplete(void) const
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
PX4AutoPilotPlugin(Vehicle *vehicle, QObject *parent)
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
bool hilMode() const
Definition Vehicle.h:543
Actuators * actuators() const
Definition Vehicle.h:544
int compId() const
Definition Vehicle.h:426
ParameterManager * parameterManager()
Definition Vehicle.h:578