Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
stabilization_attitude_ref_quat_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 
30 #include "generated/airframe.h"
32 
34 
35 #define REF_ACCEL_MAX_P BFP_OF_REAL(STABILIZATION_ATTITUDE_REF_MAX_PDOT, REF_ACCEL_FRAC)
36 #define REF_ACCEL_MAX_Q BFP_OF_REAL(STABILIZATION_ATTITUDE_REF_MAX_QDOT, REF_ACCEL_FRAC)
37 #define REF_ACCEL_MAX_R BFP_OF_REAL(STABILIZATION_ATTITUDE_REF_MAX_RDOT, REF_ACCEL_FRAC)
38 
39 #define REF_RATE_MAX_P BFP_OF_REAL(STABILIZATION_ATTITUDE_REF_MAX_P, REF_RATE_FRAC)
40 #define REF_RATE_MAX_Q BFP_OF_REAL(STABILIZATION_ATTITUDE_REF_MAX_Q, REF_RATE_FRAC)
41 #define REF_RATE_MAX_R BFP_OF_REAL(STABILIZATION_ATTITUDE_REF_MAX_R, REF_RATE_FRAC)
42 
43 #define OMEGA_P STABILIZATION_ATTITUDE_REF_OMEGA_P
44 #define ZETA_P STABILIZATION_ATTITUDE_REF_ZETA_P
45 #define ZETA_OMEGA_P_RES 10
46 #define ZETA_OMEGA_P BFP_OF_REAL((ZETA_P*OMEGA_P), ZETA_OMEGA_P_RES)
47 #define OMEGA_2_P_RES 7
48 #define OMEGA_2_P BFP_OF_REAL((OMEGA_P*OMEGA_P), OMEGA_2_P_RES)
49 
50 #define OMEGA_Q STABILIZATION_ATTITUDE_REF_OMEGA_Q
51 #define ZETA_Q STABILIZATION_ATTITUDE_REF_ZETA_Q
52 #define ZETA_OMEGA_Q_RES 10
53 #define ZETA_OMEGA_Q BFP_OF_REAL((ZETA_Q*OMEGA_Q), ZETA_OMEGA_Q_RES)
54 #define OMEGA_2_Q_RES 7
55 #define OMEGA_2_Q BFP_OF_REAL((OMEGA_Q*OMEGA_Q), OMEGA_2_Q_RES)
56 
57 #define OMEGA_R STABILIZATION_ATTITUDE_REF_OMEGA_R
58 #define ZETA_R STABILIZATION_ATTITUDE_REF_ZETA_R
59 #define ZETA_OMEGA_R_RES 10
60 #define ZETA_OMEGA_R BFP_OF_REAL((ZETA_R*OMEGA_R), ZETA_OMEGA_R_RES)
61 #define OMEGA_2_R_RES 7
62 #define OMEGA_2_R BFP_OF_REAL((OMEGA_R*OMEGA_R), OMEGA_2_R_RES)
63 
64 
71 
73  {STABILIZATION_ATTITUDE_REF_OMEGA_P, STABILIZATION_ATTITUDE_REF_OMEGA_Q, STABILIZATION_ATTITUDE_REF_OMEGA_R},
74  {STABILIZATION_ATTITUDE_REF_ZETA_P, STABILIZATION_ATTITUDE_REF_ZETA_Q, STABILIZATION_ATTITUDE_REF_ZETA_R}
75 };
76 
77 static inline void reset_psi_ref_from_body(void) {
78  //sp has been set from body using stabilization_attitude_get_yaw_i, use that value
80  stab_att_ref_rate.r = 0;
82 }
83 
85 
92 
93  /*
94  for (int i = 0; i < STABILIZATION_ATTITUDE_GAIN_NB; i++) {
95  RATES_ASSIGN(stab_att_ref_model[i].omega, omega_p[i], omega_q[i], omega_r[i]);
96  RATES_ASSIGN(stab_att_ref_model[i].zeta, zeta_p[i], zeta_q[i], zeta_r[i]);
97  }
98  */
99 
100 }
101 
103 {
105 
106  /* convert reference attitude with REF_ANGLE_FRAC to eulers with normal INT32_ANGLE_FRAC */
107  struct Int32Eulers ref_eul;
111 
112  /* set reference rate and acceleration to zero */
113  memset(&stab_att_ref_accel, 0, sizeof(struct Int32Rates));
114  memset(&stab_att_ref_rate, 0, sizeof(struct Int32Rates));
115 }
116 
117 /*
118  * Reference
119  */
120 #define DT_UPDATE (1./PERIODIC_FREQUENCY)
121 // CAUTION! Periodic frequency is assumed to be 512 Hz
122 // which is equal to >> 9
123 #define F_UPDATE_RES 9
124 
126 
127  /* integrate reference attitude */
128  struct Int32Quat qdot;
130  //QUAT_SMUL(qdot, qdot, DT_UPDATE);
131  qdot.qi = qdot.qi >> F_UPDATE_RES;
132  qdot.qx = qdot.qx >> F_UPDATE_RES;
133  qdot.qy = qdot.qy >> F_UPDATE_RES;
134  qdot.qz = qdot.qz >> F_UPDATE_RES;
137 
138  /* integrate reference rotational speeds
139  * delta rate = ref_accel * dt
140  * ref_rate = old_ref_rate + delta_rate
141  */
142  const struct Int32Rates delta_rate = {
146 
147  RATES_ADD(stab_att_ref_rate, delta_rate);
148 
149  /* compute reference angular accelerations */
150  struct Int32Quat err;
151  /* compute reference attitude error */
153  /* wrap it in the shortest direction */
155  /* propagate the 2nd order linear model */
156 
157  const struct Int32Rates accel_rate = {
161 
162  const struct Int32Rates accel_angle = {
165  ((int32_t)(-OMEGA_2_R)* (err.qz >> (REF_ANGLE_FRAC - REF_ACCEL_FRAC))) >> (OMEGA_2_R_RES) };
166 
167  RATES_SUM(stab_att_ref_accel, accel_rate, accel_angle);
168 
169 
170  /* saturate acceleration */
171  //const struct Int32Rates MIN_ACCEL = { -REF_ACCEL_MAX_P, -REF_ACCEL_MAX_Q, -REF_ACCEL_MAX_R };
172  //const struct Int32Rates MAX_ACCEL = { REF_ACCEL_MAX_P, REF_ACCEL_MAX_Q, REF_ACCEL_MAX_R };
173  //RATES_BOUND_BOX(stab_att_ref_accel, MIN_ACCEL, MAX_ACCEL);
174 
175 
176  /* compute ref_euler for debugging and telemetry */
177  struct Int32Eulers ref_eul;
180 }
int32_t p
in rad/s^2 with INT32_RATE_FRAC
#define INT32_QUAT_ZERO(_q)
struct Int32Rates stab_att_ref_rate
with REF_RATE_FRAC
Rotation quaternion.
struct Int32Quat stab_att_ref_quat
with INT32_QUAT_FRAC
#define INT32_QUAT_NORMALIZE(q)
struct Int32Eulers stab_att_ref_euler
with REF_ANGLE_FRAC
#define INT32_QUAT_DERIVATIVE(_qd, _r, _q)
#define INT32_EULERS_LSHIFT(_o, _i, _r)
#define INT32_EULERS_RSHIFT(_o, _i, _r)
#define INT_RATES_ZERO(_e)
#define REF_ACCEL_FRAC
#define INT_EULERS_ZERO(_e)
struct Int32RefModel stab_att_ref_model
static void reset_psi_ref_from_body(void)
#define INT32_QUAT_OF_EULERS(_q, _e)
void stabilization_attitude_ref_enter(void)
#define INT32_ANGLE_FRAC
#define REF_RATE_FRAC
#define RATES_ADD(_a, _b)
Definition: pprz_algebra.h:308
#define REF_ANGLE_FRAC
angular rates
signed long int32_t
Definition: types.h:19
struct Int32Eulers stab_att_sp_euler
with INT32_ANGLE_FRAC
void stabilization_attitude_ref_init(void)
void stabilization_attitude_ref_update(void)
int32_t psi
in rad with INT32_ANGLE_FRAC
General stabilization interface for rotorcrafts.
#define INT32_QUAT_INV_COMP(_b2c, _a2b, _a2c)
int32_t q
in rad/s^2 with INT32_RATE_FRAC
#define QUAT_ADD(_qo, _qi)
Definition: pprz_algebra.h:498
int32_t r
in rad/s^2 with INT32_RATE_FRAC
struct Int32Quat stab_att_sp_quat
with INT32_QUAT_FRAC
Rotorcraft attitude reference generation API.
#define INT32_EULERS_OF_QUAT(_e, _q)
struct Int32Rates stab_att_ref_accel
with REF_ACCEL_FRAC
#define INT32_QUAT_WRAP_SHORTEST(q)
#define RATES_SUM(_c, _a, _b)
Definition: pprz_algebra.h:322
euler angles