Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces 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 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 launch;
102 
103 extern bool 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 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 #include "subsystems/settings.h"
149 
150 /* try to make sure that we don't write to flash while flying */
151 static inline void autopilot_StoreSettings(float store)
152 {
153  if (kill_throttle && store) {
154  settings_store_flag = store;
155  settings_store();
156  }
157 }
158 
159 static inline void autopilot_ClearSettings(float clear)
160 {
161  if (kill_throttle && clear) {
162  settings_clear_flag = clear;
163  settings_clear();
164  }
165 }
166 
167 #if DOWNLINK
168 #include "pprzlink/pprzlink_transport.h"
169 extern void send_autopilot_version(struct transport_tx *trans, struct link_device *dev);
170 #endif
171 
172 #endif /* AUTOPILOT_H */
unsigned short uint16_t
Definition: types.h:16
uint16_t autopilot_flight_time
flight time in seconds.
Definition: autopilot.c:48
uint8_t pprz_mode
Definition: autopilot.c:41
static void autopilot_StoreSettings(float store)
Definition: autopilot.h:151
bool kill_throttle
Definition: autopilot.c:42
bool launch
Definition: sim_ap.c:38
Some architecture independent helper functions for GPIOs.
uint8_t mcu1_status
Definition: autopilot.c:43
uint8_t lateral_mode
Definition: autopilot.c:50
bool gps_lost
Definition: autopilot.c:56
int32_t settings_store(void)
store settings marked as persistent to flash
Definition: settings.c:57
void send_autopilot_version(struct transport_tx *trans, struct link_device *dev)
Definition: autopilot.c:64
void autopilot_send_mode(void)
Send mode over telemetry.
Definition: autopilot.c:167
int32_t settings_clear(void)
clear all persistent settings from flash
Definition: settings.c:77
bool power_switch
Power switch control.
Definition: autopilot.c:58
void autopilot_init(void)
Autopilot inititalization.
Definition: autopilot.c:175
bool settings_store_flag
flag for setting feedback.
Definition: settings.c:38
signed long int32_t
Definition: types.h:19
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:73
unsigned char uint8_t
Definition: types.h:14
Persistent settings interface.
int32_t current
Supply current in milliAmpere.
Definition: autopilot.c:53
float energy
Energy consumption (mAh) This is the ap copy of the measurement from fbw.
Definition: autopilot.c:54
static void autopilot_ClearSettings(float clear)
Definition: autopilot.h:159
bool settings_clear_flag
Definition: settings.c:40
uint16_t vsupply
Supply voltage in deciVolt.
Definition: autopilot.c:52