Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
autopilot.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2003 Pascal Brisset, Antoine Drouin
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 
29 #ifndef AUTOPILOT_H
30 #define AUTOPILOT_H
31 
32 #include <inttypes.h>
33 #include "std.h"
34 #include "paparazzi.h"
35 #include "mcu_periph/sys_time.h"
36 #include "generated/airframe.h"
37 
38 
41 extern void autopilot_init(void);
42 
45 #define THRESHOLD_MANUAL_PPRZ (MIN_PPRZ / 2)
46 #define THRESHOLD1 THRESHOLD_MANUAL_PPRZ
47 #define THRESHOLD2 (MAX_PPRZ/2)
48 
51 #define PPRZ_MODE_MANUAL 0
52 #define PPRZ_MODE_AUTO1 1
53 #define PPRZ_MODE_AUTO2 2
54 #define PPRZ_MODE_HOME 3
55 #define PPRZ_MODE_GPS_OUT_OF_ORDER 4
56 #define PPRZ_MODE_NB 5
57 
58 #define PPRZ_MODE_OF_PULSE(pprz) \
59  (pprz > THRESHOLD2 ? PPRZ_MODE_AUTO2 : \
60  (pprz > THRESHOLD1 ? PPRZ_MODE_AUTO1 : PPRZ_MODE_MANUAL))
61 
62 extern uint8_t pprz_mode;
63 extern bool_t kill_throttle;
64 
67 
68 #define autopilot_ResetFlightTimeAndLaunch(_) { \
69  autopilot_flight_time = 0; launch = FALSE; \
70 }
71 
72 
73 // FIXME, move to control
74 #define LATERAL_MODE_MANUAL 0
75 #define LATERAL_MODE_ROLL_RATE 1
76 #define LATERAL_MODE_ROLL 2
77 #define LATERAL_MODE_COURSE 3
78 #define LATERAL_MODE_NB 4
79 extern uint8_t lateral_mode;
80 
81 #define STICK_PUSHED(pprz) (pprz < THRESHOLD1 || pprz > THRESHOLD2)
82 #define FLOAT_OF_PPRZ(pprz, center, travel) ((float)pprz / (float)MAX_PPRZ * travel + center)
83 
84 #define THROTTLE_THRESHOLD_TAKEOFF (pprz_t)(MAX_PPRZ * 0.9)
85 
89 extern uint16_t vsupply;
90 
94 extern float energy;
95 
96 extern bool_t launch;
97 
98 extern bool_t gps_lost;
99 
102 #define ModeUpdate(_mode, _value) ({ \
103  uint8_t new_mode = _value; \
104  (_mode != new_mode ? _mode = new_mode, TRUE : FALSE); \
105 })
106 
107 
110 extern bool_t power_switch;
111 
112 #ifdef POWER_SWITCH_LED
113 #define autopilot_SetPowerSwitch(_x) { \
114  power_switch = _x; \
115  if (_x) LED_ON(POWER_SWITCH_LED) else LED_OFF(POWER_SWITCH_LED); \
116 }
117 #else // POWER_SWITCH_LED
118 #define autopilot_SetPowerSwitch(_x) { power_switch = _x; }
119 #endif // POWER_SWITCH_LED
120 
121 
122 /* CONTROL_RATE will be removed in the next release
123  * please use CONTROL_FREQUENCY instead
124  */
125 #ifndef CONTROL_FREQUENCY
126 #ifdef CONTROL_RATE
127 #define CONTROL_FREQUENCY CONTROL_RATE
128 #warning "CONTROL_RATE is deprecated. Please use CONTROL_FREQUENCY instead. Defaults to 60Hz if not defined."
129 #else
130 #define CONTROL_FREQUENCY 60
131 #endif // CONTROL_RATE
132 #endif // CONTROL_FREQUENCY
133 
134 #ifndef NAVIGATION_FREQUENCY
135 #define NAVIGATION_FREQUENCY 4
136 #endif
137 
138 #endif /* AUTOPILOT_H */
unsigned short uint16_t
Definition: types.h:16
uint16_t autopilot_flight_time
flight time in seconds.
Definition: autopilot.c:37
uint8_t pprz_mode
Definition: autopilot.c:31
bool_t launch
Definition: sim_ap.c:40
uint8_t lateral_mode
Definition: autopilot.c:39
bool_t power_switch
Power switch control.
Definition: autopilot.c:46
bool_t gps_lost
Definition: autopilot.c:44
Architecture independent timing functions.
bool_t kill_throttle
Definition: autopilot.c:32
void autopilot_init(void)
Autopilot inititalization.
Definition: autopilot.c:48
unsigned char uint8_t
Definition: types.h:14
float energy
Fuel consumption (mAh) TODO: move to electrical subsystem.
Definition: autopilot.c:42
uint16_t vsupply
Supply voltage in deciVolt.
Definition: autopilot.c:41