Paparazzi UAS  v5.15_devel-230-gc96ce27
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
stabilization.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2009 Antoine Drouin <poinix@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 
27 
28 #if (STABILIZATION_FILTER_COMMANDS_ROLL_PITCH || STABILIZATION_FILTER_COMMANDS_YAW)
30 #endif
31 
33 
34 #if STABILIZATION_FILTER_CMD_ROLL_PITCH
35 #ifndef STABILIZATION_FILTER_CMD_ROLL_CUTOFF
36 #define STABILIZATION_FILTER_CMD_ROLL_CUTOFF 20.0
37 #endif
38 
39 #ifndef STABILIZATION_FILTER_CMD_PITCH_CUTOFF
40 #define STABILIZATION_FILTER_CMD_PITCH_CUTOFF 20.0
41 #endif
42 
43 struct SecondOrderLowPass_int filter_roll;
44 struct SecondOrderLowPass_int filter_pitch;
45 #endif
46 
47 #if STABILIZATION_FILTER_CMD_YAW
48 #ifndef STABILIZATION_FILTER_CMD_YAW_CUTOFF
49 #define STABILIZATION_FILTER_CMD_YAW_CUTOFF 20.0
50 #endif
51 
52 struct SecondOrderLowPass_int filter_yaw;
53 #endif
54 
56 {
57  for (uint8_t i = 0; i < COMMANDS_NB; i++) {
58  stabilization_cmd[i] = 0;
59  }
60 
61  // Initialize low pass filters
62 #if STABILIZATION_FILTER_CMD_ROLL_PITCH
63  init_second_order_low_pass_int(&filter_roll, STABILIZATION_FILTER_CMD_ROLL_CUTOFF, 0.7071, 1.0 / PERIODIC_FREQUENCY,
64  0.0);
65  init_second_order_low_pass_int(&filter_pitch, STABILIZATION_FILTER_CMD_PITCH_CUTOFF, 0.7071, 1.0 / PERIODIC_FREQUENCY,
66  0.0);
67 #endif
68 
69 #if STABILIZATION_FILTER_CMD_YAW
70  init_second_order_low_pass_int(&filter_yaw, STABILIZATION_FILTER_CMD_YAW_CUTOFF, 0.7071, 1.0 / PERIODIC_FREQUENCY, 0.0);
71 #endif
72 
73 }
74 
76 {
77  /* Filter the commands & bound the result */
78 #if STABILIZATION_FILTER_CMD_ROLL_PITCH
79  stabilization_cmd[COMMAND_ROLL] = update_second_order_low_pass_int(&filter_roll, stabilization_cmd[COMMAND_ROLL]);
80  stabilization_cmd[COMMAND_PITCH] = update_second_order_low_pass_int(&filter_pitch, stabilization_cmd[COMMAND_PITCH]);
81 
82  BoundAbs(stabilization_cmd[COMMAND_ROLL], MAX_PPRZ);
83  BoundAbs(stabilization_cmd[COMMAND_PITCH], MAX_PPRZ);
84 #endif
85 #if STABILIZATION_FILTER_CMD_YAW
86  stabilization_cmd[COMMAND_YAW] = update_second_order_low_pass_int(&filter_yaw, stabilization_cmd[COMMAND_YAW]);
87 
88  BoundAbs(stabilization_cmd[COMMAND_YAW], MAX_PPRZ);
89 #endif
90 }
Simple first order low pass filter with bilinear transform.
void stabilization_filter_commands(void)
Definition: stabilization.c:75
void stabilization_init(void)
Definition: stabilization.c:55
static void init_second_order_low_pass_int(struct SecondOrderLowPass_int *filter, float cut_off, float Q, float sample_time, int32_t value)
Init second order low pass filter(fixed point version).
signed long int32_t
Definition: types.h:19
unsigned char uint8_t
Definition: types.h:14
static int32_t update_second_order_low_pass_int(struct SecondOrderLowPass_int *filter, int32_t value)
Update second order low pass filter state with a new value(fixed point version).
General stabilization interface for rotorcrafts.
int32_t stabilization_cmd[COMMANDS_NB]
Stabilization commands.
Definition: stabilization.c:32
#define MAX_PPRZ
Definition: paparazzi.h:8
int32_t i[2]
input history