QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
APMAutoPilotPlugin.cc
Go to the documentation of this file.
6#include "APMHeliComponent.h"
8#include "APMMotorComponent.h"
9#include "APMServoComponent.h"
10#include "APMESCComponent.h"
11#include "APMPowerComponent.h"
12#include "APMRadioComponent.h"
13#include "APMLoggingComponent.h"
17#include "APMSensorsComponent.h"
19#include "APMTuningComponent.h"
21#include "ESP8266Component.h"
22#include "ScriptingComponent.h"
23#include "JoystickComponent.h"
24#include "ParameterManager.h"
25#include "AppMessages.h"
26#include "QGCLoggingCategory.h"
27#include "Vehicle.h"
28#include "VehicleLinkManager.h"
29#include "VehicleSupports.h"
30#include "VehicleComponent.h"
31
32#include <algorithm>
33
34#ifdef QT_DEBUG
35#include "APMFollowComponent.h"
38#endif
39#ifndef QGC_NO_SERIAL_LINK
40#include "QGCSerialPortInfo.h"
41#include "SerialLink.h"
42#endif
43
44QGC_LOGGING_CATEGORY(APMAutoPilotPluginLog, "AutoPilotPlugins.APM.apmautopilotplugin")
45
47 : AutoPilotPlugin(vehicle, parent)
48{
49 // qCDebug(APMAutoPilotPluginLog) << Q_FUNC_INFO << this;
50
51#ifndef QGC_NO_SERIAL_LINK
52 (void) connect(vehicle->parameterManager(), &ParameterManager::parametersReadyChanged, this, &APMAutoPilotPlugin::_checkForBadCubeBlack);
53#endif
54}
55
57{
58 // qCDebug(APMAutoPilotPluginLog) << Q_FUNC_INFO << this;
59}
60
62{
63 if (_components.isEmpty() && !_incorrectParameterVersion) {
64 if (_vehicle->parameterManager()->parametersReady()) {
66 _airframeComponent->setupTriggerSignals();
67 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_airframeComponent)));
68
69 if (_vehicle->supports()->radio()) {
71 _radioComponent->setupTriggerSignals();
72 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_radioComponent)));
73 }
74
75 // No flight modes component for Sub versions 3.5 and up
76 if (!_vehicle->sub() || (_vehicle->versionCompare(3, 5, 0) < 0)) {
78 _flightModesComponent->setupTriggerSignals();
79 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_flightModesComponent)));
80 }
81
83 _sensorsComponent->setupTriggerSignals();
84 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_sensorsComponent)));
85
86 if (_vehicle->parameterManager()->parameterExists(-1, QStringLiteral("ARSPD_TYPE"))) {
88 _airspeedComponent->setupTriggerSignals();
89 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_airspeedComponent)));
90 }
91
93 _powerComponent->setupTriggerSignals();
94 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_powerComponent)));
95
96 // ESC page is blank without the motor PWM params (e.g. fixed-wing Plane)
97 if (_vehicle->parameterManager()->parameterExists(-1, QStringLiteral("MOT_PWM_TYPE")) ||
98 _vehicle->parameterManager()->parameterExists(-1, QStringLiteral("Q_M_PWM_TYPE"))) {
100 _escComponent->setupTriggerSignals();
101 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_escComponent)));
102 }
103
104 if (!_vehicle->sub() || (_vehicle->versionCompare(3, 5, 3) >= 0)) {
106 _motorComponent->setupTriggerSignals();
107 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_motorComponent)));
108 }
109
110 if (_vehicle->parameterManager()->parameterExists(-1, QStringLiteral("SERVO1_MIN"))) {
112 _servoComponent->setupTriggerSignals();
113 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_servoComponent)));
114 }
115
117 _flightSafetyComponent->setupTriggerSignals();
118 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_flightSafetyComponent)));
119
121 _failsafesComponent->setupTriggerSignals();
122 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_failsafesComponent)));
123
124#ifdef QT_DEBUG
125 if ((qobject_cast<ArduCopterFirmwarePlugin*>(_vehicle->firmwarePlugin()) || qobject_cast<ArduRoverFirmwarePlugin*>(_vehicle->firmwarePlugin())) &&
126 _vehicle->parameterManager()->parameterExists(-1, QStringLiteral("FOLL_ENABLE"))) {
128 _followComponent->setupTriggerSignals();
129 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_followComponent)));
130 }
131#endif
132
133 if (_vehicle->vehicleType() == MAV_TYPE_HELICOPTER && (_vehicle->versionCompare(4, 0, 0) >= 0)) {
135 _heliComponent->setupTriggerSignals();
136 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_heliComponent)));
137 }
138
139 if (!_vehicle->sub()) {
141 _tuningComponent->setupTriggerSignals();
142 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_tuningComponent)));
143 }
144
145 if (_vehicle->multiRotor()) {
147 _advancedTuningCopterComponent->setupTriggerSignals();
148 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_advancedTuningCopterComponent)));
149 }
150
152 _gimbalComponent->setupTriggerSignals();
153 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_gimbalComponent)));
154
155 if (_vehicle->sub()) {
157 _lightsComponent->setupTriggerSignals();
158 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_lightsComponent)));
159
160 if (_vehicle->versionCompare(3, 5, 0) >= 0) {
162 _subFrameComponent->setupTriggerSignals();
163 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_subFrameComponent)));
164 }
165 }
166
167 //-- Is there an ESP8266 Connected?
168 if (_vehicle->parameterManager()->parameterExists(MAV_COMP_ID_UDP_BRIDGE, "SW_VER")) {
170 _esp8266Component->setupTriggerSignals();
171 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_esp8266Component)));
172 }
173
175 _loggingComponent->setupTriggerSignals();
176 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_loggingComponent)));
177
179 _apmRemoteSupportComponent->setupTriggerSignals();
180 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_apmRemoteSupportComponent)));
181
183 _joystickComponent->setupTriggerSignals();
184 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_joystickComponent)));
185
187 _scriptingComponent->setupTriggerSignals();
188 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_scriptingComponent)));
189 } else {
190 qCWarning(APMAutoPilotPluginLog) << "Call to vehicleComponents prior to parametersReady";
191 }
192
193 std::sort(_components.begin(), _components.end(), [](const QVariant &a, const QVariant &b) {
194 return a.value<VehicleComponent*>()->name().toLower() < b.value<VehicleComponent*>()->name().toLower();
195 });
196 }
197
198 return _components;
199}
200
202{
203 bool requiresAirframeCheck = false;
204
205 if (qobject_cast<const APMFlightModesComponent*>(component)) {
206 if (_airframeComponent && !_airframeComponent->setupComplete()) {
207 return _airframeComponent->name();
208 }
209 if (_radioComponent && !_radioComponent->setupComplete()) {
210 return _radioComponent->name();
211 }
212 requiresAirframeCheck = true;
213 } else if (qobject_cast<const APMRadioComponent*>(component)) {
214 requiresAirframeCheck = true;
215 } else if (qobject_cast<const APMPowerComponent*>(component)) {
216 requiresAirframeCheck = true;
217 } else if (qobject_cast<const APMESCComponent*>(component)) {
218 requiresAirframeCheck = true;
219 } else if (qobject_cast<const APMFlightSafetyComponent*>(component)) {
220 requiresAirframeCheck = true;
221 } else if (qobject_cast<const APMTuningComponent*>(component)) {
222 requiresAirframeCheck = true;
223 } else if (qobject_cast<const APMSensorsComponent*>(component)) {
224 requiresAirframeCheck = true;
225 } else if (qobject_cast<const APMAirspeedComponent*>(component)) {
226 requiresAirframeCheck = true;
227 }
228
229 if (requiresAirframeCheck) {
230 if (_airframeComponent && !_airframeComponent->setupComplete()) {
231 return _airframeComponent->name();
232 }
233 }
234
235 return QString();
236}
237
238#ifndef QGC_NO_SERIAL_LINK
239void APMAutoPilotPlugin::_checkForBadCubeBlack(bool parametersReady)
240{
241 if (!parametersReady) {
242 return;
243 }
244
245 const SharedLinkInterfacePtr sharedLink = _vehicle->vehicleLinkManager()->primaryLink().lock();
246 if (!sharedLink) {
247 return;
248 }
249
250 if (sharedLink->linkConfiguration()->type() != LinkConfiguration::TypeSerial) {
251 return;
252 }
253
254 const SerialLink *serialLink = qobject_cast<const SerialLink*>(sharedLink.get());
255 if (!serialLink) {
256 return;
257 }
258
259 if (!QGCSerialPortInfo(*serialLink->port()).isBlackCube()) {
260 return;
261 }
262
263 ParameterManager *const paramMgr = _vehicle->parameterManager();
264
265 static const QString paramAcc3 = QStringLiteral("INS_ACC3_ID");
266 static const QString paramGyr3 = QStringLiteral("INS_GYR3_ID");
267 static const QString paramEnableMask = QStringLiteral("INS_ENABLE_MASK");
268
269 if (paramMgr->parameterExists(-1, paramAcc3) && (paramMgr->getParameter(-1, paramAcc3)->rawValue().toInt() == 0) &&
270 paramMgr->parameterExists(-1, paramGyr3) && (paramMgr->getParameter(-1, paramGyr3)->rawValue().toInt() == 0) &&
271 paramMgr->parameterExists(-1, paramEnableMask) && (paramMgr->getParameter(-1, paramEnableMask)->rawValue().toInt() >= 7)) {
273 "WARNING: The flight board you are using has a critical service bulletin against it which advises against flying. "
274 "For details see: https://discuss.cubepilot.org/t/sb-0000002-critical-service-bulletin-for-cubes-purchased-between-january-2019-to-present-do-not-fly/406"
275 ));
276 }
277}
278#endif
std::shared_ptr< LinkInterface > SharedLinkInterfacePtr
#define QGC_LOGGING_CATEGORY(name, categoryStr)
QString prerequisiteSetup(VehicleComponent *component) const override
Returns the name of the vehicle component which must complete setup prior to this one....
APMLoggingComponent * _loggingComponent
ScriptingComponent * _scriptingComponent
APMAdvancedTuningCopterComponent * _advancedTuningCopterComponent
APMAirframeComponent * _airframeComponent
APMHeliComponent * _heliComponent
const QVariantList & vehicleComponents() override
APMRadioComponent * _radioComponent
APMFlightModesComponent * _flightModesComponent
APMMotorComponent * _motorComponent
APMServoComponent * _servoComponent
APMAirspeedComponent * _airspeedComponent
APMLightsComponent * _lightsComponent
APMFollowComponent * _followComponent
APMTuningComponent * _tuningComponent
ESP8266Component * _esp8266Component
APMFlightSafetyComponent * _flightSafetyComponent
JoystickComponent * _joystickComponent
APMGimbalComponent * _gimbalComponent
APMSensorsComponent * _sensorsComponent
APMPowerComponent * _powerComponent
APMESCComponent * _escComponent
bool _incorrectParameterVersion
true: parameter version incorrect, setup not allowed
APMFailsafesComponent * _failsafesComponent
APMRemoteSupportComponent * _apmRemoteSupportComponent
APMAutoPilotPlugin(Vehicle *vehicle, QObject *parent=nullptr)
APMSubFrameComponent * _subFrameComponent
AutoPilotPlugin(Vehicle *vehicle, QObject *parent=nullptr)
QVariant rawValue() const
Definition Fact.h:87
@ TypeSerial
Serial Link.
bool parameterExists(int componentId, const QString &paramName) const
Fact * getParameter(int componentId, const QString &paramName)
void parametersReadyChanged(bool parametersReady)
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