Paparazzi UAS  v4.2.2_stable-4-gcc32f65
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
vi_datalink.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Copyright (C) 2010 The Paparazzi Team
5  *
6  * This is the implementation of the "external interface" to the autopilot.
7  * using datalink messages.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */
23 
24 #ifndef VEHICLE_INTERFACE_DATALINK_H
25 #define VEHICLE_INTERFACE_DATALINK_H
26 
27 #include "std.h"
29 #include "math/pprz_algebra_int.h"
30 
31 #ifndef VI_MAX_H_SPEED
32 #define VI_MAX_H_SPEED 4.
33 #endif
34 
35 #ifndef VI_MAX_V_SPEED
36 #define VI_MAX_V_SPEED 2.
37 #endif
38 
39 #ifndef VI_MAX_HEADING_RATE
40 #define VI_MAX_HEADING_RATE RadOfDeg(60.)
41 #endif
42 
43 extern void vi_update_wp(uint8_t wp_id);
44 
45 #ifdef VI_PHI_THETA_MAX
46 #define VI_LIMIT_ATTITUDE(_att) { \
47  BoundAbs(_att.phi, VI_PHI_THETA_MAX); \
48  BoundAbs(_att.theta, VI_PHI_THETA_MAX); \
49  }
50 #else
51 #define VI_LIMIT_ATTITUDE(_x) {}
52 #endif
53 
54 #define VI_PARSE_DATALINK(_dl_buffer) { \
55  vi.last_msg = 0; \
56  vi.input.h_mode = DL_BOOZ2_FMS_COMMAND_h_mode(_dl_buffer); \
57  vi.input.v_mode = DL_BOOZ2_FMS_COMMAND_v_mode(_dl_buffer); \
58  switch (vi.input.h_mode) { \
59  case GUIDANCE_H_MODE_KILL: \
60  case GUIDANCE_H_MODE_RATE : \
61  break; \
62  case GUIDANCE_H_MODE_ATTITUDE : \
63  { \
64  vi.input.h_sp.attitude.phi = DL_BOOZ2_FMS_COMMAND_h_sp_1(_dl_buffer); \
65  vi.input.h_sp.attitude.theta = DL_BOOZ2_FMS_COMMAND_h_sp_2(_dl_buffer); \
66  vi.input.h_sp.attitude.psi = DL_BOOZ2_FMS_COMMAND_h_sp_3(_dl_buffer); \
67  ANGLE_REF_NORMALIZE(vi.input.h_sp.attitude.psi); \
68  VI_LIMIT_ATTITUDE(vi.input.h_sp.attitude); \
69  } \
70  break; \
71  case GUIDANCE_H_MODE_HOVER : \
72  { \
73  vi.input.h_sp.pos.x = DL_BOOZ2_FMS_COMMAND_h_sp_1(_dl_buffer); \
74  vi.input.h_sp.pos.y = DL_BOOZ2_FMS_COMMAND_h_sp_2(_dl_buffer); \
75  } \
76  break; \
77  case GUIDANCE_H_MODE_NAV : \
78  { \
79  vi.input.h_sp.speed.x = DL_BOOZ2_FMS_COMMAND_h_sp_1(_dl_buffer); \
80  vi.input.h_sp.speed.y = DL_BOOZ2_FMS_COMMAND_h_sp_2(_dl_buffer); \
81  vi.input.h_sp.speed.z = DL_BOOZ2_FMS_COMMAND_h_sp_3(_dl_buffer); \
82  } \
83  break; \
84  default: \
85  break; \
86  } \
87  switch (vi.input.v_mode) { \
88  case GUIDANCE_V_MODE_KILL: \
89  case GUIDANCE_V_MODE_RC_DIRECT: \
90  case GUIDANCE_V_MODE_RC_CLIMB: \
91  break; \
92  case GUIDANCE_V_MODE_CLIMB : \
93  vi.input.v_sp.climb = DL_BOOZ2_FMS_COMMAND_v_sp(_dl_buffer); \
94  break; \
95  case GUIDANCE_V_MODE_HOVER : \
96  vi.input.v_sp.height = DL_BOOZ2_FMS_COMMAND_v_sp(_dl_buffer); \
97  break; \
98  case GUIDANCE_V_MODE_NAV : \
99  vi.input.v_sp.climb = DL_BOOZ2_FMS_COMMAND_v_sp(_dl_buffer); \
100  break; \
101  default: \
102  break; \
103  } \
104  }
105 
106 #define VI_NAV_STICK_PARSE_DL(_dl_buffer) { \
107  vi.last_msg = 0; \
108  vi.input.h_mode = GUIDANCE_H_MODE_NAV; \
109  vi.input.v_mode = GUIDANCE_V_MODE_NAV; \
110  vi.input.h_sp.speed.x = DL_BOOZ_NAV_STICK_vx_sp(_dl_buffer); \
111  vi.input.h_sp.speed.y = DL_BOOZ_NAV_STICK_vy_sp(_dl_buffer); \
112  vi.input.h_sp.speed.z = DL_BOOZ_NAV_STICK_r_sp(_dl_buffer); \
113  vi.input.v_sp.climb = DL_BOOZ_NAV_STICK_vz_sp(_dl_buffer); \
114 }
115 
116 #define NavUpdateWPFromVI(_wp) { if (vi.enabled) { vi_update_wp(uint8_t _wp); } }
117 
118 #endif /* VI_DATALINK_H */
unsigned char uint8_t
Definition: types.h:14
Paparazzi fixed point algebra.