39 #include "generated/airframe.h"
44 #if !defined(STABILIZATION_INDI_ACT_DYN_P) && !defined(STABILIZATION_INDI_ACT_DYN_Q) && !defined(STABILIZATION_INDI_ACT_DYN_R)
45 #error You have to define the first order time constant of the actuator dynamics!
50 #ifndef STABILIZATION_INDI_FILT_CUTOFF
51 #define STABILIZATION_INDI_FILT_CUTOFF 8.0
55 #ifndef STABILIZATION_INDI_FILT_CUTOFF_RDOT
56 #define STABILIZATION_INDI_FILT_CUTOFF_RDOT STABILIZATION_INDI_FILT_CUTOFF
59 #ifndef STABILIZATION_INDI_MAX_RATE
60 #define STABILIZATION_INDI_MAX_RATE 6.0
63 #if STABILIZATION_INDI_USE_ADAPTIVE
64 #warning "Use caution with adaptive indi. See the wiki for more info"
67 #ifndef STABILIZATION_INDI_MAX_R
68 #define STABILIZATION_INDI_MAX_R STABILIZATION_ATTITUDE_SP_MAX_R
71 #ifndef STABILIZATION_INDI_ESTIMATION_FILT_CUTOFF
72 #define STABILIZATION_INDI_ESTIMATION_FILT_CUTOFF 4.0
75 #ifdef STABILIZATION_INDI_FILT_CUTOFF_P
76 #define STABILIZATION_INDI_FILTER_ROLL_RATE TRUE
78 #define STABILIZATION_INDI_FILT_CUTOFF_P 20.0
81 #ifdef STABILIZATION_INDI_FILT_CUTOFF_Q
82 #define STABILIZATION_INDI_FILTER_PITCH_RATE TRUE
84 #define STABILIZATION_INDI_FILT_CUTOFF_Q 20.0
87 #ifdef STABILIZATION_INDI_FILT_CUTOFF_R
88 #define STABILIZATION_INDI_FILTER_YAW_RATE TRUE
90 #define STABILIZATION_INDI_FILT_CUTOFF_R 20.0
102 #define INDI_EST_SCALE 0.001
109 .g1 = {STABILIZATION_INDI_G1_P, STABILIZATION_INDI_G1_Q, STABILIZATION_INDI_G1_R},
110 .g2 = STABILIZATION_INDI_G2_R,
113 STABILIZATION_INDI_REF_ERR_P,
114 STABILIZATION_INDI_REF_ERR_Q,
115 STABILIZATION_INDI_REF_ERR_R
118 STABILIZATION_INDI_REF_RATE_P,
119 STABILIZATION_INDI_REF_RATE_Q,
120 STABILIZATION_INDI_REF_RATE_R
132 .mu = STABILIZATION_INDI_ADAPTIVE_MU,
135 #if STABILIZATION_INDI_USE_ADAPTIVE
142 #if PERIODIC_TELEMETRY
152 pprz_msg_send_STAB_ATTITUDE_INDI(trans,
dev, AC_ID,
168 pprz_msg_send_AHRS_REF_QUAT(trans,
dev, AC_ID,
185 #if PERIODIC_TELEMETRY
196 float tau_axis[3] = {tau, tau, tau_rdot};
198 float sample_time = 1.0 / PERIODIC_FREQUENCY;
200 for (
int8_t i = 0; i < 3; i++) {
217 float sample_time = 1.0 / PERIODIC_FREQUENCY;
304 for (
int8_t i = 0; i < 3; i++) {
305 output[i] = (filter[i].
o[0] - filter[i].
o[1]) * PERIODIC_FREQUENCY;
318 for (
int8_t i = 0; i < 3; i++) {
319 output[i] = (
new[i] - old[i])*PERIODIC_FREQUENCY;
349 #if STABILIZATION_INDI_FILTER_ROLL_RATE
352 rates_filt.
p = body_rates->
p;
354 #if STABILIZATION_INDI_FILTER_PITCH_RATE
357 rates_filt.
q = body_rates->
q;
359 #if STABILIZATION_INDI_FILTER_YAW_RATE
362 rates_filt.
r = body_rates->
r;
401 #if STABILIZATION_INDI_FULL_AUTHORITY
450 att_fb.
x = att_err.
qx;
451 att_fb.
y = att_err.
qy;
452 att_fb.
z = att_err.
qz;
473 #if USE_EARTH_BOUND_RC_SETPOINT
496 float rate_d_prev[3];
512 float error = (est->
g1.
r * du[2] + est->
g2 * ddu - est->
rate_dd[2]);
513 est->
g1.
r = est->
g1.
r - error * du[2] * est->
mu / 3;
514 est->
g2 = est->
g2 - error * 1000 * ddu * est->
mu / 3;
517 if (est->
g1.
p < 0.01) { est->
g1.
p = 0.01; }
518 if (est->
g1.
q < 0.01) { est->
g1.
q = 0.01; }
519 if (est->
g1.
r < 0.01) { est->
g1.
r = 0.01; }
520 if (est->
g2 < 0.01) { est->
g2 = 0.01; }
void float_quat_inv_comp_norm_shortest(struct FloatQuat *b2c, struct FloatQuat *a2b, struct FloatQuat *a2c)
Composition (multiplication) of two quaternions with normalization.
static void float_vect_scale(float *a, const float s, const int n)
a *= s
static void float_vect_copy(float *a, const float *b, const int n)
a = b
void float_quat_tilt_twist(struct FloatQuat *tilt, struct FloatQuat *twist, struct FloatQuat *quat)
Tilt twist decomposition of a quaternion (z axis)
#define FLOAT_RATES_ZERO(_r)
#define RATES_SMUL(_ro, _ri, _s)
#define QUAT_BFP_OF_REAL(_qi, _qf)
#define QUAT_FLOAT_OF_BFP(_qf, _qi)
int32_t phi
in rad with INT32_ANGLE_FRAC
int32_t psi
in rad with INT32_ANGLE_FRAC
int32_t theta
in rad with INT32_ANGLE_FRAC
void int32_quat_of_eulers(struct Int32Quat *q, struct Int32Eulers *e)
Quaternion from Euler angles.
static struct Int32Quat * stateGetNedToBodyQuat_i(void)
Get vehicle body attitude quaternion (int).
static struct Int32Eulers * stateGetNedToBodyEulers_i(void)
Get vehicle body attitude euler angles (int).
static struct FloatQuat * stateGetNedToBodyQuat_f(void)
Get vehicle body attitude quaternion (float).
static struct FloatRates * stateGetBodyRates_f(void)
Get vehicle body angular rate (float).
Simple first order low pass filter with bilinear transform.
static float update_first_order_low_pass(struct FirstOrderLowPass *filter, float value)
Update first order low pass filter state with a new value.
static void init_butterworth_2_low_pass(Butterworth2LowPass *filter, float tau, float sample_time, float value)
Init a second order Butterworth filter.
static void init_first_order_low_pass(struct FirstOrderLowPass *filter, float tau, float sample_time, float value)
Init first order low pass filter.
static float update_butterworth_2_low_pass(Butterworth2LowPass *filter, float value)
Update second order Butterworth low pass filter state with a new value.
First order low pass filter structure.
Second order low pass filter structure.
#define PPRZ_ITRIG_SIN(_s, _a)
#define PPRZ_ITRIG_COS(_c, _a)
Generic interface for radio control modules.
General attitude stabilization interface for rotorcrafts.
int32_t stabilization_cmd[COMMANDS_NB]
Stabilization commands.
int32_t stabilization_attitude_get_heading_i(void)
void stabilization_attitude_read_rc_setpoint_quat_earth_bound_f(struct FloatQuat *q_sp, bool in_flight, bool in_carefree, bool coordinated_turn)
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.
Read an attitude setpoint from the RC.
static void send_ahrs_ref_quat(struct transport_tx *trans, struct link_device *dev)
void stabilization_indi_read_rc(bool in_flight, bool in_carefree, bool coordinated_turn)
This function reads rc commands.
void stabilization_indi_enter(void)
Function that resets important values upon engaging INDI.
void stabilization_indi_set_failsafe_setpoint(void)
Function that calculates the failsafe setpoint.
static void finite_difference(float output[3], float new[3], float old[3])
Calculate derivative of an array via finite difference.
void stabilization_indi_attitude_run(struct Int32Quat quat_sp, bool in_flight)
runs stabilization indi
static struct FirstOrderLowPass rates_filt_fo[3]
#define STABILIZATION_INDI_ESTIMATION_FILT_CUTOFF
static void lms_estimation(void)
This is a Least Mean Squares adaptive filter It estimates the actuator effectiveness online,...
void stabilization_indi_set_earth_cmd_i(struct Int32Vect2 *cmd, int32_t heading)
Set attitude setpoint from command in earth axes.
#define STABILIZATION_INDI_FILT_CUTOFF_P
#define STABILIZATION_INDI_FILT_CUTOFF_Q
static void send_att_indi(struct transport_tx *trans, struct link_device *dev)
void stabilization_indi_simple_reset_r_filter_cutoff(float new_cutoff)
static void finite_difference_from_filter(float *output, Butterworth2LowPass *filter)
Caclulate finite difference form a filter array The filter already contains the previous values.
struct Int32Eulers stab_att_sp_euler
with INT32_ANGLE_FRAC
#define STABILIZATION_INDI_MAX_RATE
void stabilization_indi_rate_run(struct FloatRates rate_sp, bool in_flight)
Does the INDI calculations.
void stabilization_indi_init(void)
Function that initializes important values upon engaging INDI.
#define STABILIZATION_INDI_FILT_CUTOFF
void stabilization_indi_set_rpy_setpoint_i(struct Int32Eulers *rpy)
Set attitude quaternion setpoint from rpy.
struct IndiVariables indi
#define STABILIZATION_INDI_MAX_R
#define STABILIZATION_INDI_FILT_CUTOFF_R
static void filter_pqr(Butterworth2LowPass *filter, struct FloatRates *new_values)
Update butterworth filter for p, q and r of a FloatRates struct.
struct Int32Quat stab_att_sp_quat
with INT32_QUAT_FRAC
#define STABILIZATION_INDI_FILT_CUTOFF_RDOT
static void indi_init_filters(void)
Butterworth2LowPass rate[3]
struct IndiEstimation est
Estimation parameters for adaptive INDI.
struct FloatRates u_act_dyn
struct FloatRates angular_accel_ref
bool adaptive
Enable adataptive estimation.
float attitude_max_yaw_rate
Maximum yaw rate in atttiude control in rad/s.
Butterworth2LowPass rate[3]
API to get/set the generic vehicle states.
static const struct usb_device_descriptor dev
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
int int32_t
Typedef defining 32 bit int type.
signed char int8_t
Typedef defining 8 bit char type.