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->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
135 if (!_vehicle->sub()) {
138 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_tuningComponent)));
139 }
140
141 if (_vehicle->multiRotor()) {
144 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_advancedTuningCopterComponent)));
145 }
146
149 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_gimbalComponent)));
150
151 if (_vehicle->sub()) {
154 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_lightsComponent)));
155
156 if (_vehicle->versionCompare(3, 5, 0) >= 0) {
159 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_subFrameComponent)));
160 }
161 }
162
163 //-- Is there an ESP8266 Connected?
164 if (_vehicle->parameterManager()->parameterExists(MAV_COMP_ID_UDP_BRIDGE, "SW_VER")) {
167 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_esp8266Component)));
168 }
169
172 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_loggingComponent)));
173
176 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_apmRemoteSupportComponent)));
177
180 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_joystickComponent)));
181
184 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_scriptingComponent)));
185 } else {
186 qCWarning(APMAutoPilotPluginLog) << "Call to vehicleComponents prior to parametersReady";
187 }
188
189 std::sort(_components.begin(), _components.end(), [](const QVariant &a, const QVariant &b) {
190 return a.value<VehicleComponent*>()->name().toLower() < b.value<VehicleComponent*>()->name().toLower();
191 });
192 }
193
194 return _components;
195}
196
198{
199 bool requiresAirframeCheck = false;
200
201 if (qobject_cast<const APMFlightModesComponent*>(component)) {
203 return _airframeComponent->name();
204 }
206 return _radioComponent->name();
207 }
208 requiresAirframeCheck = true;
209 } else if (qobject_cast<const APMRadioComponent*>(component)) {
210 requiresAirframeCheck = true;
211 } else if (qobject_cast<const APMPowerComponent*>(component)) {
212 requiresAirframeCheck = true;
213 } else if (qobject_cast<const APMESCComponent*>(component)) {
214 requiresAirframeCheck = true;
215 } else if (qobject_cast<const APMFlightSafetyComponent*>(component)) {
216 requiresAirframeCheck = true;
217 } else if (qobject_cast<const APMTuningComponent*>(component)) {
218 requiresAirframeCheck = true;
219 } else if (qobject_cast<const APMSensorsComponent*>(component)) {
220 requiresAirframeCheck = true;
221 } else if (qobject_cast<const APMAirspeedComponent*>(component)) {
222 requiresAirframeCheck = true;
223 }
224
225 if (requiresAirframeCheck) {
227 return _airframeComponent->name();
228 }
229 }
230
231 return QString();
232}
233
234#ifndef QGC_NO_SERIAL_LINK
235void APMAutoPilotPlugin::_checkForBadCubeBlack(bool parametersReady)
236{
237 if (!parametersReady) {
238 return;
239 }
240
241 const SharedLinkInterfacePtr sharedLink = _vehicle->vehicleLinkManager()->primaryLink().lock();
242 if (!sharedLink) {
243 return;
244 }
245
246 if (sharedLink->linkConfiguration()->type() != LinkConfiguration::TypeSerial) {
247 return;
248 }
249
250 const SerialLink *serialLink = qobject_cast<const SerialLink*>(sharedLink.get());
251 if (!serialLink) {
252 return;
253 }
254
255 if (!QGCSerialPortInfo(*serialLink->port()).isBlackCube()) {
256 return;
257 }
258
259 ParameterManager *const paramMgr = _vehicle->parameterManager();
260
261 static const QString paramAcc3 = QStringLiteral("INS_ACC3_ID");
262 static const QString paramGyr3 = QStringLiteral("INS_GYR3_ID");
263 static const QString paramEnableMask = QStringLiteral("INS_ENABLE_MASK");
264
265 if (paramMgr->parameterExists(-1, paramAcc3) && (paramMgr->getParameter(-1, paramAcc3)->rawValue().toInt() == 0) &&
266 paramMgr->parameterExists(-1, paramGyr3) && (paramMgr->getParameter(-1, paramGyr3)->rawValue().toInt() == 0) &&
267 paramMgr->parameterExists(-1, paramEnableMask) && (paramMgr->getParameter(-1, paramEnableMask)->rawValue().toInt() >= 7)) {
269 "WARNING: The flight board you are using has a critical service bulletin against it which advises against flying. "
270 "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"
271 ));
272 }
273}
274#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:1746
bool multiRotor() const
Definition Vehicle.cc:1756
MAV_TYPE vehicleType() const
Definition Vehicle.h:432
VehicleLinkManager * vehicleLinkManager()
Definition Vehicle.h:579
FirmwarePlugin * firmwarePlugin()
Provides access to the Firmware Plugin for this Vehicle.
Definition Vehicle.h:448
ParameterManager * parameterManager()
Definition Vehicle.h:577
VehicleSupports * supports()
Definition Vehicle.h:406
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:2746
void showAppMessage(const QString &message, const QString &title)
Modal application message. Queued if the UI isn't ready yet.
Definition AppMessages.cc:9