Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
nav_catapult.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2012, Christophe De Wagter
3 * Copyright (C) 2016, Gautier Hattenberger <gautier.hattenberger@enac.fr>
4 *
5 * This file is part of paparazzi.
6 *
7 * paparazzi is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * paparazzi is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with paparazzi; see the file COPYING. If not, see
19 * <http://www.gnu.org/licenses/>.
20 *
21 */
22
37
38#include "state.h"
39#include "generated/airframe.h"
41#include "autopilot.h"
43
44#include "mcu_periph/uart.h"
45#include "pprzlink/messages.h"
47
48
49// Default values for take-off procedure
50
51#ifndef NAV_CATAPULT_ACCELERATION_THRESHOLD
52#define NAV_CATAPULT_ACCELERATION_THRESHOLD 1.5 // in g
53#endif
54
55#ifndef NAV_CATAPULT_ACCELERATION_DETECTION
56#define NAV_CATAPULT_ACCELERATION_DETECTION 5 // number of valid measurements for launch detection
57#endif
58
59#ifndef NAV_CATAPULT_MOTOR_DELAY
60#define NAV_CATAPULT_MOTOR_DELAY 0.75 // in seconds
61#endif
62
63#ifndef NAV_CATAPULT_HEADING_DELAY
64#define NAV_CATAPULT_HEADING_DELAY 3.0 // in seconds
65#endif
66
67#ifndef NAV_CATAPULT_INITIAL_PITCH
68#define NAV_CATAPULT_INITIAL_PITCH RadOfDeg(10) // in radians
69#endif
70
71#ifndef NAV_CATAPULT_INITIAL_THROTTLE
72#define NAV_CATAPULT_INITIAL_THROTTLE 1.0 // [0, 1]
73#endif
74
75#ifndef NAV_CATAPULT_CLIMB_DISTANCE
76#define NAV_CATAPULT_CLIMB_DISTANCE 300. // distance of the climb point ahead of catapult
77#endif
78
79#ifndef NAV_CATAPULT_TIMEOUT
80#define NAV_CATAPULT_TIMEOUT 30. // disarm timeout (in seconds)
81#endif
82
84
85
98
99//#############################################################
100// Code that Runs in a Fast Module
101
103{
106 // nothing more to do
107 return;
108 }
109
110 // increase timer
112
113 // wait for acceleration
115
116 // launch detection filter
118 // several consecutive measurements above threshold
119#ifndef SITL
122 struct FloatVect3 accel_body;
124 if (accel_body.x < nav_catapult.accel_threshold * 9.81) {
125 // accel is low, reset timer
127 return;
128 }
129#else
130 if (autopilot.launch != true) {
131 // wait for simulated launch
133 return;
134 }
135#endif
136 }
137 // launch was detected: Motor Delay Counter
139 // turn on motor
141 autopilot.launch = true;
142 // go to next stage
144 }
145 }
146
147 // reaching timeout and function still running
148 // shuting it down
152 }
153}
154
155
156//############################################################
157// Code that runs in 4Hz Nav
158
160{
161 switch (nav_catapult.status) {
163 // start high freq function if not done
166 }
167 // arm catapult
169 break;
171 // store initial position
174 nav_catapult.pos.z = stateGetPositionUtm_f()->alt; // useful ?
176 break;
178 // no throttle, zero attitude
179 NavAttitude(RadOfDeg(0.f));
182 // wait for acceleration from high speed function
183 break;
185 // fixed attitude and motor
186 NavAttitude(RadOfDeg(0.f));
190 // store heading, move climb waypoint
193 float dir_L = sqrtf(dir_x * dir_x + dir_y * dir_y);
197 // next step
199 }
200 break;
202 // normal climb: heading locked by waypoint target
203 NavVerticalAltitudeMode(WaypointAlt(_climb), 0.f); // vertical mode (folow glideslope)
204 NavVerticalAutoThrottleMode(0.f); // throttle mode
205 NavGotoWaypoint(_climb); // horizontal mode (stay on localiser)
207 // reaching climb waypoint, end procedure
209 }
210 break;
212 // end procedure
215 return false;
216 default:
217 return false;
218 }
219
220 // procedure still running
221 return true;
222
223}
224
struct pprz_autopilot autopilot
Global autopilot structure.
Definition autopilot.c:49
Core autopilot interface common to all firmwares.
bool launch
request launch
Definition autopilot.h:71
#define WaypointX(_wp)
Definition common_nav.h:45
#define WaypointAlt(_wp)
waypoint altitude in m above MSL
Definition common_nav.h:48
#define WaypointY(_wp)
Definition common_nav.h:46
Fixed wing horizontal control.
void float_rmat_transp_vmult(struct FloatVect3 *vb, struct FloatRMat *m_b2a, struct FloatVect3 *va)
rotate 3D vector by transposed rotation matrix.
rotation matrix
static struct NedCoor_f * stateGetAccelNed_f(void)
Get acceleration in NED coordinates (float).
Definition state.h:1195
static struct FloatRMat * stateGetNedToBodyRMat_f(void)
Get vehicle body attitude rotation matrix (float).
Definition state.h:1300
static struct UtmCoor_f * stateGetPositionUtm_f(void)
Get position in UTM coordinates (float).
Definition state.h:821
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
Definition state.h:848
uint16_t foo
Definition main_demo5.c:58
bool nav_approaching_xy(float x, float y, float from_x, float from_y, float approaching_time)
Decide if the UAV is approaching the current waypoint.
Definition nav.c:325
void DownlinkSendWpNr(uint8_t _wp)
Definition nav.c:497
Fixedwing Navigation library.
#define NavGotoWaypoint(_wp)
Definition nav.h:96
#define NavVerticalThrottleMode(_throttle)
Set the vertical mode to fixed throttle with the specified setpoint.
Definition nav.h:204
#define NavAttitude(_roll)
Definition nav.h:214
#define NavVerticalAltitudeMode(_alt, _pre_climb)
Set the vertical mode to altitude control with the specified altitude setpoint and climb pre-command.
Definition nav.h:191
#define NavVerticalAutoThrottleMode(_pitch)
Set the climb control to auto-throttle with the specified pitch pre-command.
Definition nav.h:177
#define NAV_CATAPULT_HEADING_DELAY
#define NAV_CATAPULT_ACCELERATION_DETECTION
#define NAV_CATAPULT_MOTOR_DELAY
#define NAV_CATAPULT_INITIAL_THROTTLE
#define NAV_CATAPULT_INITIAL_PITCH
bool nav_catapult_run(uint8_t _climb)
#define NAV_CATAPULT_ACCELERATION_THRESHOLD
#define NAV_CATAPULT_CLIMB_DISTANCE
struct nav_catapult_struct nav_catapult
void nav_catapult_init(void)
#define NAV_CATAPULT_TIMEOUT
void nav_catapult_highrate_module(void)
catapult launch timing system
uint32_t timer
internal timer
@ NAV_CATAPULT_WAIT_ACCEL
@ NAV_CATAPULT_ARMED
@ NAV_CATAPULT_DISARM
@ NAV_CATAPULT_UNINIT
@ NAV_CATAPULT_MOTOR_CLIMB
@ NAV_CATAPULT_MOTOR_ON
enum nav_catapult_state status
current procedure state
float initial_throttle
throttle during first take-off phase (in radian)
float motor_delay
delay to start motor after launch detection (in seconds)
float heading_delay
delay to estimate initial heading after launch (in seconds)
float initial_pitch
pitch angle during first take-off phase (in radian)
float accel_threshold
acceleration threshold for launch detection (in g)
struct FloatVect3 pos
catapult position
#define MAX_PPRZ
Definition paparazzi.h:8
float y
in meters
float x
in meters
float alt
in meters (above WGS84 reference ellipsoid or above MSL)
API to get/set the generic vehicle states.
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.