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) {
67 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_airframeComponent)));
68
69 if (_vehicle->supports()->radio()) {
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)) {
79 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_flightModesComponent)));
80 }
81
84 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_sensorsComponent)));
85
86 if (_vehicle->parameterManager()->parameterExists(-1, QStringLiteral("ARSPD_TYPE"))) {
89 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_airspeedComponent)));
90 }
91
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"))) {
101 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_escComponent)));
102 }
103
104 if (!_vehicle->sub() || (_vehicle->versionCompare(3, 5, 3) >= 0)) {
107 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_motorComponent)));
108 }
109
110 if (_vehicle->parameterManager()->parameterExists(-1, QStringLiteral("SERVO1_MIN"))) {
113 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_servoComponent)));
114 }
115
118 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_flightSafetyComponent)));
119
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"))) {
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)) {
136 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_heliComponent)));
137 }
138
139 if (!_vehicle->sub()) {
142 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_tuningComponent)));
143 }
144
145 if (_vehicle->multiRotor()) {
148 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_advancedTuningCopterComponent)));
149 }
150
153 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_gimbalComponent)));
154
155 if (_vehicle->sub()) {
158 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_lightsComponent)));
159
160 if (_vehicle->versionCompare(3, 5, 0) >= 0) {
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")) {
171 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_esp8266Component)));
172 }
173
176 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_loggingComponent)));
177
180 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_apmRemoteSupportComponent)));
181
184 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_joystickComponent)));
185
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)) {
207 return _airframeComponent->name();
208 }
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) {
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 name() const final
bool setupComplete() const final
This is the AutoPilotPlugin implementation for the MAV_AUTOPILOT_ARDUPILOT type.
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
APMSubFrameComponent * _subFrameComponent
bool setupComplete() const final
QString name() const final
The AutoPilotPlugin class is an abstract base class which represents the methods and objects which ar...
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)
bool parametersReady() const
QGC's version of Qt QSerialPortInfo. It provides additional information about board types that QGC ca...
A vehicle component is an object which abstracts the physical portion of a vehicle into a set of conf...
virtual void setupTriggerSignals()
WeakLinkInterfacePtr primaryLink() const
bool radio() const
bool sub() const
Definition Vehicle.cc:1765
bool multiRotor() const
Definition Vehicle.cc:1775
MAV_TYPE vehicleType() const
Definition Vehicle.h:446
VehicleLinkManager * vehicleLinkManager()
Definition Vehicle.h:597
FirmwarePlugin * firmwarePlugin()
Provides access to the Firmware Plugin for this Vehicle.
Definition Vehicle.h:462
ParameterManager * parameterManager()
Definition Vehicle.h:595
VehicleSupports * supports()
Definition Vehicle.h:420
Q_INVOKABLE int versionCompare(const QString &compare) const
Used to check if running current version is equal or higher than the one being compared.
Definition Vehicle.cc:2810
void showAppMessage(const QString &message, const QString &title)
Modal application message. Queued if the UI isn't ready yet.
Definition AppMessages.cc:9