QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
PX4AutoPilotPlugin.cc
Go to the documentation of this file.
2
3#include <algorithm>
4
5#include "ActuatorComponent.h"
6#include "Actuators.h"
7#include "AppMessages.h"
10#include "PX4AirframeLoader.h"
12#include "PX4EscComponent.h"
13#include "PX4RadioComponent.h"
15#include "PX4TuningComponent.h"
16#include "ParameterManager.h"
17#include "QGCLoggingCategory.h"
18#include "SensorsComponent.h"
19#include "Vehicle.h"
20
21QGC_LOGGING_CATEGORY(PX4AutoPilotPluginLog, "Vehicle.Actuators.PX4AutoPilotPlugin")
22
24 : AutoPilotPlugin(vehicle, parent)
26 , _airframeComponent(nullptr)
27 , _radioComponent(nullptr)
28 , _esp8266Component(nullptr)
30 , _flightModesComponent(nullptr)
31 , _sensorsComponent(nullptr)
32 , _returnLandComponent(nullptr)
33 , _collisionComponent(nullptr)
34 , _failsafesComponent(nullptr)
35 , _serialPortsComponent(nullptr)
36 , _escComponent(nullptr)
37 , _batteryComponent(nullptr)
38 , _motorComponent(nullptr)
39 , _actuatorComponent(nullptr)
40 , _tuningComponent(nullptr)
41 , _flightBehavior(nullptr)
42 , _syslinkComponent(nullptr)
43 , _joystickComponent(nullptr)
44{
45 if (!vehicle) {
46 qWarning() << "Internal error";
47 return;
48 }
49
50 _airframeFacts = new PX4AirframeLoader(this, this);
51 Q_CHECK_PTR(_airframeFacts);
52
54}
55
60
62{
63 if (_components.count() == 0 && !_incorrectParameterVersion) {
64 if (_vehicle) {
65 if (_vehicle->parameterManager()->parametersReady()) {
67 _airframeComponent->setupTriggerSignals();
68 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_airframeComponent)));
69
70 if (!_vehicle->hilMode()) {
72 _sensorsComponent->setupTriggerSignals();
73 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_sensorsComponent)));
74 }
75
77 _radioComponent->setupTriggerSignals();
78 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_radioComponent)));
79
81 _flightModesComponent->setupTriggerSignals();
82 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_flightModesComponent)));
83
84 _escComponent = new PX4EscComponent(_vehicle, this, this);
85 _escComponent->setupTriggerSignals();
86 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_escComponent)));
87
88 if (_vehicle->parameterManager()->parameterExists(ParameterManager::defaultComponentId,
89 "BAT1_SOURCE")) {
91 _batteryComponent->setupTriggerSignals();
92 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_batteryComponent)));
93 }
94
95 if (_vehicle->actuators()) {
96 _vehicle->actuators()->init(); // At this point params are loaded, so we can init the actuators
97 }
98
99 // Decide between new Actuators page or legacy Motor page
100 bool showActuatorsPage = false;
101 if (!_vehicle->actuators()) {
102 qCDebug(PX4AutoPilotPluginLog) << "Actuators page will NOT show because:";
103 qCDebug(PX4AutoPilotPluginLog) << " - Vehicle did not provide actuators metadata via component information";
104 } else if (!_vehicle->actuators()->showUi()) {
105 qCDebug(PX4AutoPilotPluginLog) << "Actuators page will NOT show because:";
106 if (!_vehicle->actuators()->isInitialized()) {
107 qCDebug(PX4AutoPilotPluginLog) << " - Actuators initialization failed:" << _vehicle->actuators()->initializationError();
108 } else {
109 qCDebug(PX4AutoPilotPluginLog) << " - Condition 'show-ui-if' evaluated to false";
110 qCDebug(PX4AutoPilotPluginLog) << " (see 'Evaluating [show-ui-if]' log above for details)";
111 }
112 } else {
113 showActuatorsPage = true;
114 qCDebug(PX4AutoPilotPluginLog) << "Actuators page WILL show (all conditions passed)";
115 }
116
117 if (showActuatorsPage) {
119 _actuatorComponent->setupTriggerSignals();
120 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_actuatorComponent)));
121 } else {
122 qCDebug(PX4AutoPilotPluginLog) << " → Using legacy Motor page instead";
123 _motorComponent = new MotorComponent(_vehicle, this, this);
124 _motorComponent->setupTriggerSignals();
125 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_motorComponent)));
126 }
127
129 _returnLandComponent->setupTriggerSignals();
130 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_returnLandComponent)));
131
132 if (_vehicle->parameterManager()->parameterExists(ParameterManager::defaultComponentId, "CP_DIST")) {
134 _collisionComponent->setupTriggerSignals();
135 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_collisionComponent)));
136 }
137
139 _failsafesComponent->setupTriggerSignals();
140 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_failsafesComponent)));
141
142 if (!PX4SerialPortsComponent::functionFacts(_vehicle->parameterManager()).isEmpty()) {
144 _serialPortsComponent->setupTriggerSignals();
145 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_serialPortsComponent)));
146 }
147
148 if (_vehicle->parameterManager()->parameterExists(ParameterManager::defaultComponentId, "SYS_FAILURE_EN")) {
150 _failureInjectionComponent->setupTriggerSignals();
151 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_failureInjectionComponent)));
152 }
153
155 _tuningComponent->setupTriggerSignals();
156 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_tuningComponent)));
157
158 if(_vehicle->parameterManager()->parameterExists(_vehicle->compId(), "SYS_VEHICLE_RESP")) {
159 _flightBehavior = new PX4FlightBehavior(_vehicle, this, this);
160 _flightBehavior->setupTriggerSignals();
161 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_flightBehavior)));
162 }
163
164 //-- Is there an ESP8266 Connected?
165 if(_vehicle->parameterManager()->parameterExists(MAV_COMP_ID_UDP_BRIDGE, "SW_VER")) {
167 _esp8266Component->setupTriggerSignals();
168 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_esp8266Component)));
169 }
170
172 _joystickComponent->setupTriggerSignals();
173 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_joystickComponent)));
174
175 } else {
176 qWarning() << "Call to vehicleCompenents prior to parametersReady";
177 }
178
179 if(_vehicle->parameterManager()->parameterExists(_vehicle->compId(), "SLNK_RADIO_CHAN")) {
181 _syslinkComponent->setupTriggerSignals();
182 _components.append(QVariant::fromValue(static_cast<VehicleComponent*>(_syslinkComponent)));
183 }
184 } else {
185 qWarning() << "Internal error";
186 }
187
188 std::sort(_components.begin(), _components.end(), [](const QVariant &a, const QVariant &b) {
189 return a.value<VehicleComponent*>()->name().toLower() < b.value<VehicleComponent*>()->name().toLower();
190 });
191 }
192
193 return _components;
194}
195
197{
198 // Base class must be called
200
201 QString hitlParam("SYS_HITL");
202 if (_vehicle->parameterManager()->parameterExists(ParameterManager::defaultComponentId, hitlParam) &&
203 _vehicle->parameterManager()->getParameter(ParameterManager::defaultComponentId, hitlParam)->rawValue().toBool()) {
204 QGC::showAppMessage(tr("Warning: Hardware In The Loop (HITL) simulation is enabled for this vehicle."));
205 }
206}
207
209{
210 bool requiresAirframeCheck = false;
211
212 if (qobject_cast<const FlightModesComponent*>(component)) {
213 if (_vehicle->parameterManager()->getParameter(-1, "COM_RC_IN_MODE")->rawValue().toInt() == 1) {
214 // No RC input
215 return QString();
216 } else {
217 if (_airframeComponent && !_airframeComponent->setupComplete()) {
218 return _airframeComponent->name();
219 } else if (_radioComponent && !_radioComponent->setupComplete()) {
220 return _radioComponent->name();
221 }
222 }
223 } else if (qobject_cast<const PX4RadioComponent*>(component)) {
224 if (_vehicle->parameterManager()->getParameter(-1, "COM_RC_IN_MODE")->rawValue().toInt() != 1) {
225 //requiresAirframeCheck = true;
226 }
227 } else if (qobject_cast<const PX4TuningComponent*>(component)) {
228 requiresAirframeCheck = true;
229 } else if (qobject_cast<const PX4EscComponent*>(component) || qobject_cast<const PX4BatteryComponent*>(component)) {
230 requiresAirframeCheck = true;
231 } else if (qobject_cast<const PX4ReturnLandComponent*>(component) ||
232 qobject_cast<const PX4CollisionComponent*>(component)) {
233 requiresAirframeCheck = true;
234 } else if (qobject_cast<const SensorsComponent*>(component)) {
235 requiresAirframeCheck = true;
236 }
237
238 if (requiresAirframeCheck) {
239 if (_airframeComponent && !_airframeComponent->setupComplete()) {
240 return _airframeComponent->name();
241 }
242 }
243
244 return QString();
245}
#define QGC_LOGGING_CATEGORY(name, categoryStr)
virtual void parametersReadyPreChecks()
AutoPilotPlugin(Vehicle *vehicle, QObject *parent=nullptr)
Collection of Parameter Facts for PX4 AutoPilot.
static void loadAirframeMetaData(void)
FailureInjectionComponent * _failureInjectionComponent
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....
PX4ReturnLandComponent * _returnLandComponent
AirframeComponent * _airframeComponent
PX4TuningComponent * _tuningComponent
const QVariantList & vehicleComponents(void) override
void parametersReadyPreChecks(void) override
JoystickComponent * _joystickComponent
PX4BatteryComponent * _batteryComponent
PX4AutoPilotPlugin(Vehicle *vehicle, QObject *parent)
SyslinkComponent * _syslinkComponent
PX4FlightBehavior * _flightBehavior
PX4EscComponent * _escComponent
ActuatorComponent * _actuatorComponent
PX4SerialPortsComponent * _serialPortsComponent
ESP8266Component * _esp8266Component
PX4FailsafesComponent * _failsafesComponent
PX4AirframeLoader * _airframeFacts
PX4CollisionComponent * _collisionComponent
SensorsComponent * _sensorsComponent
MotorComponent * _motorComponent
FlightModesComponent * _flightModesComponent
static QList< Fact * > functionFacts(ParameterManager *parameterManager)
Parameters which select the serial port a function runs on. The page is only shown when there are som...
static constexpr int defaultComponentId
A vehicle component is an object which abstracts the physical portion of a vehicle into a set of conf...
void showAppMessage(const QString &message, const QString &title)
Modal application message. Queued if the UI isn't ready yet.
Definition AppMessages.cc:9