Paparazzi UAS  v5.17_devel-24-g2ae834f
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 
32 #include "std.h"
33 #include <inttypes.h>
34 
35 #if USE_NPS
36 #include "nps_radio_control.h"
37 #else
38 #include <caml/mlvalues.h>
39 #endif
40 
41 static bool spektrum_available;
42 
44 {
45  spektrum_available = false;
46 }
47 void spektrum_event(void (*frame_handler)(void))
48 {
49  if (spektrum_available) {
53  (*frame_handler)();
54  }
55  spektrum_available = false;
56 }
57 
58 void spektrum_try_bind(void) {}
59 
60 #if USE_NPS
61 #ifdef RADIO_CONTROL
62 void radio_control_feed(void)
63 {
69  spektrum_available = true;
70 }
71 #else //RADIO_CONTROL
72 void radio_control_feed(void) {}
73 #endif //RADIO_CONTROL
74 
75 #else // not NPS -> simple ocaml sim
76 #ifdef RADIO_CONTROL
77 value update_rc_channel(value c, value v)
78 {
79  // OCaml sim sends ppm values read from radio xml
80  //assume "ppm" value range from 1000 to 2000 for now.. like in fake spektrum.xml
81  if (Int_val(c) == 0) {
82  // throttle channel has neutral at 1000
83  radio_control.values[Int_val(c)] = (Double_val(v) - 1000.0) / 1000 * MAX_PPRZ;
84  } else {
85  // all other channels at 1500
86  radio_control.values[Int_val(c)] = (Double_val(v) - 1500.0) / 500 * MAX_PPRZ;
87  }
88  return Val_unit;
89 }
90 
91 value send_ppm(value unit)
92 {
93  spektrum_available = true;
94  return unit;
95 }
96 #else // RADIO_CONTROL
97 value update_rc_channel(value c __attribute__((unused)), value v __attribute__((unused)))
98 {
99  return Val_unit;
100 }
101 value send_ppm(value unit) {return unit;}
102 #endif // RADIO_CONTROL
103 #endif // USE_NPS
#define RADIO_ROLL
Definition: intermcu_ap.h:41
uint8_t status
Definition: radio_control.h:64
value send_ppm(value unit)
Definition: spektrum_arch.c:91
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
Definition: radio_control.h:69
struct NpsRadioControl nps_radio_control
#define RADIO_MODE
Definition: intermcu_ap.h:44
struct RadioControl radio_control
Definition: radio_control.c:30
#define RADIO_THROTTLE
Definition: intermcu_ap.h:40
#define RC_OK
Definition: radio_control.h:56
void spektrum_event(void(*frame_handler)(void))
Definition: spektrum_arch.c:47
#define RADIO_PITCH
Definition: intermcu_ap.h:42
#define RADIO_YAW
Definition: intermcu_ap.h:43
static bool spektrum_available
Definition: spektrum_arch.c:41
void radio_control_impl_init(void)
Definition: spektrum_arch.c:43
uint8_t time_since_last_frame
Definition: radio_control.h:65
value update_rc_channel(value c, value v)
Definition: spektrum_arch.c:77
Radio control spektrum interface.
#define MAX_PPRZ
Definition: paparazzi.h:8
uint8_t frame_cpt
Definition: radio_control.h:68
void spektrum_try_bind(void)
Definition: spektrum_arch.c:58