Paparazzi UAS  v5.15_devel-81-gd13dafb
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 spektrum_available;
41 
43 {
44  spektrum_available = false;
45 }
46 void spektrum_event(void (*frame_handler)(void))
47 {
48  if (spektrum_available) {
52  (*frame_handler)();
53  }
54  spektrum_available = false;
55 }
56 
57 void spektrum_try_bind(void) {}
58 
59 #if USE_NPS
60 #ifdef RADIO_CONTROL
61 void radio_control_feed(void)
62 {
68  spektrum_available = true;
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
76 value update_rc_channel(value c, value v)
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 
90 value send_ppm(value unit)
91 {
92  spektrum_available = true;
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
#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:90
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:46
#define RADIO_PITCH
Definition: intermcu_ap.h:42
#define RADIO_YAW
Definition: intermcu_ap.h:43
static bool spektrum_available
Definition: spektrum_arch.c:40
void radio_control_impl_init(void)
Definition: spektrum_arch.c:42
uint8_t time_since_last_frame
Definition: radio_control.h:65
value update_rc_channel(value c, value v)
Definition: spektrum_arch.c:76
#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:57