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 
37 
38 #if (defined MODE_MANUAL) && (defined MODE_AUTO1)
39 
40 #if defined RADIO_MODE_2x3
41 
42 #define THRESHOLD_1d3_PPRZ (MAX_PPRZ / 3)
43 #define THRESHOLD_2d3_PPRZ ((MAX_PPRZ / 3) * 2)
56 uint8_t ap_mode_of_3x2way_switch(void)
57 {
59  if (radio_control.values[RADIO_MODE] < 0) {
60  val = MAX_PPRZ + val;
61  }
62  if (val < THRESHOLD_1d3_PPRZ) {
63  return MODE_MANUAL;
64  } else if (val < THRESHOLD_2d3_PPRZ) {
65  return MODE_AUTO1;
66  } else {
67  return autopilot_mode_auto2;
68  }
69 }
70 
71 #else
72 
73 #define THRESHOLD_1_PPRZ (MIN_PPRZ / 2)
74 #define THRESHOLD_2_PPRZ (MAX_PPRZ / 2)
75 
78 {
80  return autopilot_mode_auto2;
82  return MODE_AUTO1;
83  } else {
84  return MODE_MANUAL;
85  }
86 }
87 
88 #endif
89 
98 #if defined RADIO_AUTO_MODE || defined(__DOXYGEN__)
99 uint8_t ap_mode_of_two_switches(void)
100 {
102  /* RADIO_MODE in MANUAL position */
103  return MODE_MANUAL;
104  } else {
105  /* RADIO_MODE not in MANUAL position.
106  * Select AUTO mode bassed on RADIO_AUTO_MODE channel
107  */
108  if (radio_control.values[RADIO_AUTO_MODE] > THRESHOLD_2_PPRZ) {
109  return autopilot_mode_auto2;
110  } else {
111  return MODE_AUTO1;
112  }
113  }
114 }
115 #endif
116 
117 #endif // MODE_MANUAL && MODE_AUTO1
118 
123 void WEAK set_rotorcraft_commands(pprz_t *cmd_out, int32_t *cmd_in, bool in_flight __attribute__((unused)), bool motors_on __attribute__((unused)))
124 {
125 #if !ROTORCRAFT_IS_HELI
126 #if !ROTORCRAFT_COMMANDS_YAW_ALWAYS_ENABLED && defined(COMMAND_YAW)
127  if (!in_flight) {
128  cmd_in[COMMAND_YAW] = 0;
129  }
130 #endif
131  if (!motors_on) {
132  cmd_in[COMMAND_THRUST] = 0;
133  }
134 #endif
135 #ifdef COMMAND_ROLL
136  cmd_out[COMMAND_ROLL] = cmd_in[COMMAND_ROLL];
137 #endif
138 #ifdef COMMAND_PITCH
139  cmd_out[COMMAND_PITCH] = cmd_in[COMMAND_PITCH];
140 #endif
141 #ifdef COMMAND_YAW
142  cmd_out[COMMAND_YAW] = cmd_in[COMMAND_YAW];
143 #endif
144  cmd_out[COMMAND_THRUST] = cmd_in[COMMAND_THRUST];
145 }
146 
Core autopilot interface common to all firmwares.
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
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.
void WEAK set_rotorcraft_commands(pprz_t *cmd_out, int32_t *cmd_in, bool in_flight, bool motors_on)
Display descent speed in failsafe mode if needed.
Utility functions and includes for autopilots.
#define FAILSAFE_DESCENT_SPEED
Set descent speed in failsafe mode.
#define THRESHOLD_2_PPRZ
#define THRESHOLD_1_PPRZ
Display descent speed in failsafe mode if needed.
uint8_t ap_mode_of_3way_switch(void)
get autopilot mode as set by RADIO_MODE 3-way switch
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