QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GimbalController.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QTimer>
4#include <QtQmlIntegration/QtQmlIntegration>
5
6#include "Gimbal.h"
8#include "VehicleTypes.h"
9
11class Vehicle;
12
13class GimbalController : public QObject
14{
15 Q_OBJECT
16 QML_ELEMENT
17 QML_UNCREATABLE("")
18 Q_MOC_INCLUDE("QmlObjectListModel.h")
19
21
23 Q_PROPERTY(QmlObjectListModel* gimbals READ gimbals CONSTANT)
24
25public:
26 GimbalController(Vehicle *vehicle);
28
29 Gimbal *activeGimbal() const { return _activeGimbal; }
30 QmlObjectListModel *gimbals() const { return _gimbals; }
31
32 void setActiveGimbal(Gimbal *gimbal);
33
34 void sendPitchYawFlags(uint32_t flags);
35 Q_INVOKABLE void gimbalOnScreenControl(float panpct, float tiltpct, bool clickAndPoint, bool clickAndDrag, bool rateControl, bool retract = false, bool neutral = false, bool yawlock = false);
36 Q_INVOKABLE void sendPitchBodyYaw(float pitch, float yaw, bool showError = true);
37 Q_INVOKABLE void sendPitchAbsoluteYaw(float pitch, float yaw, bool showError = true);
38 Q_INVOKABLE void setGimbalRetract(bool set);
39 Q_INVOKABLE void setGimbalYawLock(bool set);
40 Q_INVOKABLE void acquireGimbalControl();
41 Q_INVOKABLE void releaseGimbalControl();
42 Q_INVOKABLE void sendRate();
43
47 Q_INVOKABLE void sendGimbalRate(float pitch_rate_deg_s, float yaw_rate_deg_s);
48
49signals:
51 void showAcquireGimbalControlPopup(); // This triggers a popup in QML asking the user for aproval to take control
52
53public slots:
54 // These slots are conected with joysticks for button control
55 void gimbalYawLock(bool yawLock) { setGimbalYawLock(yawLock); }
56 Q_INVOKABLE void centerGimbal();
57 void gimbalPitchStart(int direction);
58 void gimbalYawStart(int direction);
59 void gimbalPitchStop();
60 void gimbalYawStop();
61
62private slots:
63 void _initialConnectCompleted();
64 void _mavlinkMessageReceived(const mavlink_message_t& message);
65 void _rateSenderTimeout();
66
67private:
68 struct GimbalPairId {
69 GimbalPairId() = default;
70 GimbalPairId(uint8_t _managerCompid, uint8_t _deviceId)
71 : managerCompid(_managerCompid)
72 , deviceId(_deviceId) {}
73
74 // In order to use this as a key, we need to implement <,
75 bool operator<(const GimbalPairId &other) const {
76 // We compare managerCompid primarily, if they are equal, we compare the deviceId
77 if (managerCompid < other.managerCompid) {
78 return true;
79 } else if (managerCompid > other.managerCompid) {
80 return false;
81 } else if (deviceId < other.deviceId) {
82 return true;
83 } else {
84 return false;
85 }
86 }
87
88 bool operator==(const GimbalPairId &other) const {
89 return (managerCompid == other.managerCompid) && (deviceId == other.deviceId);
90 }
91
92 uint8_t managerCompid = 0;
93 uint8_t deviceId = 0;
94 };
95
97 bool _requestGimbalInformation(uint8_t compid);
98 static void _requestMessageResultHandler(void* resultHandlerData, MAV_RESULT result, VehicleTypes::RequestMessageResultHandlerFailureCode_t failureCode, const mavlink_message_t& message);
99 static void _requestDeviceInformationResultHandler(
100 void* resultHandlerData, MAV_RESULT result, VehicleTypes::RequestMessageResultHandlerFailureCode_t failureCode,
101 const mavlink_message_t& message);
102 void _handleHeartbeat(const mavlink_message_t &message);
103 void _handleGimbalManagerInformation(const mavlink_message_t &message);
104 void _handleGimbalManagerStatus(const mavlink_message_t &message);
105 void _handleGimbalDeviceAttitudeStatus(const mavlink_message_t &message);
106 void _handleGimbalDeviceInformation(const mavlink_message_t& message);
107 void _checkComplete(Gimbal &gimbal, GimbalPairId pairId);
108 bool _tryGetGimbalControl();
109 bool _yawInVehicleFrame(uint32_t flags);
110
111 void _sendGimbalAttitudeRates(float pitch_rate_deg_s, float yaw_rate_deg_s);
112
113 QTimer _rateSenderTimer;
114 Vehicle *_vehicle = nullptr;
115 Gimbal *_activeGimbal = nullptr;
116 int _pendingInformationRequestCompId = -1;
117
118 struct PotentialGimbalManager {
119 unsigned requestGimbalManagerInformationRetries = 6;
120 bool receivedGimbalManagerInformation = false;
121 };
122 QMap<uint8_t, PotentialGimbalManager> _potentialGimbalManagers; // key is compid
123
124 QMap<GimbalPairId, Gimbal*> _potentialGimbals;
125 QmlObjectListModel *_gimbals = nullptr;
126 bool _initialConnectComplete = false;
127
128 static constexpr const char *_gimbalFactGroupNamePrefix = "gimbal";
129};
struct __mavlink_message mavlink_message_t
void sendPitchYawFlags(uint32_t flags)
Q_INVOKABLE void sendGimbalRate(float pitch_rate_deg_s, float yaw_rate_deg_s)
Q_INVOKABLE void setGimbalYawLock(bool set)
QmlObjectListModel * gimbals() const
Q_INVOKABLE void centerGimbal()
Gimbal * activeGimbal() const
void activeGimbalChanged()
Q_INVOKABLE void sendRate()
Q_INVOKABLE void sendPitchAbsoluteYaw(float pitch, float yaw, bool showError=true)
void gimbalYawLock(bool yawLock)
friend class GimbalControllerDiscoveryTest
Q_INVOKABLE void gimbalOnScreenControl(float panpct, float tiltpct, bool clickAndPoint, bool clickAndDrag, bool rateControl, bool retract=false, bool neutral=false, bool yawlock=false)
Q_INVOKABLE void acquireGimbalControl()
void setActiveGimbal(Gimbal *gimbal)
void gimbalYawStart(int direction)
Q_INVOKABLE void setGimbalRetract(bool set)
void showAcquireGimbalControlPopup()
void gimbalPitchStart(int direction)
Q_INVOKABLE void releaseGimbalControl()
Q_INVOKABLE void sendPitchBodyYaw(float pitch, float yaw, bool showError=true)
Definition Gimbal.h:9
RequestMessageResultHandlerFailureCode_t