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
uav_recovery.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2013-2020 Chris Efstathiou hendrixgr@gmail.com
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
28#include "autopilot.h"
29#include "state.h"
32#include "generated/flight_plan.h"
33#include "generated/airframe.h"
37#include "uav_recovery.h"
38
39#if defined(USE_PARACHUTE) && USE_PARACHUTE == 1
40
41#ifndef GLUE_DEFINITIONS_STEP2
42#define GLUE_DEFINITIONS_STEP2(a, b) (a##b)
43#endif
44#ifndef GLUE_DEFINITIONS
45#define GLUE_DEFINITIONS(a, b) GLUE_DEFINITIONS_STEP2(a, b)
46#endif
47
48#if defined(PARACHUTE_SERVO_CHANNEL) && PARACHUTE_SERVO_CHANNEL != -1
49#define PARACHUTE_OUTPUT_COMMAND GLUE_DEFINITIONS(COMMAND_, PARACHUTE_SERVO_CHANNEL)
50#else
51#warning YOU HAVE NOT DEFINED A PARACHUTE RELEASE AUTOPILOT SERVO
52#endif
53
54#endif
55
57#ifndef PARACHUTE_TRIGGER_DELAY
58#define PARACHUTE_TRIGGER_DELAY 2.
59#endif
60
61#ifndef PARACHUTE_DESCENT_RATE
62#define PARACHUTE_DESCENT_RATE 3.0
63#endif
64#ifndef PARACHUTE_WIND_CORRECTION
65#define PARACHUTE_WIND_CORRECTION 1.0
66#endif
67#ifndef PARACHUTE_LINE_LENGTH
68#define PARACHUTE_LINE_LENGTH 3.0
69#endif
70
77bool wind_info_valid = false;
80
81#if PERIODIC_TELEMETRY
83
84static void send_wind_info(struct transport_tx *trans, struct link_device *dev)
85{
86
87 float foo1 = 0, foo2 = 0, foo3 = 0;
89
90 return;
91}
92#endif
93
95{
96
101 wind_info_valid = true;
102#if defined(PARACHUTE_OUTPUT_COMMAND)
104#endif
105
106#if PERIODIC_TELEMETRY
108#endif
109
110
111 return;
112}
113
114
116{
117#if defined(PARACHUTE_OUTPUT_COMMAND)
119 if (deploy_parachute_var == 1) {
121
123 }
124#else
125#warning PARACHUTE COMMAND NOT FOUND
126#endif
127
128 return;
129}
130
132{
133
135
136 return (0);
137}
138
140{
141
143
144 return (0);
145}
146
147
148uint8_t calculate_wind_no_airspeed(uint8_t wp, float radius, float height)
149{
150
151//struct EnuCoor_f* pos = stateGetPositionEnu_f();
152//struct UtmCoor_f * pos = stateGetPositionUtm_f();
153
154 static bool init = false;
155 static float circle_count = 0;
156 static bool wind_measurement_started = false;
157
158//Legacy estimator values
159 float estimator_hspeed_dir = 0;
160 float estimator_hspeed_mod = 0;
163
164 float speed_max_buf = 0;
165 float speed_min_buf = 1000.0;
166 float heading_angle_buf = 0;
167
168 if (init == false) {
172 speed_max_buf = 0;
173 speed_min_buf = 1000.;
176 init = true;
177 }
178
180 NavVerticalAltitudeMode(Height(height), 0.);
181 NavCircleWaypoint(wp, radius);
182 if (nav_in_circle == false || GetPosAlt() < Height(height - 10)) {
183 return (true);
184 }
186 // Wait until we are in altitude and in circle.
187 if (wind_measurement_started == false) {
190 }
193 }
194 // WHEN THE GROUND SPEED IS LOWEST THIS IS WHERE THE WIND IS BLOWING FROM.
197 heading_angle_buf = estimator_hspeed_dir; //180 to -180 in radians, 0 is to the NORTH!
198 }
199
200 if ((NavCircleCount() - circle_count) >= 1.1) {
201 //Update the wind direction and speed in the WEATHER message.
203#if defined(FIXED_WIND_SPEED_FOR_TESTING) && defined(SITL)
204#pragma message "Wind SPEED for UAV recovery is fixed for the simulation"
205#pragma message "You can change the value by editing 'uav_recovery.xml' file."
206 airborne_wind_speed = FIXED_WIND_SPEED_FOR_TESTING; // FOR TESTING IN SIMULATION ONLY!
207#endif
208#if defined(FIXED_WIND_DIRECTION_FOR_TESTING) && defined(SITL)
209#pragma message "Wind direction for UAV recovery is fixed for the simulation"
210#pragma message "You can change the value by editing 'uav_recovery.xml' file."
213 } else {
215 }
216#endif
217 airborne_wind_dir = DegOfRad(heading_angle_buf); //For use with the WEATHER message
218 //Convert from 180, -180 to 0, 360 in Degrees. 0=NORTH, 90=EAST
219 if (airborne_wind_dir < 0) { airborne_wind_dir += 360; }
222 wind_info_valid = true;
223
224 //NavVerticalAutoThrottleMode(RadOfDeg(0.000000));
225 // EXIT and continue the flight plan.
226 init = false;
227 return (false);
228 }
229
230 return (true);
231}
232
233
234// Compute an approximation for the RELEASE waypoint from expected descent and altitude
236{
237
238 float x = 0, y = 0;
239 float approach_dir = 0;
240 float calculated_wind_east = 0;
241 float calculated_wind_north = 0;
242
243 struct {
244 float x;
245 float y;
246 float a;
247 } start_wp;
248
249 // Calculate a starting waypoint opposite to the wind.
250 //180 TO -180 in Radians. Convert from 0 = NORTH to 0 = EAST
252 if (approach_dir > M_PI) { approach_dir -= 2 * M_PI; }
253 approach_dir -= M_PI; // reverse the direction as we must release the parachute against the wind!
254
258
259 // We approximate vx and vy, taking into account that RELEASE is close to the TARGET
260 float x_0 = waypoints[wp_target].x - start_wp.x;
261 float y_0 = waypoints[wp_target].y - start_wp.y;
262
263 // Unit vector from the calculated starting waypoint to TARGET
264 float d = sqrt(x_0 * x_0 + y_0 * y_0);
265 float x1 = x_0 / d;
266 float y_1 = y_0 / d;
267
272 if (nav_radius < 0) {
274 }
275
277
282
285
286
287 return 0;
288}
289
struct pprz_autopilot autopilot
Global autopilot structure.
Definition autopilot.c:49
Core autopilot interface common to all firmwares.
uint8_t mode
current autopilot mode
Definition autopilot.h:63
Hardware independent code for commands handling.
float ground_alt
size == nb_waypoint, waypoint 0 is a dummy waypoint
Definition common_nav.c:46
struct point waypoints[NB_WAYPOINT]
size == nb_waypoint, waypoint 0 is a dummy waypoint
Definition common_nav.c:44
float y
Definition common_nav.h:41
float a
Definition common_nav.h:42
float x
Definition common_nav.h:40
#define Height(_h)
Definition common_nav.h:49
#define AP_MODE_MANUAL
AP modes.
static float stateGetHorizontalSpeedNorm_f(void)
Get norm of horizontal ground speed (float).
Definition state.h:1076
static float stateGetHorizontalSpeedDir_f(void)
Get dir of horizontal ground speed (float).
Definition state.h:1085
uint16_t foo
Definition main_demo5.c:58
float nav_radius
Definition nav.c:56
bool nav_in_circle
Definition nav.c:66
Fixedwing Navigation library.
#define GetPosAlt()
Get current altitude above MSL.
Definition nav.h:233
#define NavCircleWaypoint(wp, radius)
Definition nav.h:151
#define NavVerticalThrottleMode(_throttle)
Set the vertical mode to fixed throttle with the specified setpoint.
Definition nav.h:204
#define NavCircleCount()
Definition nav.h:155
#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
bool init
Definition nav_gls.c:57
#define MAX_PPRZ
Definition paparazzi.h:8
#define MIN_PPRZ
Definition paparazzi.h:9
API to get/set the generic vehicle states.
static const struct usb_device_descriptor dev
Definition usb_ser_hw.c:74
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition telemetry.c:51
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
Definition telemetry.h:66
bool wind_measurements_valid
#define PARACHUTE_LINE_LENGTH
uint8_t DeployParachute(void)
void uav_recovery_periodic(void)
#define PARACHUTE_DESCENT_RATE
float airborne_wind_dir
static void send_wind_info(struct transport_tx *trans, struct link_device *dev)
bool land_direction
bool wind_info_valid
unit_t parachute_compute_approach(uint8_t baseleg, uint8_t release, uint8_t wp_target)
#define PARACHUTE_WIND_CORRECTION
uint8_t LockParachute(void)
float calculated_wind_dir
bool deploy_parachute_var
float parachute_z
uint8_t calculate_wind_no_airspeed(uint8_t wp, float radius, float height)
float parachute_start_qdr
void uav_recovery_init(void)
float airborne_wind_speed
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.