Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
stabilization_rate.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2008-2009 Antoine Drouin <poinix@gmail.com>
3 * Copyright (C) 2010 Felix Ruess <felix.ruess@gmail.com>
4 *
5 * This file is part of paparazzi.
6 *
7 * paparazzi is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * paparazzi is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with paparazzi; see the file COPYING. If not, write to
19 * the Free Software Foundation, 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 */
22
29#include "generated/airframe.h"
30
33
34#include "state.h"
35
36#include "modules/imu/imu.h"
39
40#define MAX_SUM_ERR 40000
41
42#ifndef STABILIZATION_RATE_IGAIN_P
43#define STABILIZATION_RATE_IGAIN_P 0
44#endif
45
46#ifndef STABILIZATION_RATE_IGAIN_Q
47#define STABILIZATION_RATE_IGAIN_Q 0
48#endif
49
50#ifndef STABILIZATION_RATE_IGAIN_R
51#define STABILIZATION_RATE_IGAIN_R 0
52#endif
53
54#if (STABILIZATION_RATE_GAIN_P < 0) || \
55 (STABILIZATION_RATE_GAIN_Q < 0) || \
56 (STABILIZATION_RATE_GAIN_R < 0) || \
57 (STABILIZATION_RATE_IGAIN_P < 0) || \
58 (STABILIZATION_RATE_IGAIN_Q < 0) || \
59 (STABILIZATION_RATE_IGAIN_R < 0)
60#error "ALL control gains have to be positive!!!"
61#endif
62
63// divide by 2^_b and round instead of floor
64#define OFFSET_AND_ROUND(_a, _b) (((_a)+(1<<((_b)-1)))>>(_b))
65#define OFFSET_AND_ROUND2(_a, _b) (((_a)+(1<<((_b)-1))-((_a)<0?1:0))>>(_b))
66
72
73#if PERIODIC_TELEMETRY
75
90#endif
91
112
117
118void stabilization_rate_run(bool in_flight, struct StabilizationSetpoint *rate_sp, struct ThrustSetpoint *thrust, int32_t *cmd)
119{
120 /* compute feed-back command */
121 struct FloatRates _error;
122 struct FloatRates *body_rate = stateGetBodyRates_f();
125 if (in_flight) {
126 /* update integrator */
127 //divide the sum_err_increment to make sure it doesn't accumulate to the max too fast
132 } else {
134 }
135
136 /* PI */
139
142
145
150
151 /* bound the result */
156}
157
173
float q
in rad/s
float p
in rad/s
float r
in rad/s
#define FLOAT_RATES_ZERO(_r)
angular rates
#define RATES_ASSIGN(_ra, _p, _q, _r)
#define RATES_ADD(_a, _b)
#define RATES_DIFF(_c, _a, _b)
#define RATES_BOUND_CUBE(_v, _min, _max)
#define RATES_SDIV(_ro, _ri, _s)
static struct FloatRates * stateGetBodyRates_f(void)
Get vehicle body angular rate (float).
Definition state.h:1367
Inertial Measurement Unit interface.
uint16_t foo
Definition main_demo5.c:58
#define MAX_PPRZ
Definition paparazzi.h:8
Generic interface for radio control modules.
Some helper functions to check RC sticks.
#define THROTTLE_STICK_DOWN_FROM_RC(_rc)
struct Stabilization stabilization
struct FloatRates stab_sp_to_rates_f(struct StabilizationSetpoint *sp)
struct StabilizationSetpoint stab_sp_from_rates_f(struct FloatRates *rates)
int32_t th_sp_to_thrust_i(struct ThrustSetpoint *th, int32_t thrust, uint8_t axis)
General stabilization interface for rotorcrafts.
#define THRUST_AXIS_Z
int32_t cmd[COMMANDS_NB]
output command vector, range from [-MAX_PPRZ:MAX_PPRZ] (store for messages)
#define STABILIZATION_RATE_IGAIN_P
static struct FloatRates stabilization_rate_fb_cmd
void stabilization_rate_enter(void)
struct StabilizationSetpoint stabilization_rate_read_rc(struct RadioControl *rc)
#define STABILIZATION_RATE_IGAIN_R
#define STABILIZATION_RATE_IGAIN_Q
#define MAX_SUM_ERR
void stabilization_rate_run(bool in_flight, struct StabilizationSetpoint *rate_sp, struct ThrustSetpoint *thrust, int32_t *cmd)
struct FloatRates stabilization_rate_igain
struct FloatRates stabilization_rate_gain
static void send_rate(struct transport_tx *trans, struct link_device *dev)
static struct FloatRates stabilization_rate_sp
static struct FloatRates stabilization_rate_sum_err
void stabilization_rate_init(void)
Rate stabilization for rotorcrafts.
#define RC_RATE_R
#define RC_RATE_Q
#define YAW_RATE_DEADBAND_EXCEEDED(_rc)
#define RC_RATE_P
#define ROLL_RATE_DEADBAND_EXCEEDED(_rc)
#define PITCH_RATE_DEADBAND_EXCEEDED(_rc)
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.