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
autopilot_rc_helpers.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 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 
28 #ifndef AUTOPILOT_RC_HELPERS_H
29 #define AUTOPILOT_RC_HELPERS_H
30 
31 #include "generated/airframe.h"
33 
34 #define AUTOPILOT_THROTTLE_THRESHOLD (MAX_PPRZ / 20)
35 #define AUTOPILOT_YAW_THRESHOLD (MAX_PPRZ * 19 / 20)
36 #ifndef AUTOPILOT_STICK_CENTER_THRESHOLD
37 #define AUTOPILOT_STICK_CENTER_THRESHOLD (MAX_PPRZ * 1 / 20)
38 #endif
39 
40 #define THROTTLE_STICK_DOWN() \
41  (radio_control.values[RADIO_THROTTLE] < AUTOPILOT_THROTTLE_THRESHOLD)
42 #define YAW_STICK_PUSHED() \
43  (radio_control.values[RADIO_YAW] > AUTOPILOT_YAW_THRESHOLD || \
44  radio_control.values[RADIO_YAW] < -AUTOPILOT_YAW_THRESHOLD)
45 #define YAW_STICK_CENTERED() \
46  (radio_control.values[RADIO_YAW] < AUTOPILOT_STICK_CENTER_THRESHOLD && \
47  radio_control.values[RADIO_YAW] > -AUTOPILOT_STICK_CENTER_THRESHOLD)
48 #define PITCH_STICK_CENTERED() \
49  (radio_control.values[RADIO_PITCH] < AUTOPILOT_STICK_CENTER_THRESHOLD && \
50  radio_control.values[RADIO_PITCH] > -AUTOPILOT_STICK_CENTER_THRESHOLD)
51 #define ROLL_STICK_CENTERED() \
52  (radio_control.values[RADIO_ROLL] < AUTOPILOT_STICK_CENTER_THRESHOLD && \
53  radio_control.values[RADIO_ROLL] > -AUTOPILOT_STICK_CENTER_THRESHOLD)
54 
63 static inline bool rc_mode_switch(uint8_t chan, uint8_t pos, uint8_t max)
64 {
65  if (radio_control.status != RC_OK) return false;
66  if (pos >= max) return false;
68  // round final value
69  int32_t p = (((((int32_t)max - 1) * 10 * v) / (MAX_PPRZ - MIN_PPRZ)) + 5) / 10;
70  Bound(p, 0, max - 1); // just in case
71  return pos == (uint8_t)p;
72 }
73 
76 #ifdef RADIO_MODE
77 #define RCMode0() rc_mode_switch(RADIO_MODE, 0, 3)
78 #define RCMode1() rc_mode_switch(RADIO_MODE, 1, 3)
79 #define RCMode2() rc_mode_switch(RADIO_MODE, 2, 3)
80 #endif
81 
82 static inline bool rc_attitude_sticks_centered(void)
83 {
85 }
86 
87 #ifdef RADIO_KILL_SWITCH
88 static inline bool kill_switch_is_on(void)
89 {
91  return true;
92  } else {
93  return false;
94  }
95 }
96 #else
97 static inline bool kill_switch_is_on(void)
98 {
99  return false;
100 }
101 #endif
102 
103 static inline uint8_t percent_from_rc(int channel)
104 {
105  int per = (MAX_PPRZ + (int32_t)radio_control.values[channel]) * 50 / MAX_PPRZ;
106  if (per < 0) {
107  per = 0;
108  } else if (per > 100) {
109  per = 100;
110  }
111  return per;
112 }
113 
114 
115 #endif /* AUTOPILOT_RC_HELPERS_H */
#define MIN_PPRZ
Definition: paparazzi.h:9
static bool rc_mode_switch(uint8_t chan, uint8_t pos, uint8_t max)
RC mode switch position helper switch positions threshold are evenly spaced.
uint8_t status
Definition: radio_control.h:53
static bool rc_attitude_sticks_centered(void)
Convenience macro for 3way switch.
static bool kill_switch_is_on(void)
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
Definition: radio_control.h:58
static uint8_t percent_from_rc(int channel)
struct RadioControl radio_control
Definition: radio_control.c:30
#define ROLL_STICK_CENTERED()
signed long int32_t
Definition: types.h:19
#define YAW_STICK_CENTERED()
#define RC_OK
Definition: radio_control.h:48
#define PITCH_STICK_CENTERED()
unsigned char uint8_t
Definition: types.h:14
static float p[2][2]
#define MAX_PPRZ
Definition: paparazzi.h:8
#define RADIO_KILL_SWITCH
Definition: intermcu_ap.h:44
static uint8_t channel
Definition: ADS8344.c:80