Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
vertical_ctrl_module_demo.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015
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 
28 
29 #include "generated/airframe.h"
30 #include "autopilot.h"
31 #include "paparazzi.h"
32 #include "modules/core/abi.h"
35 
36 /* Default sonar/agl to use */
37 #ifndef VERTICAL_CTRL_MODULE_AGL_ID
38 #define VERTICAL_CTRL_MODULE_AGL_ID ABI_BROADCAST
39 #endif
41 
42 #ifndef VERTICAL_CTRL_MODULE_PGAIN
43 #define VERTICAL_CTRL_MODULE_PGAIN 1.0
44 #endif
45 
46 #ifndef VERTICAL_CTRL_MODULE_IGAIN
47 #define VERTICAL_CTRL_MODULE_IGAIN 0.01
48 #endif
49 
50 static abi_event agl_ev;
51 
53 static void vertical_ctrl_agl_cb(uint8_t sender_id, uint32_t stamp, float distance);
54 
56 
57 
59 {
60  v_ctrl.agl = 0.0f;
61  v_ctrl.setpoint = 1.0f;
64  v_ctrl.sum_err = 0.0f;
65 
66  // Subscribe to the altitude above ground level ABI messages
68 }
69 
70 
71 static struct ThrustSetpoint vertical_ctrl_module_run(bool in_flight)
72 {
73  struct ThrustSetpoint th;
74  if (!in_flight) {
75  // Reset integrators
76  v_ctrl.sum_err = 0;
78  } else {
79  int32_t nominal_throttle = 0.5 * MAX_PPRZ;
80  float err = v_ctrl.setpoint - v_ctrl.agl;
81  int32_t thrust = nominal_throttle + v_ctrl.pgain * err + v_ctrl.igain * v_ctrl.sum_err;
82  Bound(thrust, 0, MAX_PPRZ);
83  th = th_sp_from_thrust_i(thrust, THRUST_AXIS_Z);
84  v_ctrl.sum_err += err;
85  }
86  return th;
87 }
88 
89 static void vertical_ctrl_agl_cb(__attribute__((unused)) uint8_t sender_id, __attribute__((unused)) uint32_t stamp, float distance)
90 {
91  v_ctrl.agl = distance;
92 }
93 
94 
96 // Call our controller
98 {
99  // reset integrator
100  v_ctrl.sum_err = 0.0f;
101 
103 }
104 
105 void guidance_module_run(bool in_flight)
106 {
107  struct ThrustSetpoint th = vertical_ctrl_module_run(in_flight);
108  struct StabilizationSetpoint stab = guidance_h_run(in_flight);
109  stabilization_run(in_flight, &stab, &th, stabilization.cmd);
110 }
Main include for ABI (AirBorneInterface).
Event structure to store callbacks in a linked list.
Definition: abi_common.h:67
Core autopilot interface common to all firmwares.
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
#define MAX_PPRZ
Definition: paparazzi.h:8
void guidance_h_mode_changed(uint8_t new_mode)
Definition: guidance_h.c:128
struct StabilizationSetpoint guidance_h_run(bool in_flight)
Definition: guidance_h.c:244
Horizontal guidance for rotorcrafts.
#define GUIDANCE_H_MODE_HOVER
Definition: guidance_h.h:57
struct Stabilization stabilization
Definition: stabilization.c:41
void stabilization_run(bool in_flight, struct StabilizationSetpoint *sp, struct ThrustSetpoint *thrust, int32_t *cmd)
Call default stabilization control.
struct ThrustSetpoint th_sp_from_thrust_i(int32_t thrust, uint8_t axis)
General stabilization interface for rotorcrafts.
#define THRUST_AXIS_Z
int32_t cmd[COMMANDS_NB]
output command vector, range from [-MAX_PPRZ:MAX_PPRZ] (store for messages)
Stabilization setpoint.
Definition: stabilization.h:53
Thrust setpoint // TODO to a setpoint header Structure to store the desired thrust vector with differ...
Definition: stabilization.h:82
void vertical_ctrl_module_init(void)
static void vertical_ctrl_agl_cb(uint8_t sender_id, uint32_t stamp, float distance)
Callback function of the ground altitude.
#define VERTICAL_CTRL_MODULE_IGAIN
void guidance_module_enter(void)
Entering the module (user switched to module)
void guidance_module_run(bool in_flight)
struct VerticalCtrlDemo v_ctrl
static struct ThrustSetpoint vertical_ctrl_module_run(bool in_flight)
#define VERTICAL_CTRL_MODULE_AGL_ID
static abi_event agl_ev
The altitude ABI event.
#define VERTICAL_CTRL_MODULE_PGAIN
int int32_t
Typedef defining 32 bit int type.
Definition: vl53l1_types.h:83
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98