Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
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 #include "generated/modules.h"
34 
35 #define AUTOPILOT_THROTTLE_THRESHOLD (MAX_PPRZ / 20)
36 #define AUTOPILOT_YAW_THRESHOLD (MAX_PPRZ * 19 / 20)
37 #ifndef AUTOPILOT_STICK_CENTER_THRESHOLD
38 #define AUTOPILOT_STICK_CENTER_THRESHOLD (MAX_PPRZ * 1 / 20)
39 #endif
40 
41 #define THROTTLE_STICK_DOWN() \
42  (radio_control.values[RADIO_THROTTLE] < AUTOPILOT_THROTTLE_THRESHOLD)
43 #define YAW_STICK_PUSHED() \
44  (radio_control.values[RADIO_YAW] > AUTOPILOT_YAW_THRESHOLD || \
45  radio_control.values[RADIO_YAW] < -AUTOPILOT_YAW_THRESHOLD)
46 #define YAW_STICK_CENTERED() \
47  (radio_control.values[RADIO_YAW] < AUTOPILOT_STICK_CENTER_THRESHOLD && \
48  radio_control.values[RADIO_YAW] > -AUTOPILOT_STICK_CENTER_THRESHOLD)
49 #define PITCH_STICK_CENTERED() \
50  (radio_control.values[RADIO_PITCH] < AUTOPILOT_STICK_CENTER_THRESHOLD && \
51  radio_control.values[RADIO_PITCH] > -AUTOPILOT_STICK_CENTER_THRESHOLD)
52 #define ROLL_STICK_CENTERED() \
53  (radio_control.values[RADIO_ROLL] < AUTOPILOT_STICK_CENTER_THRESHOLD && \
54  radio_control.values[RADIO_ROLL] > -AUTOPILOT_STICK_CENTER_THRESHOLD)
55 
56 // macros with pointer to radio control struct
57 #define THROTTLE_STICK_DOWN_FROM_RC(_rc) \
58  (_rc->values[RADIO_THROTTLE] < AUTOPILOT_THROTTLE_THRESHOLD)
59 
68 static inline bool rc_mode_switch(uint8_t chan, uint8_t pos, uint8_t max)
69 {
70  if (radio_control.status != RC_OK) return false;
71  if (pos >= max) return false;
73  // round final value
74  int32_t p = (((((int32_t)max - 1) * 10 * v) / (MAX_PPRZ - MIN_PPRZ)) + 5) / 10;
75  Bound(p, 0, max - 1); // just in case
76  return pos == (uint8_t)p;
77 }
78 
81 #ifdef RADIO_MODE
82 #define RCMode0() rc_mode_switch(RADIO_MODE, 0, 3)
83 #define RCMode1() rc_mode_switch(RADIO_MODE, 1, 3)
84 #define RCMode2() rc_mode_switch(RADIO_MODE, 2, 3)
85 #endif
86 
87 static inline bool rc_attitude_sticks_centered(void)
88 {
90 }
91 
92 #ifdef RADIO_KILL_SWITCH
93 static inline bool kill_switch_is_on(void)
94 {
96  return true;
97  } else {
98  return false;
99  }
100 }
101 #else
102 static inline bool kill_switch_is_on(void)
103 {
104  return false;
105 }
106 #endif
107 
108 static inline uint8_t percent_from_rc(int channel)
109 {
110  int per = (MAX_PPRZ + (int32_t)radio_control.values[channel]) * 50 / MAX_PPRZ;
111  if (per < 0) {
112  per = 0;
113  } else if (per > 100) {
114  per = 100;
115  }
116  return per;
117 }
118 
119 
120 #endif /* AUTOPILOT_RC_HELPERS_H */
static float p[2][2]
#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.
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
Definition: radio_control.h:67
uint8_t status
Definition: radio_control.h:61
#define RC_OK
Definition: radio_control.h:49
#define RADIO_KILL_SWITCH
Definition: rc_intermcu.h:40
#define ROLL_STICK_CENTERED()
#define PITCH_STICK_CENTERED()
static uint8_t percent_from_rc(int channel)
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.
#define YAW_STICK_CENTERED()
static bool kill_switch_is_on(void)
static bool rc_attitude_sticks_centered(void)
Convenience macro for 3way switch.
int int32_t
Typedef defining 32 bit int type.
Definition: vl53l1_types.h:83
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98