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
98 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_escComponent)));
99
100 if (!_vehicle->sub() || (_vehicle->sub() && (_vehicle->versionCompare(3, 5, 3) >= 0))) {
103 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_motorComponent)));
104 }
105
106 if (_vehicle->parameterManager()->parameterExists(-1, QStringLiteral("SERVO1_MIN"))) {
109 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_servoComponent)));
110 }
111
114 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_flightSafetyComponent)));
115
118 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_failsafesComponent)));
119
120#ifdef QT_DEBUG
121 if ((qobject_cast<ArduCopterFirmwarePlugin*>(_vehicle->firmwarePlugin()) || qobject_cast<ArduRoverFirmwarePlugin*>(_vehicle->firmwarePlugin())) &&
122 _vehicle->parameterManager()->parameterExists(-1, QStringLiteral("FOLL_ENABLE"))) {
125 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_followComponent)));
126 }
127#endif
128
129 if (_vehicle->vehicleType() == MAV_TYPE_HELICOPTER && (_vehicle->versionCompare(4, 0, 0) >= 0)) {
132 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_heliComponent)));
133 }
134
137 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_tuningComponent)));
138
139 if (_vehicle->multiRotor()) {
142 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_advancedTuningCopterComponent)));
143 }
144
147 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_gimbalComponent)));
148
149 if (_vehicle->sub()) {
152 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_lightsComponent)));
153
154 if (_vehicle->versionCompare(3, 5, 0) >= 0) {
157 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_subFrameComponent)));
158 }
159 }
160
161 //-- Is there an ESP8266 Connected?
162 if (_vehicle->parameterManager()->parameterExists(MAV_COMP_ID_UDP_BRIDGE, "SW_VER")) {
165 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_esp8266Component)));
166 }
167
170 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_loggingComponent)));
171
174 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_apmRemoteSupportComponent)));
175
178 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_joystickComponent)));
179
182 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_scriptingComponent)));
183 } else {
184 qCWarning(APMAutoPilotPluginLog) << "Call to vehicleComponents prior to parametersReady";
185 }
186
187 std::sort(_components.begin(), _components.end(), [](const QVariant &a, const QVariant &b) {
188 return a.value<VehicleComponent*>()->name().toLower() < b.value<VehicleComponent*>()->name().toLower();
189 });
190 }
191
192 return _components;
193}
194
196{
197 bool requiresAirframeCheck = false;
198
199 if (qobject_cast<const APMFlightModesComponent*>(component)) {
201 return _airframeComponent->name();
202 }
204 return _radioComponent->name();
205 }
206 requiresAirframeCheck = true;
207 } else if (qobject_cast<const APMRadioComponent*>(component)) {
208 requiresAirframeCheck = true;
209 } else if (qobject_cast<const APMPowerComponent*>(component)) {
210 requiresAirframeCheck = true;
211 } else if (qobject_cast<const APMESCComponent*>(component)) {
212 requiresAirframeCheck = true;
213 } else if (qobject_cast<const APMFlightSafetyComponent*>(component)) {
214 requiresAirframeCheck = true;
215 } else if (qobject_cast<const APMTuningComponent*>(component)) {
216 requiresAirframeCheck = true;
217 } else if (qobject_cast<const APMSensorsComponent*>(component)) {
218 requiresAirframeCheck = true;
219 } else if (qobject_cast<const APMAirspeedComponent*>(component)) {
220 requiresAirframeCheck = true;
221 }
222
223 if (requiresAirframeCheck) {
225 return _airframeComponent->name();
226 }
227 }
228
229 return QString();
230}
231
232#ifndef QGC_NO_SERIAL_LINK
233void APMAutoPilotPlugin::_checkForBadCubeBlack(bool parametersReady)
234{
235 if (!parametersReady) {
236 return;
237 }
238
239 const SharedLinkInterfacePtr sharedLink = _vehicle->vehicleLinkManager()->primaryLink().lock();
240 if (!sharedLink) {
241 return;
242 }
243
244 if (sharedLink->linkConfiguration()->type() != LinkConfiguration::TypeSerial) {
245 return;
246 }
247
248 const SerialLink *serialLink = qobject_cast<const SerialLink*>(sharedLink.get());
249 if (!serialLink) {
250 return;
251 }
252
253 if (!QGCSerialPortInfo(*serialLink->port()).isBlackCube()) {
254 return;
255 }
256
257 ParameterManager *const paramMgr = _vehicle->parameterManager();
258
259 static const QString paramAcc3 = QStringLiteral("INS_ACC3_ID");
260 static const QString paramGyr3 = QStringLiteral("INS_GYR3_ID");
261 static const QString paramEnableMask = QStringLiteral("INS_ENABLE_MASK");
262
263 if (paramMgr->parameterExists(-1, paramAcc3) && (paramMgr->getParameter(-1, paramAcc3)->rawValue().toInt() == 0) &&
264 paramMgr->parameterExists(-1, paramGyr3) && (paramMgr->getParameter(-1, paramGyr3)->rawValue().toInt() == 0) &&
265 paramMgr->parameterExists(-1, paramEnableMask) && (paramMgr->getParameter(-1, paramEnableMask)->rawValue().toInt() >= 7)) {
267 "WARNING: The flight board you are using has a critical service bulletin against it which advises against flying. "
268 "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"
269 ));
270 }
271}
272#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
Value after translation.
Definition Fact.h:85
@ 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:1748
bool multiRotor() const
Definition Vehicle.cc:1758
MAV_TYPE vehicleType() const
Definition Vehicle.h:428
VehicleLinkManager * vehicleLinkManager()
Definition Vehicle.h:575
FirmwarePlugin * firmwarePlugin()
Provides access to the Firmware Plugin for this Vehicle.
Definition Vehicle.h:444
ParameterManager * parameterManager()
Definition Vehicle.h:573
VehicleSupports * supports()
Definition Vehicle.h:402
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:2743
void showAppMessage(const QString &message, const QString &title)
Modal application message. Queued if the UI isn't ready yet.
Definition AppMessages.cc:9