Paparazzi UAS  v5.12_stable-4-g9b43e9b
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 (+ GPS OK ? FIXME)
94  } else {
95  // else reset timer
97  }
98  // if timer is finished, start launching
99  if (takeoff_detect.timer > (int)(TAKEOFF_DETECT_PERIODIC_FREQ * TAKEOFF_DETECT_TIMER)) {
100  autopilot.launch = true;
102  takeoff_detect.timer = 0;
103  }
104  break;
105  case TO_DETECT_LAUNCHING:
106  // abort if pitch goes below threshold while launching
109  // back to ARMED state
110  autopilot.launch = false;
112  }
113  // increment timer and disable detection after some time
115  if (takeoff_detect.timer > (int)(TAKEOFF_DETECT_PERIODIC_FREQ * TAKEOFF_DETECT_DISABLE_TIMER)) {
117  }
118  break;
119  case TO_DETECT_DISABLED:
120  // stop periodic call
121  takeoff_detect_takeoff_detect_periodic_status = MODULES_STOP;
122  break;
123  default:
124  // No kidding ?!
126  break;
127  }
128 }
129 
130 
bool launch
request launch
Definition: autopilot.h:65
Automatic takeoff assistance for fixed-wing.
#define TAKEOFF_DETECT_LAUNCH_PITCH
Default pitch angle to trigger launch.
void takeoff_detect_start(void)
Start function called once before periodic.
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
Definition: state.h:1143
#define TAKEOFF_DETECT_ABORT_PITCH
Default pitch angle to cancel launch.
struct pprz_autopilot autopilot
Global autopilot structure.
Definition: autopilot.c:50
takeoff_detect_state
Takeoff detection states.
#define TAKEOFF_DETECT_DISABLE_TIMER
Disable timer in seconds.
#define AP_MODE_AUTO2
void takeoff_detect_periodic(void)
Periodic call.
#define TAKEOFF_DETECT_TIMER
Detection timer in seconds.
void takeoff_detect_init(void)
Init function.
unsigned long uint32_t
Definition: types.h:18
Core autopilot interface common to all firmwares.
API to get/set the generic vehicle states.
Takeoff detection structure.
enum takeoff_detect_state state
static struct takeoff_detect_struct takeoff_detect
uint8_t autopilot_get_mode(void)
get autopilot mode
Definition: autopilot.c:179