Paparazzi UAS  v5.12_stable-4-g9b43e9b
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
rc_datalink.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010-2014 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, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
29 
31 volatile bool rc_dl_frame_available;
32 
33 
35 {
36  rc_dl_frame_available = false;
37 }
38 
39 
40 void parse_rc_3ch_datalink(uint8_t throttle_mode,
41  int8_t roll,
42  int8_t pitch)
43 {
44  uint8_t throttle = ((throttle_mode & 0xFC) >> 2) * (128 / 64);
45  uint8_t mode = throttle_mode & 0x03;
46 
47  rc_dl_values[RADIO_ROLL] = roll;
48  rc_dl_values[RADIO_PITCH] = pitch;
49  rc_dl_values[RADIO_THROTTLE] = (int8_t)throttle;
52 
53  rc_dl_frame_available = true;
54 }
55 
57  uint8_t mode,
58  uint8_t throttle,
59  int8_t roll,
60  int8_t pitch,
61  int8_t yaw)
62 {
64  rc_dl_values[RADIO_THROTTLE] = (int8_t)throttle;
65  rc_dl_values[RADIO_ROLL] = roll;
66  rc_dl_values[RADIO_PITCH] = pitch;
67  rc_dl_values[RADIO_YAW] = yaw;
68 
69  rc_dl_frame_available = true;
70 }
71 
75 static void rc_datalink_normalize(int8_t *in, int16_t *out)
76 {
77  out[RADIO_ROLL] = (MAX_PPRZ / 128) * in[RADIO_ROLL];
78  Bound(out[RADIO_ROLL], MIN_PPRZ, MAX_PPRZ);
79  out[RADIO_PITCH] = (MAX_PPRZ / 128) * in[RADIO_PITCH];
80  Bound(out[RADIO_PITCH], MIN_PPRZ, MAX_PPRZ);
81  out[RADIO_YAW] = (MAX_PPRZ / 128) * in[RADIO_YAW];
82  Bound(out[RADIO_YAW], MIN_PPRZ, MAX_PPRZ);
83  out[RADIO_THROTTLE] = ((MAX_PPRZ / 128) * in[RADIO_THROTTLE]);
84  Bound(out[RADIO_THROTTLE], 0, MAX_PPRZ);
85  out[RADIO_MODE] = MAX_PPRZ * (in[RADIO_MODE] - 1);
86  Bound(out[RADIO_MODE], MIN_PPRZ, MAX_PPRZ);
87 }
88 
89 void radio_control_impl_event(void (* _received_frame_handler)(void))
90 {
97  _received_frame_handler();
98  rc_dl_frame_available = false;
99  }
100 }
#define RADIO_ROLL
Definition: spektrum_arch.h:43
#define MIN_PPRZ
Definition: paparazzi.h:9
#define RADIO_YAW
Definition: spektrum_arch.h:45
uint8_t radio_ok_cpt
Definition: radio_control.h:55
uint8_t status
Definition: radio_control.h:53
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
Definition: radio_control.h:58
#define RADIO_PITCH
Definition: spektrum_arch.h:44
signed short int16_t
Definition: types.h:17
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
unsigned char uint8_t
Definition: types.h:14
static uint8_t mode
mode holds the current sonar mode mode = 0 used at high altitude, uses 16 wave patterns mode = 1 used...
Definition: sonar_bebop.c:66
uint8_t time_since_last_frame
Definition: radio_control.h:54
#define MAX_PPRZ
Definition: paparazzi.h:8
signed char int8_t
Definition: types.h:15
uint8_t frame_cpt
Definition: radio_control.h:57