Paparazzi UAS  v5.8.2_stable-0-g6260b7c
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  *
3  * Copyright (C) 2012, Christophe De Wagter
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, write to
19  * the Free Software Foundation, 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  *
22  */
23 
37 #include "generated/airframe.h"
38 #include "state.h"
42 #include "generated/flight_plan.h"
45 
46 // Imu is required
47 #include "subsystems/imu.h"
48 
49 #include "mcu_periph/uart.h"
50 #include "messages.h"
52 
53 
54 static bool_t nav_catapult_armed = FALSE;
56 
57 #ifndef NAV_CATAPULT_ACCELERATION_THRESHOLD
58 #define NAV_CATAPULT_ACCELERATION_THRESHOLD 1.5
59 #endif
60 
62 
63 #ifndef NAV_CATAPULT_MOTOR_DELAY
64 #define NAV_CATAPULT_MOTOR_DELAY 0.75 // seconds
65 #endif
66 
68 
69 #ifndef NAV_CATAPULT_HEADING_DELAY
70 #define NAV_CATAPULT_HEADING_DELAY 3.0 // seconds
71 #endif
72 
74 
75 #ifndef NAV_CATAPULT_INITIAL_PITCH
76 #define NAV_CATAPULT_INITIAL_PITCH RadOfDeg(10)
77 #endif
78 
80 
81 #ifndef NAV_CATAPULT_INITIAL_THROTTLE
82 #define NAV_CATAPULT_INITIAL_THROTTLE 1.0
83 #endif
84 
86 
88 
89 static float nav_catapult_x = 0;
90 static float nav_catapult_y = 0;
91 
92 //###############################################################################################
93 // Code that Runs in a Fast Module
94 
96 {
97  bool_t reset_lauch;
98  // Only run when
99  if (nav_catapult_armed) {
100  if (nav_catapult_launch < nav_catapult_heading_delay * NAV_CATAPULT_HIGHRATE_MODULE_FREQ) {
102  }
103 
104  // Launch detection Filter
105  if (nav_catapult_launch < 5) {
106  // Five consecutive measurements > 1.5
107 #ifndef SITL
108  struct Int32Vect3 accel_meas_body;
109  struct Int32RMat *body_to_imu_rmat = orientationGetRMat_i(&imu.body_to_imu);
110  int32_rmat_transp_vmult(&accel_meas_body, body_to_imu_rmat, &imu.accel);
111  reset_lauch = ACCEL_FLOAT_OF_BFP(accel_meas_body.x) < (nav_catapult_acceleration_threshold * 9.81);
112 #else
113  reset_lauch = launch != 1;
114 #endif
115  if (reset_lauch)
116  {
118  }
119  }
120  // Launch was detected: Motor Delay Counter
121  else if (nav_catapult_launch >= nav_catapult_motor_delay * NAV_CATAPULT_HIGHRATE_MODULE_FREQ) {
122  // Turn on Motor
124  launch = 1;
125  }
126  } else {
128  }
129 }
130 
131 //###############################################################################################
132 // Code that runs in 4Hz Nav
133 
134 bool_t nav_catapult_setup(void)
135 {
136 
139 
140  return FALSE;
141 }
142 
143 
144 
145 bool_t nav_catapult_run(uint8_t _to, uint8_t _climb)
146 {
147  float alt = WaypointAlt(_climb);
148 
149  nav_catapult_armed = 1;
150 
151  // No Roll, Climb Pitch, No motor Phase
152  if (nav_catapult_launch <= nav_catapult_motor_delay * NAV_CATAPULT_HIGHRATE_MODULE_FREQ) {
153  NavAttitude(RadOfDeg(0));
155  NavVerticalThrottleMode(9600 * (0));
156 
157 
160 
161  // Store take-off waypoint
162  WaypointX(_to) = nav_catapult_x;
163  WaypointY(_to) = nav_catapult_y;
165 
166  }
167  // No Roll, Climb Pitch, Full Power
168  else if (nav_catapult_launch < nav_catapult_heading_delay * NAV_CATAPULT_HIGHRATE_MODULE_FREQ) {
169  NavAttitude(RadOfDeg(0));
172  }
173  // Normal Climb: Heading Locked by Waypoint Target
174  else if (nav_catapult_launch == 0xffff) {
175  NavVerticalAltitudeMode(alt, 0); // vertical mode (folow glideslope)
176  NavVerticalAutoThrottleMode(0); // throttle mode
177  NavGotoWaypoint(_climb); // horizontal mode (stay on localiser)
178  } else {
179  // Store Heading, move Climb
180  nav_catapult_launch = 0xffff;
181 
182  float dir_x = stateGetPositionEnu_f()->x - nav_catapult_x;
183  float dir_y = stateGetPositionEnu_f()->y - nav_catapult_y;
184 
185  float dir_L = sqrt(dir_x * dir_x + dir_y * dir_y);
186 
187  WaypointX(_climb) = nav_catapult_x + (dir_x / dir_L) * 300;
188  WaypointY(_climb) = nav_catapult_y + (dir_y / dir_L) * 300;
189 
190  DownlinkSendWp(&(DefaultChannel).trans_tx, &(DefaultDevice).device, _climb);
191  }
192 
193 
194  return TRUE;
195 
196 }
197 
199 {
203  return FALSE;
204 }
205 
unsigned short uint16_t
Definition: types.h:16
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
bool_t launch
Definition: sim_ap.c:39
static struct Int32RMat * orientationGetRMat_i(struct OrientationReps *orientation)
Get vehicle body attitude rotation matrix (int).
#define WaypointAlt(_wp)
Definition: common_nav.h:47
float alt
in meters above WGS84 reference ellipsoid
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
Definition: state.h:702
#define FALSE
Definition: std.h:5
Fixed wing horizontal control.
#define TRUE
Definition: std.h:4
struct Int32Vect3 accel
accelerometer measurements in m/s^2 in BFP with INT32_ACCEL_FRAC
Definition: imu.h:43
#define WaypointX(_wp)
Definition: common_nav.h:45
float x
in meters
#define ACCEL_FLOAT_OF_BFP(_ai)
struct Imu imu
global IMU state
Definition: imu_aspirin2.c:43
Inertial Measurement Unit interface.
#define WaypointY(_wp)
Definition: common_nav.h:46
struct OrientationReps body_to_imu
rotation from body to imu frame
Definition: imu.h:53
static struct UtmCoor_f * stateGetPositionUtm_f(void)
Get position in UTM coordinates (float).
Definition: state.h:675
unsigned char uint8_t
Definition: types.h:14
API to get/set the generic vehicle states.
void int32_rmat_transp_vmult(struct Int32Vect3 *vb, struct Int32RMat *m_b2a, struct Int32Vect3 *va)
rotate 3D vector by transposed rotation matrix.
rotation matrix
float y
in meters
Fixedwing autopilot modes.