Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
stabilization_attitude_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#include "std.h"
29#include "generated/airframe.h"
30
33#include "paparazzi.h"
34#include "state.h"
35
37#ifndef USE_ATTITUDE_REF
38#define USE_ATTITUDE_REF 1
39#endif
40
42#ifndef STABILIZATION_ATTITUDE_PHI_FFDGAIN
43#define STABILIZATION_ATTITUDE_PHI_FFDGAIN 0
44#endif
45#ifndef STABILIZATION_ATTITUDE_THETA_FFDGAIN
46#define STABILIZATION_ATTITUDE_THETA_FFDGAIN 0
47#endif
48#ifndef STABILIZATION_ATTITUDE_PSI_FFDGAIN
49#define STABILIZATION_ATTITUDE_PSI_FFDGAIN 0
50#endif
51
53
54/* warn if some gains are still negative */
55#if (STABILIZATION_ATTITUDE_PHI_PGAIN < 0) || \
56 (STABILIZATION_ATTITUDE_THETA_PGAIN < 0) || \
57 (STABILIZATION_ATTITUDE_PSI_PGAIN < 0) || \
58 (STABILIZATION_ATTITUDE_PHI_DGAIN < 0) || \
59 (STABILIZATION_ATTITUDE_THETA_DGAIN < 0) || \
60 (STABILIZATION_ATTITUDE_PSI_DGAIN < 0) || \
61 (STABILIZATION_ATTITUDE_PHI_IGAIN < 0) || \
62 (STABILIZATION_ATTITUDE_THETA_IGAIN < 0) || \
63 (STABILIZATION_ATTITUDE_PSI_IGAIN < 0)
64#error "ALL control gains have to be positive!!!"
65#endif
66
68
71
74
75static inline void reset_psi_ref_from_body(void)
76{
77 //sp has been set from body using stabilization_attitude_get_yaw_i, use that value
81}
82
83#if PERIODIC_TELEMETRY
85
109
126#endif
127
168
174
175#define OFFSET_AND_ROUND(_a, _b) (((_a)+(1<<((_b)-1)))>>(_b))
176#define OFFSET_AND_ROUND2(_a, _b) (((_a)+(1<<((_b)-1))-((_a)<0?1:0))>>(_b))
177
178#define MAX_SUM_ERR 4000000
179
180void stabilization_attitude_run(bool in_flight, struct StabilizationSetpoint *sp, struct ThrustSetpoint *thrust, int32_t *cmd)
181{
183
184 /* update reference */
185#if USE_ATTITUDE_REF
187#else
191#endif
192
193 const struct Int32Eulers att_ref_scaled = {
197 };
198 const struct Int32Rates rate_ref_scaled = {
202 };
203
204 /* compute feedforward command */
214
215 /* with FFD gain of 100, reference rate of 180deg/s (3.14 rad/s)
216 * INT32_RATE_FRAC = 12, CMD_SHIFT = 11
217 * fb cmd: 100 * 3.14 * 2^INT32_RATE_FRAC / 2^CMD_SHIFT = 628
218 * max possible command is 9600
219 */
220
221 /* compute feedback command */
222 /* attitude error */
223 struct Int32Eulers att_err;
224 struct Int32Eulers *ltp_to_body_euler = stateGetNedToBodyEulers_i();
225 EULERS_DIFF(att_err, att_ref_scaled, (*ltp_to_body_euler));
227
228 if (in_flight) {
229 /* update integrator */
232 } else {
234 }
235
236 /* rate error */
237 struct Int32Rates rate_err;
238 struct Int32Rates *body_rate = stateGetBodyRates_i();
239 RATES_DIFF(rate_err, rate_ref_scaled, (*body_rate));
240
241 /* PID */
246
251
256
257
258 /* with P gain of 100, att_err of 180deg (3.14 rad)
259 * fb cmd: 100 * 3.14 * 2^12 / 2^CMD_SHIFT = 628
260 * max possible command is 9600
261 */
262#define CMD_SHIFT 11
263
264 /* sum feedforward and feedback */
265 cmd[COMMAND_ROLL] =
267
268 cmd[COMMAND_PITCH] =
270
271 cmd[COMMAND_YAW] =
273
275
276 /* bound the result */
281
282}
#define EULERS_BOUND_CUBE(_v, _min, _max)
#define EULERS_DIFF(_c, _a, _b)
#define VECT3_ASSIGN(_a, _x, _y, _z)
#define EULERS_ADD(_a, _b)
#define RATES_DIFF(_c, _a, _b)
int32_t p
in rad/s with INT32_RATE_FRAC
int32_t r
in rad/s with INT32_RATE_FRAC
int32_t phi
in rad with INT32_ANGLE_FRAC
int32_t q
in rad/s with INT32_RATE_FRAC
int32_t psi
in rad with INT32_ANGLE_FRAC
int32_t theta
in rad with INT32_ANGLE_FRAC
#define INT_RATES_ZERO(_e)
#define INT32_ANGLE_FRAC
#define INT32_EULERS_LSHIFT(_o, _i, _r)
#define INT32_RATE_FRAC
#define INT_EULERS_ZERO(_e)
#define INT32_ANGLE_NORMALIZE(_a)
euler angles
angular rates
static struct Int32Eulers * stateGetNedToBodyEulers_i(void)
Get vehicle body attitude euler angles (int).
Definition state.h:1288
static struct Int32Rates * stateGetBodyRates_i(void)
Get vehicle body angular rate (int).
Definition state.h:1358
uint16_t foo
Definition main_demo5.c:58
#define MAX_PPRZ
Definition paparazzi.h:8
struct Stabilization stabilization
struct Int32Eulers stab_sp_to_eulers_i(struct StabilizationSetpoint *sp)
int32_t th_sp_to_thrust_i(struct ThrustSetpoint *th, int32_t thrust, uint8_t axis)
#define THRUST_AXIS_Z
int32_t cmd[COMMANDS_NB]
output command vector, range from [-MAX_PPRZ:MAX_PPRZ] (store for messages)
void stabilization_attitude_run(bool in_flight, struct StabilizationSetpoint *sp, struct ThrustSetpoint *thrust, int32_t *cmd)
Attitude control run function.
#define OFFSET_AND_ROUND2(_a, _b)
void stabilization_attitude_enter(void)
Attitude control enter function.
int32_t stabilization_att_ff_cmd[COMMANDS_NB]
static void send_att_ref(struct transport_tx *trans, struct link_device *dev)
#define STABILIZATION_ATTITUDE_PSI_FFDGAIN
#define OFFSET_AND_ROUND(_a, _b)
static struct Int32Eulers stab_att_sp_euler
static void reset_psi_ref_from_body(void)
struct Int32AttitudeGains stabilization_gains
#define CMD_SHIFT
struct Int32Eulers stabilization_att_sum_err
int32_t stabilization_att_fb_cmd[COMMANDS_NB]
#define STABILIZATION_ATTITUDE_THETA_FFDGAIN
void stabilization_attitude_euler_int_init(void)
#define STABILIZATION_ATTITUDE_PHI_FFDGAIN
explicitly define to zero to disable feed-forward rate term by default
static struct AttRefEulerInt att_ref_euler_i
static void send_att(struct transport_tx *trans, struct link_device *dev)
void attitude_ref_euler_int_update(struct AttRefEulerInt *ref, struct Int32Eulers *sp_euler)
Propagate reference model.
void attitude_ref_euler_int_init(struct AttRefEulerInt *ref)
Rotorcraft attitude reference generation (euler int version)
struct Int32Rates accel
with REF_ACCEL_FRAC
struct Int32Rates rate
with REF_RATE_FRAC
struct Int32Eulers euler
with REF_ANGLE_FRAC
Attitude reference models and state/output (euler int)
#define REF_RATE_FRAC
#define REF_ANGLE_FRAC
API to get/set the generic vehicle states.
static const struct usb_device_descriptor dev
Definition usb_ser_hw.c:74
Stabilization setpoint.
Thrust setpoint // TODO to a setpoint header Structure to store the desired thrust vector with differ...
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition telemetry.c:51
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
Definition telemetry.h:66
int int32_t
Typedef defining 32 bit int type.