forked from ArduPilot/ardupilot
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathRC_Channel.cpp
436 lines (382 loc) · 13 KB
/
RC_Channel.cpp
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
#include "Plane.h"
#include "RC_Channel.h"
// defining these two macros and including the RC_Channels_VarInfo
// header defines the parameter information common to all vehicle
// types
#define RC_CHANNELS_SUBCLASS RC_Channels_Plane
#define RC_CHANNEL_SUBCLASS RC_Channel_Plane
#include <RC_Channel/RC_Channels_VarInfo.h>
// note that this callback is not presently used on Plane:
int8_t RC_Channels_Plane::flight_mode_channel_number() const
{
return plane.g.flight_mode_channel.get();
}
bool RC_Channels_Plane::has_valid_input() const
{
if (plane.rc_failsafe_active() || plane.failsafe.rc_failsafe) {
return false;
}
if (plane.failsafe.throttle_counter != 0) {
return false;
}
return true;
}
RC_Channel * RC_Channels_Plane::get_arming_channel(void) const
{
return plane.channel_rudder;
}
void RC_Channel_Plane::do_aux_function_change_mode(const Mode::Number number,
const AuxSwitchPos ch_flag)
{
switch(ch_flag) {
case AuxSwitchPos::HIGH: {
// engage mode (if not possible we remain in current flight mode)
plane.set_mode_by_number(number, ModeReason::RC_COMMAND);
break;
}
default:
// return to flight mode switch's flight mode if we are currently
// in this mode
if (plane.control_mode->mode_number() == number) {
rc().reset_mode_switch();
}
}
}
#if HAL_QUADPLANE_ENABLED
void RC_Channel_Plane::do_aux_function_q_assist_state(AuxSwitchPos ch_flag)
{
switch(ch_flag) {
case AuxSwitchPos::HIGH:
gcs().send_text(MAV_SEVERITY_INFO, "QAssist: Force enabled");
plane.quadplane.set_q_assist_state(plane.quadplane.Q_ASSIST_STATE_ENUM::Q_ASSIST_FORCE);
break;
case AuxSwitchPos::MIDDLE:
gcs().send_text(MAV_SEVERITY_INFO, "QAssist: Enabled");
plane.quadplane.set_q_assist_state(plane.quadplane.Q_ASSIST_STATE_ENUM::Q_ASSIST_ENABLED);
break;
case AuxSwitchPos::LOW:
gcs().send_text(MAV_SEVERITY_INFO, "QAssist: Disabled");
plane.quadplane.set_q_assist_state(plane.quadplane.Q_ASSIST_STATE_ENUM::Q_ASSIST_DISABLED);
break;
}
}
#endif // HAL_QUADPLANE_ENABLED
void RC_Channel_Plane::do_aux_function_crow_mode(AuxSwitchPos ch_flag)
{
switch(ch_flag) {
case AuxSwitchPos::HIGH:
plane.crow_mode = Plane::CrowMode::CROW_DISABLED;
gcs().send_text(MAV_SEVERITY_INFO, "Crow Flaps Disabled");
break;
case AuxSwitchPos::MIDDLE:
gcs().send_text(MAV_SEVERITY_INFO, "Progressive Crow Flaps");
plane.crow_mode = Plane::CrowMode::PROGRESSIVE;
break;
case AuxSwitchPos::LOW:
plane.crow_mode = Plane::CrowMode::NORMAL;
gcs().send_text(MAV_SEVERITY_INFO, "Normal Crow Flaps");
break;
}
}
void RC_Channel_Plane::do_aux_function_soaring_3pos(AuxSwitchPos ch_flag)
{
#if HAL_SOARING_ENABLED
SoaringController::ActiveStatus desired_state = SoaringController::ActiveStatus::SOARING_DISABLED;
switch (ch_flag) {
case AuxSwitchPos::LOW:
desired_state = SoaringController::ActiveStatus::SOARING_DISABLED;
break;
case AuxSwitchPos::MIDDLE:
desired_state = SoaringController::ActiveStatus::MANUAL_MODE_CHANGE;
break;
case AuxSwitchPos::HIGH:
desired_state = SoaringController::ActiveStatus::AUTO_MODE_CHANGE;
break;
}
plane.g2.soaring_controller.set_pilot_desired_state(desired_state);
#endif
}
void RC_Channel_Plane::do_aux_function_flare(AuxSwitchPos ch_flag)
{
switch(ch_flag) {
case AuxSwitchPos::HIGH:
plane.flare_mode = Plane::FlareMode::ENABLED_PITCH_TARGET;
#if HAL_QUADPLANE_ENABLED
plane.quadplane.set_q_assist_state(plane.quadplane.Q_ASSIST_STATE_ENUM::Q_ASSIST_DISABLED);
#endif
break;
case AuxSwitchPos::MIDDLE:
plane.flare_mode = Plane::FlareMode::ENABLED_NO_PITCH_TARGET;
#if HAL_QUADPLANE_ENABLED
plane.quadplane.set_q_assist_state(plane.quadplane.Q_ASSIST_STATE_ENUM::Q_ASSIST_DISABLED);
#endif
break;
case AuxSwitchPos::LOW:
#if HAL_QUADPLANE_ENABLED
plane.quadplane.set_q_assist_state(plane.quadplane.Q_ASSIST_STATE_ENUM::Q_ASSIST_ENABLED);
#endif
plane.flare_mode = Plane::FlareMode::FLARE_DISABLED;
break;
}
}
void RC_Channel_Plane::init_aux_function(const RC_Channel::aux_func_t ch_option,
const RC_Channel::AuxSwitchPos ch_flag)
{
switch(ch_option) {
// the following functions do not need to be initialised:
case AUX_FUNC::AUTO:
case AUX_FUNC::CIRCLE:
case AUX_FUNC::ACRO:
case AUX_FUNC::TRAINING:
case AUX_FUNC::FLAP:
case AUX_FUNC::GUIDED:
case AUX_FUNC::INVERTED:
case AUX_FUNC::LOITER:
case AUX_FUNC::MANUAL:
case AUX_FUNC::RTL:
case AUX_FUNC::TAKEOFF:
case AUX_FUNC::FBWA:
case AUX_FUNC::AIRBRAKE:
#if HAL_QUADPLANE_ENABLED
case AUX_FUNC::QRTL:
case AUX_FUNC::QSTABILIZE:
#endif
case AUX_FUNC::FBWA_TAILDRAGGER:
case AUX_FUNC::FWD_THR:
case AUX_FUNC::LANDING_FLARE:
case AUX_FUNC::PARACHUTE_RELEASE:
case AUX_FUNC::MODE_SWITCH_RESET:
case AUX_FUNC::CRUISE:
#if HAL_QUADPLANE_ENABLED
case AUX_FUNC::ARMDISARM_AIRMODE:
#endif
case AUX_FUNC::PLANE_AUTO_LANDING_ABORT:
case AUX_FUNC::TRIM_TO_CURRENT_SERVO_RC:
case AUX_FUNC::EMERGENCY_LANDING_EN:
case AUX_FUNC::FW_AUTOTUNE:
break;
case AUX_FUNC::SOARING:
#if HAL_QUADPLANE_ENABLED
case AUX_FUNC::Q_ASSIST:
case AUX_FUNC::AIRMODE:
case AUX_FUNC::WEATHER_VANE_ENABLE:
#endif
#if AP_AIRSPEED_AUTOCAL_ENABLE
case AUX_FUNC::ARSPD_CALIBRATE:
#endif
case AUX_FUNC::TER_DISABLE:
case AUX_FUNC::CROW_SELECT:
run_aux_function(ch_option, ch_flag, AuxFuncTriggerSource::INIT);
break;
case AUX_FUNC::REVERSE_THROTTLE:
plane.have_reverse_throttle_rc_option = true;
// setup input throttle as a range. This is needed as init_aux_function is called
// after set_control_channels()
if (plane.channel_throttle) {
plane.channel_throttle->set_range(100);
}
// note that we don't call do_aux_function() here as we don't
// want to startup with reverse thrust
break;
default:
// handle in parent class
RC_Channel::init_aux_function(ch_option, ch_flag);
break;
}
}
// do_aux_function - implement the function invoked by auxiliary switches
bool RC_Channel_Plane::do_aux_function(const aux_func_t ch_option, const AuxSwitchPos ch_flag)
{
switch(ch_option) {
case AUX_FUNC::INVERTED:
plane.inverted_flight = (ch_flag == AuxSwitchPos::HIGH);
break;
case AUX_FUNC::REVERSE_THROTTLE:
plane.reversed_throttle = (ch_flag == AuxSwitchPos::HIGH);
gcs().send_text(MAV_SEVERITY_INFO, "RevThrottle: %s", plane.reversed_throttle?"ENABLE":"DISABLE");
break;
case AUX_FUNC::AUTO:
do_aux_function_change_mode(Mode::Number::AUTO, ch_flag);
break;
case AUX_FUNC::CIRCLE:
do_aux_function_change_mode(Mode::Number::CIRCLE, ch_flag);
break;
case AUX_FUNC::ACRO:
do_aux_function_change_mode(Mode::Number::ACRO, ch_flag);
break;
case AUX_FUNC::TRAINING:
do_aux_function_change_mode(Mode::Number::TRAINING, ch_flag);
break;
case AUX_FUNC::LOITER:
do_aux_function_change_mode(Mode::Number::LOITER, ch_flag);
break;
case AUX_FUNC::GUIDED:
do_aux_function_change_mode(Mode::Number::GUIDED, ch_flag);
break;
case AUX_FUNC::MANUAL:
do_aux_function_change_mode(Mode::Number::MANUAL, ch_flag);
break;
case AUX_FUNC::RTL:
do_aux_function_change_mode(Mode::Number::RTL, ch_flag);
break;
case AUX_FUNC::TAKEOFF:
do_aux_function_change_mode(Mode::Number::TAKEOFF, ch_flag);
break;
case AUX_FUNC::FBWA:
do_aux_function_change_mode(Mode::Number::FLY_BY_WIRE_A, ch_flag);
break;
#if HAL_QUADPLANE_ENABLED
case AUX_FUNC::QRTL:
do_aux_function_change_mode(Mode::Number::QRTL, ch_flag);
break;
case AUX_FUNC::QSTABILIZE:
do_aux_function_change_mode(Mode::Number::QSTABILIZE, ch_flag);
break;
#endif
case AUX_FUNC::SOARING:
do_aux_function_soaring_3pos(ch_flag);
break;
case AUX_FUNC::FLAP:
case AUX_FUNC::FBWA_TAILDRAGGER:
case AUX_FUNC::AIRBRAKE:
break; // input labels, nothing to do
#if HAL_QUADPLANE_ENABLED
case AUX_FUNC::Q_ASSIST:
do_aux_function_q_assist_state(ch_flag);
break;
#endif
case AUX_FUNC::FWD_THR:
break; // VTOL forward throttle input label, nothing to do
case AUX_FUNC::TER_DISABLE:
switch (ch_flag) {
case AuxSwitchPos::HIGH:
plane.non_auto_terrain_disable = true;
if (plane.control_mode->allows_terrain_disable()) {
plane.set_target_altitude_current();
}
break;
case AuxSwitchPos::MIDDLE:
break;
case AuxSwitchPos::LOW:
plane.non_auto_terrain_disable = false;
if (plane.control_mode->allows_terrain_disable()) {
plane.set_target_altitude_current();
}
break;
}
gcs().send_text(MAV_SEVERITY_INFO, "NON AUTO TERRN: %s", plane.non_auto_terrain_disable?"OFF":"ON");
break;
case AUX_FUNC::CROW_SELECT:
do_aux_function_crow_mode(ch_flag);
break;
#if HAL_QUADPLANE_ENABLED
case AUX_FUNC::AIRMODE:
switch (ch_flag) {
case AuxSwitchPos::HIGH:
plane.quadplane.air_mode = AirMode::ON;
plane.quadplane.throttle_wait = false;
break;
case AuxSwitchPos::MIDDLE:
break;
case AuxSwitchPos::LOW:
plane.quadplane.air_mode = AirMode::OFF;
break;
}
break;
#endif
case AUX_FUNC::ARSPD_CALIBRATE:
#if AP_AIRSPEED_AUTOCAL_ENABLE
switch (ch_flag) {
case AuxSwitchPos::HIGH:
plane.airspeed.set_calibration_enabled(true);
break;
case AuxSwitchPos::MIDDLE:
break;
case AuxSwitchPos::LOW:
plane.airspeed.set_calibration_enabled(false);
break;
}
#endif
break;
case AUX_FUNC::LANDING_FLARE:
do_aux_function_flare(ch_flag);
break;
case AUX_FUNC::PARACHUTE_RELEASE:
#if PARACHUTE == ENABLED
if (ch_flag == AuxSwitchPos::HIGH) {
plane.parachute_manual_release();
}
#endif
break;
case AUX_FUNC::MODE_SWITCH_RESET:
rc().reset_mode_switch();
break;
case AUX_FUNC::CRUISE:
do_aux_function_change_mode(Mode::Number::CRUISE, ch_flag);
break;
#if HAL_QUADPLANE_ENABLED
case AUX_FUNC::ARMDISARM_AIRMODE:
RC_Channel::do_aux_function_armdisarm(ch_flag);
if (plane.arming.is_armed()) {
plane.quadplane.air_mode = AirMode::ON;
plane.quadplane.throttle_wait = false;
}
break;
case AUX_FUNC::WEATHER_VANE_ENABLE: {
if (plane.quadplane.weathervane != nullptr) {
switch (ch_flag) {
case AuxSwitchPos::HIGH:
plane.quadplane.weathervane->allow_weathervaning(true);
break;
case AuxSwitchPos::MIDDLE:
// nothing
break;
case AuxSwitchPos::LOW:
plane.quadplane.weathervane->allow_weathervaning(false);
break;
}
}
break;
}
#endif
case AUX_FUNC::PLANE_AUTO_LANDING_ABORT:
switch(ch_flag) {
case AuxSwitchPos::HIGH:
IGNORE_RETURN(plane.trigger_land_abort(0));
break;
case AuxSwitchPos::MIDDLE:
case AuxSwitchPos::LOW:
break;
}
break;
case AUX_FUNC::TRIM_TO_CURRENT_SERVO_RC:
if (ch_flag == AuxSwitchPos::HIGH) {
plane.trim_radio();
}
break;
case AUX_FUNC::EMERGENCY_LANDING_EN:
switch (ch_flag) {
case AuxSwitchPos::HIGH:
plane.emergency_landing = true;
break;
case AuxSwitchPos::MIDDLE:
break;
case AuxSwitchPos::LOW:
plane.emergency_landing = false;
break;
}
break;
case AUX_FUNC::FW_AUTOTUNE:
if (ch_flag == AuxSwitchPos::HIGH && plane.control_mode->mode_allows_autotuning()) {
plane.autotune_enable(true);
} else if (ch_flag == AuxSwitchPos::HIGH) {
GCS_SEND_TEXT(MAV_SEVERITY_WARNING, "Autotuning not allowed in this mode!");
} else {
plane.autotune_enable(false);
}
break;
default:
return RC_Channel::do_aux_function(ch_option, ch_flag);
}
return true;
}