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