Paparazzi UAS  v5.15_devel-88-gb3ad7fe
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
autopilot_utils.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Gautier Hattenberger <gautier.hattenberger@enac.fr>
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_UTILS_H
30 #define AUTOPILOT_UTILS_H
31 
32 #include "std.h"
33 #include "inter_mcu.h"
34 #include "generated/airframe.h"
35 
38 #define AP_MODE_OF_PULSE(pprz) \
39  (pprz > THRESHOLD2 ? AP_MODE_AUTO2 : \
40  (pprz > THRESHOLD1 ? AP_MODE_AUTO1 : AP_MODE_MANUAL))
41 
44 #define STICK_PUSHED(pprz) (pprz < THRESHOLD1 || pprz > THRESHOLD2)
45 
48 #define FLOAT_OF_PPRZ(pprz, center, travel) ((float)pprz / (float)MAX_PPRZ * travel + center)
49 
52 #define THROTTLE_THRESHOLD_TAKEOFF (pprz_t)(MAX_PPRZ * 0.9)
53 
56 #define THRESHOLD_MANUAL_PPRZ (MIN_PPRZ / 2)
57 #define THRESHOLD1 THRESHOLD_MANUAL_PPRZ
58 #define THRESHOLD2 (MAX_PPRZ/2)
59 
63 // COMMAND_ROLL
64 #define AP_COMMAND_SET_ROLL(_roll) { ap_state->commands[COMMAND_ROLL] = _roll; }
65 
66 // COMMAND_PITCH
67 #define AP_COMMAND_SET_PITCH(_pitch) { ap_state->commands[COMMAND_PITCH] = _pitch; }
68 
69 // COMMAND_YAW
70 #if H_CTL_YAW_LOOP && defined COMMAND_YAW
71 #define AP_COMMAND_SET_YAW(_yaw) { ap_state->commands[COMMAND_YAW] = _yaw; }
72 #else
73 #define AP_COMMAND_SET_YAW(_yaw) {}
74 #endif
75 
76 // COMMAND_THROTTLE
77 #define AP_COMMAND_SET_THROTTLE(_throttle) { \
78  ap_state->commands[COMMAND_THROTTLE] = _throttle; \
79  autopilot.throttle = _throttle; \
80 }
81 
82 // COMMAND_CL
83 #if H_CTL_CL_LOOP && defined COMMAND_CL
84 #define AP_COMMAND_SET_CL(_cl) { ap_state->commands[COMMAND_CL] = cl; }
85 #else
86 #define AP_COMMAND_SET_CL(_cl) {}
87 #endif
88 
89 // ROLL setpoint from RADIO
90 #define AP_SETPOINT_ROLL(_roll, _max) { \
91  _roll = FLOAT_OF_PPRZ(fbw_state->channels[RADIO_ROLL], 0., _max); \
92 }
93 
94 // PITCH setpoint from RADIO
95 #define AP_SETPOINT_PITCH(_pitch, _max) { \
96  _pitch = FLOAT_OF_PPRZ(fbw_state->channels[RADIO_PITCH], 0., _max); \
97 }
98 
99 // PITCH setpoint from RADIO
100 #if H_CTL_YAW_LOOP && defined RADIO_YAW
101 #define AP_SETPOINT_YAW_RATE(_yaw, _max) { \
102  _yaw = FLOAT_OF_PPRZ(fbw_state->channels[RADIO_YAW], 0., _max); \
103 }
104 #else
105 #define AP_SETPOINT_YAW_RATE(_yaw, _max) {}
106 #endif
107 
108 // THROTTLE setpoint from RADIO
109 #define AP_SETPOINT_THROTTLE(_throttle) { \
110  _throttle = fbw_state->channels[RADIO_THROTTLE]; \
111 }
112 
113 
114 #endif // AUTOPILOT_UTILS_H
115 
Communication between fbw and ap processes.