Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
stabilization_indi.c File Reference
+ Include dependency graph for stabilization_indi.c:

Go to the source code of this file.

Macros

#define INDI_ALLOWED_G_FACTOR   2.0
 
#define STABILIZATION_INDI_FILT_CUTOFF_P   20.0
 
#define STABILIZATION_INDI_FILT_CUTOFF_Q   20.0
 
#define STABILIZATION_INDI_FILT_CUTOFF_R   20.0
 
#define STABILIZATION_INDI_ALLOCATION_PSEUDO_INVERSE   FALSE
 
#define STABILIZATION_INDI_FILTER_RATES_SECOND_ORDER   FALSE
 
#define STABILIZATION_INDI_THROTTLE_LIMIT_AIRSPEED_FWD   8.0
 

Functions

static void lms_estimation (void)
 Function that estimates the control effectiveness of each actuator online. More...
 
static void get_actuator_state (void)
 Function that tries to get actuator feedback. More...
 
static void calc_g1_element (float dx_error, int8_t i, int8_t j, float mu_extra)
 
static void calc_g2_element (float dx_error, int8_t j, float mu_extra)
 
static void bound_g_mat (void)
 
void init_filters (void)
 Function that resets the filters to zeros. More...
 
void sum_g1_g2 (void)
 Function that sums g1 and g2 to obtain the g1g2 matrix It also undoes the scaling that was done to make the values readable. More...
 
static void send_wls_v_stab (struct transport_tx *trans, struct link_device *dev)
 
static void send_wls_u_stab (struct transport_tx *trans, struct link_device *dev)
 
static void send_eff_mat_g_indi (struct transport_tx *trans, struct link_device *dev)
 
static void send_ahrs_ref_quat (struct transport_tx *trans, struct link_device *dev)
 
static void send_att_full_indi (struct transport_tx *trans, struct link_device *dev)
 
void stabilization_indi_init (void)
 Function that initializes important values upon engaging INDI. More...
 
void stabilization_indi_enter (void)
 Function that resets important values upon engaging INDI. More...
 
void stabilization_indi_update_filt_freq (float freq)
 
void stabilization_indi_rate_run (bool in_flight, struct StabilizationSetpoint *sp, struct ThrustSetpoint *thrust, int32_t *cmd)
 
void WEAK stabilization_indi_set_wls_settings (void)
 Function that sets the u_min, u_max and u_pref if function not elsewhere defined. More...
 
void stabilization_indi_attitude_run (bool in_flight, struct StabilizationSetpoint *att_sp, struct ThrustSetpoint *thrust, int32_t *cmd)
 

Variables

struct WLS_t wls_stab_p
 
float indi_v [INDI_OUTPUTS]
 
float * Bwls [INDI_OUTPUTS]
 
int32_t stabilization_att_indi_cmd [COMMANDS_NB]
 
struct Indi_gains indi_gains
 
bool indi_use_adaptive = false
 
bool act_is_servo [INDI_NUM_ACT] = {0}
 
bool act_is_thruster_x [INDI_NUM_ACT] = {0}
 
bool act_is_thruster_z [INDI_NUM_ACT]
 
float act_pref [INDI_NUM_ACT] = {0.0}
 
float act_first_order_cutoff [INDI_NUM_ACT] = STABILIZATION_INDI_ACT_FREQ
 
float act_dyn_discrete [INDI_NUM_ACT]
 
float stablization_indi_yaw_dist_limit = 99999.f
 Limit the maximum specific moment that can be compensated (units rad/s^2) More...
 
float actuator_state_filt_vect [INDI_NUM_ACT]
 
struct FloatRates angular_accel_ref = {0., 0., 0.}
 
struct FloatRates angular_rate_ref = {0., 0., 0.}
 
float angular_acceleration [3] = {0., 0., 0.}
 
float actuator_state [INDI_NUM_ACT]
 
float indi_u [INDI_NUM_ACT]
 
float q_filt = 0.0
 
float r_filt = 0.0
 
float stabilization_indi_filter_freq = 20.0
 
float g1g2_trans_mult [INDI_OUTPUTS][INDI_OUTPUTS]
 
float g1g2inv [INDI_OUTPUTS][INDI_OUTPUTS]
 
float actuator_state_filt_vectd [INDI_NUM_ACT]
 
float actuator_state_filt_vectdd [INDI_NUM_ACT]
 
float estimation_rate_d [INDI_NUM_ACT]
 
float estimation_rate_dd [INDI_NUM_ACT]
 
float du_estimation [INDI_NUM_ACT]
 
float ddu_estimation [INDI_NUM_ACT]
 
float mu1 [INDI_OUTPUTS] = {0.00001, 0.00001, 0.000003, 0.000002}
 
float mu2 = 0.002
 
float act_obs [INDI_NUM_ACT]
 
int32_t num_thrusters
 
int32_t num_thrusters_x
 
static struct Int32Eulers stab_att_sp_euler
 
static struct Int32Quat stab_att_sp_quat
 
float g1g2_pseudo_inv [INDI_NUM_ACT][INDI_OUTPUTS]
 
float g2 [INDI_NUM_ACT] = STABILIZATION_INDI_G2
 
float g1 [INDI_OUTPUTS][INDI_NUM_ACT]
 
float g1g2 [INDI_OUTPUTS][INDI_NUM_ACT]
 
float g1_est [INDI_OUTPUTS][INDI_NUM_ACT]
 
float g2_est [INDI_NUM_ACT]
 
float g1_init [INDI_OUTPUTS][INDI_NUM_ACT]
 
float g2_init [INDI_NUM_ACT]
 
Butterworth2LowPass actuator_lowpass_filters [INDI_NUM_ACT]
 
Butterworth2LowPass estimation_input_lowpass_filters [INDI_NUM_ACT]
 
Butterworth2LowPass measurement_lowpass_filters [3]
 
Butterworth2LowPass estimation_output_lowpass_filters [3]
 
Butterworth2LowPass acceleration_lowpass_filter
 
Butterworth2LowPass acceleration_body_x_filter
 
static struct FirstOrderLowPass rates_filt_fo [3]
 
struct FloatVect3 body_accel_f
 

Macro Definition Documentation

◆ INDI_ALLOWED_G_FACTOR

#define INDI_ALLOWED_G_FACTOR   2.0

Definition at line 48 of file stabilization_indi.c.

◆ STABILIZATION_INDI_ALLOCATION_PSEUDO_INVERSE

#define STABILIZATION_INDI_ALLOCATION_PSEUDO_INVERSE   FALSE

Definition at line 70 of file stabilization_indi.c.

◆ STABILIZATION_INDI_FILT_CUTOFF_P

#define STABILIZATION_INDI_FILT_CUTOFF_P   20.0

Definition at line 53 of file stabilization_indi.c.

◆ STABILIZATION_INDI_FILT_CUTOFF_Q

#define STABILIZATION_INDI_FILT_CUTOFF_Q   20.0

Definition at line 59 of file stabilization_indi.c.

◆ STABILIZATION_INDI_FILT_CUTOFF_R

#define STABILIZATION_INDI_FILT_CUTOFF_R   20.0

Definition at line 65 of file stabilization_indi.c.

◆ STABILIZATION_INDI_FILTER_RATES_SECOND_ORDER

#define STABILIZATION_INDI_FILTER_RATES_SECOND_ORDER   FALSE

Definition at line 74 of file stabilization_indi.c.

◆ STABILIZATION_INDI_THROTTLE_LIMIT_AIRSPEED_FWD

#define STABILIZATION_INDI_THROTTLE_LIMIT_AIRSPEED_FWD   8.0

Definition at line 80 of file stabilization_indi.c.

Function Documentation

◆ bound_g_mat()

static void bound_g_mat ( void  )
static

Definition at line 1036 of file stabilization_indi.c.

References g1_est, g1_init, g2_est, g2_init, and INDI_ALLOWED_G_FACTOR.

Referenced by lms_estimation().

+ Here is the caller graph for this function:

◆ calc_g1_element()

void calc_g1_element ( float  ddx_error,
int8_t  i,
int8_t  j,
float  mu 
)
static
Parameters
ddx_errorerror in output change
irow of the matrix element
jcolumn of the matrix element
mulearning rate

Function that calculates an element of the G1 matrix. The elements are stored in a different matrix, because the old matrix is necessary to caclulate more elements.

Definition at line 852 of file stabilization_indi.c.

References du_estimation, g1_est, and mu.

Referenced by lms_estimation().

+ Here is the caller graph for this function:

◆ calc_g2_element()

void calc_g2_element ( float  ddx_error,
int8_t  j,
float  mu 
)
static
Parameters
ddx_errorerror in output change
jcolumn of the matrix element
mulearning rate

Function that calculates an element of the G2 matrix. The elements are stored in a different matrix, because the old matrix is necessary to caclulate more elements.

Definition at line 866 of file stabilization_indi.c.

References ddu_estimation, g2_est, and mu.

Referenced by lms_estimation().

+ Here is the caller graph for this function:

◆ get_actuator_state()

void get_actuator_state ( void  )
static

Function that tries to get actuator feedback.

If this is not available it will use a first order filter to approximate the actuator state. It is also possible to model rate limits (unit: PPRZ/loop cycle)

Definition at line 816 of file stabilization_indi.c.

References act_dyn_discrete, act_obs, actuator_state, float_vect_copy(), indi_u, and UNUSED.

Referenced by stabilization_indi_rate_run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_filters()

◆ lms_estimation()

void lms_estimation ( void  )
static

Function that estimates the control effectiveness of each actuator online.

It is assumed that disturbances do not play a large role. All elements of the G1 and G2 matrices are be estimated.

Definition at line 876 of file stabilization_indi.c.

References acceleration_lowpass_filter, ACCELS_FLOAT_OF_BFP, actuator_state_filt_vectd, actuator_state_filt_vectdd, body_accel_f, bound_g_mat(), calc_g1_element(), calc_g2_element(), ddu_estimation, du_estimation, estimation_rate_dd, float_vect_copy(), float_vect_smul(), g1, g1_est, g2, g2_est, mu1, mu2, SecondOrderLowPass::o, stateGetAccelBody_i(), sum_g1_g2(), update_butterworth_2_low_pass(), and FloatVect3::z.

+ Here is the call graph for this function:

◆ send_ahrs_ref_quat()

static void send_ahrs_ref_quat ( struct transport_tx *  trans,
struct link_device *  dev 
)
static

Definition at line 319 of file stabilization_indi.c.

References dev, Int32Quat::qi, Int32Quat::qx, Int32Quat::qy, Int32Quat::qz, stab_att_sp_quat, and stateGetNedToBodyQuat_i().

Referenced by stabilization_indi_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ send_att_full_indi()

static void send_att_full_indi ( struct transport_tx *  trans,
struct link_device *  dev 
)
static

◆ send_eff_mat_g_indi()

static void send_eff_mat_g_indi ( struct transport_tx *  trans,
struct link_device *  dev 
)
static

Definition at line 309 of file stabilization_indi.c.

References dev, g1g2, and g2_est.

Referenced by stabilization_indi_init().

+ Here is the caller graph for this function:

◆ send_wls_u_stab()

static void send_wls_u_stab ( struct transport_tx *  trans,
struct link_device *  dev 
)
static

Definition at line 304 of file stabilization_indi.c.

References dev, send_wls_u(), and wls_stab_p.

Referenced by stabilization_indi_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ send_wls_v_stab()

static void send_wls_v_stab ( struct transport_tx *  trans,
struct link_device *  dev 
)
static

Definition at line 300 of file stabilization_indi.c.

References dev, send_wls_v(), and wls_stab_p.

Referenced by stabilization_indi_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stabilization_indi_attitude_run()

void stabilization_indi_attitude_run ( bool  in_flight,
struct StabilizationSetpoint att_sp,
struct ThrustSetpoint thrust,
int32_t cmd 
)
Parameters
in_flightenable integrator only in flight
att_spattitude stabilization setpoint
thrustthrust setpoint
[out]outputcommand vector

Function that should be called to run the INDI controller

Definition at line 760 of file stabilization_indi.c.

References angular_rate_ref, Indi_gains::att, float_quat_inv_comp_norm_shortest(), float_quat_tilt_twist(), indi_gains, FloatRates::p, FloatRates::q, FloatQuat::qx, FloatQuat::qy, FloatQuat::qz, FloatRates::r, Indi_gains::rate, RATES_ADD, StabilizationSetpoint::sp, stab_att_sp_euler, stab_att_sp_quat, stab_sp_from_rates_f(), stab_sp_to_eulers_i(), stab_sp_to_quat_f(), stab_sp_to_quat_i(), stab_sp_to_rates_f(), stabilization_indi_rate_run(), stateGetNedToBodyQuat_f(), FloatVect3::x, FloatVect3::y, and FloatVect3::z.

Referenced by stabilization_attitude_run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stabilization_indi_enter()

void stabilization_indi_enter ( void  )

Function that resets important values upon engaging INDI.

Don't reset inputs and filters, because it is unlikely to switch stabilization in flight, and there are multiple modes that use (the same) stabilization. Resetting the controller is not so nice when you are flying. FIXME: Ideally we should detect when coming from something that is not INDI

Definition at line 442 of file stabilization_indi.c.

References ddu_estimation, du_estimation, and float_vect_zero().

Referenced by stabilization_attitude_enter(), and stabilization_rate_enter().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stabilization_indi_init()

◆ stabilization_indi_rate_run()

◆ stabilization_indi_set_wls_settings()

void stabilization_indi_set_wls_settings ( void  )

Function that sets the u_min, u_max and u_pref if function not elsewhere defined.

Definition at line 728 of file stabilization_indi.c.

References act_is_servo, act_pref, guidance_h, GUIDANCE_H_MODE_HOVER, GUIDANCE_H_MODE_NAV, MAX_PPRZ, HorizontalGuidance::mode, STABILIZATION_INDI_THROTTLE_LIMIT_AIRSPEED_FWD, stateGetAirspeed_f(), WLS_t::u_max, WLS_t::u_min, WLS_t::u_pref, and wls_stab_p.

+ Here is the call graph for this function:

◆ stabilization_indi_update_filt_freq()

void stabilization_indi_update_filt_freq ( float  freq)

Definition at line 448 of file stabilization_indi.c.

References init_butterworth_2_low_pass(), init_first_order_low_pass(), p, rates_filt_fo, stabilization_indi_filter_freq, and stateGetBodyRates_f().

+ Here is the call graph for this function:

◆ sum_g1_g2()

void sum_g1_g2 ( void  )

Function that sums g1 and g2 to obtain the g1g2 matrix It also undoes the scaling that was done to make the values readable.

Definition at line 959 of file stabilization_indi.c.

References g1, g1g2, g2, and INDI_G_SCALING.

Referenced by lms_estimation(), and stabilization_indi_init().

+ Here is the caller graph for this function:

Variable Documentation

◆ acceleration_body_x_filter

Butterworth2LowPass acceleration_body_x_filter

Definition at line 287 of file stabilization_indi.c.

Referenced by init_filters(), and stabilization_indi_rate_run().

◆ acceleration_lowpass_filter

Butterworth2LowPass acceleration_lowpass_filter

Definition at line 286 of file stabilization_indi.c.

Referenced by init_filters(), and lms_estimation().

◆ act_dyn_discrete

float act_dyn_discrete[INDI_NUM_ACT]

Definition at line 197 of file stabilization_indi.c.

Referenced by get_actuator_state(), and stabilization_indi_init().

◆ act_first_order_cutoff

float act_first_order_cutoff[INDI_NUM_ACT] = STABILIZATION_INDI_ACT_FREQ

Definition at line 196 of file stabilization_indi.c.

Referenced by stabilization_indi_init().

◆ act_is_servo

bool act_is_servo[INDI_NUM_ACT] = {0}

◆ act_is_thruster_x

bool act_is_thruster_x[INDI_NUM_ACT] = {0}

Definition at line 177 of file stabilization_indi.c.

Referenced by stabilization_indi_init().

◆ act_is_thruster_z

bool act_is_thruster_z[INDI_NUM_ACT]

Definition at line 180 of file stabilization_indi.c.

Referenced by stabilization_indi_init().

◆ act_obs

float act_obs[INDI_NUM_ACT]

Definition at line 238 of file stabilization_indi.c.

Referenced by get_actuator_state().

◆ act_pref

float act_pref[INDI_NUM_ACT] = {0.0}

◆ actuator_lowpass_filters

Butterworth2LowPass actuator_lowpass_filters[INDI_NUM_ACT]

Definition at line 282 of file stabilization_indi.c.

Referenced by init_filters(), and stabilization_indi_rate_run().

◆ actuator_state

float actuator_state[INDI_NUM_ACT]

Definition at line 214 of file stabilization_indi.c.

Referenced by get_actuator_state(), and stabilization_indi_rate_run().

◆ actuator_state_filt_vect

◆ actuator_state_filt_vectd

float actuator_state_filt_vectd[INDI_NUM_ACT]

◆ actuator_state_filt_vectdd

float actuator_state_filt_vectdd[INDI_NUM_ACT]

◆ angular_accel_ref

struct FloatRates angular_accel_ref = {0., 0., 0.}

Definition at line 210 of file stabilization_indi.c.

Referenced by send_att_full_indi(), and stabilization_indi_rate_run().

◆ angular_acceleration

float angular_acceleration[3] = {0., 0., 0.}

Definition at line 213 of file stabilization_indi.c.

Referenced by send_att_full_indi(), and stabilization_indi_rate_run().

◆ angular_rate_ref

struct FloatRates angular_rate_ref = {0., 0., 0.}

Definition at line 210 of file stabilization_indi.c.

Referenced by send_att_full_indi(), and stabilization_indi_attitude_run().

◆ body_accel_f

struct FloatVect3 body_accel_f

◆ Bwls

float* Bwls[INDI_OUTPUTS]

◆ ddu_estimation

float ddu_estimation[INDI_NUM_ACT]

Definition at line 230 of file stabilization_indi.c.

Referenced by calc_g2_element(), lms_estimation(), and stabilization_indi_enter().

◆ du_estimation

float du_estimation[INDI_NUM_ACT]

Definition at line 229 of file stabilization_indi.c.

Referenced by calc_g1_element(), lms_estimation(), and stabilization_indi_enter().

◆ estimation_input_lowpass_filters

Butterworth2LowPass estimation_input_lowpass_filters[INDI_NUM_ACT]

Definition at line 283 of file stabilization_indi.c.

Referenced by init_filters(), and stabilization_indi_rate_run().

◆ estimation_output_lowpass_filters

Butterworth2LowPass estimation_output_lowpass_filters[3]

Definition at line 285 of file stabilization_indi.c.

Referenced by init_filters(), and stabilization_indi_rate_run().

◆ estimation_rate_d

float estimation_rate_d[INDI_NUM_ACT]

Definition at line 227 of file stabilization_indi.c.

Referenced by stabilization_indi_init(), and stabilization_indi_rate_run().

◆ estimation_rate_dd

float estimation_rate_dd[INDI_NUM_ACT]

◆ g1

float g1[INDI_OUTPUTS][INDI_NUM_ACT]
Initial value:
= {STABILIZATION_INDI_G1_ROLL,
STABILIZATION_INDI_G1_PITCH, STABILIZATION_INDI_G1_YAW, STABILIZATION_INDI_G1_THRUST
}

Definition at line 270 of file stabilization_indi.c.

Referenced by gain_scheduling_periodic(), lms_estimation(), stabilization_indi_init(), and sum_g1_g2().

◆ g1_est

float g1_est[INDI_OUTPUTS][INDI_NUM_ACT]

◆ g1_init

float g1_init[INDI_OUTPUTS][INDI_NUM_ACT]

Definition at line 279 of file stabilization_indi.c.

Referenced by bound_g_mat(), and stabilization_indi_init().

◆ g1g2

◆ g1g2_pseudo_inv

float g1g2_pseudo_inv[INDI_NUM_ACT][INDI_OUTPUTS]

Definition at line 259 of file stabilization_indi.c.

◆ g1g2_trans_mult

float g1g2_trans_mult[INDI_OUTPUTS][INDI_OUTPUTS]

Definition at line 223 of file stabilization_indi.c.

◆ g1g2inv

float g1g2inv[INDI_OUTPUTS][INDI_OUTPUTS]

Definition at line 224 of file stabilization_indi.c.

◆ g2

float g2[INDI_NUM_ACT] = STABILIZATION_INDI_G2

◆ g2_est

float g2_est[INDI_NUM_ACT]

◆ g2_init

float g2_init[INDI_NUM_ACT]

Definition at line 280 of file stabilization_indi.c.

Referenced by bound_g_mat(), and stabilization_indi_init().

◆ indi_gains

struct Indi_gains indi_gains
Initial value:
= {
.att = {
STABILIZATION_INDI_REF_ERR_P,
STABILIZATION_INDI_REF_ERR_Q,
STABILIZATION_INDI_REF_ERR_R
},
.rate = {
STABILIZATION_INDI_REF_RATE_P,
STABILIZATION_INDI_REF_RATE_Q,
STABILIZATION_INDI_REF_RATE_R
},
}

Definition at line 144 of file stabilization_indi.c.

Referenced by eff_scheduling_periodic_b(), stabilization_indi_attitude_run(), and stabilization_indi_rate_run().

◆ indi_u

float indi_u[INDI_NUM_ACT]

Definition at line 215 of file stabilization_indi.c.

Referenced by get_actuator_state().

◆ indi_use_adaptive

bool indi_use_adaptive = false

Definition at line 161 of file stabilization_indi.c.

◆ indi_v

float indi_v[INDI_OUTPUTS]

Definition at line 132 of file stabilization_indi.c.

◆ measurement_lowpass_filters

Butterworth2LowPass measurement_lowpass_filters[3]

Definition at line 284 of file stabilization_indi.c.

Referenced by init_filters(), and stabilization_indi_rate_run().

◆ mu1

float mu1[INDI_OUTPUTS] = {0.00001, 0.00001, 0.000003, 0.000002}

Definition at line 233 of file stabilization_indi.c.

Referenced by lms_estimation().

◆ mu2

float mu2 = 0.002

Definition at line 235 of file stabilization_indi.c.

Referenced by lms_estimation().

◆ num_thrusters

int32_t num_thrusters

Definition at line 241 of file stabilization_indi.c.

Referenced by stabilization_indi_init().

◆ num_thrusters_x

int32_t num_thrusters_x

Definition at line 242 of file stabilization_indi.c.

Referenced by stabilization_indi_init().

◆ q_filt

float q_filt = 0.0

Definition at line 217 of file stabilization_indi.c.

◆ r_filt

float r_filt = 0.0

Definition at line 218 of file stabilization_indi.c.

◆ rates_filt_fo

struct FirstOrderLowPass rates_filt_fo[3]
static

◆ stab_att_sp_euler

struct Int32Eulers stab_att_sp_euler
static

Definition at line 242 of file stabilization_indi.c.

Referenced by send_att_full_indi(), and stabilization_indi_attitude_run().

◆ stab_att_sp_quat

struct Int32Quat stab_att_sp_quat
static

◆ stabilization_att_indi_cmd

int32_t stabilization_att_indi_cmd[COMMANDS_NB]

Definition at line 144 of file stabilization_indi.c.

◆ stabilization_indi_filter_freq

float stabilization_indi_filter_freq = 20.0

Definition at line 220 of file stabilization_indi.c.

Referenced by stabilization_indi_update_filt_freq().

◆ stablization_indi_yaw_dist_limit

float stablization_indi_yaw_dist_limit = 99999.f

Limit the maximum specific moment that can be compensated (units rad/s^2)

Definition at line 206 of file stabilization_indi.c.

Referenced by stabilization_indi_rate_run().

◆ wls_stab_p

struct WLS_t wls_stab_p
Initial value:
= {
.nu = INDI_NUM_ACT,
.nv = INDI_OUTPUTS,
.gamma_sq = 10000.0,
.v = {0.0},
.Wv = {1000, 1000, 1, 100},
.Wu = {[0 ... INDI_NUM_ACT - 1] = 1.0},
.u_pref = {0.0},
.u_min = {0.0},
.u_max = {0.0},
.PC = 0.0,
.SC = 0.0,
.iter = 0
}

Definition at line 1 of file stabilization_indi.c.

Referenced by schdule_control_effectiveness(), send_wls_u_stab(), send_wls_v_stab(), and stabilization_indi_set_wls_settings().