Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
stabilization_attitude_ref_euler_int.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 
29 #include "generated/airframe.h"
30 
35 
37 
42 
43 }
44 
45 #define F_UPDATE_RES 9
46 #define F_UPDATE (1<<F_UPDATE_RES)
47 
48 #define REF_ACCEL_MAX_P BFP_OF_REAL(STABILIZATION_ATTITUDE_REF_MAX_PDOT, REF_ACCEL_FRAC)
49 #define REF_ACCEL_MAX_Q BFP_OF_REAL(STABILIZATION_ATTITUDE_REF_MAX_QDOT, REF_ACCEL_FRAC)
50 #define REF_ACCEL_MAX_R BFP_OF_REAL(STABILIZATION_ATTITUDE_REF_MAX_RDOT, REF_ACCEL_FRAC)
51 
52 #define REF_RATE_MAX_P BFP_OF_REAL(STABILIZATION_ATTITUDE_REF_MAX_P, REF_RATE_FRAC)
53 #define REF_RATE_MAX_Q BFP_OF_REAL(STABILIZATION_ATTITUDE_REF_MAX_Q, REF_RATE_FRAC)
54 #define REF_RATE_MAX_R BFP_OF_REAL(STABILIZATION_ATTITUDE_REF_MAX_R, REF_RATE_FRAC)
55 
56 #define OMEGA_P STABILIZATION_ATTITUDE_REF_OMEGA_P
57 #define ZETA_P STABILIZATION_ATTITUDE_REF_ZETA_P
58 #define ZETA_OMEGA_P_RES 10
59 #define ZETA_OMEGA_P BFP_OF_REAL((ZETA_P*OMEGA_P), ZETA_OMEGA_P_RES)
60 #define OMEGA_2_P_RES 7
61 #define OMEGA_2_P BFP_OF_REAL((OMEGA_P*OMEGA_P), OMEGA_2_P_RES)
62 
63 #define OMEGA_Q STABILIZATION_ATTITUDE_REF_OMEGA_Q
64 #define ZETA_Q STABILIZATION_ATTITUDE_REF_ZETA_Q
65 #define ZETA_OMEGA_Q_RES 10
66 #define ZETA_OMEGA_Q BFP_OF_REAL((ZETA_Q*OMEGA_Q), ZETA_OMEGA_Q_RES)
67 #define OMEGA_2_Q_RES 7
68 #define OMEGA_2_Q BFP_OF_REAL((OMEGA_Q*OMEGA_Q), OMEGA_2_Q_RES)
69 
70 #define OMEGA_R STABILIZATION_ATTITUDE_REF_OMEGA_R
71 #define ZETA_R STABILIZATION_ATTITUDE_REF_ZETA_R
72 #define ZETA_OMEGA_R_RES 10
73 #define ZETA_OMEGA_R BFP_OF_REAL((ZETA_R*OMEGA_R), ZETA_OMEGA_R_RES)
74 #define OMEGA_2_R_RES 7
75 #define OMEGA_2_R BFP_OF_REAL((OMEGA_R*OMEGA_R), OMEGA_2_R_RES)
76 
77 
78 #define REF_ANGLE_PI BFP_OF_REAL(3.1415926535897932384626433832795029, REF_ANGLE_FRAC)
79 #define REF_ANGLE_TWO_PI BFP_OF_REAL(2.*3.1415926535897932384626433832795029, REF_ANGLE_FRAC)
80 #define ANGLE_REF_NORMALIZE(_a) { \
81  while (_a > REF_ANGLE_PI) _a -= REF_ANGLE_TWO_PI; \
82  while (_a < -REF_ANGLE_PI) _a += REF_ANGLE_TWO_PI; \
83  }
84 
85 
87 #ifndef USE_ATTITUDE_REF
88 #define USE_ATTITUDE_REF 1
89 #endif
90 
92 
93 #if USE_ATTITUDE_REF
94 
95  /* dumb integrate reference attitude */
96  const struct Int32Eulers d_angle = {
100  EULERS_ADD(stab_att_ref_euler, d_angle );
102 
103  /* integrate reference rotational speeds */
104  const struct Int32Rates d_rate = {
108  RATES_ADD(stab_att_ref_rate, d_rate);
109 
110  /* attitude setpoint with REF_ANGLE_FRAC */
111  struct Int32Eulers sp_ref;
113 
114  /* compute reference attitude error */
115  struct Int32Eulers ref_err;
116  EULERS_DIFF(ref_err, stab_att_ref_euler, sp_ref);
117  /* wrap it in the shortest direction */
118  ANGLE_REF_NORMALIZE(ref_err.psi);
119 
120  /* compute reference angular accelerations */
121  const struct Int32Rates accel_rate = {
123  >> (ZETA_OMEGA_P_RES),
125  >> (ZETA_OMEGA_Q_RES),
127  >> (ZETA_OMEGA_R_RES) };
128 
129  const struct Int32Rates accel_angle = {
130  ((int32_t)(-OMEGA_2_P)* (ref_err.phi >> (REF_ANGLE_FRAC - REF_ACCEL_FRAC))) >> (OMEGA_2_P_RES),
131  ((int32_t)(-OMEGA_2_Q)* (ref_err.theta >> (REF_ANGLE_FRAC - REF_ACCEL_FRAC))) >> (OMEGA_2_Q_RES),
132  ((int32_t)(-OMEGA_2_R)* (ref_err.psi >> (REF_ANGLE_FRAC - REF_ACCEL_FRAC))) >> (OMEGA_2_R_RES) };
133 
134  RATES_SUM(stab_att_ref_accel, accel_rate, accel_angle);
135 
136  /* saturate acceleration */
137  const struct Int32Rates MIN_ACCEL = { -REF_ACCEL_MAX_P, -REF_ACCEL_MAX_Q, -REF_ACCEL_MAX_R };
138  const struct Int32Rates MAX_ACCEL = { REF_ACCEL_MAX_P, REF_ACCEL_MAX_Q, REF_ACCEL_MAX_R };
139  RATES_BOUND_BOX(stab_att_ref_accel, MIN_ACCEL, MAX_ACCEL);
140 
141  /* saturate speed and trim accel accordingly */
143 
144 #else /* !USE_ATTITUDE_REF */
148 #endif /* USE_ATTITUDE_REF */
149 
150 }
void stabilization_attitude_ref_init(void)
int32_t phi
in rad with INT32_ANGLE_FRAC
#define EULERS_ADD(_a, _b)
Definition: pprz_algebra.h:270
#define EULERS_DIFF(_c, _a, _b)
Definition: pprz_algebra.h:284
int32_t p
in rad/s with INT32_RATE_FRAC
Common rotorcraft attitude reference saturation include.
struct Int32Eulers stab_att_ref_euler
with REF_ANGLE_FRAC
#define INT32_EULERS_LSHIFT(_o, _i, _r)
#define INT_RATES_ZERO(_e)
struct Int32Eulers stab_att_sp_euler
with INT32_ANGLE_FRAC
int32_t theta
in rad with INT32_ANGLE_FRAC
#define REF_ACCEL_FRAC
#define INT_EULERS_ZERO(_e)
#define SATURATE_SPEED_TRIM_ACCEL()
#define INT32_ANGLE_FRAC
#define ANGLE_REF_NORMALIZE(_a)
#define REF_RATE_FRAC
Rotorcraft attitude reference generation (euler int version)
#define RATES_ADD(_a, _b)
Definition: pprz_algebra.h:333
#define REF_ANGLE_FRAC
angular rates
struct Int32Rates stab_att_ref_rate
with REF_RATE_FRAC
signed long int32_t
Definition: types.h:19
void stabilization_attitude_ref_update()
#define RATES_BOUND_BOX(_v, _v_min, _v_max)
Definition: pprz_algebra.h:396
int32_t psi
in rad with INT32_ANGLE_FRAC
int32_t q
in rad/s with INT32_RATE_FRAC
int32_t r
in rad/s with INT32_RATE_FRAC
struct Int32Rates stab_att_ref_accel
with REF_ACCEL_FRAC
#define RATES_SUM(_c, _a, _b)
Definition: pprz_algebra.h:347
euler angles