CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Blimp/mode.h
Views: 1798
1
#pragma once
2
3
#include "Blimp.h"
4
class Parameters;
5
class ParametersG2;
6
7
class GCS_Blimp;
8
9
class Mode
10
{
11
12
public:
13
14
// Auto Pilot Modes enumeration
15
enum class Number : uint8_t {
16
LAND = 0, // currently just stops moving
17
MANUAL = 1, // manual control
18
VELOCITY = 2, // velocity mode
19
LOITER = 3, // loiter mode (position hold)
20
RTL = 4, // rtl
21
// Mode number 30 reserved for "offboard" for external/lua control.
22
};
23
24
// constructor
25
Mode(void);
26
27
// do not allow copying
28
CLASS_NO_COPY(Mode);
29
30
// child classes should override these methods
31
virtual bool init(bool ignore_checks)
32
{
33
return true;
34
}
35
virtual void run() = 0;
36
virtual bool requires_GPS() const = 0;
37
virtual bool has_manual_throttle() const = 0;
38
virtual bool allows_arming(bool from_gcs) const = 0;
39
virtual bool is_autopilot() const
40
{
41
return false;
42
}
43
virtual bool has_user_takeoff(bool must_navigate) const
44
{
45
return false;
46
}
47
virtual bool in_guided_mode() const
48
{
49
return false;
50
}
51
52
// return a string for this flightmode
53
virtual const char *name() const = 0;
54
virtual const char *name4() const = 0;
55
56
// returns a unique number specific to this mode
57
virtual Mode::Number number() const = 0;
58
59
virtual bool is_landing() const
60
{
61
return false;
62
}
63
64
// mode requires terrain to be present to be functional
65
virtual bool requires_terrain_failsafe() const
66
{
67
return false;
68
}
69
70
// functions for reporting to GCS
71
virtual bool get_wp(Location &loc)
72
{
73
return false;
74
};
75
virtual int32_t wp_bearing() const
76
{
77
return 0;
78
}
79
virtual uint32_t wp_distance() const
80
{
81
return 0;
82
}
83
virtual float crosstrack_error() const
84
{
85
return 0.0f;
86
}
87
88
void update_navigation();
89
90
// pilot input processing
91
void get_pilot_input(Vector3f &pilot, float &yaw);
92
93
protected:
94
95
// navigation support functions
96
virtual void run_autopilot() {}
97
98
// helper functions
99
bool is_disarmed_or_landed() const;
100
101
// functions to control landing
102
// in modes that support landing
103
void land_run_horizontal_control();
104
void land_run_vertical_control(bool pause_descent = false);
105
106
// convenience references to avoid code churn in conversion:
107
Parameters &g;
108
ParametersG2 &g2;
109
AP_InertialNav &inertial_nav;
110
AP_AHRS &ahrs;
111
Fins *&motors;
112
Loiter *&loiter;
113
RC_Channel *&channel_right;
114
RC_Channel *&channel_front;
115
RC_Channel *&channel_up;
116
RC_Channel *&channel_yaw;
117
float &G_Dt;
118
119
public:
120
// pass-through functions to reduce code churn on conversion;
121
// these are candidates for moving into the Mode base
122
// class.
123
bool set_mode(Mode::Number mode, ModeReason reason);
124
GCS_Blimp &gcs();
125
126
// end pass-through functions
127
};
128
129
class ModeManual : public Mode
130
{
131
132
public:
133
// inherit constructor
134
using Mode::Mode;
135
136
virtual void run() override;
137
138
bool requires_GPS() const override
139
{
140
return false;
141
}
142
bool has_manual_throttle() const override
143
{
144
return true;
145
}
146
bool allows_arming(bool from_gcs) const override
147
{
148
return true;
149
};
150
bool is_autopilot() const override
151
{
152
return false;
153
}
154
155
protected:
156
157
const char *name() const override
158
{
159
return "MANUAL";
160
}
161
const char *name4() const override
162
{
163
return "MANU";
164
}
165
166
Mode::Number number() const override { return Mode::Number::MANUAL; }
167
168
private:
169
170
};
171
172
class ModeVelocity : public Mode
173
{
174
175
public:
176
// inherit constructor
177
using Mode::Mode;
178
179
virtual void run() override;
180
181
bool requires_GPS() const override
182
{
183
return true;
184
}
185
bool has_manual_throttle() const override
186
{
187
return false;
188
}
189
bool allows_arming(bool from_gcs) const override
190
{
191
return true;
192
};
193
bool is_autopilot() const override
194
{
195
return false;
196
//TODO
197
}
198
199
protected:
200
201
const char *name() const override
202
{
203
return "VELOCITY";
204
}
205
const char *name4() const override
206
{
207
return "VELY";
208
}
209
210
Mode::Number number() const override { return Mode::Number::VELOCITY; }
211
212
private:
213
214
};
215
216
class ModeLoiter : public Mode
217
{
218
219
public:
220
// inherit constructor
221
using Mode::Mode;
222
223
virtual bool init(bool ignore_checks) override;
224
virtual void run() override;
225
226
bool requires_GPS() const override
227
{
228
return true;
229
}
230
bool has_manual_throttle() const override
231
{
232
return false;
233
}
234
bool allows_arming(bool from_gcs) const override
235
{
236
return true;
237
};
238
bool is_autopilot() const override
239
{
240
return false;
241
//TODO
242
}
243
244
protected:
245
246
const char *name() const override
247
{
248
return "LOITER";
249
}
250
const char *name4() const override
251
{
252
return "LOIT";
253
}
254
255
Mode::Number number() const override { return Mode::Number::LOITER; }
256
257
private:
258
Vector3f target_pos;
259
float target_yaw;
260
};
261
262
class ModeLand : public Mode
263
{
264
265
public:
266
// inherit constructor
267
using Mode::Mode;
268
269
virtual void run() override;
270
271
bool requires_GPS() const override
272
{
273
return false;
274
}
275
bool has_manual_throttle() const override
276
{
277
return true;
278
}
279
bool allows_arming(bool from_gcs) const override
280
{
281
return false;
282
};
283
bool is_autopilot() const override
284
{
285
return false;
286
}
287
288
protected:
289
290
const char *name() const override
291
{
292
return "LAND";
293
}
294
const char *name4() const override
295
{
296
return "LAND";
297
}
298
299
Mode::Number number() const override { return Mode::Number::LAND; }
300
301
private:
302
303
};
304
305
class ModeRTL : public Mode
306
{
307
308
public:
309
// inherit constructor
310
using Mode::Mode;
311
312
virtual bool init(bool ignore_checks) override;
313
virtual void run() override;
314
315
bool requires_GPS() const override
316
{
317
return true;
318
}
319
bool has_manual_throttle() const override
320
{
321
return false;
322
}
323
bool allows_arming(bool from_gcs) const override
324
{
325
return true;
326
};
327
bool is_autopilot() const override
328
{
329
return false;
330
//TODO
331
}
332
333
protected:
334
335
const char *name() const override
336
{
337
return "RTL";
338
}
339
const char *name4() const override
340
{
341
return "RTL";
342
}
343
344
Mode::Number number() const override { return Mode::Number::RTL; }
345
346
};
347
348