Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
nav_bungee_takeoff.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2015 The Paparazzi Team
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 
61 
62 #include "state.h"
63 #include "paparazzi.h"
65 #include "autopilot.h"
66 #include "generated/flight_plan.h"
67 #include "generated/airframe.h"
69 
70 
71 // Backward compatibility
72 #ifdef Takeoff_Distance
73 #warning "Takeoff_Distance depreciated, please use BUNGEE_TAKEOFF_DISTANCE instead"
74 #define BUNGEE_TAKEOFF_DISTANCE Takeoff_Distance
75 #endif
76 #ifdef Takeoff_Height
77 #warning "Takeoff_Height depreciated, please use BUNGEE_TAKEOFF_HEIGHT instead"
78 #define BUNGEE_TAKEOFF_HEIGHT Takeoff_Height
79 #endif
80 #ifdef Takeoff_Speed
81 #warning "Takeoff_Speed depreciated, please use BUNGEE_TAKEOFF_AIRSPEED instead (beware that USE_AIRSPEED flag is needed)"
82 #define BUNGEE_TAKEOFF_AIRSPEED Takeoff_Speed
83 #endif
84 #ifdef Takeoff_MinSpeed
85 #warning "Takeoff_MinSpeed depreciated, please use BUNGEE_TAKEOFF_MIN_SPEED instead"
86 #define BUNGEE_TAKEOFF_MIN_SPEED Takeoff_MinSpeed
87 #endif
88 
89 
90 #ifndef BUNGEE_TAKEOFF_DISTANCE
91 #define BUNGEE_TAKEOFF_DISTANCE 10.0
92 #endif
93 #ifndef BUNGEE_TAKEOFF_HEIGHT
94 #define BUNGEE_TAKEOFF_HEIGHT 30.0
95 #endif
96 #if USE_AIRSPEED
97 #ifndef BUNGEE_TAKEOFF_AIRSPEED
98 #define BUNGEE_TAKEOFF_AIRSPEED 15.0
99 #endif
100 #else
101 #ifdef BUNGEE_TAKEOFF_AIRSPEED
102 #warning "BUNGEE_TAKEOFF_AIRSPEED is defined but not USE_AIRSPEED. Airspeed limit will not be used"
103 #endif
104 #endif
105 #ifndef BUNGEE_TAKEOFF_MIN_SPEED
106 #define BUNGEE_TAKEOFF_MIN_SPEED 5.0
107 #endif
108 #ifndef BUNGEE_TAKEOFF_THROTTLE
109 #define BUNGEE_TAKEOFF_THROTTLE 1.0
110 #endif
111 #ifndef BUNGEE_TAKEOFF_PITCH
112 #ifdef AGR_CLIMB_PITCH
113 #define BUNGEE_TAKEOFF_PITCH AGR_CLIMB_PITCH
114 #else
115 #define BUNGEE_TAKEOFF_PITCH RadOfDeg(15.)
116 #endif
117 #endif
118 
123 };
124 
126 
127 static struct FloatVect2 init_point;
129 static struct FloatVect2 takeoff_dir;
130 static struct FloatVect3 bungee_point;
131 
132 static void compute_points_from_bungee(void)
133 {
134  // Store init point (current position, where the plane will be released)
136  // Compute unitary 2D vector (bungee_point - init_point) = takeoff direction
139  // Find throttle point (the point where the throttle line and launch line intersect)
140  // If TakeOff_Distance is positive, throttle point is after bungee point, before otherwise
143 }
144 
146 {
147  // Store bungee point (from WP id, altitude is current hmsl (e.g. ground alt))
148  VECT3_ASSIGN(bungee_point, WaypointX(bungee_wp), WaypointY(bungee_wp), stateGetPositionUtm_f()->alt);
149 
150  // Compute other points
152 
153  // Enable Launch Status and turn kill throttle on
156 }
157 
159 {
160  float cross = 0.;
161 
162  // Get current position
163  struct FloatVect2 pos;
165 
166  switch (CTakeoffStatus) {
167  case Launch:
168  // Recalculate lines if below min speed
171  }
172 
173  // Follow Launch Line with takeoff pitch and no throttle
176  // FIXME previously using altitude mode, maybe not wise without motors
177  //NavVerticalAltitudeMode(bungee_point.z + BUNGEE_TAKEOFF_HEIGHT, 0.);
179 
181 
182  // Find out if UAV has crossed the line
183  VECT2_DIFF(pos, pos, throttle_point); // position local to throttle_point
184  cross = VECT2_DOT_PRODUCT(pos, takeoff_dir);
185 
189  nav_init_stage();
190  } else {
191  // If not crossed stay in this status
192  break;
193  }
194  // Start throttle imidiatelly
195  case Throttle:
196  //Follow Launch Line
199  autopilot.launch = true; // turn on motor
202 
204 #if USE_AIRSPEED
205  && (stateGetAirspeed_f() > BUNGEE_TAKEOFF_AIRSPEED)
206 #endif
207  ) {
209  return false;
210  } else {
211  return true;
212  }
213  break;
214  default:
215  // Invalid status or Finished, end function
216  return false;
217  }
218  return true;
219 }
220 
MAX_PPRZ
#define MAX_PPRZ
Definition: paparazzi.h:8
BUNGEE_TAKEOFF_THROTTLE
#define BUNGEE_TAKEOFF_THROTTLE
Definition: nav_bungee_takeoff.c:109
VECT2_SMUL
#define VECT2_SMUL(_vo, _vi, _s)
Definition: pprz_algebra.h:98
throttle_point
static struct FloatVect2 throttle_point
Definition: nav_bungee_takeoff.c:128
BUNGEE_TAKEOFF_PITCH
#define BUNGEE_TAKEOFF_PITCH
Definition: nav_bungee_takeoff.c:115
nav_bungee_takeoff.h
WaypointY
#define WaypointY(_wp)
Definition: common_nav.h:46
stateGetPositionEnu_f
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
Definition: state.h:719
BUNGEE_TAKEOFF_MIN_SPEED
#define BUNGEE_TAKEOFF_MIN_SPEED
Definition: nav_bungee_takeoff.c:106
WaypointX
#define WaypointX(_wp)
Definition: common_nav.h:45
float_vect2_normalize
static void float_vect2_normalize(struct FloatVect2 *v)
normalize 2D vector in place
Definition: pprz_algebra_float.h:145
NavVerticalThrottleMode
#define NavVerticalThrottleMode(_throttle)
Set the vertical mode to fixed throttle with the specified setpoint.
Definition: nav.h:198
pprz_algebra_float.h
Paparazzi floating point algebra.
stateGetPositionUtm_f
static struct UtmCoor_f * stateGetPositionUtm_f(void)
Get position in UTM coordinates (float).
Definition: state.h:692
paparazzi.h
NavVerticalAutoThrottleMode
#define NavVerticalAutoThrottleMode(_pitch)
Set the climb control to auto-throttle with the specified pitch pre-command.
Definition: nav.h:171
VECT2_DIFF
#define VECT2_DIFF(_c, _a, _b)
Definition: pprz_algebra.h:92
FloatVect2
Definition: pprz_algebra_float.h:49
FloatVect3
Definition: pprz_algebra_float.h:54
nav_route_xy
void nav_route_xy(float last_wp_x, float last_wp_y, float wp_x, float wp_y)
Computes the carrot position along the desired segment.
Definition: nav.c:381
USE_AIRSPEED
#define USE_AIRSPEED
Definition: disco.h:113
nav_bungee_takeoff_run
bool nav_bungee_takeoff_run(void)
Bungee takeoff run function.
Definition: nav_bungee_takeoff.c:158
autopilot
struct pprz_autopilot autopilot
Global autopilot structure.
Definition: autopilot.c:50
stateGetAirspeed_f
static float stateGetAirspeed_f(void)
Get airspeed (float).
Definition: state.h:1407
nav_init_stage
void nav_init_stage(void)
needs to be implemented by fixedwing and rotorcraft seperately
Definition: nav.c:93
uint8_t
unsigned char uint8_t
Definition: types.h:14
autopilot.h
takeoff_dir
static struct FloatVect2 takeoff_dir
Definition: nav_bungee_takeoff.c:129
TakeoffStatus
TakeoffStatus
Definition: nav_bungee_takeoff.c:119
FloatVect3::y
float y
Definition: pprz_algebra_float.h:56
FloatVect2::y
float y
Definition: pprz_algebra_float.h:51
autopilot_set_kill_throttle
void autopilot_set_kill_throttle(bool kill)
set kill throttle
Definition: autopilot.c:219
Launch
@ Launch
Definition: nav_bungee_takeoff.c:120
VECT2_ASSIGN
#define VECT2_ASSIGN(_a, _x, _y)
Definition: pprz_algebra.h:62
nav.h
stateGetHorizontalSpeedNorm_f
static float stateGetHorizontalSpeedNorm_f(void)
Get norm of horizontal ground speed (float).
Definition: state.h:935
init_point
static struct FloatVect2 init_point
Definition: nav_bungee_takeoff.c:127
FloatVect3::x
float x
Definition: pprz_algebra_float.h:55
Finished
@ Finished
Definition: nav_bungee_takeoff.c:122
nav_bungee_takeoff_setup
void nav_bungee_takeoff_setup(uint8_t bungee_wp)
Initialization function.
Definition: nav_bungee_takeoff.c:145
VECT2_SUM
#define VECT2_SUM(_c, _a, _b)
Definition: pprz_algebra.h:86
Throttle
@ Throttle
Definition: nav_bungee_takeoff.c:121
FloatVect3::z
float z
Definition: pprz_algebra_float.h:57
CTakeoffStatus
static enum TakeoffStatus CTakeoffStatus
Definition: nav_bungee_takeoff.c:125
bungee_point
static struct FloatVect3 bungee_point
Definition: nav_bungee_takeoff.c:130
VECT2_DOT_PRODUCT
#define VECT2_DOT_PRODUCT(_v1, _v2)
Definition: pprz_algebra.h:116
FloatVect2::x
float x
Definition: pprz_algebra_float.h:50
BUNGEE_TAKEOFF_HEIGHT
#define BUNGEE_TAKEOFF_HEIGHT
Definition: nav_bungee_takeoff.c:94
state.h
VECT3_ASSIGN
#define VECT3_ASSIGN(_a, _x, _y, _z)
Definition: pprz_algebra.h:125
BUNGEE_TAKEOFF_DISTANCE
#define BUNGEE_TAKEOFF_DISTANCE
Definition: nav_bungee_takeoff.c:91
compute_points_from_bungee
static void compute_points_from_bungee(void)
Definition: nav_bungee_takeoff.c:132
pprz_autopilot::launch
bool launch
request launch
Definition: autopilot.h:71