Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
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
68static 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#ifdef AP_MODE_SWITCH
88#define RCAP0() rc_mode_switch(AP_MODE_SWITCH, 0, 3)
89#define RCAP1() rc_mode_switch(AP_MODE_SWITCH, 1, 3)
90#define RCAP2() rc_mode_switch(AP_MODE_SWITCH, 2, 3)
91#endif
92
93static inline bool rc_attitude_sticks_centered(void)
94{
96}
97
98#ifdef RADIO_KILL_SWITCH
99static inline bool kill_switch_is_on(void)
100{
102 return true;
103 } else {
104 return false;
105 }
106}
107#else
108static inline bool kill_switch_is_on(void)
109{
110 return false;
111}
112#endif
113
114static inline uint8_t percent_from_rc(int channel)
115{
116 int per = (MAX_PPRZ + (int32_t)radio_control.values[channel]) * 50 / MAX_PPRZ;
117 if (per < 0) {
118 per = 0;
119 } else if (per > 100) {
120 per = 100;
121 }
122 return per;
123}
124
125
126#endif /* AUTOPILOT_RC_HELPERS_H */
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.
static float p[2][2]
uint16_t foo
Definition main_demo5.c:58
#define MAX_PPRZ
Definition paparazzi.h:8
#define MIN_PPRZ
Definition paparazzi.h:9
struct RadioControl radio_control
Generic interface for radio control modules.
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
#define RC_OK
#define ROLL_STICK_CENTERED()
#define PITCH_STICK_CENTERED()
static uint8_t percent_from_rc(int channel)
#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.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.