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
guidance_v_n.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010 ENAC
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
30#include "state.h"
32#include "generated/airframe.h"
33#include "autopilot.h"
34
35/* mode */
37
38/* outer loop */
43
44/* inner loop */
48
49#ifndef V_CTL_AUTO_THROTTLE_DGAIN
50#define V_CTL_AUTO_THROTTLE_DGAIN 0.
51#endif
52
53/* "auto throttle" inner loop parameters */
63#define V_CTL_AUTO_THROTTLE_MAX_SUM_ERR 0.4
66
67#ifndef V_CTL_AUTO_THROTTLE_PITCH_OF_VZ_DGAIN
68#define V_CTL_AUTO_THROTTLE_PITCH_OF_VZ_DGAIN 0.
69#endif
70
71/* "auto pitch" inner loop parameters */
76#define V_CTL_AUTO_PITCH_MAX_SUM_ERR (RadOfDeg(10.))
77
78#ifndef V_CTL_AUTO_PITCH_DGAIN
79#define V_CTL_AUTO_PITCH_DGAIN 0.
80#endif
81#ifndef V_CTL_AUTO_PITCH_IGAIN
82#define V_CTL_AUTO_PITCH_IGAIN 0.
83#endif
84
89#ifndef V_CTL_PITCH_TRIM
90#define V_CTL_PITCH_TRIM 0.
91#endif
93
94// Set higher than 2*V_CTL_ALTITUDE_MAX_CLIMB to disable
95#ifndef V_CTL_AUTO_CLIMB_LIMIT
96#define V_CTL_AUTO_CLIMB_LIMIT (0.5/4.0) // m/s/s
97#endif
98
100
101#if USE_AIRSPEED
116#define V_CTL_AUTO_AIRSPEED_PITCH_MAX_SUM_ERR (RadOfDeg(15.))
117#define V_CTL_AUTO_AIRSPEED_THROTTLE_MAX_SUM_ERR 0.2
118#define V_CTL_AUTO_GROUNDSPEED_MAX_SUM_ERR 100
119#endif
120
121void v_ctl_init(void)
122{
123 /* mode */
126
127 /* outer loop */
132
133 /* inner loops */
137
140
141 /* "auto throttle" inner loop parameters */
153
154 /* "auto pitch" inner loop parameters */
159
160#if USE_AIRSPEED
171
176#endif
177
180}
181
183{
186 }
187#if CTRL_VERTICAL_LANDING
190 } else {
191#endif
195 } else {
198 } /* v_ctl_mode >= V_CTL_MODE_AUTO_CLIMB */
199 } /* v_ctl_mode == V_CTL_MODE_AUTO_THROTTLE */
200#if CTRL_VERTICAL_LANDING
201 } /* v_ctl_mode == V_CTL_MODE_LANDING */
202#endif
203
204#if defined V_CTL_THROTTLE_IDLE
206#endif
207
208#ifdef V_CTL_POWER_CTL_BAT_NOMINAL
209 if (electrical.vsupply > 0.) {
212 }
213#endif
214
217 }
218}
219
225// Don't use lead controller unless you know what you're doing
226#define LEAD_CTRL_TAU 0.8
227#define LEAD_CTRL_A 1.
228#define LEAD_CTRL_Te (1./60.)
229
231{
232 static float v_ctl_climb_setpoint_last = 0.;
233 //static float last_lead_input = 0.;
234
235 // Altitude error
238
239 // Lead controller
240 //v_ctl_climb_setpoint = ((LEAD_CTRL_TAU*LEAD_CTRL_A + LEAD_CTRL_Te)*climb_sp + LEAD_CTRL_TAU*(v_ctl_climb_setpoint - LEAD_CTRL_A*last_lead_input)) / (LEAD_CTRL_TAU + LEAD_CTRL_Te);
241 //last_lead_input = pitch_sp;
242
243 // Limit rate of change of climb setpoint
247
248 // Limit climb setpoint
251}
252
253static inline void v_ctl_set_pitch(void)
254{
255 static float last_err = 0.;
256
257 if (autopilot_get_mode() == AP_MODE_MANUAL || autopilot.launch == false) {
259 }
260
261 // Compute errors
263 float d_err = err - last_err;
264 last_err = err;
265
266 if (v_ctl_auto_pitch_igain > 0.) {
267 v_ctl_auto_pitch_sum_err += err * (1. / 60.);
269 }
270
271 // PI loop + feedforward ctl
276 + v_ctl_auto_pitch_dgain * d_err
278
279}
280
281static inline void v_ctl_set_throttle(void)
282{
283 static float last_err = 0.;
284
285 if (autopilot_get_mode() == AP_MODE_MANUAL || autopilot.launch == false) {
287 }
288
289 // Compute errors
291 float d_err = err - last_err;
292 last_err = err;
293
294 if (v_ctl_auto_throttle_igain > 0.) {
295 v_ctl_auto_throttle_sum_err += err * (1. / 60.);
297 }
298
299 // PID loop + feedforward ctl
305
306}
307
308#if USE_AIRSPEED
309#define AIRSPEED_LOOP_PERIOD (1./60.)
310
311// Airspeed control loop (input: [airspeed controlled, climb_setpoint], output: [throttle controlled, pitch setpoint])
312static inline void v_ctl_set_airspeed(void)
313{
314 static float last_err_vz = 0.;
315 static float last_err_as = 0.;
316
317 // Bound airspeed setpoint
319
320 // Compute errors
324 if (v_ctl_auto_throttle_igain > 0.) {
327 }
328 if (v_ctl_auto_pitch_igain > 0.) {
331 }
332
340 }
344 }
345
346
347 // Reset integrators in manual or before flight
348 if (autopilot_get_mode() == AP_MODE_MANUAL || autopilot.launch == false) {
353 }
354
355 // Pitch loop
365
366 // Throttle loop
375
376}
377
378static inline void v_ctl_set_groundspeed(void)
379{
380 // Ground speed control loop (input: groundspeed error, output: airspeed controlled)
386
387}
388#endif
389
391{
392
393 switch (v_ctl_speed_mode) {
395 // Set pitch
397 // Set throttle
399 break;
400#if USE_AIRSPEED
403 break;
407 break;
408#endif
409 default:
411 break;
412 }
413
414 // Set Pitch output
416 // Set Throttle output
418
419}
420
421#ifdef V_CTL_THROTTLE_SLEW_LIMITER
422#define V_CTL_THROTTLE_SLEW (1./CONTROL_FREQUENCY/(V_CTL_THROTTLE_SLEW_LIMITER))
423#endif
424
425#ifndef V_CTL_THROTTLE_SLEW
426#define V_CTL_THROTTLE_SLEW (1.)
427#endif
uint8_t autopilot_get_mode(void)
get autopilot mode
Definition autopilot.c:222
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
bool kill_throttle
allow autopilot to use throttle
Definition autopilot.h:69
uint16_t flight_time
flight time in seconds
Definition autopilot.h:65
struct Electrical electrical
Definition electrical.c:92
float vsupply
supply voltage in V
Definition electrical.h:45
float v_ctl_auto_groundspeed_sum_err
float v_ctl_auto_airspeed_controlled
float v_ctl_auto_groundspeed_igain
#define V_CTL_AUTO_GROUNDSPEED_MAX_SUM_ERR
#define V_CTL_ALTITUDE_MAX_CLIMB
float v_ctl_auto_airspeed_setpoint
in meters per second
float v_ctl_auto_groundspeed_pgain
float v_ctl_auto_groundspeed_setpoint
in meters per second
#define V_CTL_SPEED_THROTTLE
Definition energy_ctrl.h:36
#define V_CTL_SPEED_GROUNDSPEED
Definition energy_ctrl.h:38
#define V_CTL_SPEED_AIRSPEED
Definition energy_ctrl.h:37
#define AP_MODE_MANUAL
AP modes.
Vertical control for fixed wing vehicles.
static struct UtmCoor_f * stateGetPositionUtm_f(void)
Get position in UTM coordinates (float).
Definition state.h:821
static float stateGetHorizontalSpeedNorm_f(void)
Get norm of horizontal ground speed (float).
Definition state.h:1076
static struct EnuCoor_f * stateGetSpeedEnu_f(void)
Get ground speed in local ENU coordinates (float).
Definition state.h:1058
static float stateGetAirspeed_f(void)
Get airspeed (float).
Definition state.h:1590
void v_ctl_landing_loop(void)
Definition guidance_v.c:357
#define V_CTL_MODE_AUTO_THROTTLE
#define V_CTL_MODE_MANUAL
#define V_CTL_AUTO_THROTTLE_STANDARD
#define V_CTL_MODE_LANDING
#define V_CTL_MODE_AUTO_ALT
#define V_CTL_CLIMB_MODE_AUTO_THROTTLE
#define V_CTL_MODE_AUTO_CLIMB
#define V_CTL_PITCH_TRIM
#define V_CTL_AUTO_CLIMB_LIMIT
float v_ctl_auto_throttle_pgain
float v_ctl_auto_pitch_igain
static void v_ctl_set_pitch(void)
pprz_t v_ctl_throttle_setpoint
#define V_CTL_AUTO_THROTTLE_MAX_SUM_ERR
float v_ctl_auto_throttle_climb_throttle_increment
#define V_CTL_AUTO_THROTTLE_PITCH_OF_VZ_DGAIN
void v_ctl_climb_loop(void)
Auto-throttle inner loop.
float v_ctl_auto_pitch_pgain
float v_ctl_auto_throttle_min_cruise_throttle
static void v_ctl_set_throttle(void)
uint8_t v_ctl_climb_mode
float v_ctl_auto_pitch_sum_err
uint8_t v_ctl_auto_throttle_submode
#define V_CTL_AUTO_PITCH_MAX_SUM_ERR
float v_ctl_auto_throttle_max_cruise_throttle
float v_ctl_auto_throttle_igain
float v_ctl_altitude_pgain
float v_ctl_pitch_setpoint
void v_ctl_guidance_loop(void)
General guidance logic This will call the proper control loops according to the sub-modes.
void v_ctl_throttle_slew(void)
Computes slewed throttle from throttle setpoint called at 20Hz.
float controlled_throttle
float v_ctl_auto_throttle_sum_err
float v_ctl_altitude_setpoint
in meters above MSL
#define V_CTL_AUTO_PITCH_IGAIN
pprz_t v_ctl_throttle_slewed
float v_ctl_auto_throttle_nominal_cruise_throttle
float v_ctl_auto_throttle_pitch_of_vz_dgain
float v_ctl_auto_pitch_dgain
#define V_CTL_AUTO_PITCH_DGAIN
uint8_t v_ctl_speed_mode
float v_ctl_auto_throttle_pitch_of_vz_pgain
void v_ctl_altitude_loop(void)
outer loop
#define V_CTL_THROTTLE_SLEW
float v_ctl_auto_throttle_cruise_throttle
void v_ctl_init(void)
float v_ctl_altitude_pre_climb
Path Angle.
float v_ctl_pitch_trim
float v_ctl_altitude_error
in meters, (setpoint - alt) -> positive = too low
float v_ctl_auto_throttle_dgain
#define V_CTL_AUTO_THROTTLE_DGAIN
float v_ctl_climb_setpoint
uint8_t v_ctl_mode
"New" vertical control for fixed wing vehicles.
float v_ctl_auto_airspeed_pitch_sum_err
float v_ctl_auto_airspeed_pitch_pgain
float v_ctl_auto_airspeed_pitch_igain
float v_ctl_auto_airspeed_throttle_dgain
float v_ctl_auto_airspeed_pitch_dgain
float v_ctl_auto_airspeed_throttle_sum_err
float v_ctl_auto_airspeed_throttle_igain
float v_ctl_auto_airspeed_throttle_pgain
uint16_t foo
Definition main_demo5.c:58
pprz_t nav_throttle_setpoint
Definition nav.c:309
float nav_pitch
Definition nav.c:310
Fixedwing Navigation library.
#define TRIM_UPPRZ(pprz)
Definition paparazzi.h:14
int16_t pprz_t
Definition paparazzi.h:6
#define MAX_PPRZ
Definition paparazzi.h:8
#define TRIM_PPRZ(pprz)
Definition paparazzi.h:11
float alt
in meters (above WGS84 reference ellipsoid or above MSL)
float z
in meters
API to get/set the generic vehicle states.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.