QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
APMAutoPilotPlugin.cc
Go to the documentation of this file.
5#include "APMHeliComponent.h"
7#include "APMMotorComponent.h"
8#include "APMPowerComponent.h"
9#include "APMRadioComponent.h"
11#include "APMSafetyComponent.h"
12#include "APMSensorsComponent.h"
14#include "APMTuningComponent.h"
15#include "ESP8266Component.h"
16#include "ScriptingComponent.h"
17#include "JoystickComponent.h"
18#include "ParameterManager.h"
19#include "QGCApplication.h"
20#include "QGCLoggingCategory.h"
21#include "Vehicle.h"
22#include "VehicleSupports.h"
23#include "VehicleComponent.h"
24#ifdef QT_DEBUG
25#include "APMFollowComponent.h"
28#endif
29#ifndef QGC_NO_SERIAL_LINK
30#include "QGCSerialPortInfo.h"
31#include "SerialLink.h"
32#endif
33
34QGC_LOGGING_CATEGORY(APMAutoPilotPluginLog, "AutoPilotPlugins.APM.apmautopilotplugin")
35
37 : AutoPilotPlugin(vehicle, parent)
38{
39 // qCDebug(APMAutoPilotPluginLog) << Q_FUNC_INFO << this;
40
41#ifndef QGC_NO_SERIAL_LINK
42 (void) connect(vehicle->parameterManager(), &ParameterManager::parametersReadyChanged, this, &APMAutoPilotPlugin::_checkForBadCubeBlack);
43#endif
44}
45
47{
48 // qCDebug(APMAutoPilotPluginLog) << Q_FUNC_INFO << this;
49}
50
52{
53 if (_components.isEmpty() && !_incorrectParameterVersion) {
56 _airframeComponent->setupTriggerSignals();
57 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_airframeComponent)));
58
59 if (_vehicle->supports()->radio()) {
61 _radioComponent->setupTriggerSignals();
62 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_radioComponent)));
63 }
64
65 // No flight modes component for Sub versions 3.5 and up
66 if (!_vehicle->sub() || (_vehicle->versionCompare(3, 5, 0) < 0)) {
68 _flightModesComponent->setupTriggerSignals();
69 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_flightModesComponent)));
70 }
71
73 _sensorsComponent->setupTriggerSignals();
74 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_sensorsComponent)));
75
77 _powerComponent->setupTriggerSignals();
78 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_powerComponent)));
79
80 if (!_vehicle->sub() || (_vehicle->sub() && (_vehicle->versionCompare(3, 5, 3) >= 0))) {
82 _motorComponent->setupTriggerSignals();
83 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_motorComponent)));
84 }
85
87 _safetyComponent->setupTriggerSignals();
88 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_safetyComponent)));
89
90#ifdef QT_DEBUG
91 if ((qobject_cast<ArduCopterFirmwarePlugin*>(_vehicle->firmwarePlugin()) || qobject_cast<ArduRoverFirmwarePlugin*>(_vehicle->firmwarePlugin())) &&
92 _vehicle->parameterManager()->parameterExists(-1, QStringLiteral("FOLL_ENABLE"))) {
94 _followComponent->setupTriggerSignals();
95 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_followComponent)));
96 }
97#endif
98
99 if (_vehicle->vehicleType() == MAV_TYPE_HELICOPTER && (_vehicle->versionCompare(4, 0, 0) >= 0)) {
101 _heliComponent->setupTriggerSignals();
102 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_heliComponent)));
103 }
104
106 _tuningComponent->setupTriggerSignals();
107 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_tuningComponent)));
108
110 _gimbalComponent->setupTriggerSignals();
111 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_gimbalComponent)));
112
113 if (_vehicle->sub()) {
115 _lightsComponent->setupTriggerSignals();
116 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_lightsComponent)));
117
118 if (_vehicle->versionCompare(3, 5, 0) >= 0) {
120 _subFrameComponent->setupTriggerSignals();
121 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_subFrameComponent)));
122 }
123 }
124
125 //-- Is there an ESP8266 Connected?
126 if (_vehicle->parameterManager()->parameterExists(MAV_COMP_ID_UDP_BRIDGE, "SW_VER")) {
128 _esp8266Component->setupTriggerSignals();
129 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_esp8266Component)));
130 }
131
133 _apmRemoteSupportComponent->setupTriggerSignals();
134 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_apmRemoteSupportComponent)));
135
137 _joystickComponent->setupTriggerSignals();
138 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_joystickComponent)));
139
141 _scriptingComponent->setupTriggerSignals();
142 _components.append(QVariant::fromValue(qobject_cast<VehicleComponent*>(_scriptingComponent)));
143 } else {
144 qCWarning(APMAutoPilotPluginLog) << "Call to vehicleComponents prior to parametersReady";
145 }
146 }
147
148 return _components;
149}
150
152{
153 bool requiresAirframeCheck = false;
154
155 if (qobject_cast<const APMFlightModesComponent*>(component)) {
157 return _airframeComponent->name();
158 }
160 return _radioComponent->name();
161 }
162 requiresAirframeCheck = true;
163 } else if (qobject_cast<const APMRadioComponent*>(component)) {
164 requiresAirframeCheck = true;
165 } else if (qobject_cast<const APMPowerComponent*>(component)) {
166 requiresAirframeCheck = true;
167 } else if (qobject_cast<const APMSafetyComponent*>(component)) {
168 requiresAirframeCheck = true;
169 } else if (qobject_cast<const APMTuningComponent*>(component)) {
170 requiresAirframeCheck = true;
171 } else if (qobject_cast<const APMSensorsComponent*>(component)) {
172 requiresAirframeCheck = true;
173 }
174
175 if (requiresAirframeCheck) {
177 return _airframeComponent->name();
178 }
179 }
180
181 return QString();
182}
183
184#ifndef QGC_NO_SERIAL_LINK
185void APMAutoPilotPlugin::_checkForBadCubeBlack(bool parametersReady)
186{
187 if (!parametersReady) {
188 return;
189 }
190
191 const SharedLinkInterfacePtr sharedLink = _vehicle->vehicleLinkManager()->primaryLink().lock();
192 if (!sharedLink) {
193 return;
194 }
195
196 if (sharedLink->linkConfiguration()->type() != LinkConfiguration::TypeSerial) {
197 return;
198 }
199
200 const SerialLink *serialLink = qobject_cast<const SerialLink*>(sharedLink.get());
201 if (!serialLink) {
202 return;
203 }
204
205 if (!QGCSerialPortInfo(*serialLink->port()).isBlackCube()) {
206 return;
207 }
208
209 ParameterManager *const paramMgr = _vehicle->parameterManager();
210
211 static const QString paramAcc3 = QStringLiteral("INS_ACC3_ID");
212 static const QString paramGyr3 = QStringLiteral("INS_GYR3_ID");
213 static const QString paramEnableMask = QStringLiteral("INS_ENABLE_MASK");
214
215 if (paramMgr->parameterExists(-1, paramAcc3) && (paramMgr->getParameter(-1, paramAcc3)->rawValue().toInt() == 0) &&
216 paramMgr->parameterExists(-1, paramGyr3) && (paramMgr->getParameter(-1, paramGyr3)->rawValue().toInt() == 0) &&
217 paramMgr->parameterExists(-1, paramEnableMask) && (paramMgr->getParameter(-1, paramEnableMask)->rawValue().toInt() >= 7)) {
218 qgcApp()->showAppMessage(tr(
219 "WARNING: The flight board you are using has a critical service bulletin against it which advises against flying. "
220 "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"
221 ));
222 }
223}
224#endif
std::shared_ptr< LinkInterface > SharedLinkInterfacePtr
#define qgcApp()
#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....
ScriptingComponent * _scriptingComponent
APMAirframeComponent * _airframeComponent
APMHeliComponent * _heliComponent
const QVariantList & vehicleComponents() override
APMRadioComponent * _radioComponent
APMFlightModesComponent * _flightModesComponent
APMSafetyComponent * _safetyComponent
APMMotorComponent * _motorComponent
APMLightsComponent * _lightsComponent
APMFollowComponent * _followComponent
APMTuningComponent * _tuningComponent
ESP8266Component * _esp8266Component
JoystickComponent * _joystickComponent
APMGimbalComponent * _gimbalComponent
APMSensorsComponent * _sensorsComponent
APMPowerComponent * _powerComponent
bool _incorrectParameterVersion
true: parameter version incorrect, setup not allowed
APMRemoteSupportComponent * _apmRemoteSupportComponent
APMSubFrameComponent * _subFrameComponent
bool setupComplete() const final
QString name() const final
bool parameterExists(int componentId, const QString &paramName) const
Fact * getParameter(int componentId, const QString &paramName)
void parametersReadyChanged(bool parametersReady)
bool parametersReady() const
WeakLinkInterfacePtr primaryLink() const
bool radio() const
bool sub() const
Definition Vehicle.cc:1854
MAV_TYPE vehicleType() const
Definition Vehicle.h:428
VehicleLinkManager * vehicleLinkManager()
Definition Vehicle.h:580
FirmwarePlugin * firmwarePlugin()
Provides access to the Firmware Plugin for this Vehicle.
Definition Vehicle.h:444
ParameterManager * parameterManager()
Definition Vehicle.h:578
VehicleSupports * supports()
Definition Vehicle.h:405
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:3646