Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
spektrum_arch.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010-2012 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 
31 #include "std.h"
32 #include <inttypes.h>
33 
34 #if USE_NPS
35 #include "nps_radio_control.h"
36 #else
37 #include <caml/mlvalues.h>
38 #endif
39 
40 static bool_t spektrum_available;
41 
43 
45 {
47 }
48 void RadioControlEventImp(void (*frame_handler)(void))
49 {
50  if (spektrum_available) {
54  (*frame_handler)();
55  }
57 }
58 
59 #if USE_NPS
60 #ifdef RADIO_CONTROL
61 void radio_control_feed(void)
62 {
63  radio_control.values[RADIO_ROLL] = nps_radio_control.roll * MAX_PPRZ;
64  radio_control.values[RADIO_PITCH] = nps_radio_control.pitch * MAX_PPRZ;
65  radio_control.values[RADIO_YAW] = nps_radio_control.yaw * MAX_PPRZ;
66  radio_control.values[RADIO_THROTTLE] = nps_radio_control.throttle * MAX_PPRZ;
67  radio_control.values[RADIO_MODE] = nps_radio_control.mode * MAX_PPRZ;
69 }
70 #else //RADIO_CONTROL
71 void radio_control_feed(void) {}
72 #endif //RADIO_CONTROL
73 
74 #else // not NPS -> simple ocaml sim
75 #ifdef RADIO_CONTROL
77 {
78  // OCaml sim sends ppm values read from radio xml
79  //assume "ppm" value range from 1000 to 2000 for now.. like in fake spektrum.xml
80  if (Int_val(c) == 0) {
81  // throttle channel has neutral at 1000
82  radio_control.values[Int_val(c)] = (Double_val(v) - 1000.0) / 1000 * MAX_PPRZ;
83  } else {
84  // all other channels at 1500
85  radio_control.values[Int_val(c)] = (Double_val(v) - 1500.0) / 500 * MAX_PPRZ;
86  }
87  return Val_unit;
88 }
89 
91 {
93  return unit;
94 }
95 #else // RADIO_CONTROL
96 value update_rc_channel(value c __attribute__((unused)), value v __attribute__((unused)))
97 {
98  return Val_unit;
99 }
100 value send_ppm(value unit) {return unit;}
101 #endif // RADIO_CONTROL
102 #endif // USE_NPS
void radio_control_impl_init(void)
Definition: spektrum_arch.c:30
value update_rc_channel(value c, value v)
Definition: spektrum_arch.c:76
#define RADIO_ROLL
Definition: spektrum_arch.h:43
uint16_t value
Definition: adc_arch.c:586
#define RADIO_YAW
Definition: spektrum_arch.h:45
uint8_t status
Definition: radio_control.h:53
value send_ppm(value unit)
Definition: spektrum_arch.c:90
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
Definition: radio_control.h:58
#define FALSE
Definition: std.h:5
#define TRUE
Definition: std.h:4
static bool_t spektrum_available
Definition: spektrum_arch.c:40
#define RADIO_PITCH
Definition: spektrum_arch.h:44
struct RadioControl radio_control
Definition: radio_control.c:30
#define RADIO_THROTTLE
Definition: spektrum_arch.h:42
#define RC_OK
Definition: radio_control.h:48
#define RADIO_MODE
Definition: spektrum_arch.h:59
void RadioControlEventImp(void(*frame_handler)(void))
Definition: spektrum_arch.c:48
void radio_control_spektrum_try_bind(void)
Definition: spektrum_arch.c:42
uint8_t time_since_last_frame
Definition: radio_control.h:54
Radio control spektrum interface.
#define MAX_PPRZ
Definition: paparazzi.h:8
uint8_t frame_cpt
Definition: radio_control.h:57