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 
64 static inline bool rc_mode_switch(uint8_t chan, uint8_t pos, uint8_t max)
65 {
66  if (radio_control.status != RC_OK) return false;
67  if (pos >= max) return false;
69  // round final value
70  int32_t p = (((((int32_t)max - 1) * 10 * v) / (MAX_PPRZ - MIN_PPRZ)) + 5) / 10;
71  Bound(p, 0, max - 1); // just in case
72  return pos == (uint8_t)p;
73 }
74 
77 #ifdef RADIO_MODE
78 #define RCMode0() rc_mode_switch(RADIO_MODE, 0, 3)
79 #define RCMode1() rc_mode_switch(RADIO_MODE, 1, 3)
80 #define RCMode2() rc_mode_switch(RADIO_MODE, 2, 3)
81 #endif
82 
83 static inline bool rc_attitude_sticks_centered(void)
84 {
86 }
87 
88 #ifdef RADIO_KILL_SWITCH
89 static inline bool kill_switch_is_on(void)
90 {
92  return true;
93  } else {
94  return false;
95  }
96 }
97 #else
98 static inline bool kill_switch_is_on(void)
99 {
100  return false;
101 }
102 #endif
103 
104 static inline uint8_t percent_from_rc(int channel)
105 {
106  int per = (MAX_PPRZ + (int32_t)radio_control.values[channel]) * 50 / MAX_PPRZ;
107  if (per < 0) {
108  per = 0;
109  } else if (per > 100) {
110  per = 100;
111  }
112  return per;
113 }
114 
115 
116 #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 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