Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
autopilot_utils.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 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, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
30 #include "autopilot.h"
32 #include "state.h"
34 
36 PRINT_CONFIG_VAR(FAILSAFE_DESCENT_SPEED)
37 
38 
39 #if defined RADIO_MODE_2x3
40 
41 #define THRESHOLD_1d3_PPRZ (MAX_PPRZ / 3)
42 #define THRESHOLD_2d3_PPRZ ((MAX_PPRZ / 3) * 2)
55 uint8_t ap_mode_of_3x2way_switch(void)
56 {
58  if (radio_control.values[RADIO_MODE] < 0) {
59  val = MAX_PPRZ + val;
60  }
61  if (val < THRESHOLD_1d3_PPRZ) {
62  return MODE_MANUAL;
63  } else if (val < THRESHOLD_2d3_PPRZ) {
64  return MODE_AUTO1;
65  } else {
66  return autopilot_mode_auto2;
67  }
68 }
69 
70 #else
71 
72 #define THRESHOLD_1_PPRZ (MIN_PPRZ / 2)
73 #define THRESHOLD_2_PPRZ (MAX_PPRZ / 2)
74 
77 {
79  return autopilot_mode_auto2;
81  return MODE_AUTO1;
82  } else {
83  return MODE_MANUAL;
84  }
85 }
86 
87 #endif
88 
97 #if defined RADIO_AUTO_MODE || defined(__DOXYGEN__)
98 uint8_t ap_mode_of_two_switches(void)
99 {
101  /* RADIO_MODE in MANUAL position */
102  return MODE_MANUAL;
103  } else {
104  /* RADIO_MODE not in MANUAL position.
105  * Select AUTO mode bassed on RADIO_AUTO_MODE channel
106  */
107  if (radio_control.values[RADIO_AUTO_MODE] > THRESHOLD_2_PPRZ) {
108  return autopilot_mode_auto2;
109  } else {
110  return MODE_AUTO1;
111  }
112  }
113 }
114 #endif
115 
116 
121 void WEAK set_rotorcraft_commands(pprz_t *cmd_out, int32_t *cmd_in, bool in_flight __attribute__((unused)), bool motors_on __attribute__((unused)))
122 {
123 #if !ROTORCRAFT_IS_HELI
124 #if !ROTORCRAFT_COMMANDS_YAW_ALWAYS_ENABLED && defined(COMMAND_YAW)
125  if (!in_flight) {
126  cmd_in[COMMAND_YAW] = 0;
127  }
128 #endif
129  if (!motors_on) {
130  cmd_in[COMMAND_THRUST] = 0;
131  }
132 #endif
133 #ifdef COMMAND_ROLL
134  cmd_out[COMMAND_ROLL] = cmd_in[COMMAND_ROLL];
135 #endif
136 #ifdef COMMAND_PITCH
137  cmd_out[COMMAND_PITCH] = cmd_in[COMMAND_PITCH];
138 #endif
139 #ifdef COMMAND_YAW
140  cmd_out[COMMAND_YAW] = cmd_in[COMMAND_YAW];
141 #endif
142  cmd_out[COMMAND_THRUST] = cmd_in[COMMAND_THRUST];
143 }
144 
Core autopilot interface common to all firmwares.
int16_t pprz_t
Definition: paparazzi.h:6
#define MAX_PPRZ
Definition: paparazzi.h:8
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 autopilot_mode_auto2
Some helper functions to check RC sticks.
#define MODE_AUTO1
#define MODE_MANUAL
Default RC mode.
#define THRESHOLD_2_PPRZ
#define THRESHOLD_1_PPRZ
Display descent speed in failsafe mode if needed.
void WEAK set_rotorcraft_commands(pprz_t *cmd_out, int32_t *cmd_in, bool in_flight, bool motors_on)
Get autopilot mode from two 2way switches.
uint8_t ap_mode_of_3way_switch(void)
get autopilot mode as set by RADIO_MODE 3-way switch
Utility functions and includes for autopilots.
#define FAILSAFE_DESCENT_SPEED
Set descent speed in failsafe mode.
API to get/set the generic vehicle states.
uint16_t val[TCOUPLE_NB]
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