Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
autopilot.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2009 Antoine Drouin <poinix@gmail.com>
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
22 #ifndef AUTOPILOT_H
23 #define AUTOPILOT_H
24 
25 #include "std.h"
26 
27 #include "led.h"
28 
29 #include "generated/airframe.h"
30 #include "subsystems/ins.h"
31 
32 #define AP_MODE_FAILSAFE 0
33 #define AP_MODE_KILL 1
34 #define AP_MODE_RATE_DIRECT 2
35 #define AP_MODE_ATTITUDE_DIRECT 3
36 #define AP_MODE_RATE_RC_CLIMB 4
37 #define AP_MODE_ATTITUDE_RC_CLIMB 5
38 #define AP_MODE_ATTITUDE_CLIMB 6
39 #define AP_MODE_RATE_Z_HOLD 7
40 #define AP_MODE_ATTITUDE_Z_HOLD 8
41 #define AP_MODE_HOVER_DIRECT 9
42 #define AP_MODE_HOVER_CLIMB 10
43 #define AP_MODE_HOVER_Z_HOLD 11
44 #define AP_MODE_NAV 12
45 #define AP_MODE_RC_DIRECT 13 // Safety Pilot Direct Commands for helicopter direct control: appropriately chosen as mode "13"
46 
47 
48 extern uint8_t autopilot_mode;
50 extern bool_t autopilot_motors_on;
51 extern bool_t autopilot_in_flight;
52 extern bool_t kill_throttle;
53 extern bool_t autopilot_rc;
54 
55 extern bool_t autopilot_power_switch;
56 
57 extern void autopilot_init(void);
58 extern void autopilot_periodic(void);
59 extern void autopilot_on_rc_frame(void);
60 extern void autopilot_set_mode(uint8_t new_autopilot_mode);
61 extern void autopilot_set_motors_on(bool_t motors_on);
62 
63 extern bool_t autopilot_detect_ground;
64 extern bool_t autopilot_detect_ground_once;
65 
67 
68 
69 
70 #ifndef MODE_MANUAL
71 #define MODE_MANUAL AP_MODE_RATE_DIRECT
72 #endif
73 #ifndef MODE_AUTO1
74 #define MODE_AUTO1 AP_MODE_ATTITUDE_DIRECT
75 #endif
76 #ifndef MODE_AUTO2
77 #define MODE_AUTO2 AP_MODE_ATTITUDE_Z_HOLD
78 #endif
79 
80 
81 #define THRESHOLD_1_PPRZ (MIN_PPRZ / 2)
82 #define THRESHOLD_2_PPRZ (MAX_PPRZ / 2)
83 
84 #define AP_MODE_OF_PPRZ(_rc, _mode) { \
85  if (_rc > THRESHOLD_2_PPRZ) \
86  _mode = autopilot_mode_auto2; \
87  else if (_rc > THRESHOLD_1_PPRZ) \
88  _mode = MODE_AUTO1; \
89  else \
90  _mode = MODE_MANUAL; \
91  }
92 
93 #define autopilot_KillThrottle(_kill) { \
94  if (_kill) \
95  autopilot_set_motors_on(FALSE); \
96  else \
97  autopilot_set_motors_on(TRUE); \
98  }
99 
100 #ifdef POWER_SWITCH_LED
101 #define autopilot_SetPowerSwitch(_v) { \
102  autopilot_power_switch = _v; \
103  if (_v) { LED_OFF(POWER_SWITCH_LED); } \
104  else { LED_ON(POWER_SWITCH_LED); } \
105  }
106 #else
107 #define autopilot_SetPowerSwitch(_v) { \
108  autopilot_power_switch = _v; \
109  }
110 #endif
111 
112 #ifndef THRESHOLD_GROUND_DETECT
113 #define THRESHOLD_GROUND_DETECT ACCEL_BFP_OF_REAL(15.)
114 #endif
115 static inline void DetectGroundEvent(void) {
121  }
122  }
123 }
124 
125 #endif /* AUTOPILOT_H */
unsigned short uint16_t
Definition: types.h:16
void autopilot_periodic(void)
Definition: autopilot.c:87
bool_t autopilot_power_switch
Definition: autopilot.c:42
void autopilot_set_mode(uint8_t new_autopilot_mode)
Definition: autopilot.c:117
bool_t autopilot_rc
Definition: autopilot.c:41
void autopilot_init(void)
Definition: autopilot.c:68
struct NedCoor_i ins_ltp_accel
Definition: ins.c:79
Device independent INS code.
uint16_t autopilot_flight_time
Definition: autopilot.c:36
bool_t autopilot_in_flight
Definition: autopilot.c:34
bool_t autopilot_detect_ground
Definition: autopilot.c:44
#define FALSE
Definition: imu_chimu.h:141
bool_t autopilot_motors_on
Definition: autopilot.c:38
#define THRESHOLD_GROUND_DETECT
Definition: autopilot.h:113
bool_t autopilot_detect_ground_once
Definition: autopilot.c:45
bool_t kill_throttle
Definition: main_ap.c:120
#define TRUE
Definition: imu_chimu.h:144
unsigned char uint8_t
Definition: types.h:14
void autopilot_on_rc_frame(void)
Definition: autopilot.c:244
arch independent LED (Light Emitting Diodes) API
#define AP_MODE_FAILSAFE
Definition: autopilot.h:32
void autopilot_set_motors_on(bool_t motors_on)
Definition: autopilot.c:234
uint8_t autopilot_mode_auto2
Definition: autopilot.c:32
uint8_t autopilot_mode
Definition: autopilot.c:31
static void DetectGroundEvent(void)
Definition: autopilot.h:115