Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
takeoff_detect.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 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  */
21 
30 #include "std.h"
32 #include "autopilot.h"
33 #include "state.h"
34 #include "generated/modules.h" // for status and function's period
35 
37 #ifndef TAKEOFF_DETECT_LAUNCH_PITCH
38 #define TAKEOFF_DETECT_LAUNCH_PITCH RadOfDeg(30.)
39 #endif
40 
42 #ifndef TAKEOFF_DETECT_ABORT_PITCH
43 #define TAKEOFF_DETECT_ABORT_PITCH RadOfDeg(-20.)
44 #endif
45 
47 #ifndef TAKEOFF_DETECT_TIMER
48 #define TAKEOFF_DETECT_TIMER 2.
49 #endif
50 
52 #ifndef TAKEOFF_DETECT_DISABLE_TIMER
53 #define TAKEOFF_DETECT_DISABLE_TIMER 4.
54 #endif
55 
61 };
62 
67 };
68 
70 
71 // Init
73 {
74  // variable init is done in start function
75 }
76 
77 // Start
79 {
80  takeoff_detect.state = TO_DETECT_ARMED; // always start periodic with ARMED state
81  takeoff_detect.timer = 0; // and reset timer
82 }
83 
84 // Periodic
86 {
87  // Run detection state machine here
88  switch (takeoff_detect.state) {
89  case TO_DETECT_ARMED:
90  // test for "nose up" + AP in AUTO2, optionally AUTO1 not default since risky if one does not know what it does
92  {
93 #ifndef TAKEOFF_DETECT_ALSO_IN_AUTO1
95 #else
97 #endif
98  {
100  }
101  }
102  else {
103  // else reset timer
104  takeoff_detect.timer = 0;
105  }
106  // if timer is finished, start launching
107  if (takeoff_detect.timer > (int)(TAKEOFF_DETECT_PERIODIC_FREQ * TAKEOFF_DETECT_TIMER)) {
108  autopilot.launch = true;
110  takeoff_detect.timer = 0;
111  }
112  break;
113 
114  case TO_DETECT_LAUNCHING:
115  // abort if pitch goes below threshold while launching
117  {
118 #ifndef TAKEOFF_DETECT_ALSO_IN_AUTO1
120 #else
122 #endif
123  {
124  // back to ARMED state
125  autopilot.launch = false;
127  }
128  }
129  // increment timer and disable detection after some time
131  if (takeoff_detect.timer > (int)(TAKEOFF_DETECT_PERIODIC_FREQ * TAKEOFF_DETECT_DISABLE_TIMER)) {
133  }
134  break;
135 
136  case TO_DETECT_DISABLED:
137  // stop periodic call
138  takeoff_detect_takeoff_detect_periodic_status = MODULES_STOP;
139  break;
140 
141  default:
142  // No kidding ?!
144  break;
145  }
146 }
147 
148 
takeoff_detect_periodic
void takeoff_detect_periodic(void)
Periodic call.
Definition: takeoff_detect.c:85
takeoff_detect_start
void takeoff_detect_start(void)
Start function called once before periodic.
Definition: takeoff_detect.c:78
TO_DETECT_DISABLED
@ TO_DETECT_DISABLED
Definition: takeoff_detect.c:58
takeoff_detect_init
void takeoff_detect_init(void)
Init function.
Definition: takeoff_detect.c:72
takeoff_detect
static struct takeoff_detect_struct takeoff_detect
Definition: takeoff_detect.c:69
AP_MODE_AUTO2
#define AP_MODE_AUTO2
Definition: autopilot_static.h:38
takeoff_detect_struct::state
enum takeoff_detect_state state
Definition: takeoff_detect.c:65
stateGetNedToBodyEulers_f
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
Definition: state.h:1143
uint32_t
unsigned long uint32_t
Definition: types.h:18
TAKEOFF_DETECT_LAUNCH_PITCH
#define TAKEOFF_DETECT_LAUNCH_PITCH
Default pitch angle to trigger launch.
Definition: takeoff_detect.c:38
std.h
autopilot
struct pprz_autopilot autopilot
Global autopilot structure.
Definition: autopilot.c:50
TAKEOFF_DETECT_ABORT_PITCH
#define TAKEOFF_DETECT_ABORT_PITCH
Default pitch angle to cancel launch.
Definition: takeoff_detect.c:43
autopilot.h
takeoff_detect_struct::timer
uint32_t timer
Definition: takeoff_detect.c:66
TAKEOFF_DETECT_TIMER
#define TAKEOFF_DETECT_TIMER
Detection timer in seconds.
Definition: takeoff_detect.c:48
takeoff_detect.h
takeoff_detect_state
takeoff_detect_state
Takeoff detection states.
Definition: takeoff_detect.c:57
TAKEOFF_DETECT_DISABLE_TIMER
#define TAKEOFF_DETECT_DISABLE_TIMER
Disable timer in seconds.
Definition: takeoff_detect.c:53
autopilot_get_mode
uint8_t autopilot_get_mode(void)
get autopilot mode
Definition: autopilot.c:184
state.h
TO_DETECT_ARMED
@ TO_DETECT_ARMED
Definition: takeoff_detect.c:59
takeoff_detect_struct
Takeoff detection structure.
Definition: takeoff_detect.c:64
pprz_autopilot::launch
bool launch
request launch
Definition: autopilot.h:71
TO_DETECT_LAUNCHING
@ TO_DETECT_LAUNCHING
Definition: takeoff_detect.c:60
AP_MODE_AUTO1
#define AP_MODE_AUTO1
Definition: autopilot_static.h:37