Paparazzi UAS  v6.2_unstable
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 #include "modules/core/abi.h"
30 #include "pprzlink/dl_protocol.h"
31 
33 volatile bool rc_dl_frame_available;
34 
35 
36 void rc_datalink_init(void)
37 {
39  rc_dl_frame_available = false;
40 }
41 
43 {
44 #ifdef RADIO_CONTROL_DATALINK_LED
45  LED_TOGGLE(RADIO_CONTROL_DATALINK_LED);
46 #endif
48  DL_RC_3CH_throttle_mode(buf),
49  DL_RC_3CH_roll(buf),
50  DL_RC_3CH_pitch(buf));
51 }
52 
54 {
55 #ifdef RADIO_CONTROL_DATALINK_LED
56  LED_TOGGLE(RADIO_CONTROL_DATALINK_LED);
57 #endif
58  parse_rc_4ch_datalink(DL_RC_4CH_mode(buf),
59  DL_RC_4CH_throttle(buf),
60  DL_RC_4CH_roll(buf),
61  DL_RC_4CH_pitch(buf),
62  DL_RC_4CH_yaw(buf));
63 }
64 
65 void parse_rc_3ch_datalink(uint8_t throttle_mode,
66  int8_t roll,
67  int8_t pitch)
68 {
69  uint8_t throttle = ((throttle_mode & 0xFC) >> 2) * (128 / 64);
70  uint8_t mode = throttle_mode & 0x03;
71 
72  rc_dl_values[RADIO_ROLL] = roll;
73  rc_dl_values[RADIO_PITCH] = pitch;
74  rc_dl_values[RADIO_THROTTLE] = (int8_t)throttle;
77 
78  rc_dl_frame_available = true;
79 }
80 
82  uint8_t mode,
83  uint8_t throttle,
84  int8_t roll,
85  int8_t pitch,
86  int8_t yaw)
87 {
89  rc_dl_values[RADIO_THROTTLE] = (int8_t)throttle;
90  rc_dl_values[RADIO_ROLL] = roll;
91  rc_dl_values[RADIO_PITCH] = pitch;
92  rc_dl_values[RADIO_YAW] = yaw;
93 
94  rc_dl_frame_available = true;
95 }
96 
100 static void rc_datalink_normalize(int8_t *in, int16_t *out)
101 {
102  out[RADIO_ROLL] = (MAX_PPRZ / 128) * in[RADIO_ROLL];
103  Bound(out[RADIO_ROLL], MIN_PPRZ, MAX_PPRZ);
104  out[RADIO_PITCH] = (MAX_PPRZ / 128) * in[RADIO_PITCH];
105  Bound(out[RADIO_PITCH], MIN_PPRZ, MAX_PPRZ);
106  out[RADIO_YAW] = (MAX_PPRZ / 128) * in[RADIO_YAW];
107  Bound(out[RADIO_YAW], MIN_PPRZ, MAX_PPRZ);
108  out[RADIO_THROTTLE] = ((MAX_PPRZ / 128) * in[RADIO_THROTTLE]);
109  Bound(out[RADIO_THROTTLE], 0, MAX_PPRZ);
110  out[RADIO_MODE] = MAX_PPRZ * (in[RADIO_MODE] - 1);
111  Bound(out[RADIO_MODE], MIN_PPRZ, MAX_PPRZ);
112 }
113 
115 {
116  if (rc_dl_frame_available) {
122  AbiSendMsgRADIO_CONTROL(RADIO_CONTROL_DATALINK_ID, &radio_control);
123  rc_dl_frame_available = false;
124  }
125 }
radio_control.h
MAX_PPRZ
#define MAX_PPRZ
Definition: paparazzi.h:8
int8_t
signed char int8_t
Typedef defining 8 bit char type.
Definition: vl53l1_types.h:103
RadioControl::radio_ok_cpt
uint8_t radio_ok_cpt
Definition: radio_control.h:63
uint8_t
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98
abi.h
RADIO_CONTROL_DATALINK_ID
#define RADIO_CONTROL_DATALINK_ID
Definition: abi_sender_ids.h:569
RadioControl::time_since_last_frame
uint8_t time_since_last_frame
Definition: radio_control.h:62
LED_TOGGLE
#define LED_TOGGLE(i)
Definition: led_hw.h:53
RadioControl::nb_channel
uint8_t nb_channel
Definition: radio_control.h:66
int16_t
short int16_t
Typedef defining 16 bit short type.
Definition: vl53l1_types.h:93
MIN_PPRZ
#define MIN_PPRZ
Definition: paparazzi.h:9
RadioControl::status
uint8_t status
Definition: radio_control.h:61
RadioControl::frame_cpt
uint8_t frame_cpt
Definition: radio_control.h:65
RC_OK
#define RC_OK
Definition: radio_control.h:49
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_control
struct RadioControl radio_control
Definition: radio_control.c:33
RadioControl::values
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
Definition: radio_control.h:67