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
radio_control.h
Go to the documentation of this file.
1 /*
2  * Paparazzi $Id$
3  *
4  * Copyright (C) 2006 Pascal Brisset, Antoine Drouin
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 
25 #ifndef RADIO_CONTROL_H
26 #define RADIO_CONTROL_H
27 
28 #if defined RADIO_CONTROL
29 
30 #include "led.h"
31 #include "generated/airframe.h"
32 #include "paparazzi.h"
33 
34 /* underlying hardware */
35 #include RADIO_CONTROL_TYPE_H
36 /* must be defined by underlying hardware */
37 extern void radio_control_impl_init(void);
38 /* RADIO_CONTROL_NB_CHANNEL has to be defined by the implementation */
39 
40 /* timeouts - for now assumes 60Hz periodic */
41 #define RC_AVG_PERIOD 8 /* TODO remove if IIR filter is used */
42 #define RC_LOST_TIME 30 /* 500ms with a 60Hz timer */
43 #define RC_REALLY_LOST_TIME 60 /* ~1s */
44 /* Number of valid frames before going back to RC OK */
45 #define RC_OK_CPT 15
46 
47 #define RC_OK 0
48 #define RC_LOST 1
49 #define RC_REALLY_LOST 2
50 
51 struct RadioControl {
53  uint8_t time_since_last_frame;
54  uint8_t radio_ok_cpt;
55  uint8_t frame_rate;
56  uint8_t frame_cpt;
58 };
59 
60 extern struct RadioControl radio_control;
61 
62 
63 /************* INIT ******************************************************/
64 static inline void radio_control_init ( void ) {
65  uint8_t i;
66  for (i=0; i<RADIO_CONTROL_NB_CHANNEL; i++)
67  radio_control.values[i] = 0;
68  radio_control.status = RC_REALLY_LOST;
69  radio_control.time_since_last_frame = RC_REALLY_LOST_TIME;
70  radio_control.radio_ok_cpt = 0;
71  radio_control.frame_rate = 0;
72  radio_control.frame_cpt = 0;
74 }
75 
76 /************* PERIODIC ******************************************************/
77 static inline void radio_control_periodic_task ( void ) {
78  static uint8_t _1Hz;
79  _1Hz++;
80 
81  if (_1Hz >= 60) {
82  _1Hz = 0;
83  radio_control.frame_rate = radio_control.frame_cpt;
84  radio_control.frame_cpt = 0;
85  }
86 
87  if (radio_control.time_since_last_frame >= RC_REALLY_LOST_TIME) {
88  radio_control.status = RC_REALLY_LOST;
89  } else {
90  if (radio_control.time_since_last_frame >= RC_LOST_TIME) {
91  radio_control.status = RC_LOST;
92  radio_control.radio_ok_cpt = RC_OK_CPT;
93  }
94  radio_control.time_since_last_frame++;
95  }
96 
97 #if defined RADIO_CONTROL_LED
98  if (radio_control.status == RC_OK) {
99  LED_ON(RADIO_CONTROL_LED);
100  }
101  else {
102  LED_OFF(RADIO_CONTROL_LED);
103  }
104 #endif
105 
106 }
107 
108 /********** EVENT ************************************************************/
109 // Implemented in radio_control/*.h
110 
111 
112 #endif /* RADIO_CONTROL */
113 
114 #endif /* RADIO_CONTROL_H */
void radio_control_impl_init(void)
Definition: spektrum_arch.c:32
status
Definition: anemotaxis.c:10
int16_t pprz_t
Definition: paparazzi.h:6
#define LED_ON(i)
Definition: led_hw.h:28
static uint8_t values[6]
struct RadioControl radio_control
Definition: radio_control.c:27
#define RADIO_CONTROL_NB_CHANNEL
Definition: spektrum_arch.h:36
unsigned char uint8_t
Definition: types.h:14
#define LED_OFF(i)
Definition: led_hw.h:29
arch independent LED (Light Emitting Diodes) API