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/QMutex>
8#include <QtNetwork/QAbstractSocket>
9
11{
12 enum Mode : uint32_t {
13 AUTO = 3,
14 GUIDED = 4,
15 RTL = 6,
17 };
18};
19
23{
24 Q_OBJECT
25
26public:
27 QList<MAV_CMD> supportedMissionCommands(QGCMAVLink::VehicleClass_t vehicleClass) const override;
28 AutoPilotPlugin *autopilotPlugin(Vehicle* vehicle) const override;
29 bool isCapable(const Vehicle *vehicle, FirmwareCapabilities capabilities) const override;
30 void setGuidedMode(Vehicle *vehicle, bool guidedMode) const override;
31 void guidedModeTakeoff(Vehicle *vehicle, double altitudeRel) const override;
32 bool guidedModeGotoLocation(Vehicle *vehicle, const QGeoCoordinate& gotoCoord, double forwardFlightLoiterRadius) const override;
33 double minimumTakeoffAltitudeMeters(Vehicle *vehicle) const override;
34 void startTakeoff(Vehicle *vehicle) const override;
35 void startMission(Vehicle *vehicle) const override;
36 VehicleReadiness* createVehicleReadiness(Vehicle* vehicle) const override;
37 QStringList flightModes(Vehicle *vehicle) const override;
38 QString flightMode(uint8_t base_mode, uint32_t custom_mode) const override;
39 bool setFlightMode(const QString &flightMode, uint8_t *base_mode, uint32_t *custom_mode) const override;
40 bool MAV_CMD_DO_SET_MODE_is_supported() const override { return true; }
41 bool isGuidedMode(const Vehicle *vehicle) const override;
42 QString gotoFlightMode() const override { return guidedFlightMode(); }
43 QString rtlFlightMode() const override;
44 QString smartRTLFlightMode() const override;
45 QString missionFlightMode() const override;
46 virtual QString guidedFlightMode() const;
47 void pauseVehicle(Vehicle *vehicle) const override;
48 void guidedModeRTL(Vehicle *vehicle, bool smartRTL) const override;
49 void guidedModeChangeAltitude(Vehicle *vehicle, double altitudeChange, bool pauseVehicle) override;
50 void guidedModeChangeHeading(Vehicle *vehicle, const QGeoCoordinate &headingCoord) const override;
51 bool adjustIncomingMavlinkMessage(Vehicle *vehicle, mavlink_message_t *message) override;
52 void adjustOutgoingMavlinkMessageThreadSafe(Vehicle *vehicle, LinkInterface *outgoingLink, mavlink_message_t *message) override;
53 virtual void initializeStreamRates(Vehicle *vehicle);
54 void initializeVehicle(Vehicle *vehicle) override;
55 bool sendHomePositionToVehicle() const override { return true; }
56 QString missionCommandOverrides(QGCMAVLink::VehicleClass_t vehicleClass) const override;
57 QString _internalParameterMetaDataFile(const Vehicle* vehicle) const override;
58 MAV_AUTOPILOT _autopilotType() const override { return MAV_AUTOPILOT_ARDUPILOTMEGA; }
60 QString getHobbsMeter(Vehicle *vehicle) const override;
61 bool hasGripper(const Vehicle *vehicle) const override;
62 const QVariantList &toolIndicators(const Vehicle *vehicle) override;
63 double maximumEquivalentAirspeed(Vehicle *vehicle) const override;
64 double minimumEquivalentAirspeed(Vehicle *vehicle) const override;
65 bool fixedWingAirSpeedLimitsAvailable(Vehicle *vehicle) const override;
66 void guidedModeChangeEquivalentAirspeedMetersSecond(Vehicle* vehicle, double airspeed_equiv) const override;
67 void sendGCSMotionReport(Vehicle *vehicle, const FollowMe::GCSMotionReport& motionReport, uint8_t estimatationCapabilities) const override;
68 QVariant expandedToolbarIndicatorSource (const Vehicle* vehicle, const QString& indicatorName) const override;
69
70 // support for changing speed in Copter guide mode:
71 bool mulirotorSpeedLimitsAvailable(Vehicle *vehicle) const override;
72 double maximumHorizontalSpeedMultirotorMetersSecond(Vehicle *vehicle) const override;
73 void guidedModeChangeGroundSpeedMetersSecond(Vehicle *vehicle, double speed) const override;
74
75 static QPair<QMetaObject::Connection,QMetaObject::Connection> startCompensatingBaro(Vehicle *vehicle);
76 static bool stopCompensatingBaro(const Vehicle *vehicle, QPair<QMetaObject::Connection,QMetaObject::Connection> updaters);
77 static qreal calcAltOffsetPT(uint32_t atmospheric1, qreal temperature1, uint32_t atmospheric2, qreal temperature2);
78 static qreal calcAltOffsetP(uint32_t atmospheric1, uint32_t atmospheric2);
79
80protected:
82 explicit APMFirmwarePlugin(QObject *parent = nullptr);
83 virtual ~APMFirmwarePlugin();
84
85 void setSupportedModes(QList<APMCustomMode> supportedModes) { _supportedModes = supportedModes; }
86
87 bool _coaxialMotors = false;
88
89 const QString _guidedFlightMode = tr("Guided");
90 const QString _rtlFlightMode = tr("RTL");
91 const QString _smartRtlFlightMode = tr("Smart RTL");
92 const QString _autoFlightMode = tr("Auto");
93
94private slots:
95 void _artooSocketError(QAbstractSocket::SocketError socketError);
96
97private:
98 void _adjustCalibrationMessageSeverity(mavlink_message_t *message) const;
99 void _setInfoSeverity(mavlink_message_t *message) const;
100 void _handleIncomingParamValue(Vehicle *vehicle, mavlink_message_t *message);
101 bool _handleIncomingStatusText(Vehicle *vehicle, mavlink_message_t *message);
102 void _handleIncomingHeartbeat(Vehicle *vehicle, mavlink_message_t *message);
103 void _handleOutgoingParamSetThreadSafe(Vehicle *vehicle, LinkInterface *outgoingLink, mavlink_message_t *message);
104 void _soloVideoHandshake();
105 bool _guidedModeTakeoff(Vehicle *vehicle, double altitudeRel) const;
106 void _handleRCChannels(Vehicle *vehicle, mavlink_message_t* message);
107 void _handleRCChannelsRaw(Vehicle *vehicle, mavlink_message_t* message);
108 QString _getLatestVersionFileUrl(Vehicle *vehicle) const final;
109 QString _versionRegex() const final { return QStringLiteral(" V([0-9,\\.]*)$"); }
110 QString _vehicleClassToString(QGCMAVLink::VehicleClass_t vehicleClass) const;
111
112 static void _setBaroGndTemp(Vehicle *vehicle, qreal temperature);
113 static void _setBaroAltOffset(Vehicle *vehicle, qreal offset);
114
115 // Any instance data here must be global to all vehicles
116 // Vehicle specific data should go into APMFirmwarePluginInstanceData
117
118 QVariantList _toolIndicatorList;
119 QList<APMCustomMode> _supportedModes;
120 QMap<quint32 /* vehicle id */, QMap<int /* componentId */, bool /* true: component is part of ArduPilot stack */>>
121 _ardupilotComponentMap;
122
123 QMutex _adjustOutgoingMavlinkMutex;
124
125 static constexpr const char *_artooIP = "10.1.1.1";
126 static constexpr int _artooVideoHandshakePort = 5502;
127
128 static uint8_t _reencodeMavlinkChannel();
129 static QMutex &_reencodeMavlinkChannelMutex();
130
131 struct FirmwareParameterHeader {
132 MAV_AUTOPILOT firmwareType = MAV_AUTOPILOT_GENERIC;
133 MAV_TYPE vehicleType = MAV_TYPE_GENERIC;
134 QVersionNumber versionNumber;
135 FIRMWARE_VERSION_TYPE versionType;
136 QString gitRevision;
137 };
138 static FirmwareParameterHeader _parseParamsHeader(const QString &filePath);
139};
140
141/*===========================================================================*/
142
144{
145 Q_OBJECT
146
147 using FirmwarePluginInstanceData::FirmwarePluginInstanceData;
148
149public:
150
151 // anyVersionSupportsCommand returns
152 // CommandSupportedResult::SUPPORTED if any version of the
153 // firmware has supported cmd. It return UNSUPPORTED if no
154 // version ever has. It returns UNKNOWN if that information is
155 // not known.
157 {
158 switch (cmd) {
159 case MAV_CMD_DO_SET_MISSION_CURRENT:
161 default:
163 }
164 }
165
168
171};
struct __mavlink_message mavlink_message_t
CommandSupportedResult anyVersionSupportsCommand(MAV_CMD cmd) const final
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
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
void sendGCSMotionReport(Vehicle *vehicle, const FollowMe::GCSMotionReport &motionReport, uint8_t estimatationCapabilities) const override
Sends the appropriate mavlink message for follow me support.
bool fixedWingAirSpeedLimitsAvailable(Vehicle *vehicle) const override
bool guidedModeGotoLocation(Vehicle *vehicle, const QGeoCoordinate &gotoCoord, double forwardFlightLoiterRadius) 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)
const QString _guidedFlightMode
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
MAV_AUTOPILOT _autopilotType() const override
VehicleReadiness * createVehicleReadiness(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)
APMFirmwarePlugin(QObject *parent=nullptr)
All access to singleton is through stack specific implementation.
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
ParameterMetaData * _createParameterMetaData() 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
QList< MAV_CMD > supportedMissionCommands(QGCMAVLink::VehicleClass_t vehicleClass) const override
List of supported mission commands. Empty list for all commands supported.
const QString _smartRtlFlightMode
double maximumHorizontalSpeedMultirotorMetersSecond(Vehicle *vehicle) const override
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
The AutoPilotPlugin class is an abstract base class which represents the methods and objects which ar...
FirmwareCapabilities
Set of optional capabilites which firmware may support.
virtual QString _versionRegex() const
Returns regex QString to extract version information from text.
QVariantList _toolIndicatorList
FirmwarePlugin(QObject *parent=nullptr)
The link interface defines the interface for all links used to communicate with the ground station ap...
Whether the vehicle would accept the Arm, Takeoff and Start Mission guided actions.