Paparazzi UAS  v4.2.2_stable-4-gcc32f65
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros 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 
28 
33 
35 
40 
41 }
42 
43 #define F_UPDATE_RES 9
44 #define F_UPDATE (1<<F_UPDATE_RES)
45 
46 #define REF_ACCEL_MAX_P BFP_OF_REAL(STABILIZATION_ATTITUDE_REF_MAX_PDOT, REF_ACCEL_FRAC)
47 #define REF_ACCEL_MAX_Q BFP_OF_REAL(STABILIZATION_ATTITUDE_REF_MAX_QDOT, REF_ACCEL_FRAC)
48 #define REF_ACCEL_MAX_R BFP_OF_REAL(STABILIZATION_ATTITUDE_REF_MAX_RDOT, REF_ACCEL_FRAC)
49 
50 #define REF_RATE_MAX_P BFP_OF_REAL(STABILIZATION_ATTITUDE_REF_MAX_P, REF_RATE_FRAC)
51 #define REF_RATE_MAX_Q BFP_OF_REAL(STABILIZATION_ATTITUDE_REF_MAX_Q, REF_RATE_FRAC)
52 #define REF_RATE_MAX_R BFP_OF_REAL(STABILIZATION_ATTITUDE_REF_MAX_R, REF_RATE_FRAC)
53 
54 #define OMEGA_P STABILIZATION_ATTITUDE_REF_OMEGA_P
55 #define ZETA_P STABILIZATION_ATTITUDE_REF_ZETA_P
56 #define ZETA_OMEGA_P_RES 10
57 #define ZETA_OMEGA_P BFP_OF_REAL((ZETA_P*OMEGA_P), ZETA_OMEGA_P_RES)
58 #define OMEGA_2_P_RES 7
59 #define OMEGA_2_P BFP_OF_REAL((OMEGA_P*OMEGA_P), OMEGA_2_P_RES)
60 
61 #define OMEGA_Q STABILIZATION_ATTITUDE_REF_OMEGA_Q
62 #define ZETA_Q STABILIZATION_ATTITUDE_REF_ZETA_Q
63 #define ZETA_OMEGA_Q_RES 10
64 #define ZETA_OMEGA_Q BFP_OF_REAL((ZETA_Q*OMEGA_Q), ZETA_OMEGA_Q_RES)
65 #define OMEGA_2_Q_RES 7
66 #define OMEGA_2_Q BFP_OF_REAL((OMEGA_Q*OMEGA_Q), OMEGA_2_Q_RES)
67 
68 #define OMEGA_R STABILIZATION_ATTITUDE_REF_OMEGA_R
69 #define ZETA_R STABILIZATION_ATTITUDE_REF_ZETA_R
70 #define ZETA_OMEGA_R_RES 10
71 #define ZETA_OMEGA_R BFP_OF_REAL((ZETA_R*OMEGA_R), ZETA_OMEGA_R_RES)
72 #define OMEGA_2_R_RES 7
73 #define OMEGA_2_R BFP_OF_REAL((OMEGA_R*OMEGA_R), OMEGA_2_R_RES)
74 
75 
77 #ifndef USE_ATTITUDE_REF
78 #define USE_ATTITUDE_REF 1
79 #endif
80 
82 
83 #if USE_ATTITUDE_REF
84 
85  /* dumb integrate reference attitude */
86  const struct Int32Eulers d_angle = {
90  EULERS_ADD(stab_att_ref_euler, d_angle );
92 
93  /* integrate reference rotational speeds */
94  const struct Int32Rates d_rate = {
99 
100  /* attitude setpoint with REF_ANGLE_FRAC */
101  struct Int32Eulers sp_ref;
103 
104  /* compute reference attitude error */
105  struct Int32Eulers ref_err;
106  EULERS_DIFF(ref_err, stab_att_ref_euler, sp_ref);
107  /* wrap it in the shortest direction */
108  ANGLE_REF_NORMALIZE(ref_err.psi);
109 
110  /* compute reference angular accelerations */
111  const struct Int32Rates accel_rate = {
113  >> (ZETA_OMEGA_P_RES),
115  >> (ZETA_OMEGA_Q_RES),
117  >> (ZETA_OMEGA_R_RES) };
118 
119  const struct Int32Rates accel_angle = {
120  ((int32_t)(-OMEGA_2_P)* (ref_err.phi >> (REF_ANGLE_FRAC - REF_ACCEL_FRAC))) >> (OMEGA_2_P_RES),
121  ((int32_t)(-OMEGA_2_Q)* (ref_err.theta >> (REF_ANGLE_FRAC - REF_ACCEL_FRAC))) >> (OMEGA_2_Q_RES),
122  ((int32_t)(-OMEGA_2_R)* (ref_err.psi >> (REF_ANGLE_FRAC - REF_ACCEL_FRAC))) >> (OMEGA_2_R_RES) };
123 
124  RATES_SUM(stab_att_ref_accel, accel_rate, accel_angle);
125 
126  /* saturate acceleration */
127  const struct Int32Rates MIN_ACCEL = { -REF_ACCEL_MAX_P, -REF_ACCEL_MAX_Q, -REF_ACCEL_MAX_R };
128  const struct Int32Rates MAX_ACCEL = { REF_ACCEL_MAX_P, REF_ACCEL_MAX_Q, REF_ACCEL_MAX_R };
129  RATES_BOUND_BOX(stab_att_ref_accel, MIN_ACCEL, MAX_ACCEL);
130 
131  /* saturate speed and trim accel accordingly */
133 
134 #else /* !USE_ATTITUDE_REF */
138 #endif /* USE_ATTITUDE_REF */
139 
140 }
void stabilization_attitude_ref_init(void)
int32_t phi
in rad with INT32_ANGLE_FRAC
#define EULERS_ADD(_a, _b)
Definition: pprz_algebra.h:249
#define EULERS_DIFF(_c, _a, _b)
Definition: pprz_algebra.h:263
int32_t p
in rad/s^2 with INT32_RATE_FRAC
#define SATURATE_SPEED_TRIM_ACCEL()
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 INT32_ANGLE_FRAC
#define REF_RATE_FRAC
#define RATES_ADD(_a, _b)
Definition: pprz_algebra.h:310
#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:373
int32_t psi
in rad with INT32_ANGLE_FRAC
General stabilization interface for rotorcrafts.
int32_t q
in rad/s^2 with INT32_RATE_FRAC
int32_t r
in rad/s^2 with INT32_RATE_FRAC
#define ANGLE_REF_NORMALIZE(_a)
struct Int32Rates stab_att_ref_accel
with REF_ACCEL_FRAC
#define RATES_SUM(_c, _a, _b)
Definition: pprz_algebra.h:324
euler angles