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