Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
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
send_ppm
value send_ppm(value unit)
Definition: spektrum_arch.c:91
c
VIC slots used for the LPC2148 define name e g gps UART1_VIC_SLOT e g modem SPI1_VIC_SLOT SPI1 in mcu_periph spi_arch c or spi_slave_hs_arch c(and some others not using the SPI peripheral yet..) I2C0_VIC_SLOT 8 mcu_periph/i2c_arch.c I2C1_VIC_SLOT 9 mcu_periph/i2c_arch.c USB_VIC_SLOT 10 usb
radio_control.h
MAX_PPRZ
#define MAX_PPRZ
Definition: paparazzi.h:8
RADIO_ROLL
#define RADIO_ROLL
Definition: intermcu_ap.h:41
NpsRadioControl::roll
double roll
Definition: nps_radio_control.h:46
RADIO_MODE
#define RADIO_MODE
Definition: intermcu_ap.h:44
NpsRadioControl::yaw
double yaw
Definition: nps_radio_control.h:48
RadioControl::time_since_last_frame
uint8_t time_since_last_frame
Definition: radio_control.h:65
spektrum.h
NpsRadioControl::mode
double mode
Definition: nps_radio_control.h:49
update_rc_channel
value update_rc_channel(value c, value v)
Definition: spektrum_arch.c:77
spektrum_arch.h
std.h
nps_radio_control
struct NpsRadioControl nps_radio_control
Definition: nps_radio_control.c:31
nps_radio_control.h
NpsRadioControl::pitch
double pitch
Definition: nps_radio_control.h:47
RadioControl::status
uint8_t status
Definition: radio_control.h:64
RadioControl::frame_cpt
uint8_t frame_cpt
Definition: radio_control.h:68
spektrum_try_bind
void spektrum_try_bind(void)
Definition: spektrum_arch.c:58
spektrum_event
void spektrum_event(void(*frame_handler)(void))
Definition: spektrum_arch.c:47
RADIO_THROTTLE
#define RADIO_THROTTLE
Definition: intermcu_ap.h:40
RC_OK
#define RC_OK
Definition: radio_control.h:56
radio_control_impl_init
void radio_control_impl_init(void)
Definition: spektrum_arch.c:43
unit
static unit_t unit
Definition: nav.c:31
RADIO_YAW
#define RADIO_YAW
Definition: intermcu_ap.h:43
RADIO_PITCH
#define RADIO_PITCH
Definition: intermcu_ap.h:42
inttypes.h
spektrum_available
static bool spektrum_available
Definition: spektrum_arch.c:41
NpsRadioControl::throttle
double throttle
Definition: nps_radio_control.h:45
radio_control
struct RadioControl radio_control
Definition: radio_control.c:30
RadioControl::values
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
Definition: radio_control.h:69