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
rc_datalink.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 The Paparazzi Team
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 
22 #ifndef RC_DATALINK_H
23 #define RC_DATALINK_H
24 
25 #include "std.h"
26 
27 #define RC_DL_NB_CHANNEL 5
28 #define RADIO_CONTROL_NB_CHANNEL RC_DL_NB_CHANNEL
29 
34 #define RADIO_ROLL 0
35 #define RADIO_PITCH 1
36 #define RADIO_YAW 2
37 #define RADIO_THROTTLE 3
38 #define RADIO_MODE 4
39 
41 extern volatile bool_t rc_dl_frame_available;
42 
47 extern void parse_rc_3ch_datalink(
48  uint8_t throttle_mode,
49  int8_t roll,
50  int8_t pitch);
51 
55 extern void parse_rc_4ch_datalink(
56  uint8_t mode,
57  uint8_t throttle,
58  int8_t roll,
59  int8_t pitch,
60  int8_t yaw);
61 
65 #define NormalizeRcDl(_in, _out) { \
66  _out[RADIO_ROLL] = (MAX_PPRZ/128) * _in[RADIO_ROLL]; \
67  Bound(_out[RADIO_ROLL], MIN_PPRZ, MAX_PPRZ); \
68  _out[RADIO_PITCH] = (MAX_PPRZ/128) * _in[RADIO_PITCH]; \
69  Bound(_out[RADIO_PITCH], MIN_PPRZ, MAX_PPRZ); \
70  _out[RADIO_YAW] = (MAX_PPRZ/128) * _in[RADIO_YAW]; \
71  Bound(_out[RADIO_YAW], MIN_PPRZ, MAX_PPRZ); \
72  _out[RADIO_THROTTLE] = ((MAX_PPRZ/128) * _in[RADIO_THROTTLE]); \
73  Bound(_out[RADIO_THROTTLE], 0, MAX_PPRZ); \
74  _out[RADIO_MODE] = MAX_PPRZ * (_in[RADIO_MODE] - 1); \
75  Bound(_out[RADIO_MODE], MIN_PPRZ, MAX_PPRZ); \
76 }
77 
81 #define RadioControlEvent(_received_frame_handler) { \
82  if (rc_dl_frame_available) { \
83  radio_control.frame_cpt++; \
84  radio_control.time_since_last_frame = 0; \
85  radio_control.radio_ok_cpt = 0; \
86  radio_control.status = RC_OK; \
87  NormalizeRcDl(rc_dl_values,radio_control.values); \
88  _received_frame_handler(); \
89  rc_dl_frame_available = FALSE; \
90  } \
91 }
92 
93 #endif /* RC_DATALINK_H */
unsigned char uint8_t
Definition: types.h:14
signed char int8_t
Definition: types.h:15