37 #include "generated/airframe.h"
40 #if !defined(STABILIZATION_INDI_ACT_DYN_P) && !defined(STABILIZATION_INDI_ACT_DYN_Q) && !defined(STABILIZATION_INDI_ACT_DYN_R)
41 #error You have to define the first order time constant of the actuator dynamics!
46 struct FloatRates g1 = {STABILIZATION_INDI_G1_P, STABILIZATION_INDI_G1_Q, STABILIZATION_INDI_G1_R};
47 float g2 = STABILIZATION_INDI_G2_R;
49 STABILIZATION_INDI_REF_ERR_Q,
50 STABILIZATION_INDI_REF_ERR_R,
51 STABILIZATION_INDI_REF_RATE_P,
52 STABILIZATION_INDI_REF_RATE_Q,
53 STABILIZATION_INDI_REF_RATE_R,
79 #define INDI_EST_SCALE 0.001 //The G values are scaled to avoid numerical problems during the estimation
82 float mu = STABILIZATION_INDI_ADAPTIVE_MU;
84 #if STABILIZATION_INDI_USE_ADAPTIVE
85 #warning "Use caution with adaptive indi. See the wiki for more info"
91 #ifndef STABILIZATION_INDI_FILT_OMEGA
92 #define STABILIZATION_INDI_FILT_OMEGA 50.0
95 #ifndef STABILIZATION_INDI_FILT_ZETA
96 #define STABILIZATION_INDI_FILT_ZETA 0.55
99 #define STABILIZATION_INDI_FILT_OMEGA2 (STABILIZATION_INDI_FILT_OMEGA*STABILIZATION_INDI_FILT_OMEGA)
101 #ifndef STABILIZATION_INDI_FILT_OMEGA_R
102 #define STABILIZATION_INDI_FILT_OMEGA_R STABILIZATION_INDI_FILT_OMEGA
103 #define STABILIZATION_INDI_FILT_ZETA_R STABILIZATION_INDI_FILT_ZETA
106 #define STABILIZATION_INDI_FILT_OMEGA2_R (STABILIZATION_INDI_FILT_OMEGA_R*STABILIZATION_INDI_FILT_OMEGA_R)
108 #if PERIODIC_TELEMETRY
118 pprz_msg_send_STAB_ATTITUDE_INDI(trans, dev, AC_ID,
135 #if PERIODIC_TELEMETRY
198 #if STABILIZATION_INDI_FILTER_ROLL_RATE
203 - reference_acceleration.
rate_p * body_rate->
p;
205 #if STABILIZATION_INDI_FILTER_PITCH_RATE
210 - reference_acceleration.
rate_q * body_rate->
q;
212 #if STABILIZATION_INDI_FILTER_YAW_RATE
217 - reference_acceleration.
rate_r * body_rate->
r;
234 Bound(indi.
u_in.
p, -4500, 4500);
235 Bound(indi.
u_in.
q, -4500, 4500);
236 Bound(indi.
u_in.
r, -4500, 4500);
261 indi_commands[COMMAND_ROLL] = indi.
u_in.
p;
262 indi_commands[COMMAND_PITCH] = indi.
u_in.
q;
263 indi_commands[COMMAND_YAW] = indi.
u_in.
r;
300 #if USE_EARTH_BOUND_RC_SETPOINT
314 float omega2 = omega * omega;
315 float omega2_r = omega_r *
omega_r;
317 filter_ddx->
p = -filter_dx->
p * 2 * zeta * omega + (input->
p - filter_x->
p) * omega2; \
318 filter_ddx->q = -filter_dx->
q * 2 * zeta * omega + (input->
q - filter_x->
q) * omega2; \
319 filter_ddx->r = -filter_dx->
r * 2 * zeta * omega_r + (input->
r - filter_x->
r) * omega2_r;
334 &filtered_rate_estimation, omega, zeta, omega);
338 g_est.
p = g_est.
p - (g_est.
p * du - filtered_rate_2deriv_estimation.
p) * du *
mu;
340 g_est.
q = g_est.
q - (g_est.
q * du - filtered_rate_2deriv_estimation.
q) * du *
mu;
343 float error = (g_est.
r * du +
g2_est * ddu - filtered_rate_2deriv_estimation.
r);
344 g_est.
r = g_est.
r - error * du *
mu / 3;
348 if (g_est.
p < 0.01) { g_est.
p = 0.01; }
349 if (g_est.
q < 0.01) { g_est.
q = 0.01; }
350 if (g_est.
r < 0.01) { g_est.
r = 0.01; }
int32_t psi
in rad with INT32_ANGLE_FRAC
void stabilization_indi_second_order_filter(struct FloatRates *input, struct FloatRates *filter_ddx, struct FloatRates *filter_dx, struct FloatRates *filter_x, float omega, float zeta, float omega_r)
static void int32_quat_normalize(struct Int32Quat *q)
normalize a quaternion inplace
struct FloatRates udotdot_estimation
void int32_quat_inv_comp(struct Int32Quat *b2c, struct Int32Quat *a2b, struct Int32Quat *a2c)
Composition (multiplication) of two quaternions.
Generic transmission transport header.
struct FloatRates udot_estimation
Periodic telemetry system header (includes downlink utility and generated code).
General attitude stabilization interface for rotorcrafts.
int32_t theta
in rad with INT32_ANGLE_FRAC
void int32_quat_of_eulers(struct Int32Quat *q, struct Int32Eulers *e)
Quaternion from Euler angles.
int32_t stabilization_attitude_get_heading_i(void)
Read an attitude setpoint from the RC.
void stabilization_attitude_read_rc(bool_t in_flight, bool_t in_carefree, bool_t coordinated_turn)
int32_t stabilization_att_indi_cmd[COMMANDS_NB]
#define FLOAT_RATES_ZERO(_r)
static struct Int32Quat * stateGetNedToBodyQuat_i(void)
Get vehicle body attitude quaternion (int).
#define STABILIZATION_INDI_FILT_OMEGA
void stabilization_attitude_set_rpy_setpoint_i(struct Int32Eulers *rpy)
static const float omega_r[]
struct FloatRates indi_u_estimation
void stabilization_attitude_init(void)
struct FloatRates angular_accel_ref
#define PPRZ_ITRIG_SIN(_s, _a)
struct Int32Eulers stab_att_sp_euler
with INT32_ANGLE_FRAC
#define STABILIZATION_INDI_FILT_OMEGA_R
void stabilization_attitude_set_failsafe_setpoint(void)
void float_rates_integrate_fi(struct FloatRates *r, struct FloatRates *dr, float dt)
in place first order integration of angular rates
#define QUAT_BFP_OF_REAL(_qi, _qf)
struct FloatRates udotdot
struct FloatRates u_act_dyn
#define DefaultPeriodic
Set default periodic telemetry.
struct ReferenceSystem reference_acceleration
struct FloatRates filtered_rate_deriv_estimation
struct FloatRates filtered_rate
#define RATES_SMUL(_ro, _ri, _s)
struct FloatRates filtered_rate_estimation
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
int32_t phi
in rad with INT32_ANGLE_FRAC
API to get/set the generic vehicle states.
void stabilization_attitude_read_rc_setpoint_quat_f(struct FloatQuat *q_sp, bool_t in_flight, bool_t in_carefree, bool_t coordinated_turn)
Read attitude setpoint from RC as quaternion Interprets the stick positions as axes.
#define STABILIZATION_INDI_FILT_ZETA
static void int32_quat_wrap_shortest(struct Int32Quat *q)
int32_t stabilization_cmd[COMMANDS_NB]
Stabilization commands.
void stabilization_attitude_enter(void)
#define PERIODIC_FREQUENCY
void stabilization_attitude_run(bool_t enable_integrator)
struct FloatRates filtered_rate_deriv
Butterworth2LowPass_int filter_x
struct IndiVariables indi
struct FloatRates filtered_rate_2deriv_estimation
static struct Int32Eulers * stateGetNedToBodyEulers_i(void)
Get vehicle body attitude euler angles (int).
void stabilization_attitude_read_rc_setpoint_quat_earth_bound_f(struct FloatQuat *q_sp, bool_t in_flight, bool_t in_carefree, bool_t coordinated_turn)
void lms_estimation(void)
static void attitude_run_indi(int32_t indi_commands[], struct Int32Quat *att_err, bool_t in_flight)
struct FloatRates filtered_rate_2deriv
void stabilization_attitude_set_earth_cmd_i(struct Int32Vect2 *cmd, int32_t heading)
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
#define PPRZ_ITRIG_COS(_c, _a)
struct Int32Quat stab_att_sp_quat
with INT32_QUAT_FRAC