QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
VehicleReadiness.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QLoggingCategory>
4#include <QtCore/QObject>
5#include <QtCore/QString>
6#include <QtCore/QTimer>
7#include <QtQmlIntegration/QtQmlIntegration>
8
9class Vehicle;
10class VehicleReadinessPX4Test;
11class VehicleReadinessTest;
12
13Q_DECLARE_LOGGING_CATEGORY(VehicleReadinessLog)
14
15
26class VehicleReadiness : public QObject
27{
28 Q_OBJECT
29 QML_ELEMENT
30 QML_UNCREATABLE("")
31
32 Q_PROPERTY(bool canArm READ canArm NOTIFY readinessChanged)
33 Q_PROPERTY(bool canTakeoff READ canTakeoff NOTIFY readinessChanged)
34 Q_PROPERTY(bool canStartMission READ canStartMission NOTIFY readinessChanged)
35 Q_PROPERTY(Status status READ status NOTIFY readinessChanged)
36
37public:
38 explicit VehicleReadiness(Vehicle* vehicle);
39
40 enum class Status
41 {
43 NotReady,
44 Ready,
45 Syncing,
46 };
47 Q_ENUM(Status)
48
49 bool canArm() const { return _result.canArm; }
50
51 bool canTakeoff() const { return _result.canTakeoff; }
52
53 bool canStartMission() const { return _result.canStartMission; }
54
55 Status status() const { return _result.status; }
56
58 void update();
59
60signals:
62
63protected:
64 enum class GuidedAction
65 {
66 Takeoff,
67 StartMission,
68 };
69
72 {
73 QString armFlightMode;
75 };
76
79
84 virtual bool _canArm(bool genericCanArm) const { return genericCanArm; }
85
86 virtual bool _canTakeoff(bool genericCanTakeoff) const { return genericCanTakeoff; }
87
88 virtual bool _canStartMission(bool genericCanStartMission) const { return genericCanStartMission; }
89
90 virtual Status _status(Status genericStatus) const { return genericStatus; }
91
93
94 Vehicle* _vehicle = nullptr;
95
96private:
99
101 struct ActionModeGroups
102 {
103 int armModeGroup = -1;
104 int targetModeGroup = -1;
105 };
106
107 struct Inputs
108 {
109 bool armed = false;
110 bool checklistBlocksArming = false;
111 bool initialConnectComplete = false;
112 bool healthReportWaitExpired = false;
113
114 bool healthAndArmingChecksSupported = false;
115 bool healthAndArmingChecksReported = false;
116 int currentModeGroup = -1;
117 ActionModeGroups takeoff{};
118 ActionModeGroups startMission{};
119 quint64 canArmModeGroups = 0;
120 quint64 canRunModeGroups = 0;
121
122 bool prearmCheckAvailable = false;
123 bool prearmCheckPassed = false;
124
125 bool sensorsHealthy = false;
126 bool setupComplete = false;
127 };
128
129 struct Result
130 {
131 bool canArm = false;
132 bool canTakeoff = false;
133 bool canStartMission = false;
134 Status status = Status::Unknown;
135
136 bool operator==(const Result& other) const = default;
137 };
138
139 static Result _evaluate(const Inputs& inputs);
142 static void _applyLockouts(Result& result, const Inputs& inputs);
143 Inputs _gatherInputs() const;
144 ActionModeGroups _actionModeGroups(GuidedAction action) const;
145 int _modeGroup(const QString& flightMode) const;
146
147 void _healthReportWaitTimeout();
148
150 static constexpr int _healthReportWaitMs = 10000;
151
152 Result _result;
153 QTimer _healthReportWaitTimer;
154 bool _healthReportWaitExpired = false;
155};
bool canStartMission() const
friend class VehicleReadinessTest
virtual bool _canStartMission(bool genericCanStartMission) const
virtual bool _canTakeoff(bool genericCanTakeoff) const
bool canTakeoff() const
virtual ActionFlightModes _actionFlightModes(GuidedAction) const
Firmware returns the modes its plugin uses for the action. Unknown modes fall back to the current mod...
void readinessChanged()
virtual Status _status(Status genericStatus) const
VehicleReadiness(Vehicle *vehicle)
bool canArm() const
friend class VehicleReadinessPX4Test
virtual bool _canArm(bool genericCanArm) const
Status status() const
Flight modes a guided action uses, as the firmware plugin performs it.
QString armFlightMode
Mode the vehicle is in when the action arms it.
QString targetFlightMode
Mode the action ends up in, which an armed vehicle switches into.