Paparazzi UAS  v5.15_devel-230-gc96ce27
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) 2017 Gautier Hattenberger <gautier.hattenberger@enac.fr>
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 
27 #ifndef AUTOPILOT_RC_HELPERS_H
28 #define AUTOPILOT_RC_HELPERS_H
29 
30 #include "generated/airframe.h"
32 
41 static inline bool rc_mode_switch(uint8_t chan, uint8_t pos, uint8_t max)
42 {
43  if (radio_control.status != RC_OK) return false;
44  if (pos >= max) return false;
46  // round final value
47  int32_t p = (((((int32_t)max - 1) * 10 * v) / (MAX_PPRZ - MIN_PPRZ)) + 5) / 10;
48  Bound(p, 0, max - 1); // just in case
49  return pos == (uint8_t)p;
50 }
51 
54 #ifdef RADIO_MODE
55 #define RCMode0() rc_mode_switch(RADIO_MODE, 0, 3)
56 #define RCMode1() rc_mode_switch(RADIO_MODE, 1, 3)
57 #define RCMode2() rc_mode_switch(RADIO_MODE, 2, 3)
58 #endif
59 
60 
61 #endif /* AUTOPILOT_RC_HELPERS_H */
#define MIN_PPRZ
Definition: paparazzi.h:9
uint8_t status
Definition: radio_control.h:64
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
Definition: radio_control.h:69
struct RadioControl radio_control
Definition: radio_control.c:30
signed long int32_t
Definition: types.h:19
#define RC_OK
Definition: radio_control.h:56
unsigned char uint8_t
Definition: types.h:14
static float p[2][2]
#define MAX_PPRZ
Definition: paparazzi.h:8
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.