QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
APMFirmwarePlugin.h
Go to the documentation of this file.
1#pragma once
2
3#include "FirmwarePlugin.h"
4#include "FollowMe.h"
5#include "QGCMAVLink.h"
6
7#include <QtCore/QLoggingCategory>
8#include <QtCore/QMutex>
9#include <QtNetwork/QAbstractSocket>
10
11Q_DECLARE_LOGGING_CATEGORY(APMFirmwarePluginLog)
12
14{
15 enum Mode : uint32_t {
16 AUTO = 3,
17 GUIDED = 4,
18 RTL = 6,
19 SMART_RTL = 21
20 };
21};
22
25{
26 Q_OBJECT
27
28public:
29 QList<MAV_CMD> supportedMissionCommands(QGCMAVLink::VehicleClass_t vehicleClass) const override;
30 AutoPilotPlugin *autopilotPlugin(Vehicle* vehicle) const override;
31 bool isCapable(const Vehicle *vehicle, FirmwareCapabilities capabilities) const override;
32 void setGuidedMode(Vehicle *vehicle, bool guidedMode) const override;
33 void guidedModeTakeoff(Vehicle *vehicle, double altitudeRel) const override;
34 void guidedModeGotoLocation(Vehicle *vehicle, const QGeoCoordinate& gotoCoord, double forwardFlightLoiterRadius) const override;
35 double minimumTakeoffAltitudeMeters(Vehicle *vehicle) const override;
36 void startTakeoff(Vehicle *vehicle) const override;
37 void startMission(Vehicle *vehicle) const override;
38 QStringList flightModes(Vehicle *vehicle) const override;
39 QString flightMode(uint8_t base_mode, uint32_t custom_mode) const override;
40 bool setFlightMode(const QString &flightMode, uint8_t *base_mode, uint32_t *custom_mode) const override;
41 bool MAV_CMD_DO_SET_MODE_is_supported() const override { return true; }
42 bool isGuidedMode(const Vehicle *vehicle) const override;
43 QString gotoFlightMode() const override { return guidedFlightMode(); }
44 QString rtlFlightMode() const override;
45 QString smartRTLFlightMode() const override;
46 QString missionFlightMode() const override;
47 virtual QString guidedFlightMode() const;
48 void pauseVehicle(Vehicle *vehicle) const override;
49 void guidedModeRTL(Vehicle *vehicle, bool smartRTL) const override;
50 void guidedModeChangeAltitude(Vehicle *vehicle, double altitudeChange, bool pauseVehicle) override;
51 void guidedModeChangeHeading(Vehicle *vehicle, const QGeoCoordinate &headingCoord) const override;
52 bool adjustIncomingMavlinkMessage(Vehicle *vehicle, mavlink_message_t *message) override;
53 void adjustOutgoingMavlinkMessageThreadSafe(Vehicle *vehicle, LinkInterface *outgoingLink, mavlink_message_t *message) override;
54 virtual void initializeStreamRates(Vehicle *vehicle);
55 void initializeVehicle(Vehicle *vehicle) override;
56 bool sendHomePositionToVehicle() const override { return true; }
57 QString missionCommandOverrides(QGCMAVLink::VehicleClass_t vehicleClass) const override;
58 QString _internalParameterMetaDataFile(const Vehicle* vehicle) const override;
59 FactMetaData *_getMetaDataForFact(QObject *parameterMetaData, const QString &name, FactMetaData::ValueType_t type, MAV_TYPE vehicleType) const override;
60 void _getParameterMetaDataVersionInfo(const QString &metaDataFile, int &majorVersion, int &minorVersion) const override;
61 QObject *_loadParameterMetaData(const QString &metaDataFile) override;
62 QString brandImageIndoor(const Vehicle *vehicle) const override { Q_UNUSED(vehicle); return QStringLiteral("/qmlimages/APM/BrandImage"); }
63 QString brandImageOutdoor(const Vehicle *vehicle) const override { Q_UNUSED(vehicle); return QStringLiteral("/qmlimages/APM/BrandImage"); }
64 QString getHobbsMeter(Vehicle *vehicle) const override;
65 bool hasGripper(const Vehicle *vehicle) const override;
66 const QVariantList &toolIndicators(const Vehicle *vehicle) override;
67 double maximumEquivalentAirspeed(Vehicle *vehicle) const override;
68 double minimumEquivalentAirspeed(Vehicle *vehicle) const override;
69 bool fixedWingAirSpeedLimitsAvailable(Vehicle *vehicle) const override;
70 void guidedModeChangeEquivalentAirspeedMetersSecond(Vehicle* vehicle, double airspeed_equiv) const override;
71 void sendGCSMotionReport(Vehicle *vehicle, const FollowMe::GCSMotionReport& motionReport, uint8_t estimatationCapabilities) const override;
72 QVariant expandedToolbarIndicatorSource (const Vehicle* vehicle, const QString& indicatorName) const override;
73
74 // support for changing speed in Copter guide mode:
75 bool mulirotorSpeedLimitsAvailable(Vehicle *vehicle) const override;
76 double maximumHorizontalSpeedMultirotor(Vehicle *vehicle) const override;
77 void guidedModeChangeGroundSpeedMetersSecond(Vehicle *vehicle, double speed) const override;
78
79 static QPair<QMetaObject::Connection,QMetaObject::Connection> startCompensatingBaro(Vehicle *vehicle);
80 static bool stopCompensatingBaro(const Vehicle *vehicle, QPair<QMetaObject::Connection,QMetaObject::Connection> updaters);
81 static qreal calcAltOffsetPT(uint32_t atmospheric1, qreal temperature1, uint32_t atmospheric2, qreal temperature2);
82 static qreal calcAltOffsetP(uint32_t atmospheric1, uint32_t atmospheric2);
83
84protected:
86 explicit APMFirmwarePlugin(QObject *parent = nullptr);
87 virtual ~APMFirmwarePlugin();
88
89 void setSupportedModes(QList<APMCustomMode> supportedModes) { _supportedModes = supportedModes; }
90
91 bool _coaxialMotors = false;
92
93 const QString _guidedFlightMode = tr("Guided");
94 const QString _rtlFlightMode = tr("RTL");
95 const QString _smartRtlFlightMode = tr("Smart RTL");
96 const QString _autoFlightMode = tr("Auto");
97
98private slots:
99 void _artooSocketError(QAbstractSocket::SocketError socketError);
100
101private:
102 void _adjustCalibrationMessageSeverity(mavlink_message_t *message) const;
103 void _setInfoSeverity(mavlink_message_t *message) const;
104 void _handleIncomingParamValue(Vehicle *vehicle, mavlink_message_t *message);
105 bool _handleIncomingStatusText(Vehicle *vehicle, mavlink_message_t *message);
106 void _handleIncomingHeartbeat(Vehicle *vehicle, mavlink_message_t *message);
107 void _handleOutgoingParamSetThreadSafe(Vehicle *vehicle, LinkInterface *outgoingLink, mavlink_message_t *message);
108 void _soloVideoHandshake();
109 bool _guidedModeTakeoff(Vehicle *vehicle, double altitudeRel) const;
110 void _handleRCChannels(Vehicle *vehicle, mavlink_message_t* message);
111 void _handleRCChannelsRaw(Vehicle *vehicle, mavlink_message_t* message);
112 QString _getLatestVersionFileUrl(Vehicle *vehicle) const final;
113 QString _versionRegex() const final { return QStringLiteral(" V([0-9,\\.]*)$"); }
114 QString _vehicleClassToString(QGCMAVLink::VehicleClass_t vehicleClass) const;
115
116 static void _setBaroGndTemp(Vehicle *vehicle, qreal temperature);
117 static void _setBaroAltOffset(Vehicle *vehicle, qreal offset);
118
119 // Any instance data here must be global to all vehicles
120 // Vehicle specific data should go into APMFirmwarePluginInstanceData
121
122 QVariantList _toolIndicatorList;
123 QList<APMCustomMode> _supportedModes;
124 QMap<int /* vehicle id */, QMap<int /* componentId */, bool /* true: component is part of ArduPilot stack */>> _ardupilotComponentMap;
125
126 QMutex _adjustOutgoingMavlinkMutex;
127
128 static constexpr const char *_artooIP = "10.1.1.1";
129 static constexpr int _artooVideoHandshakePort = 5502;
130
131 static uint8_t _reencodeMavlinkChannel();
132 static QMutex &_reencodeMavlinkChannelMutex();
133
134 struct FirmwareParameterHeader {
135 MAV_AUTOPILOT firmwareType = MAV_AUTOPILOT_GENERIC;
136 MAV_TYPE vehicleType = MAV_TYPE_GENERIC;
137 QVersionNumber versionNumber;
138 FIRMWARE_VERSION_TYPE versionType;
139 QString gitRevision;
140 };
141 static FirmwareParameterHeader _parseParamsHeader(const QString &filePath);
142};
143
144/*===========================================================================*/
145
147{
148 Q_OBJECT
149
150 using FirmwarePluginInstanceData::FirmwarePluginInstanceData;
151
152public:
153
154 // anyVersionSupportsCommand returns
155 // CommandSupportedResult::SUPPORTED if any version of the
156 // firmware has supported cmd. It return UNSUPPORTED if no
157 // version ever has. It returns UNKNOWN if that information is
158 // not known.
160 {
161 switch (cmd) {
162 case MAV_CMD_DO_SET_MISSION_CURRENT:
164 default:
166 }
167 }
168
171
174};
Q_DECLARE_LOGGING_CATEGORY(AndroidSerialLog)
struct __mavlink_message mavlink_message_t
CommandSupportedResult anyVersionSupportsCommand(MAV_CMD cmd) const final
This is the base class for all stack specific APM firmware plugins.
bool isGuidedMode(const Vehicle *vehicle) const override
Returns whether the vehicle is in guided mode or not.
QVariant expandedToolbarIndicatorSource(const Vehicle *vehicle, const QString &indicatorName) const override
void setGuidedMode(Vehicle *vehicle, bool guidedMode) const override
Set guided flight mode.
bool sendHomePositionToVehicle() const override
QString flightMode(uint8_t base_mode, uint32_t custom_mode) const override
FactMetaData * _getMetaDataForFact(QObject *parameterMetaData, const QString &name, FactMetaData::ValueType_t type, MAV_TYPE vehicleType) const override
QString rtlFlightMode() const override
Returns the flight mode for RTL.
bool setFlightMode(const QString &flightMode, uint8_t *base_mode, uint32_t *custom_mode) const override
static qreal calcAltOffsetPT(uint32_t atmospheric1, qreal temperature1, uint32_t atmospheric2, qreal temperature2)
QString getHobbsMeter(Vehicle *vehicle) const override
gets hobbs meter from autopilot. This should be reimplmeented for each firmware
QString brandImageOutdoor(const Vehicle *vehicle) const override
Return the resource file which contains the brand image for the vehicle for Outdoor theme.
void sendGCSMotionReport(Vehicle *vehicle, const FollowMe::GCSMotionReport &motionReport, uint8_t estimatationCapabilities) const override
Sends the appropriate mavlink message for follow me support.
double maximumHorizontalSpeedMultirotor(Vehicle *vehicle) const override
bool fixedWingAirSpeedLimitsAvailable(Vehicle *vehicle) const override
static QPair< QMetaObject::Connection, QMetaObject::Connection > startCompensatingBaro(Vehicle *vehicle)
void setSupportedModes(QList< APMCustomMode > supportedModes)
void startMission(Vehicle *vehicle) const override
Command the vehicle to start the mission.
virtual void initializeStreamRates(Vehicle *vehicle)
void _getParameterMetaDataVersionInfo(const QString &metaDataFile, int &majorVersion, int &minorVersion) const override
void guidedModeGotoLocation(Vehicle *vehicle, const QGeoCoordinate &gotoCoord, double forwardFlightLoiterRadius) const override
Command vehicle to move to specified location (altitude is included and relative)
const QString _guidedFlightMode
QString brandImageIndoor(const Vehicle *vehicle) const override
Return the resource file which contains the brand image for the vehicle for Indoor theme.
QString missionCommandOverrides(QGCMAVLink::VehicleClass_t vehicleClass) const override
void guidedModeChangeGroundSpeedMetersSecond(Vehicle *vehicle, double speed) const override
void guidedModeChangeHeading(Vehicle *vehicle, const QGeoCoordinate &headingCoord) const override
Command vehicle to rotate towards specified location.
bool hasGripper(const Vehicle *vehicle) const override
double minimumTakeoffAltitudeMeters(Vehicle *vehicle) const override
QStringList flightModes(Vehicle *vehicle) const override
void guidedModeRTL(Vehicle *vehicle, bool smartRTL) const override
Command vehicle to return to launch.
bool adjustIncomingMavlinkMessage(Vehicle *vehicle, mavlink_message_t *message) override
static bool stopCompensatingBaro(const Vehicle *vehicle, QPair< QMetaObject::Connection, QMetaObject::Connection > updaters)
void guidedModeTakeoff(Vehicle *vehicle, double altitudeRel) const override
Command vehicle to takeoff from current location to the specified height.
double minimumEquivalentAirspeed(Vehicle *vehicle) const override
void startTakeoff(Vehicle *vehicle) const override
Command the vehicle to start a takeoff.
void adjustOutgoingMavlinkMessageThreadSafe(Vehicle *vehicle, LinkInterface *outgoingLink, mavlink_message_t *message) override
QString smartRTLFlightMode() const override
Returns the flight mode for Smart RTL.
const QString _autoFlightMode
double maximumEquivalentAirspeed(Vehicle *vehicle) const override
QString missionFlightMode() const override
Returns the flight mode for running missions.
void guidedModeChangeAltitude(Vehicle *vehicle, double altitudeChange, bool pauseVehicle) override
bool mulirotorSpeedLimitsAvailable(Vehicle *vehicle) const override
QObject * _loadParameterMetaData(const QString &metaDataFile) override
QList< MAV_CMD > supportedMissionCommands(QGCMAVLink::VehicleClass_t vehicleClass) const override
List of supported mission commands. Empty list for all commands supported.
const QString _smartRtlFlightMode
bool isCapable(const Vehicle *vehicle, FirmwareCapabilities capabilities) const override
void guidedModeChangeEquivalentAirspeedMetersSecond(Vehicle *vehicle, double airspeed_equiv) const override
static qreal calcAltOffsetP(uint32_t atmospheric1, uint32_t atmospheric2)
AutoPilotPlugin * autopilotPlugin(Vehicle *vehicle) const override
virtual QString guidedFlightMode() const
const QVariantList & toolIndicators(const Vehicle *vehicle) override
bool MAV_CMD_DO_SET_MODE_is_supported() const override
returns true if this flight stack supports MAV_CMD_DO_SET_MODE
QString _internalParameterMetaDataFile(const Vehicle *vehicle) const override
void pauseVehicle(Vehicle *vehicle) const override
void initializeVehicle(Vehicle *vehicle) override
Called when Vehicle is first created to perform any firmware specific setup.
QString gotoFlightMode() const override
Returns the flight mode which the vehicle will be in if it is performing a goto location.
const QString _rtlFlightMode
FirmwareCapabilities
Set of optional capabilites which firmware may support.
The link interface defines the interface for all links used to communicate with the ground station ap...