Paparazzi UAS  v7.0_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 }
Main include for ABI (AirBorneInterface).
#define RADIO_CONTROL_DATALINK_ID
#define LED_TOGGLE(i)
Definition: led_hw.h:53
#define MAX_PPRZ
Definition: paparazzi.h:8
#define MIN_PPRZ
Definition: paparazzi.h:9
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 radio_ok_cpt
Definition: radio_control.h:63
uint8_t frame_cpt
Definition: radio_control.h:65
#define RC_OK
Definition: radio_control.h:49
uint8_t nb_channel
Definition: radio_control.h:66
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
short int16_t
Typedef defining 16 bit short type.
Definition: vl53l1_types.h:93
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98
signed char int8_t
Typedef defining 8 bit char type.
Definition: vl53l1_types.h:103