Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
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 }
radio_control.h
MAX_PPRZ
#define MAX_PPRZ
Definition: paparazzi.h:8
RadioControl::radio_ok_cpt
uint8_t radio_ok_cpt
Definition: radio_control.h:66
RADIO_ROLL
#define RADIO_ROLL
Definition: intermcu_ap.h:41
RADIO_MODE
#define RADIO_MODE
Definition: intermcu_ap.h:44
RadioControl::time_since_last_frame
uint8_t time_since_last_frame
Definition: radio_control.h:65
int16_t
signed short int16_t
Definition: types.h:17
uint8_t
unsigned char uint8_t
Definition: types.h:14
MIN_PPRZ
#define MIN_PPRZ
Definition: paparazzi.h:9
RadioControl::status
uint8_t status
Definition: radio_control.h:64
RadioControl::frame_cpt
uint8_t frame_cpt
Definition: radio_control.h:68
int8_t
signed char int8_t
Definition: types.h:15
RADIO_THROTTLE
#define RADIO_THROTTLE
Definition: intermcu_ap.h:40
RC_OK
#define RC_OK
Definition: radio_control.h:56
RADIO_YAW
#define RADIO_YAW
Definition: intermcu_ap.h:43
mode
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:69
RADIO_PITCH
#define RADIO_PITCH
Definition: intermcu_ap.h:42
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