38 #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 #warning STABILIZATION_INDI_ACT_DYN is deprecated, use STABILIZATION_INDI_ACT_FREQ instead.
45 #warning You now have to define the continuous time corner frequency in rad/s of the actuators.
46 #warning "Use -ln(1 - old_number) * PERIODIC_FREQUENCY to compute it from the old values."
48 #if !defined(STABILIZATION_INDI_ACT_FREQ_P) && !defined(STABILIZATION_INDI_ACT_FREQ_Q) && !defined(STABILIZATION_INDI_ACT_FREQ_R)
49 #warning You have to define the corner frequency of the first order actuator dynamics model in rad/s!
55 #ifndef STABILIZATION_INDI_FILT_CUTOFF
56 #define STABILIZATION_INDI_FILT_CUTOFF 8.0
60 #ifndef STABILIZATION_INDI_FILT_CUTOFF_RDOT
61 #define STABILIZATION_INDI_FILT_CUTOFF_RDOT STABILIZATION_INDI_FILT_CUTOFF
64 #ifndef STABILIZATION_INDI_MAX_RATE
65 #define STABILIZATION_INDI_MAX_RATE 6.0
68 #if STABILIZATION_INDI_USE_ADAPTIVE
69 #warning "Use caution with adaptive indi. See the wiki for more info"
72 #ifndef STABILIZATION_INDI_MAX_R
73 #define STABILIZATION_INDI_MAX_R STABILIZATION_ATTITUDE_SP_MAX_R
76 #ifndef STABILIZATION_INDI_ESTIMATION_FILT_CUTOFF
77 #define STABILIZATION_INDI_ESTIMATION_FILT_CUTOFF 4.0
80 #ifdef STABILIZATION_INDI_FILT_CUTOFF_P
81 #define STABILIZATION_INDI_FILTER_ROLL_RATE TRUE
83 #define STABILIZATION_INDI_FILT_CUTOFF_P 20.0
86 #ifdef STABILIZATION_INDI_FILT_CUTOFF_Q
87 #define STABILIZATION_INDI_FILTER_PITCH_RATE TRUE
89 #define STABILIZATION_INDI_FILT_CUTOFF_Q 20.0
92 #ifdef STABILIZATION_INDI_FILT_CUTOFF_R
93 #define STABILIZATION_INDI_FILTER_YAW_RATE TRUE
95 #define STABILIZATION_INDI_FILT_CUTOFF_R 20.0
107 #define INDI_EST_SCALE 0.001
114 .g1 = {STABILIZATION_INDI_G1_P, STABILIZATION_INDI_G1_Q, STABILIZATION_INDI_G1_R},
115 .g2 = STABILIZATION_INDI_G2_R,
118 STABILIZATION_INDI_REF_ERR_P,
119 STABILIZATION_INDI_REF_ERR_Q,
120 STABILIZATION_INDI_REF_ERR_R
123 STABILIZATION_INDI_REF_RATE_P,
124 STABILIZATION_INDI_REF_RATE_Q,
125 STABILIZATION_INDI_REF_RATE_R
137 .mu = STABILIZATION_INDI_ADAPTIVE_MU,
140 #if STABILIZATION_INDI_USE_ADAPTIVE
147 #if PERIODIC_TELEMETRY
155 pprz_msg_send_STAB_ATTITUDE(trans,
dev, AC_ID,
162 3, temp_indi_ang_acc_ref,
173 pprz_msg_send_EFF_MAT_STAB(trans,
dev, AC_ID,
184 pprz_msg_send_AHRS_REF_QUAT(trans,
dev, AC_ID,
201 #ifdef STABILIZATION_INDI_ACT_FREQ_P
202 indi.
act_dyn.
p = 1-exp(-STABILIZATION_INDI_ACT_FREQ_P/PERIODIC_FREQUENCY);
203 indi.
act_dyn.
q = 1-exp(-STABILIZATION_INDI_ACT_FREQ_Q/PERIODIC_FREQUENCY);
204 indi.
act_dyn.
r = 1-exp(-STABILIZATION_INDI_ACT_FREQ_R/PERIODIC_FREQUENCY);
211 #if PERIODIC_TELEMETRY
223 float tau_axis[3] = {tau, tau, tau_rdot};
225 float sample_time = 1.0 / PERIODIC_FREQUENCY;
227 for (
int8_t i = 0; i < 3; i++) {
244 float sample_time = 1.0 / PERIODIC_FREQUENCY;
285 for (
int8_t i = 0; i < 3; i++) {
286 output[i] = (filter[i].
o[0] - filter[i].
o[1]) * PERIODIC_FREQUENCY;
299 for (
int8_t i = 0; i < 3; i++) {
300 output[i] = (
new[i] - old[i])*PERIODIC_FREQUENCY;
333 #if STABILIZATION_INDI_FILTER_ROLL_RATE
336 rates_filt.
p = body_rates->
p;
338 #if STABILIZATION_INDI_FILTER_PITCH_RATE
341 rates_filt.
q = body_rates->
q;
343 #if STABILIZATION_INDI_FILTER_YAW_RATE
346 rates_filt.
r = body_rates->
r;
386 #if STABILIZATION_INDI_FULL_AUTHORITY
405 BoundAbs(cmd[COMMAND_ROLL],
MAX_PPRZ);
406 BoundAbs(cmd[COMMAND_PITCH],
MAX_PPRZ);
407 BoundAbs(cmd[COMMAND_YAW],
MAX_PPRZ);
408 BoundAbs(cmd[COMMAND_THRUST],
MAX_PPRZ);
438 att_fb.
x = att_err.
qx;
439 att_fb.
y = att_err.
qy;
440 att_fb.
z = att_err.
qz;
473 float rate_d_prev[3];
489 float error = (est->
g1.
r * du[2] + est->
g2 * ddu - est->
rate_dd[2]);
490 est->
g1.
r = est->
g1.
r - error * du[2] * est->
mu / 3;
491 est->
g2 = est->
g2 - error * 1000 * ddu * est->
mu / 3;
494 if (est->
g1.
p < 0.01) { est->
g1.
p = 0.01; }
495 if (est->
g1.
q < 0.01) { est->
g1.
q = 0.01; }
496 if (est->
g1.
r < 0.01) { est->
g1.
r = 0.01; }
497 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 RATES_ADD(_a, _b)
int32_t psi
in rad with INT32_ANGLE_FRAC
static struct Int32Quat * stateGetNedToBodyQuat_i(void)
Get vehicle body attitude quaternion (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.
Generic interface for radio control modules.
struct FloatRates stab_sp_to_rates_f(struct StabilizationSetpoint *sp)
struct Int32Quat stab_sp_to_quat_i(struct StabilizationSetpoint *sp)
struct Int32Eulers stab_sp_to_eulers_i(struct StabilizationSetpoint *sp)
struct StabilizationSetpoint stab_sp_from_rates_f(struct FloatRates *rates)
struct FloatQuat stab_sp_to_quat_f(struct StabilizationSetpoint *sp)
int32_t th_sp_to_thrust_i(struct ThrustSetpoint *th, int32_t thrust, uint8_t axis)
int32_t stabilization_attitude_get_heading_i(void)
Get attitude heading as int (avoiding jumps)
Read an attitude setpoint from the RC.
static void send_ahrs_ref_quat(struct transport_tx *trans, struct link_device *dev)
void stabilization_indi_enter(void)
Function that resets important values upon engaging INDI.
static void finite_difference(float output[3], float new[3], float old[3])
Calculate derivative of an array via finite difference.
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,...
#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
#define STABILIZATION_INDI_MAX_RATE
static void send_eff_mat_g_indi_simple(struct transport_tx *trans, struct link_device *dev)
void stabilization_indi_init(void)
Function that initializes important values upon engaging INDI.
#define STABILIZATION_INDI_FILT_CUTOFF
void stabilization_indi_attitude_run(bool in_flight, struct StabilizationSetpoint *att_sp, struct ThrustSetpoint *thrust, int32_t *cmd)
runs stabilization indi
void stabilization_indi_rate_run(bool in_flight, struct StabilizationSetpoint *sp, struct ThrustSetpoint *thrust, int32_t *cmd)
Does the INDI calculations.
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
#define STABILIZATION_INDI_FILT_CUTOFF_RDOT
static void indi_init_filters(void)
Butterworth2LowPass rate[3]
struct FloatRates act_dyn
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
union StabilizationSetpoint::@278 sp
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.
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.