Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
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 "generated/airframe.h"
36 
37 
40 extern void autopilot_init(void);
41 
44 #define THRESHOLD_MANUAL_PPRZ (MIN_PPRZ / 2)
45 #define THRESHOLD1 THRESHOLD_MANUAL_PPRZ
46 #define THRESHOLD2 (MAX_PPRZ/2)
47 
50 #define PPRZ_MODE_MANUAL 0
51 #define PPRZ_MODE_AUTO1 1
52 #define PPRZ_MODE_AUTO2 2
53 #define PPRZ_MODE_HOME 3
54 #define PPRZ_MODE_GPS_OUT_OF_ORDER 4
55 #define PPRZ_MODE_NB 5
56 
57 #define PPRZ_MODE_OF_PULSE(pprz) \
58  (pprz > THRESHOLD2 ? PPRZ_MODE_AUTO2 : \
59  (pprz > THRESHOLD1 ? PPRZ_MODE_AUTO1 : PPRZ_MODE_MANUAL))
60 
61 extern uint8_t pprz_mode;
62 extern bool_t kill_throttle;
63 extern uint8_t mcu1_status;
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 int32_t current; // milliAmpere
95 
99 extern float energy;
100 
101 extern bool_t launch;
102 
103 extern bool_t gps_lost;
104 
107 #define ModeUpdate(_mode, _value) ({ \
108  uint8_t new_mode = _value; \
109  (_mode != new_mode ? _mode = new_mode, TRUE : FALSE); \
110 })
111 
114 extern void autopilot_send_mode(void);
115 
118 extern bool_t power_switch;
119 
120 #ifdef POWER_SWITCH_GPIO
121 #include "mcu_periph/gpio.h"
122 #define autopilot_SetPowerSwitch(_x) { \
123  power_switch = _x; \
124  if (_x) { gpio_set(POWER_SWITCH_GPIO); } \
125  else { gpio_clear(POWER_SWITCH_GPIO); } \
126 }
127 #else // POWER_SWITCH_GPIO
128 #define autopilot_SetPowerSwitch(_x) { power_switch = _x; }
129 #endif // POWER_SWITCH_GPIO
130 
131 
132 /* CONTROL_RATE will be removed in the next release
133  * please use CONTROL_FREQUENCY instead
134  */
135 #ifndef CONTROL_FREQUENCY
136 #ifdef CONTROL_RATE
137 #define CONTROL_FREQUENCY CONTROL_RATE
138 #warning "CONTROL_RATE is deprecated. Please use CONTROL_FREQUENCY instead. Defaults to 60Hz if not defined."
139 #else
140 #define CONTROL_FREQUENCY 60
141 #endif // CONTROL_RATE
142 #endif // CONTROL_FREQUENCY
143 
144 #ifndef NAVIGATION_FREQUENCY
145 #define NAVIGATION_FREQUENCY 4
146 #endif
147 
148 #endif /* AUTOPILOT_H */
unsigned short uint16_t
Definition: types.h:16
uint16_t autopilot_flight_time
flight time in seconds.
Definition: autopilot.c:47
uint8_t pprz_mode
Definition: autopilot.c:40
bool_t launch
Definition: sim_ap.c:40
Some architecture independent helper functions for GPIOs.
uint8_t mcu1_status
Definition: autopilot.c:42
uint8_t lateral_mode
Definition: autopilot.c:49
bool_t power_switch
Power switch control.
Definition: autopilot.c:57
bool_t gps_lost
Definition: autopilot.c:55
void autopilot_send_mode(void)
Send mode over telemetry.
Definition: autopilot.c:73
bool_t kill_throttle
Definition: autopilot.c:41
void autopilot_init(void)
Autopilot inititalization.
Definition: autopilot.c:142
signed long int32_t
Definition: types.h:19
unsigned char uint8_t
Definition: types.h:14
int32_t current
Supply current in milliAmpere.
Definition: autopilot.c:52
float energy
Energy consumption (mAh) This is the ap copy of the measurement from fbw.
Definition: autopilot.c:53
uint16_t vsupply
Supply voltage in deciVolt.
Definition: autopilot.c:51