39 #include "generated/airframe.h"
43 #if !defined(STABILIZATION_INDI_ACT_DYN_P) && !defined(STABILIZATION_INDI_ACT_DYN_Q) && !defined(STABILIZATION_INDI_ACT_DYN_R)
44 #error You have to define the first order time constant of the actuator dynamics!
49 #ifndef STABILIZATION_INDI_FILT_OMEGA
50 #define STABILIZATION_INDI_FILT_OMEGA 50.0
53 #ifndef STABILIZATION_INDI_FILT_ZETA
54 #define STABILIZATION_INDI_FILT_ZETA 0.55
58 #ifndef STABILIZATION_INDI_FILT_OMEGA_R
59 #define STABILIZATION_INDI_FILT_OMEGA_R STABILIZATION_INDI_FILT_OMEGA
62 #ifndef STABILIZATION_INDI_FILT_ZETA_R
63 #define STABILIZATION_INDI_FILT_ZETA_R STABILIZATION_INDI_FILT_ZETA
66 #ifndef STABILIZATION_INDI_MAX_RATE
67 #define STABILIZATION_INDI_MAX_RATE 6.0
70 #if STABILIZATION_INDI_USE_ADAPTIVE
71 #warning "Use caution with adaptive indi. See the wiki for more info"
74 #ifndef STABILIZATION_INDI_MAX_R
75 #define STABILIZATION_INDI_MAX_R STABILIZATION_ATTITUDE_SP_MAX_R
87 #define INDI_EST_SCALE 0.001 //The G values are scaled to avoid numerical problems during the estimation
92 .g1 = {STABILIZATION_INDI_G1_P, STABILIZATION_INDI_G1_Q, STABILIZATION_INDI_G1_R},
93 .g2 = STABILIZATION_INDI_G2_R,
94 .reference_acceleration = {
95 STABILIZATION_INDI_REF_ERR_P,
96 STABILIZATION_INDI_REF_ERR_Q,
97 STABILIZATION_INDI_REF_ERR_R,
98 STABILIZATION_INDI_REF_RATE_P,
99 STABILIZATION_INDI_REF_RATE_Q,
100 STABILIZATION_INDI_REF_RATE_R},
109 .mu = STABILIZATION_INDI_ADAPTIVE_MU,
112 #if STABILIZATION_INDI_USE_ADAPTIVE
119 #if PERIODIC_TELEMETRY
129 pprz_msg_send_STAB_ATTITUDE_INDI(trans, dev, AC_ID,
151 #if PERIODIC_TELEMETRY
216 RATES_COPY(rates_for_feedback, (*body_rates));
220 #if STABILIZATION_INDI_FILTER_ROLL_RATE
221 rates_for_feedback.
p = indi.
rate.
x.
p;
223 #if STABILIZATION_INDI_FILTER_PITCH_RATE
224 rates_for_feedback.
q = indi.
rate.
x.
q;
226 #if STABILIZATION_INDI_FILTER_YAW_RATE
227 rates_for_feedback.
r = indi.
rate.
x.
r;
262 Bound(indi.
u_in.
p, -4500, 4500);
263 Bound(indi.
u_in.
q, -4500, 4500);
264 Bound(indi.
u_in.
r, -4500, 4500);
291 indi_commands[COMMAND_ROLL] = indi.
u_in.
p;
292 indi_commands[COMMAND_PITCH] = indi.
u_in.
q;
293 indi_commands[COMMAND_YAW] = indi.
u_in.
r;
324 #if USE_EARTH_BOUND_RC_SETPOINT
335 filter->
omega = omega;
336 filter->
omega2 = omega * omega;
370 float error = (est->
g1.
r * du + est->
g2 * ddu - est->
rate.
ddx.
r);
371 est->
g1.
r = est->
g1.
r - error * du * est->
mu / 3;
372 est->
g2 = est->
g2 - error * 1000 * ddu * est->
mu / 3;
375 if (est->
g1.
p < 0.01) { est->
g1.
p = 0.01; }
376 if (est->
g1.
q < 0.01) { est->
g1.
q = 0.01; }
377 if (est->
g1.
r < 0.01) { est->
g1.
r = 0.01; }
378 if (est->
g2 < 0.01) { est->
g2 = 0.01; }
int32_t psi
in rad with INT32_ANGLE_FRAC
void stabilization_indi_init(void)
void stabilization_attitude_read_rc_setpoint_quat_f(struct FloatQuat *q_sp, bool in_flight, bool in_carefree, bool coordinated_turn)
Read attitude setpoint from RC as quaternion Interprets the stick positions as axes.
static void int32_quat_normalize(struct Int32Quat *q)
normalize a quaternion inplace
void stabilization_indi_set_failsafe_setpoint(void)
void int32_quat_inv_comp(struct Int32Quat *b2c, struct Int32Quat *a2b, struct Int32Quat *a2c)
Composition (multiplication) of two quaternions.
static void stabilization_indi_calc_cmd(int32_t indi_commands[], struct Int32Quat *att_err, bool rate_control)
static void stabilization_indi_second_order_filter(struct IndiFilter *filter, struct FloatRates *input)
#define STABILIZATION_INDI_FILT_OMEGA
Periodic telemetry system header (includes downlink utility and generated code).
General attitude stabilization interface for rotorcrafts.
bool adaptive
Enable adataptive estimation.
#define STABILIZATION_INDI_FILT_ZETA
int32_t theta
in rad with INT32_ANGLE_FRAC
int32_t stabilization_attitude_get_heading_i(void)
#define STABILIZATION_INDI_MAX_RATE
Read an attitude setpoint from the RC.
static void lms_estimation(void)
#define FLOAT_RATES_ZERO(_r)
void stabilization_indi_set_rpy_setpoint_i(struct Int32Eulers *rpy)
float attitude_max_yaw_rate
Maximum yaw rate in atttiude control in rad/s.
struct FloatRates u_act_dyn
void stabilization_indi_enter(void)
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
static struct Int32Quat * stateGetNedToBodyQuat_i(void)
Get vehicle body attitude quaternion (int).
static const float omega_r[]
float max_rate
Maximum rate in rate control in rad/s.
#define STABILIZATION_INDI_MAX_R
void stabilization_attitude_read_rc_setpoint_quat_earth_bound_f(struct FloatQuat *q_sp, bool in_flight, bool in_carefree, bool coordinated_turn)
#define PPRZ_ITRIG_SIN(_s, _a)
struct IndiVariables indi
void float_rates_integrate_fi(struct FloatRates *r, struct FloatRates *dr, float dt)
in place first order integration of angular rates
void stabilization_indi_read_rc(bool in_flight, bool in_carefree, bool coordinated_turn)
struct ReferenceSystem reference_acceleration
#define QUAT_BFP_OF_REAL(_qi, _qf)
static int32_t stabilization_att_indi_cmd[COMMANDS_NB]
#define DefaultPeriodic
Set default periodic telemetry.
void stabilization_indi_run(bool enable_integrator, bool rate_control)
struct RadioControl radio_control
struct FloatRates angular_accel_ref
#define RATES_SMUL(_ro, _ri, _s)
static struct FloatRates * stateGetBodyRates_f(void)
Get vehicle body angular rate (float).
#define QUAT1_FLOAT_OF_BFP(_qi)
static const struct usb_device_descriptor dev
void stabilization_indi_set_earth_cmd_i(struct Int32Vect2 *cmd, int32_t heading)
int32_t phi
in rad with INT32_ANGLE_FRAC
API to get/set the generic vehicle states.
static void int32_quat_wrap_shortest(struct Int32Quat *q)
int32_t stabilization_cmd[COMMANDS_NB]
Stabilization commands.
static void send_att_indi(struct transport_tx *trans, struct link_device *dev)
static void stabilization_indi_second_order_filter_init(struct IndiFilter *filter, float omega, float zeta, float omega_r)
#define RATES_COPY(_a, _b)
static struct Int32Eulers * stateGetNedToBodyEulers_i(void)
Get vehicle body attitude euler angles (int).
#define STABILIZATION_INDI_FILT_OMEGA_R
struct IndiEstimation est
Estimation parameters for adaptive INDI.
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
struct Int32Quat stab_att_sp_quat
with INT32_QUAT_FRAC
struct Int32Eulers stab_att_sp_euler
with INT32_ANGLE_FRAC
#define PPRZ_ITRIG_COS(_c, _a)