Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
radio_control.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006 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  */
22 
23 #ifndef RADIO_CONTROL_H
24 #define RADIO_CONTROL_H
25 
26 #if defined RADIO_CONTROL
27 
28 #include "led.h"
29 #include "generated/airframe.h"
30 #include "paparazzi.h"
31 
32 /* underlying hardware */
33 #include RADIO_CONTROL_TYPE_H
34 /* must be defined by underlying hardware */
35 extern void radio_control_impl_init(void);
36 /* RADIO_CONTROL_NB_CHANNEL has to be defined by the implementation */
37 
38 /* timeouts - for now assumes 60Hz periodic */
39 #define RC_AVG_PERIOD 8 /* TODO remove if IIR filter is used */
40 #define RC_LOST_TIME 30 /* 500ms with a 60Hz timer */
41 #define RC_REALLY_LOST_TIME 60 /* ~1s */
42 /* Number of valid frames before going back to RC OK */
43 #define RC_OK_CPT 15
44 
45 #define RC_OK 0
46 #define RC_LOST 1
47 #define RC_REALLY_LOST 2
48 
49 struct RadioControl {
56 };
57 
58 extern struct RadioControl radio_control;
59 
60 
61 /************* INIT ******************************************************/
62 static inline void radio_control_init ( void ) {
63  uint8_t i;
64  for (i=0; i<RADIO_CONTROL_NB_CHANNEL; i++)
65  radio_control.values[i] = 0;
72 }
73 
74 /************* PERIODIC ******************************************************/
75 static inline void radio_control_periodic_task ( void ) {
76  static uint8_t _1Hz;
77  _1Hz++;
78 
79  if (_1Hz >= 60) {
80  _1Hz = 0;
83  }
84 
87  } else {
91  }
93  }
94 
95 #if defined RADIO_CONTROL_LED
96  if (radio_control.status == RC_OK) {
97  LED_ON(RADIO_CONTROL_LED);
98  }
99  else {
100  LED_OFF(RADIO_CONTROL_LED);
101  }
102 #endif
103 
104 }
105 
106 /********** EVENT ************************************************************/
107 // Implemented in radio_control/*.h
108 
109 
110 #endif /* RADIO_CONTROL */
111 
112 #endif /* RADIO_CONTROL_H */
#define RC_LOST
Definition: radio_control.h:46
static void radio_control_periodic_task(void)
Definition: radio_control.h:75
uint8_t frame_cpt
Definition: radio_control.h:54
int16_t pprz_t
Definition: paparazzi.h:6
uint8_t time_since_last_frame
Definition: radio_control.h:51
#define LED_ON(i)
Definition: led_hw.h:28
#define RC_LOST_TIME
Definition: radio_control.h:40
#define RC_REALLY_LOST_TIME
Definition: radio_control.h:41
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
Definition: radio_control.h:55
void radio_control_impl_init(void)
Definition: spektrum_arch.c:30
static void radio_control_init(void)
Definition: radio_control.h:62
uint8_t radio_ok_cpt
Definition: radio_control.h:52
uint8_t frame_rate
Definition: radio_control.h:53
#define RC_REALLY_LOST
Definition: radio_control.h:47
#define RC_OK
Definition: radio_control.h:45
uint8_t status
Definition: radio_control.h:50
#define RC_OK_CPT
Definition: radio_control.h:43
#define RADIO_CONTROL_NB_CHANNEL
Definition: spektrum_arch.h:34
unsigned char uint8_t
Definition: types.h:14
#define LED_OFF(i)
Definition: led_hw.h:29
arch independent LED (Light Emitting Diodes) API
struct RadioControl radio_control
Definition: radio_control.c:25