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/ArduPlane/Plane.h
Views: 1798
1
/*
2
Lead developer: Andrew Tridgell & Tom Pittenger
3
4
Authors: Doug Weibel, Jose Julio, Jordi Munoz, Jason Short, Randy Mackay, Pat Hickey, John Arne Birkeland, Olivier Adler, Amilcar Lucas, Gregory Fletcher, Paul Riseborough, Brandon Jones, Jon Challinger
5
Thanks to: Chris Anderson, Michael Oborne, Paul Mather, Bill Premerlani, James Cohen, JB from rotorFX, Automatik, Fefenin, Peter Meister, Remzibi, Yury Smirnov, Sandro Benigno, Max Levine, Roberto Navoni, Lorenz Meier, Yury MonZon
6
7
Please contribute your ideas! See http://dev.ardupilot.com for details
8
9
This program is free software: you can redistribute it and/or modify
10
it under the terms of the GNU General Public License as published by
11
the Free Software Foundation, either version 3 of the License, or
12
(at your option) any later version.
13
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
18
19
You should have received a copy of the GNU General Public License
20
along with this program. If not, see <http://www.gnu.org/licenses/>.
21
*/
22
#pragma once
23
24
////////////////////////////////////////////////////////////////////////////////
25
// Header includes
26
////////////////////////////////////////////////////////////////////////////////
27
28
#include <cmath>
29
#include <stdarg.h>
30
#include <stdio.h>
31
32
#include <AP_HAL/AP_HAL.h>
33
#include <AP_Common/AP_Common.h>
34
#include <AP_Airspeed/AP_Airspeed.h>
35
#include <AP_Param/AP_Param.h>
36
#include <StorageManager/StorageManager.h>
37
#include <AP_Math/AP_Math.h> // ArduPilot Mega Vector/Matrix math Library
38
#include <AP_InertialSensor/AP_InertialSensor.h> // Inertial Sensor Library
39
#include <AP_AccelCal/AP_AccelCal.h> // interface and maths for accelerometer calibration
40
#include <AP_AHRS/AP_AHRS.h> // ArduPilot Mega DCM Library
41
#include <SRV_Channel/SRV_Channel.h>
42
#include <AP_RangeFinder/AP_RangeFinder_config.h> // Range finder library
43
#include <Filter/Filter.h> // Filter library
44
#include <AP_Camera/AP_Camera.h> // Photo or video camera
45
#include <AP_Terrain/AP_Terrain.h>
46
#include <AP_RPM/AP_RPM.h>
47
#include <AP_Beacon/AP_Beacon.h>
48
49
#include <AP_AdvancedFailsafe/AP_AdvancedFailsafe.h>
50
#include <APM_Control/APM_Control.h>
51
#include <APM_Control/AP_AutoTune.h>
52
#include <GCS_MAVLink/GCS_MAVLink.h> // MAVLink GCS definitions
53
#include <AP_Mount/AP_Mount.h> // Camera/Antenna mount
54
#include <AP_Declination/AP_Declination.h> // ArduPilot Mega Declination Helper Library
55
#include <AP_Logger/AP_Logger.h>
56
#include <AP_Scheduler/AP_Scheduler.h> // main loop scheduler
57
#include <AP_Scheduler/PerfInfo.h> // loop perf monitoring
58
59
#include <AP_Navigation/AP_Navigation.h>
60
#include <AP_L1_Control/AP_L1_Control.h>
61
#include <AP_RCMapper/AP_RCMapper.h> // RC input mapping library
62
63
#include <AP_Vehicle/AP_Vehicle.h>
64
#include <AP_TECS/AP_TECS.h>
65
#include <AP_NavEKF2/AP_NavEKF2.h>
66
#include <AP_NavEKF3/AP_NavEKF3.h>
67
#include <AP_Mission/AP_Mission.h> // Mission command library
68
69
#include <AP_Soaring/AP_Soaring.h>
70
#include <AP_BattMonitor/AP_BattMonitor.h> // Battery monitor library
71
72
#include <AP_Arming/AP_Arming.h>
73
#include <AP_Frsky_Telem/AP_Frsky_Telem.h>
74
#include <AP_OSD/AP_OSD.h>
75
76
#include <AP_Rally/AP_Rally.h>
77
78
#include <AP_OpticalFlow/AP_OpticalFlow.h> // Optical Flow library
79
#include <AP_Parachute/AP_Parachute.h>
80
#include <AP_ADSB/AP_ADSB.h>
81
#include <AP_ICEngine/AP_ICEngine.h>
82
#include <AP_Landing/AP_Landing.h>
83
#include <AP_LandingGear/AP_LandingGear.h> // Landing Gear library
84
#include <AP_Follow/AP_Follow.h>
85
#include <AP_ExternalControl/AP_ExternalControl_config.h>
86
#if AP_EXTERNAL_CONTROL_ENABLED
87
#include "AP_ExternalControl_Plane.h"
88
#endif
89
90
#include <AC_PrecLand/AC_PrecLand_config.h>
91
#if AC_PRECLAND_ENABLED
92
# include <AC_PrecLand/AC_PrecLand.h>
93
#endif
94
95
#include "GCS_MAVLink_Plane.h"
96
#include "GCS_Plane.h"
97
#include "quadplane.h"
98
#include <AP_Tuning/AP_Tuning_config.h>
99
#if AP_TUNING_ENABLED
100
#include "tuning.h"
101
#endif
102
103
// Configuration
104
#include "config.h"
105
106
#if AP_ADVANCEDFAILSAFE_ENABLED
107
#include "afs_plane.h"
108
#endif
109
110
// Local modules
111
#include "defines.h"
112
#include "mode.h"
113
114
#if AP_SCRIPTING_ENABLED
115
#include <AP_Scripting/AP_Scripting.h>
116
#endif
117
118
#include "RC_Channel_Plane.h" // RC Channel Library
119
#include "Parameters.h"
120
#if HAL_ADSB_ENABLED
121
#include "avoidance_adsb.h"
122
#endif
123
#include "AP_Arming.h"
124
#include "pullup.h"
125
126
/*
127
main APM:Plane class
128
*/
129
class Plane : public AP_Vehicle {
130
public:
131
friend class GCS_MAVLINK_Plane;
132
friend class Parameters;
133
friend class ParametersG2;
134
friend class AP_Arming_Plane;
135
friend class QuadPlane;
136
friend class QAutoTune;
137
friend class AP_Tuning_Plane;
138
friend class AP_AdvancedFailsafe_Plane;
139
friend class AP_Avoidance_Plane;
140
friend class GCS_Plane;
141
friend class RC_Channel_Plane;
142
friend class RC_Channels_Plane;
143
friend class Tailsitter;
144
friend class Tiltrotor;
145
friend class SLT_Transition;
146
friend class Tailsitter_Transition;
147
friend class VTOL_Assist;
148
149
friend class Mode;
150
friend class ModeCircle;
151
friend class ModeStabilize;
152
friend class ModeTraining;
153
friend class ModeAcro;
154
friend class ModeFBWA;
155
friend class ModeFBWB;
156
friend class ModeCruise;
157
friend class ModeAutoTune;
158
friend class ModeAuto;
159
friend class ModeRTL;
160
friend class ModeLoiter;
161
friend class ModeAvoidADSB;
162
friend class ModeGuided;
163
friend class ModeInitializing;
164
friend class ModeManual;
165
friend class ModeQStabilize;
166
friend class ModeQHover;
167
friend class ModeQLoiter;
168
friend class ModeQLand;
169
friend class ModeQRTL;
170
friend class ModeQAcro;
171
friend class ModeQAutotune;
172
friend class ModeTakeoff;
173
friend class ModeThermal;
174
friend class ModeLoiterAltQLand;
175
#if MODE_AUTOLAND_ENABLED
176
friend class ModeAutoLand;
177
#endif
178
#if AP_EXTERNAL_CONTROL_ENABLED
179
friend class AP_ExternalControl_Plane;
180
#endif
181
#if AP_PLANE_GLIDER_PULLUP_ENABLED
182
friend class GliderPullup;
183
#endif
184
185
Plane(void);
186
187
private:
188
189
// key aircraft parameters passed to multiple libraries
190
AP_FixedWing aparm;
191
192
// Global parameters are all contained within the 'g' and 'g2' classes.
193
Parameters g;
194
ParametersG2 g2;
195
196
// mapping between input channels
197
RCMapper rcmap;
198
199
// primary input channels
200
RC_Channel *channel_roll;
201
RC_Channel *channel_pitch;
202
RC_Channel *channel_throttle;
203
RC_Channel *channel_rudder;
204
RC_Channel *channel_flap;
205
RC_Channel *channel_airbrake;
206
207
// scaled roll limit based on pitch
208
int32_t roll_limit_cd;
209
float pitch_limit_min;
210
211
// flight modes convenience array
212
AP_Int8 *flight_modes = &g.flight_mode1;
213
const uint8_t num_flight_modes = 6;
214
215
#if AP_RANGEFINDER_ENABLED
216
AP_FixedWing::Rangefinder_State rangefinder_state;
217
218
/*
219
orientation of rangefinder to use for landing
220
*/
221
Rotation rangefinder_orientation(void) const {
222
return Rotation(g2.rangefinder_land_orient.get());
223
}
224
#endif
225
226
#if AP_MAVLINK_MAV_CMD_SET_HAGL_ENABLED
227
struct {
228
// allow for external height above ground estimate
229
float hagl;
230
uint32_t last_update_ms;
231
uint32_t timeout_ms;
232
} external_hagl;
233
bool get_external_HAGL(float &height_agl);
234
void handle_external_hagl(const mavlink_command_int_t &packet);
235
#endif // AP_MAVLINK_MAV_CMD_SET_HAGL_ENABLED
236
237
float get_landing_height(bool &using_rangefinder);
238
239
240
#if AP_RPM_ENABLED
241
AP_RPM rpm_sensor;
242
#endif
243
244
AP_TECS TECS_controller{ahrs, aparm, landing, MASK_LOG_TECS};
245
AP_L1_Control L1_controller{ahrs, &TECS_controller};
246
247
// Attitude to servo controllers
248
AP_RollController rollController{aparm};
249
AP_PitchController pitchController{aparm};
250
AP_YawController yawController{aparm};
251
AP_SteerController steerController{};
252
253
// Training mode
254
bool training_manual_roll; // user has manual roll control
255
bool training_manual_pitch; // user has manual pitch control
256
257
// should throttle be pass-thru in guided?
258
bool guided_throttle_passthru;
259
260
// are we doing calibration? This is used to allow heartbeat to
261
// external failsafe boards during baro and airspeed calibration
262
bool in_calibration;
263
264
// are we currently in long failsafe but have postponed it in MODE TAKEOFF until min level alt is reached
265
bool long_failsafe_pending;
266
267
// GCS selection
268
GCS_Plane _gcs; // avoid using this; use gcs()
269
GCS_Plane &gcs() { return _gcs; }
270
271
// selected navigation controller
272
AP_Navigation *nav_controller = &L1_controller;
273
274
// Camera
275
#if AP_CAMERA_ENABLED
276
AP_Camera camera{MASK_LOG_CAMERA};
277
#endif
278
279
#if AP_OPTICALFLOW_ENABLED
280
// Optical flow sensor
281
AP_OpticalFlow optflow;
282
#endif
283
284
#if HAL_RALLY_ENABLED
285
// Rally Points
286
AP_Rally rally;
287
#endif
288
289
#if AC_PRECLAND_ENABLED
290
void precland_update(void);
291
#endif
292
293
// returns a Location for a rally point or home; if
294
// HAL_RALLY_ENABLED is false, just home.
295
Location calc_best_rally_or_home_location(const Location &current_loc, float rtl_home_alt_amsl_cm) const;
296
297
#if OSD_ENABLED || OSD_PARAM_ENABLED
298
AP_OSD osd;
299
#endif
300
301
ModeCircle mode_circle;
302
ModeStabilize mode_stabilize;
303
ModeTraining mode_training;
304
ModeAcro mode_acro;
305
ModeFBWA mode_fbwa;
306
ModeFBWB mode_fbwb;
307
ModeCruise mode_cruise;
308
ModeAutoTune mode_autotune;
309
ModeAuto mode_auto;
310
ModeRTL mode_rtl;
311
ModeLoiter mode_loiter;
312
#if HAL_ADSB_ENABLED
313
ModeAvoidADSB mode_avoidADSB;
314
#endif
315
ModeGuided mode_guided;
316
ModeInitializing mode_initializing;
317
ModeManual mode_manual;
318
#if HAL_QUADPLANE_ENABLED
319
ModeQStabilize mode_qstabilize;
320
ModeQHover mode_qhover;
321
ModeQLoiter mode_qloiter;
322
ModeQLand mode_qland;
323
ModeQRTL mode_qrtl;
324
ModeQAcro mode_qacro;
325
ModeLoiterAltQLand mode_loiter_qland;
326
#if QAUTOTUNE_ENABLED
327
ModeQAutotune mode_qautotune;
328
#endif // QAUTOTUNE_ENABLED
329
#endif // HAL_QUADPLANE_ENABLED
330
ModeTakeoff mode_takeoff;
331
#if MODE_AUTOLAND_ENABLED
332
ModeAutoLand mode_autoland;
333
#endif
334
#if HAL_SOARING_ENABLED
335
ModeThermal mode_thermal;
336
#endif
337
338
#if AP_QUICKTUNE_ENABLED
339
AP_Quicktune quicktune;
340
#endif
341
342
// This is the state of the flight control system
343
// There are multiple states defined such as MANUAL, FBW-A, AUTO
344
Mode *control_mode = &mode_initializing;
345
Mode *previous_mode = &mode_initializing;
346
347
// time of last mode change
348
uint32_t last_mode_change_ms;
349
350
// Used to maintain the state of the previous control switch position
351
// This is set to 254 when we need to re-read the switch
352
uint8_t oldSwitchPosition = 254;
353
354
// This is used to enable the inverted flight feature
355
bool inverted_flight;
356
357
// last time we ran roll/pitch stabilization
358
uint32_t last_stabilize_ms;
359
360
// Failsafe
361
struct {
362
// Used to track if the value on channel 3 (throttle) has fallen below the failsafe threshold
363
// RC receiver should be set up to output a low throttle value when signal is lost
364
bool rc_failsafe;
365
366
// true if an adsb related failsafe has occurred
367
bool adsb;
368
369
// saved flight mode
370
enum Mode::Number saved_mode_number;
371
372
// A tracking variable for type of failsafe active
373
// Used for failsafe based on loss of RC signal or GCS signal
374
int16_t state;
375
376
// number of low throttle values
377
uint8_t throttle_counter;
378
379
// A timer used to track how long we have been in a "short failsafe" condition due to loss of RC signal
380
uint32_t short_timer_ms;
381
382
uint32_t last_valid_rc_ms;
383
384
//keeps track of the last valid rc as it relates to the AFS system
385
//Does not count rc inputs as valid if the standard failsafe is on
386
uint32_t AFS_last_valid_rc_ms;
387
} failsafe;
388
389
#if HAL_QUADPLANE_ENABLED
390
// Landing
391
class VTOLApproach {
392
public:
393
enum class Stage {
394
RTL,
395
LOITER_TO_ALT,
396
ENSURE_RADIUS,
397
WAIT_FOR_BREAKOUT,
398
APPROACH_LINE,
399
VTOL_LANDING,
400
};
401
402
Stage approach_stage;
403
float approach_direction_deg;
404
} vtol_approach_s;
405
#endif
406
407
bool any_failsafe_triggered() {
408
return failsafe.state != FAILSAFE_NONE || battery.has_failsafed() || failsafe.adsb;
409
}
410
411
// A counter used to count down valid gps fixes to allow the gps estimate to settle
412
// before recording our home position (and executing a ground start if we booted with an air start)
413
uint8_t ground_start_count = 5;
414
415
// true if we have a position estimate from AHRS
416
bool have_position;
417
418
// Airspeed
419
// The calculated airspeed to use in FBW-B. Also used in higher modes for insuring min ground speed is met.
420
// Also used for flap deployment criteria. Centimeters per second.
421
int32_t target_airspeed_cm;
422
int32_t new_airspeed_cm = -1; //temp variable for AUTO and GUIDED mode speed changes
423
424
// The difference between current and desired airspeed. Used in the pitch controller. Meters per second.
425
float airspeed_error;
426
427
// An amount that the airspeed should be increased in auto modes based on the user positioning the
428
// throttle stick in the top half of the range. Centimeters per second.
429
int16_t airspeed_nudge_cm;
430
431
// Similar to airspeed_nudge, but used when no airspeed sensor.
432
// 0-(throttle_max - throttle_cruise) : throttle nudge in Auto mode using top 1/2 of throttle stick travel
433
int16_t throttle_nudge;
434
435
// Ground speed
436
// The amount current ground speed is below min ground speed. Centimeters per second
437
int32_t groundspeed_undershoot;
438
bool groundspeed_undershoot_is_valid;
439
440
// speed scaler for control surfaces, updated at 10Hz
441
float surface_speed_scaler = 1.0;
442
443
// Battery Sensors
444
AP_BattMonitor battery{MASK_LOG_CURRENT,
445
FUNCTOR_BIND_MEMBER(&Plane::handle_battery_failsafe, void, const char*, const int8_t),
446
_failsafe_priorities};
447
448
struct {
449
uint32_t last_tkoff_arm_time;
450
uint32_t last_check_ms;
451
uint32_t rudder_takeoff_warn_ms;
452
uint32_t last_report_ms;
453
bool launchTimerStarted;
454
uint8_t accel_event_counter;
455
uint32_t accel_event_ms;
456
uint32_t start_time_ms;
457
bool waiting_for_rudder_neutral;
458
float throttle_lim_max;
459
float throttle_lim_min;
460
uint32_t throttle_max_timer_ms;
461
uint32_t level_off_start_time_ms;
462
// Good candidate for keeping the initial time for TKOFF_THR_MAX_T.
463
#if MODE_AUTOLAND_ENABLED
464
struct {
465
float heading; // deg
466
bool initialized;
467
} initial_direction;
468
#endif
469
} takeoff_state;
470
471
// ground steering controller state
472
struct {
473
// Direction held during phases of takeoff and landing centidegrees
474
// A value of -1 indicates the course has not been set/is not in use
475
// this is a 0..36000 value, or -1 for disabled
476
int32_t hold_course_cd = -1;
477
478
// locked_course and locked_course_cd are used in stabilize mode
479
// when ground steering is active, and for steering in auto-takeoff
480
bool locked_course;
481
float locked_course_err;
482
uint32_t last_steer_ms;
483
} steer_state;
484
485
// flight mode specific
486
struct {
487
// Altitude threshold to complete a takeoff command in autonomous
488
// modes. Centimeters above home
489
int32_t takeoff_altitude_rel_cm;
490
491
// Begin leveling out the enforced takeoff pitch angle min at this height to reduce/eliminate overshoot
492
int32_t height_below_takeoff_to_level_off_cm;
493
494
// the highest airspeed we have reached since entering AUTO. Used
495
// to control ground takeoff
496
float highest_airspeed;
497
498
// turn angle for next leg of mission
499
float next_turn_angle {90};
500
501
// filtered sink rate for landing
502
float sink_rate;
503
504
// time when we first pass min GPS speed on takeoff
505
uint32_t takeoff_speed_time_ms;
506
507
// distance to next waypoint
508
float wp_distance;
509
510
// proportion to next waypoint
511
float wp_proportion;
512
513
// last time is_flying() returned true in milliseconds
514
uint32_t last_flying_ms;
515
516
// time stamp of when we start flying while in auto mode in milliseconds
517
uint32_t started_flying_in_auto_ms;
518
519
// barometric altitude at start of takeoff
520
float baro_takeoff_alt;
521
522
// initial pitch. Used to detect if nose is rising in a tail dragger
523
int16_t initial_pitch_cd;
524
525
// Minimum pitch to hold during takeoff command execution. Hundredths of a degree
526
int16_t takeoff_pitch_cd;
527
528
// Flag for using gps ground course instead of INS yaw. Set false when takeoff command in process.
529
bool takeoff_complete;
530
531
// are we headed to the land approach waypoint? Works for any nav type
532
bool wp_is_land_approach;
533
534
// should we fly inverted?
535
bool inverted_flight;
536
537
// should we enable cross-tracking for the next waypoint?
538
bool next_wp_crosstrack;
539
540
// should we use cross-tracking for this waypoint?
541
bool crosstrack;
542
543
// in FBWA taildragger takeoff mode
544
bool fbwa_tdrag_takeoff_mode;
545
546
// have we checked for an auto-land?
547
bool checked_for_autoland;
548
549
// Altitude threshold to complete a takeoff command in autonomous modes. Centimeters
550
// are we in idle mode? used for balloon launch to stop servo
551
// movement until altitude is reached
552
bool idle_mode;
553
554
// are we in VTOL mode in AUTO?
555
bool vtol_mode;
556
557
// are we doing loiter mode as a VTOL?
558
bool vtol_loiter;
559
560
// how much correction have we added for terrain data
561
float terrain_correction;
562
563
// last home altitude for detecting changes
564
int32_t last_home_alt_cm;
565
} auto_state;
566
567
#if AP_SCRIPTING_ENABLED
568
// support for scripting nav commands, with verify
569
struct {
570
bool enabled;
571
uint16_t id;
572
float roll_rate_dps;
573
float pitch_rate_dps;
574
float yaw_rate_dps;
575
float throttle_pct;
576
uint32_t start_ms;
577
uint32_t current_ms;
578
float rudder_offset_pct;
579
bool run_yaw_rate_controller;
580
} nav_scripting;
581
#endif
582
583
struct {
584
// roll pitch yaw commanded from external controller in centidegrees
585
Vector3l forced_rpy_cd;
586
// last time we heard from the external controller
587
Vector3l last_forced_rpy_ms;
588
589
// throttle commanded from external controller in percent
590
float forced_throttle;
591
uint32_t last_forced_throttle_ms;
592
593
#if AP_PLANE_OFFBOARD_GUIDED_SLEW_ENABLED
594
// airspeed adjustments
595
float target_airspeed_cm = -1; // don't default to zero here, as zero is a valid speed.
596
float target_airspeed_accel;
597
uint32_t target_airspeed_time_ms;
598
599
// altitude adjustments
600
Location target_location;
601
float target_alt_rate;
602
uint32_t target_alt_time_ms = 0;
603
uint8_t target_mav_frame = -1;
604
605
// heading track
606
float target_heading = -4; // don't default to zero or -1 here, as both are valid headings in radians
607
float target_heading_accel_limit;
608
uint32_t target_heading_time_ms;
609
guided_heading_type_t target_heading_type;
610
bool target_heading_limit;
611
#endif // AP_PLANE_OFFBOARD_GUIDED_SLEW_ENABLED
612
} guided_state;
613
614
#if AP_LANDINGGEAR_ENABLED
615
// landing gear state
616
struct {
617
AP_FixedWing::FlightStage last_flight_stage;
618
} gear;
619
#endif
620
621
struct {
622
// on hard landings, only check once after directly a landing so you
623
// don't trigger a crash when picking up the aircraft
624
bool checkedHardLanding;
625
626
// crash detection. True when we are crashed
627
bool is_crashed;
628
629
// impact detection flag. Expires after a few seconds via impact_timer_ms
630
bool impact_detected;
631
632
// debounce timer
633
uint32_t debounce_timer_ms;
634
635
// delay time for debounce to count to
636
uint32_t debounce_time_total_ms;
637
638
// length of time impact_detected has been true. Times out after a few seconds. Used to clip isFlyingProbability
639
uint32_t impact_timer_ms;
640
} crash_state;
641
642
// this controls throttle suppression in auto modes
643
bool throttle_suppressed;
644
645
#if AP_BATTERY_WATT_MAX_ENABLED
646
// reduce throttle to eliminate battery over-current
647
int8_t throttle_watt_limit_max;
648
int8_t throttle_watt_limit_min; // for reverse thrust
649
uint32_t throttle_watt_limit_timer_ms;
650
#endif
651
652
AP_FixedWing::FlightStage flight_stage = AP_FixedWing::FlightStage::NORMAL;
653
654
// probability of aircraft is currently in flight. range from 0 to
655
// 1 where 1 is 100% sure we're in flight
656
float isFlyingProbability;
657
658
// previous value of is_flying()
659
bool previous_is_flying;
660
661
// time since started flying in any mode in milliseconds
662
uint32_t started_flying_ms;
663
664
// ground mode is true when disarmed and not flying
665
bool ground_mode;
666
667
// Navigation control variables
668
// The instantaneous desired bank angle. Hundredths of a degree
669
int32_t nav_roll_cd;
670
671
// The instantaneous desired pitch angle. Hundredths of a degree
672
int32_t nav_pitch_cd;
673
674
// the aerodynamic load factor. This is calculated from the demanded
675
// roll before the roll is clipped, using 1/sqrt(cos(nav_roll))
676
float aerodynamic_load_factor = 1.0f;
677
678
// a smoothed airspeed estimate, used for limiting roll angle
679
float smoothed_airspeed;
680
681
// Mission library
682
AP_Mission mission{
683
FUNCTOR_BIND_MEMBER(&Plane::start_command_callback, bool, const AP_Mission::Mission_Command &),
684
FUNCTOR_BIND_MEMBER(&Plane::verify_command_callback, bool, const AP_Mission::Mission_Command &),
685
FUNCTOR_BIND_MEMBER(&Plane::exit_mission_callback, void)};
686
687
688
#if HAL_PARACHUTE_ENABLED
689
AP_Parachute parachute;
690
#endif
691
692
// terrain handling
693
#if AP_TERRAIN_AVAILABLE
694
AP_Terrain terrain;
695
#endif
696
697
AP_Landing landing{mission,ahrs,&TECS_controller,nav_controller,aparm,
698
FUNCTOR_BIND_MEMBER(&Plane::set_target_altitude_proportion, void, const Location&, float),
699
FUNCTOR_BIND_MEMBER(&Plane::constrain_target_altitude_location, void, const Location&, const Location&),
700
FUNCTOR_BIND_MEMBER(&Plane::adjusted_altitude_cm, int32_t),
701
FUNCTOR_BIND_MEMBER(&Plane::adjusted_relative_altitude_cm, int32_t),
702
FUNCTOR_BIND_MEMBER(&Plane::disarm_if_autoland_complete, void),
703
FUNCTOR_BIND_MEMBER(&Plane::update_flight_stage, void)};
704
#if HAL_ADSB_ENABLED
705
AP_ADSB adsb;
706
707
// avoidance of adsb enabled vehicles (normally manned vehicles)
708
AP_Avoidance_Plane avoidance_adsb{adsb};
709
#endif
710
711
// Outback Challenge Failsafe Support
712
#if AP_ADVANCEDFAILSAFE_ENABLED
713
AP_AdvancedFailsafe_Plane afs;
714
#endif
715
716
/*
717
meta data to support counting the number of circles in a loiter
718
*/
719
struct {
720
// previous target bearing, used to update sum_cd
721
int32_t old_target_bearing_cd;
722
723
// Total desired rotation in a loiter. Used for Loiter Turns commands.
724
int32_t total_cd;
725
726
// total angle completed in the loiter so far
727
int32_t sum_cd;
728
729
// Direction for loiter. 1 for clockwise, -1 for counter-clockwise
730
int8_t direction;
731
732
// when loitering and an altitude is involved, this flag is true when it has been reached at least once
733
bool reached_target_alt;
734
735
// check for scenarios where updrafts can keep you from loitering down indefinitely.
736
bool unable_to_acheive_target_alt;
737
738
// start time of the loiter. Milliseconds.
739
uint32_t start_time_ms;
740
741
// altitude at start of loiter loop lap. Used to detect delta alt of each lap.
742
// only valid when sum_cd > 36000
743
int32_t start_lap_alt_cm;
744
int32_t next_sum_lap_cd;
745
746
// The amount of time we should stay in a loiter for the Loiter Time command. Milliseconds.
747
uint32_t time_max_ms;
748
749
// current value of loiter radius in metres used by the controller
750
float radius;
751
} loiter;
752
753
// Conditional command
754
// A value used in condition commands (eg delay, change alt, etc.)
755
// For example in a change altitude command, it is the altitude to change to.
756
int32_t condition_value;
757
758
// A starting value used to check the status of a conditional command.
759
// For example in a delay command the condition_start records that start time for the delay
760
uint32_t condition_start;
761
// A value used in condition commands. For example the rate at which to change altitude.
762
int16_t condition_rate;
763
764
// 3D Location vectors
765
// Location structure defined in AP_Common
766
const Location &home = ahrs.get_home();
767
768
// The location of the previous waypoint. Used for track following and altitude ramp calculations
769
Location prev_WP_loc {};
770
771
// The plane's current location
772
Location current_loc {};
773
774
// The location of the current/active waypoint. Used for altitude ramp, track following and loiter calculations.
775
Location next_WP_loc {};
776
777
// Altitude control
778
struct {
779
// target altitude above sea level in cm. Used for barometric
780
// altitude navigation
781
int32_t amsl_cm;
782
783
// Altitude difference between previous and current waypoint in
784
// centimeters. Used for glide slope handling
785
int32_t offset_cm;
786
787
#if AP_TERRAIN_AVAILABLE
788
// are we trying to follow terrain?
789
bool terrain_following;
790
791
// are we waiting to load terrain data to init terrain following
792
bool terrain_following_pending;
793
794
// target altitude above terrain in cm, valid if terrain_following
795
// is set
796
int32_t terrain_alt_cm;
797
798
// lookahead value for height error reporting
799
float lookahead;
800
#endif
801
802
// last input for FBWB/CRUISE height control
803
float last_elevator_input;
804
805
// last time we checked for pilot control of height
806
uint32_t last_elev_check_us;
807
} target_altitude {};
808
809
float relative_altitude;
810
811
// loop performance monitoring:
812
AP::PerfInfo perf_info;
813
struct {
814
uint32_t last_trim_check;
815
uint32_t last_trim_save;
816
} auto_trim;
817
818
struct {
819
bool done_climb;
820
} rtl;
821
822
// last time home was updated while disarmed
823
uint32_t last_home_update_ms;
824
825
// Camera/Antenna mount tracking and stabilisation stuff
826
#if HAL_MOUNT_ENABLED
827
AP_Mount camera_mount;
828
#endif
829
830
// Arming/Disarming management class
831
AP_Arming_Plane arming;
832
833
AP_Param param_loader {var_info};
834
835
// external control library
836
#if AP_EXTERNAL_CONTROL_ENABLED
837
AP_ExternalControl_Plane external_control;
838
#endif
839
840
static const AP_Scheduler::Task scheduler_tasks[];
841
static const AP_Param::Info var_info[];
842
843
// time that rudder arming has been running
844
uint32_t rudder_arm_timer;
845
846
// have we seen neutral rudder since arming with rudder?
847
bool seen_neutral_rudder;
848
849
#if HAL_QUADPLANE_ENABLED
850
// support for quadcopter-plane
851
QuadPlane quadplane{ahrs};
852
#endif
853
854
#if AP_TUNING_ENABLED
855
// support for transmitter tuning
856
AP_Tuning_Plane tuning;
857
#endif
858
859
static const struct LogStructure log_structure[];
860
861
// rudder mixing gain for differential thrust (0 - 1)
862
float rudder_dt;
863
864
// soaring mode-change timer
865
uint32_t soaring_mode_timer_ms;
866
867
// terrain disable for non AUTO modes, set with an RC Option switch
868
bool non_auto_terrain_disable;
869
bool terrain_disabled();
870
#if AP_TERRAIN_AVAILABLE
871
bool terrain_enabled_in_current_mode() const;
872
bool terrain_enabled_in_mode(Mode::Number num) const;
873
enum class terrain_bitmask {
874
ALL = 1U << 0,
875
FLY_BY_WIRE_B = 1U << 1,
876
CRUISE = 1U << 2,
877
AUTO = 1U << 3,
878
RTL = 1U << 4,
879
AVOID_ADSB = 1U << 5,
880
GUIDED = 1U << 6,
881
LOITER = 1U << 7,
882
CIRCLE = 1U << 8,
883
QRTL = 1U << 9,
884
QLAND = 1U << 10,
885
QLOITER = 1U << 11,
886
};
887
struct TerrainLookupTable{
888
Mode::Number mode_num;
889
terrain_bitmask bitmask;
890
};
891
static const TerrainLookupTable Terrain_lookup[];
892
#endif
893
894
#if AP_QUICKTUNE_ENABLED
895
void update_quicktune(void);
896
#endif
897
898
// Attitude.cpp
899
void adjust_nav_pitch_throttle(void);
900
void update_load_factor(void);
901
void adjust_altitude_target();
902
void setup_glide_slope(void);
903
int32_t get_RTL_altitude_cm() const;
904
float relative_ground_altitude(bool use_rangefinder_if_available);
905
float relative_ground_altitude(bool use_rangefinder_if_available, bool use_terrain_if_available);
906
void set_target_altitude_current(void);
907
void set_target_altitude_current_adjusted(void);
908
void set_target_altitude_location(const Location &loc);
909
int32_t relative_target_altitude_cm(void);
910
void change_target_altitude(int32_t change_cm);
911
void set_target_altitude_proportion(const Location &loc, float proportion);
912
void constrain_target_altitude_location(const Location &loc1, const Location &loc2);
913
int32_t calc_altitude_error_cm(void);
914
void check_fbwb_altitude(void);
915
void reset_offset_altitude(void);
916
void set_offset_altitude_location(const Location &start_loc, const Location &destination_loc);
917
bool above_location_current(const Location &loc);
918
void setup_terrain_target_alt(Location &loc);
919
int32_t adjusted_altitude_cm(void);
920
int32_t adjusted_relative_altitude_cm(void);
921
float mission_alt_offset(void);
922
float height_above_target(void);
923
float lookahead_adjustment(void);
924
#if AP_RANGEFINDER_ENABLED
925
float rangefinder_correction(void);
926
void rangefinder_height_update(void);
927
void rangefinder_terrain_correction(float &height);
928
#endif
929
void stabilize();
930
void calc_throttle();
931
void calc_nav_roll();
932
void calc_nav_pitch();
933
float calc_speed_scaler(void);
934
float get_speed_scaler(void) const { return surface_speed_scaler; }
935
bool stick_mixing_enabled(void);
936
void stabilize_roll();
937
float stabilize_roll_get_roll_out();
938
void stabilize_pitch();
939
float stabilize_pitch_get_pitch_out();
940
void stabilize_stick_mixing_fbw();
941
void stabilize_yaw();
942
int16_t calc_nav_yaw_coordinated();
943
int16_t calc_nav_yaw_course(void);
944
int16_t calc_nav_yaw_ground(void);
945
946
#if HAL_LOGGING_ENABLED
947
948
// methods for AP_Vehicle:
949
const AP_Int32 &get_log_bitmask() override { return g.log_bitmask; }
950
const struct LogStructure *get_log_structures() const override {
951
return log_structure;
952
}
953
uint8_t get_num_log_structures() const override;
954
955
// Log.cpp
956
void Log_Write_FullRate(void);
957
void Log_Write_Attitude(void);
958
void Log_Write_Control_Tuning();
959
void Log_Write_OFG_Guided();
960
void Log_Write_Guided(void);
961
void Log_Write_Nav_Tuning();
962
void Log_Write_Status();
963
void Log_Write_RC(void);
964
void Log_Write_Vehicle_Startup_Messages();
965
void Log_Write_AETR();
966
#endif
967
968
// Parameters.cpp
969
void load_parameters(void) override;
970
971
// commands_logic.cpp
972
void set_next_WP(const Location &loc);
973
void do_RTL(int32_t alt);
974
bool verify_takeoff();
975
bool verify_loiter_unlim(const AP_Mission::Mission_Command &cmd);
976
bool verify_loiter_time();
977
bool verify_loiter_turns(const AP_Mission::Mission_Command &cmd);
978
bool verify_loiter_to_alt(const AP_Mission::Mission_Command &cmd);
979
bool verify_RTL();
980
bool verify_continue_and_change_alt();
981
bool verify_wait_delay();
982
bool verify_within_distance();
983
bool verify_altitude_wait(const AP_Mission::Mission_Command &cmd);
984
void do_loiter_at_location();
985
bool verify_loiter_heading(bool init);
986
void exit_mission_callback();
987
bool start_command(const AP_Mission::Mission_Command& cmd);
988
bool verify_command(const AP_Mission::Mission_Command& cmd);
989
void do_takeoff(const AP_Mission::Mission_Command& cmd);
990
void do_nav_wp(const AP_Mission::Mission_Command& cmd);
991
void do_land(const AP_Mission::Mission_Command& cmd);
992
#if HAL_QUADPLANE_ENABLED
993
void do_landing_vtol_approach(const AP_Mission::Mission_Command& cmd);
994
#endif
995
void loiter_set_direction_wp(const AP_Mission::Mission_Command& cmd);
996
void do_loiter_unlimited(const AP_Mission::Mission_Command& cmd);
997
void do_loiter_turns(const AP_Mission::Mission_Command& cmd);
998
void do_loiter_time(const AP_Mission::Mission_Command& cmd);
999
void do_continue_and_change_alt(const AP_Mission::Mission_Command& cmd);
1000
void do_altitude_wait(const AP_Mission::Mission_Command& cmd);
1001
void do_loiter_to_alt(const AP_Mission::Mission_Command& cmd);
1002
void do_vtol_takeoff(const AP_Mission::Mission_Command& cmd);
1003
void do_vtol_land(const AP_Mission::Mission_Command& cmd);
1004
bool verify_nav_wp(const AP_Mission::Mission_Command& cmd);
1005
#if HAL_QUADPLANE_ENABLED
1006
bool verify_landing_vtol_approach(const AP_Mission::Mission_Command& cmd);
1007
#endif
1008
void do_wait_delay(const AP_Mission::Mission_Command& cmd);
1009
void do_within_distance(const AP_Mission::Mission_Command& cmd);
1010
bool do_change_speed(const AP_Mission::Mission_Command& cmd);
1011
void do_set_home(const AP_Mission::Mission_Command& cmd);
1012
bool start_command_callback(const AP_Mission::Mission_Command &cmd);
1013
bool verify_command_callback(const AP_Mission::Mission_Command& cmd);
1014
float get_wp_radius() const;
1015
1016
bool is_land_command(uint16_t cmd) const;
1017
1018
bool do_change_speed(uint8_t speedtype, float speed_target_ms, float rhtottle_pct);
1019
/*
1020
return true if in a specific AUTO mission command
1021
*/
1022
bool in_auto_mission_id(uint16_t command) const;
1023
1024
#if AP_SCRIPTING_ENABLED
1025
// nav scripting support
1026
void do_nav_script_time(const AP_Mission::Mission_Command& cmd);
1027
bool verify_nav_script_time(const AP_Mission::Mission_Command& cmd);
1028
#endif
1029
1030
// commands.cpp
1031
void set_guided_WP(const Location &loc);
1032
1033
// update home position. Return true if update done
1034
bool update_home();
1035
1036
// update current_loc
1037
void update_current_loc(void);
1038
1039
// set home location and store it persistently:
1040
bool set_home_persistently(const Location &loc) WARN_IF_UNUSED;
1041
bool set_home_to_current_location(bool lock) override WARN_IF_UNUSED;
1042
bool set_home(const Location& loc, bool lock) override WARN_IF_UNUSED;
1043
1044
// control_modes.cpp
1045
void read_control_switch();
1046
uint8_t readSwitch(void) const;
1047
void autotune_start(void);
1048
void autotune_restore(void);
1049
void autotune_enable(bool enable);
1050
bool fly_inverted(void);
1051
bool mode_allows_autotuning(void);
1052
uint8_t get_mode() const override { return (uint8_t)control_mode->mode_number(); }
1053
Mode *mode_from_mode_num(const enum Mode::Number num);
1054
bool current_mode_requires_mission() const override {
1055
return control_mode == &mode_auto;
1056
}
1057
1058
bool autotuning;
1059
1060
// events.cpp
1061
void failsafe_short_on_event(enum failsafe_state fstype, ModeReason reason);
1062
void failsafe_long_on_event(enum failsafe_state fstype, ModeReason reason);
1063
void failsafe_short_off_event(ModeReason reason);
1064
void failsafe_long_off_event(ModeReason reason);
1065
void handle_battery_failsafe(const char* type_str, const int8_t action);
1066
bool failsafe_in_landing_sequence() const; // returns true if the vehicle is in landing sequence. Intended only for use in failsafe code.
1067
1068
#if AP_FENCE_ENABLED
1069
// fence.cpp
1070
void fence_check();
1071
bool fence_stickmixing() const;
1072
bool in_fence_recovery() const;
1073
#endif
1074
1075
// Plane.cpp
1076
void disarm_if_autoland_complete();
1077
bool trigger_land_abort(const float climb_to_alt_m);
1078
void get_osd_roll_pitch_rad(float &roll, float &pitch) const override;
1079
float tecs_hgt_afe(void);
1080
void efi_update(void);
1081
void get_scheduler_tasks(const AP_Scheduler::Task *&tasks,
1082
uint8_t &task_count,
1083
uint32_t &log_bit) override;
1084
void ahrs_update();
1085
void update_speed_height(void);
1086
void update_GPS_50Hz(void);
1087
void update_GPS_10Hz(void);
1088
void update_compass(void);
1089
void update_alt(void);
1090
#if AP_ADVANCEDFAILSAFE_ENABLED
1091
void afs_fs_check(void);
1092
#endif
1093
void one_second_loop(void);
1094
void three_hz_loop(void);
1095
#if AP_AIRSPEED_AUTOCAL_ENABLE
1096
void airspeed_ratio_update(void);
1097
#endif
1098
void compass_save(void);
1099
void update_logging10(void);
1100
void update_logging25(void);
1101
void update_control_mode(void);
1102
void update_fly_forward(void);
1103
void update_flight_stage();
1104
void set_flight_stage(AP_FixedWing::FlightStage fs);
1105
bool flight_option_enabled(FlightOptions flight_option) const;
1106
1107
// navigation.cpp
1108
void loiter_angle_reset(void);
1109
void loiter_angle_update(void);
1110
void navigate();
1111
void check_home_alt_change(void);
1112
void calc_airspeed_errors();
1113
float mode_auto_target_airspeed_cm();
1114
void calc_gndspeed_undershoot();
1115
void update_loiter(uint16_t radius);
1116
void update_loiter_update_nav(uint16_t radius);
1117
void update_cruise();
1118
void update_fbwb_speed_height(void);
1119
void setup_turn_angle(void);
1120
bool reached_loiter_target(void);
1121
1122
// radio.cpp
1123
void set_control_channels(void) override;
1124
void init_rc_in();
1125
void init_rc_out_main();
1126
void init_rc_out_aux();
1127
void rudder_arm_disarm_check();
1128
void read_radio();
1129
int16_t rudder_input(void);
1130
void control_failsafe();
1131
void trim_radio();
1132
bool rc_throttle_value_ok(void) const;
1133
bool rc_failsafe_active(void) const;
1134
1135
#if AP_RANGEFINDER_ENABLED
1136
// sensors.cpp
1137
void read_rangefinder(void);
1138
#endif
1139
1140
// system.cpp
1141
void init_ardupilot() override;
1142
bool set_mode(Mode& new_mode, const ModeReason reason);
1143
bool set_mode(const uint8_t mode, const ModeReason reason) override;
1144
bool set_mode_by_number(const Mode::Number new_mode_number, const ModeReason reason);
1145
void check_long_failsafe();
1146
void check_short_failsafe();
1147
void startup_INS(void);
1148
bool should_log(uint32_t mask);
1149
int8_t throttle_percentage(void);
1150
void notify_mode(const Mode& mode);
1151
bool gcs_mode_enabled(const Mode::Number mode_num) const;
1152
1153
// takeoff.cpp
1154
bool auto_takeoff_check(void);
1155
void takeoff_calc_roll(void);
1156
void takeoff_calc_pitch(void);
1157
void takeoff_calc_throttle();
1158
int8_t takeoff_tail_hold(void);
1159
int16_t get_takeoff_pitch_min_cd(void);
1160
void landing_gear_update(void);
1161
bool check_takeoff_timeout(void);
1162
bool check_takeoff_timeout_level_off(void);
1163
1164
// avoidance_adsb.cpp
1165
void avoidance_adsb_update(void);
1166
1167
// servos.cpp
1168
void set_servos();
1169
float apply_throttle_limits(float throttle_in);
1170
void set_throttle(void);
1171
void set_takeoff_expected(void);
1172
void set_servos_old_elevons(void);
1173
void set_servos_flaps(void);
1174
void set_landing_gear(void);
1175
void dspoiler_update(void);
1176
void airbrake_update(void);
1177
void landing_neutral_control_surface_servos(void);
1178
void servos_output(void);
1179
void servos_auto_trim(void);
1180
void servos_twin_engine_mix();
1181
void force_flare();
1182
void throttle_watt_limiter(int8_t &min_throttle, int8_t &max_throttle);
1183
void throttle_slew_limit();
1184
bool suppress_throttle(void);
1185
void update_throttle_hover();
1186
void channel_function_mixer(SRV_Channel::Aux_servo_function_t func1_in, SRV_Channel::Aux_servo_function_t func2_in,
1187
SRV_Channel::Aux_servo_function_t func1_out, SRV_Channel::Aux_servo_function_t func2_out) const;
1188
void flaperon_update();
1189
void indicate_waiting_for_rud_neutral_to_takeoff(void);
1190
1191
// is_flying.cpp
1192
void update_is_flying_5Hz(void);
1193
void crash_detection_update(void);
1194
bool in_preLaunch_flight_stage(void);
1195
bool is_flying(void);
1196
1197
// parachute.cpp
1198
void parachute_check();
1199
#if HAL_PARACHUTE_ENABLED
1200
void do_parachute(const AP_Mission::Mission_Command& cmd);
1201
void parachute_release();
1202
bool parachute_manual_release();
1203
#endif
1204
1205
// soaring.cpp
1206
#if HAL_SOARING_ENABLED
1207
void update_soaring();
1208
#endif
1209
1210
// RC_Channel.cpp
1211
bool emergency_landing;
1212
1213
// vehicle specific waypoint info helpers
1214
bool get_wp_distance_m(float &distance) const override;
1215
bool get_wp_bearing_deg(float &bearing) const override;
1216
bool get_wp_crosstrack_error_m(float &xtrack_error) const override;
1217
1218
// reverse_thrust.cpp
1219
bool reversed_throttle;
1220
bool have_reverse_throttle_rc_option;
1221
bool allow_reverse_thrust(void) const;
1222
bool have_reverse_thrust(void) const;
1223
float get_throttle_input(bool no_deadzone=false) const;
1224
float get_adjusted_throttle_input(bool no_deadzone=false) const;
1225
1226
#if AP_SCRIPTING_ENABLED
1227
// support for NAV_SCRIPT_TIME mission command
1228
bool nav_scripting_active(void);
1229
bool nav_script_time(uint16_t &id, uint8_t &cmd, float &arg1, float &arg2, int16_t &arg3, int16_t &arg4) override;
1230
void nav_script_time_done(uint16_t id) override;
1231
1232
// command throttle percentage and roll, pitch, yaw target
1233
// rates. For use with scripting controllers
1234
void set_target_throttle_rate_rpy(float throttle_pct, float roll_rate_dps, float pitch_rate_dps, float yaw_rate_dps) override;
1235
void set_rudder_offset(float rudder_pct, bool run_yaw_rate_controller) override;
1236
bool nav_scripting_enable(uint8_t mode) override;
1237
#endif
1238
1239
enum Failsafe_Action {
1240
Failsafe_Action_None = 0,
1241
Failsafe_Action_RTL = 1,
1242
Failsafe_Action_Land = 2,
1243
Failsafe_Action_Terminate = 3,
1244
#if HAL_QUADPLANE_ENABLED
1245
Failsafe_Action_QLand = 4,
1246
#endif
1247
Failsafe_Action_Parachute = 5,
1248
#if HAL_QUADPLANE_ENABLED
1249
Failsafe_Action_Loiter_alt_QLand = 6,
1250
#endif
1251
};
1252
1253
// list of priorities, highest priority first
1254
static constexpr int8_t _failsafe_priorities[] = {
1255
Failsafe_Action_Terminate,
1256
Failsafe_Action_Parachute,
1257
#if HAL_QUADPLANE_ENABLED
1258
Failsafe_Action_QLand,
1259
#endif
1260
Failsafe_Action_Land,
1261
Failsafe_Action_RTL,
1262
Failsafe_Action_None,
1263
-1 // the priority list must end with a sentinel of -1
1264
};
1265
static_assert(_failsafe_priorities[ARRAY_SIZE(_failsafe_priorities) - 1] == -1,
1266
"_failsafe_priorities is missing the sentinel");
1267
1268
// EKF checks for loss of navigation performed in ekf_check.cpp
1269
// These are specific to VTOL operation
1270
void ekf_check();
1271
bool ekf_over_threshold();
1272
void failsafe_ekf_event();
1273
void failsafe_ekf_off_event(void);
1274
1275
enum class CrowMode {
1276
NORMAL,
1277
PROGRESSIVE,
1278
CROW_DISABLED,
1279
};
1280
1281
enum class ThrFailsafe {
1282
Disabled = 0,
1283
Enabled = 1,
1284
EnabledNoFS = 2
1285
};
1286
1287
CrowMode crow_mode = CrowMode::NORMAL;
1288
1289
enum class FlareMode {
1290
FLARE_DISABLED = 0,
1291
ENABLED_NO_PITCH_TARGET,
1292
ENABLED_PITCH_TARGET
1293
};
1294
1295
enum class AutoTuneAxis {
1296
ROLL = 1U <<0,
1297
PITCH = 1U <<1,
1298
YAW = 1U <<2,
1299
};
1300
1301
FlareMode flare_mode;
1302
bool throttle_at_zero(void) const;
1303
1304
// expo handling
1305
float roll_in_expo(bool use_dz) const;
1306
float pitch_in_expo(bool use_dz) const;
1307
float rudder_in_expo(bool use_dz) const;
1308
1309
// mode reason for entering previous mode
1310
ModeReason previous_mode_reason = ModeReason::UNKNOWN;
1311
1312
// last target alt we passed to tecs
1313
int32_t tecs_target_alt_cm;
1314
1315
public:
1316
void failsafe_check(void);
1317
bool is_landing() const override;
1318
bool is_taking_off() const override;
1319
#if AP_SCRIPTING_ENABLED || AP_EXTERNAL_CONTROL_ENABLED
1320
bool set_target_location(const Location& target_loc) override;
1321
#endif //AP_SCRIPTING_ENABLED || AP_EXTERNAL_CONTROL_ENABLED
1322
#if AP_SCRIPTING_ENABLED
1323
bool get_target_location(Location& target_loc) override;
1324
bool update_target_location(const Location &old_loc, const Location &new_loc) override;
1325
bool set_velocity_match(const Vector2f &velocity) override;
1326
1327
// allow for landing descent rate to be overridden by a script, may be -ve to climb
1328
bool set_land_descent_rate(float descent_rate) override;
1329
1330
// allow scripts to override mission/guided crosstrack behaviour
1331
// It's up to the Lua script to ensure the provided location makes sense
1332
bool set_crosstrack_start(const Location &new_start_location) override;
1333
1334
#endif // AP_SCRIPTING_ENABLED
1335
1336
};
1337
1338
extern Plane plane;
1339
1340
using AP_HAL::millis;
1341
using AP_HAL::micros;
1342
1343