Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
rc_datalink.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Copyright (C) 2010 The Paparazzi Team
5  *
6  * This file is part of paparazzi.
7  *
8  * paparazzi is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2, or (at your option)
11  * any later version.
12  *
13  * paparazzi is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with paparazzi; see the file COPYING. If not, write to
20  * the Free Software Foundation, 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
24 #ifndef RC_DATALINK_H
25 #define RC_DATALINK_H
26 
27 #include "std.h"
28 
29 #define RC_DL_NB_CHANNEL 5
30 #define RADIO_CONTROL_NB_CHANNEL RC_DL_NB_CHANNEL
31 
36 #define RADIO_ROLL 0
37 #define RADIO_PITCH 1
38 #define RADIO_YAW 2
39 #define RADIO_THROTTLE 3
40 #define RADIO_MODE 4
41 
43 extern volatile bool_t rc_dl_frame_available;
44 
49 extern void parse_rc_3ch_datalink(
50  uint8_t throttle_mode,
51  int8_t roll,
52  int8_t pitch);
53 
57 extern void parse_rc_4ch_datalink(
58  uint8_t mode,
59  uint8_t throttle,
60  int8_t roll,
61  int8_t pitch,
62  int8_t yaw);
63 
67 #define NormalizeRcDl(_in, _out) { \
68  _out[RADIO_ROLL] = (MAX_PPRZ/128) * _in[RADIO_ROLL]; \
69  Bound(_out[RADIO_ROLL], MIN_PPRZ, MAX_PPRZ); \
70  _out[RADIO_PITCH] = (MAX_PPRZ/128) * _in[RADIO_PITCH]; \
71  Bound(_out[RADIO_PITCH], MIN_PPRZ, MAX_PPRZ); \
72  _out[RADIO_YAW] = (MAX_PPRZ/128) * _in[RADIO_YAW]; \
73  Bound(_out[RADIO_YAW], MIN_PPRZ, MAX_PPRZ); \
74  _out[RADIO_THROTTLE] = ((MAX_PPRZ/128) * _in[RADIO_THROTTLE]); \
75  Bound(_out[RADIO_THROTTLE], 0, MAX_PPRZ); \
76  _out[RADIO_MODE] = MAX_PPRZ * (_in[RADIO_MODE] - 1); \
77  Bound(_out[RADIO_MODE], MIN_PPRZ, MAX_PPRZ); \
78 }
79 
83 #define RadioControlEvent(_received_frame_handler) { \
84  if (rc_dl_frame_available) { \
85  radio_control.frame_cpt++; \
86  radio_control.time_since_last_frame = 0; \
87  radio_control.radio_ok_cpt = 0; \
88  radio_control.status = RC_OK; \
89  NormalizeRcDl(rc_dl_values,radio_control.values); \
90  _received_frame_handler(); \
91  rc_dl_frame_available = FALSE; \
92  } \
93 }
94 
95 #endif /* RC_DATALINK_H */
unsigned char uint8_t
Definition: types.h:14
signed char int8_t
Definition: types.h:15