Paparazzi UAS  v6.2.0_stable
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 "modules/core/abi.h"
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 
43 void spektrum_init(void)
44 {
45  spektrum_available = false;
46 }
47 
48 void spektrum_event(void)
49 {
50  if (spektrum_available) {
54  AbiSendMsgRADIO_CONTROL(RADIO_CONTROL_SPEKTRUM_ID, &radio_control);
55  }
56  spektrum_available = false;
57 }
58 
59 void spektrum_try_bind(void) {}
60 
61 #if USE_NPS
62 #ifdef RADIO_CONTROL
63 void radio_control_feed(void)
64 {
70  spektrum_available = true;
71 }
72 #else //RADIO_CONTROL
73 void radio_control_feed(void) {}
74 #endif //RADIO_CONTROL
75 
76 #else // not NPS -> simple ocaml sim
77 #ifdef RADIO_CONTROL
78 value update_rc_channel(value c, value v)
79 {
80  // OCaml sim sends ppm values read from radio xml
81  //assume "ppm" value range from 1000 to 2000 for now.. like in fake spektrum.xml
82  if (Int_val(c) == 0) {
83  // throttle channel has neutral at 1000
84  radio_control.values[Int_val(c)] = (Double_val(v) - 1000.0) / 1000 * MAX_PPRZ;
85  } else {
86  // all other channels at 1500
87  radio_control.values[Int_val(c)] = (Double_val(v) - 1500.0) / 500 * MAX_PPRZ;
88  }
89  return Val_unit;
90 }
91 
92 value send_ppm(value unit)
93 {
94  spektrum_available = true;
95  return unit;
96 }
97 #else // RADIO_CONTROL
98 value update_rc_channel(value c __attribute__((unused)), value v __attribute__((unused)))
99 {
100  return Val_unit;
101 }
102 value send_ppm(value unit) {return unit;}
103 #endif // RADIO_CONTROL
104 #endif // USE_NPS
Main include for ABI (AirBorneInterface).
#define RADIO_CONTROL_SPEKTRUM_ID
static unit_t unit
Definition: nav.c:31
struct NpsRadioControl nps_radio_control
#define MAX_PPRZ
Definition: paparazzi.h:8
struct RadioControl radio_control
Definition: radio_control.c:33
Generic interface for radio control modules.
uint8_t time_since_last_frame
Definition: radio_control.h:62
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
Definition: radio_control.h:67
uint8_t status
Definition: radio_control.h:61
uint8_t frame_cpt
Definition: radio_control.h:65
#define RC_OK
Definition: radio_control.h:49
Radio control spektrum interface.
value update_rc_channel(value c, value v)
Definition: spektrum_arch.c:78
void spektrum_event(void)
Definition: spektrum_arch.c:48
static bool spektrum_available
Definition: spektrum_arch.c:41
value send_ppm(value unit)
Definition: spektrum_arch.c:92
void spektrum_init(void)
Definition: spektrum_arch.c:43
void spektrum_try_bind(void)
Definition: spektrum_arch.c:59