|
Paparazzi UAS
v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
|
Go to the documentation of this file.
40 #include "generated/airframe.h"
49 #define INDI_ALLOWED_G_FACTOR 2.0
68 STABILIZATION_INDI_REF_ERR_P,
69 STABILIZATION_INDI_REF_ERR_Q,
70 STABILIZATION_INDI_REF_ERR_R
73 STABILIZATION_INDI_REF_RATE_P,
74 STABILIZATION_INDI_REF_RATE_Q,
75 STABILIZATION_INDI_REF_RATE_R
79 #if STABILIZATION_INDI_USE_ADAPTIVE
85 #ifdef STABILIZATION_INDI_ACT_RATE_LIMIT
86 float act_rate_limit[INDI_NUM_ACT] = STABILIZATION_INDI_ACT_RATE_LIMIT;
89 #ifdef STABILIZATION_INDI_ACT_IS_SERVO
90 bool act_is_servo[INDI_NUM_ACT] = STABILIZATION_INDI_ACT_IS_SERVO;
95 #ifdef STABILIZATION_INDI_ACT_PREF
97 float act_pref[INDI_NUM_ACT] = STABILIZATION_INDI_ACT_PREF;
103 float act_dyn[INDI_NUM_ACT] = STABILIZATION_INDI_ACT_DYN;
105 #ifdef STABILIZATION_INDI_WLS_PRIORITIES
106 static float Wv[INDI_OUTPUTS] = STABILIZATION_INDI_WLS_PRIORITIES;
109 static float Wv[INDI_OUTPUTS] = {1000, 1000, 1, 100};
135 float mu1[INDI_OUTPUTS] = {0.00001, 0.00001, 0.000003, 0.000002};
157 float g2[INDI_NUM_ACT] = STABILIZATION_INDI_G2;
158 float g1[INDI_OUTPUTS][INDI_NUM_ACT] = {STABILIZATION_INDI_G1_ROLL,
159 STABILIZATION_INDI_G1_PITCH, STABILIZATION_INDI_G1_YAW, STABILIZATION_INDI_G1_THRUST
161 float g1g2[INDI_OUTPUTS][INDI_NUM_ACT];
162 float g1_est[INDI_OUTPUTS][INDI_NUM_ACT];
177 #if PERIODIC_TELEMETRY
181 pprz_msg_send_INDI_G(trans,
dev, AC_ID, INDI_NUM_ACT,
g1_est[0],
191 pprz_msg_send_AHRS_REF_QUAT(trans,
dev, AC_ID,
225 for (i = 0; i < INDI_OUTPUTS; i++) {
238 for (i = 0; i < INDI_NUM_ACT; i++) {
242 #if PERIODIC_TELEMETRY
273 float sample_time = 1.0 / PERIODIC_FREQUENCY;
276 for (i = 0; i < 3; i++) {
282 for (i = 0; i < INDI_NUM_ACT; i++) {
351 float rate_vect[3] = {body_rates->
p, body_rates->
q, body_rates->
r};
353 for (i = 0; i < 3; i++) {
377 for (i = 0; i < INDI_NUM_ACT; i++) {
383 float v_thrust = 0.0;
389 for (i = 0; i < INDI_NUM_ACT; i++) {
396 for (i = 0; i < INDI_NUM_ACT; i++) {
408 #if STABILIZATION_INDI_ALLOCATION_PSEUDO_INVERSE
410 for (i = 0; i < INDI_NUM_ACT; i++) {
418 for (i = 0; i < INDI_NUM_ACT; i++) {
423 #ifdef GUIDANCE_INDI_MIN_THROTTLE
440 wls_alloc(
indi_du,
indi_v,
du_min,
du_max,
Bwls, 0, 0,
Wv, 0,
du_pref, 10000, 10);
447 for (i = 0; i < INDI_NUM_ACT; i++) {
463 for (i = 0; i < INDI_NUM_ACT; i++) {
480 for (i = 0; i < INDI_NUM_ACT; i++) {
528 #if USE_EARTH_BOUND_RC_SETPOINT
545 #if INDI_RPM_FEEDBACK
550 float UNUSED prev_actuator_state;
551 for (i = 0; i < INDI_NUM_ACT; i++) {
557 #ifdef STABILIZATION_INDI_ACT_RATE_LIMIT
558 if ((
actuator_state[i] - prev_actuator_state) > act_rate_limit[i]) {
560 }
else if ((
actuator_state[i] - prev_actuator_state) < -act_rate_limit[i]) {
628 for (i = 0; i < INDI_OUTPUTS; i++) {
630 float ddx_error = - ddx_estimation[i];
632 for (j = 0; j < INDI_NUM_ACT; j++) {
642 for (j = 0; j < INDI_NUM_ACT; j++) {
647 if (fabs(indi_accel_d) > 60.0) {
653 for (j = 0; j < INDI_NUM_ACT; j++) {
665 #if STABILIZATION_INDI_ALLOCATION_PSEUDO_INVERSE
680 for (i = 0; i < INDI_OUTPUTS; i++) {
681 for (j = 0; j < INDI_NUM_ACT; j++) {
695 for (row = 0; row < INDI_OUTPUTS; row++) {
696 for (col = 0; col < INDI_OUTPUTS; col++) {
698 for (i = 0; i < INDI_NUM_ACT; i++) {
699 element = element +
g1g2[row][i] *
g1g2[col][i];
716 for (row = 0; row < INDI_NUM_ACT; row++) {
717 for (col = 0; col < INDI_OUTPUTS; col++) {
719 for (i = 0; i < INDI_OUTPUTS; i++) {
720 element = element +
g1g2[i][row] *
g1g2inv[col][i];
729 #if INDI_RPM_FEEDBACK
731 for (i = 0; i < num_act; i++) {
733 act_obs[i] *= (
MAX_PPRZ / (float)(get_servo_max(i) - get_servo_min(i)));
752 for (j = 0; j < INDI_NUM_ACT; j++) {
757 for (i = 0; i < INDI_OUTPUTS; i++) {
766 if (
g1_est[i][j] > max_limit) {
769 if (
g1_est[i][j] < min_limit) {
783 if (
g2_est[j] > max_limit) {
786 if (
g2_est[j] < min_limit) {
void int32_quat_of_eulers(struct Int32Quat *q, struct Int32Eulers *e)
Quaternion from Euler angles.
int32_t theta
in rad with INT32_ANGLE_FRAC
static void send_indi_g(struct transport_tx *trans, struct link_device *dev)
static void send_ahrs_ref_quat(struct transport_tx *trans, struct link_device *dev)
static float update_butterworth_2_low_pass(Butterworth2LowPass *filter, float value)
Update second order Butterworth low pass filter state with a new value.
float g1g2[INDI_OUTPUTS][INDI_NUM_ACT]
float indi_du[INDI_NUM_ACT]
struct Indi_gains indi_gains
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_indi_init(void)
Function that initializes important values upon engaging INDI.
float du_pref[INDI_NUM_ACT]
bool indi_thrust_increment_set
#define THRUST_INCREMENT_ID
float act_obs[INDI_NUM_ACT]
Butterworth2LowPass acceleration_lowpass_filter
static void bound_g_mat(void)
float estimation_rate_dd[INDI_NUM_ACT]
float * Bwls[INDI_OUTPUTS]
float du_min[INDI_NUM_ACT]
#define INDI_ALLOWED_G_FACTOR
static struct Int32Quat * stateGetNedToBodyQuat_i(void)
Get vehicle body attitude quaternion (int).
Event structure to store callbacks in a linked list.
float indi_thrust_increment
static struct FloatRates * stateGetBodyRates_f(void)
Get vehicle body angular rate (float).
float ddu_estimation[INDI_NUM_ACT]
#define PPRZ_ITRIG_COS(_c, _a)
bool float_mat_inv_4d(float invOut[16], float mat_in[16])
4x4 Matrix inverse
Butterworth2LowPass actuator_lowpass_filters[INDI_NUM_ACT]
Second order low pass filter structure.
float g1_est[INDI_OUTPUTS][INDI_NUM_ACT]
float estimation_rate_d[INDI_NUM_ACT]
float g2_est[INDI_NUM_ACT]
static void int32_quat_normalize(struct Int32Quat *q)
normalize a quaternion inplace
float actuator_state_filt_vectdd[INDI_NUM_ACT]
Paparazzi floating point algebra.
static void calc_g1g2_pseudo_inv(void)
Function that calculates the pseudo-inverse of (G1+G2).
struct Int32Quat stab_att_sp_quat
with INT32_QUAT_FRAC
float indi_v[INDI_OUTPUTS]
void int32_quat_inv_comp(struct Int32Quat *b2c, struct Int32Quat *a2b, struct Int32Quat *a2c)
Composition (multiplication) of two quaternions.
int32_t stabilization_attitude_get_heading_i(void)
void stabilization_indi_set_failsafe_setpoint(void)
Function that calculates the failsafe setpoint.
static void calc_g1_element(float dx_error, int8_t i, int8_t j, float mu_extra)
static void int32_quat_wrap_shortest(struct Int32Quat *q)
int wls_alloc(float *u, float *v, float *umin, float *umax, float **B, float *u_guess, float *W_init, float *Wv, float *Wu, float *up, float gamma_sq, int imax)
active set algorithm for control allocation
void stabilization_indi_rate_run(struct FloatRates rate_sp, bool in_flight)
void stabilization_indi_set_rpy_setpoint_i(struct Int32Eulers *rpy)
void stabilization_indi_enter(void)
Function that resets important values upon engaging INDI.
Butterworth2LowPass estimation_input_lowpass_filters[INDI_NUM_ACT]
int32_t psi
in rad with INT32_ANGLE_FRAC
int32_t stabilization_att_indi_cmd[COMMANDS_NB]
int32_t phi
in rad with INT32_ANGLE_FRAC
#define GUIDANCE_H_MODE_HOVER
float act_pref[INDI_NUM_ACT]
static float stateGetAirspeed_f(void)
Get airspeed (float).
static const struct usb_device_descriptor dev
static void float_vect_zero(float *a, const int n)
a = 0
float actuator_state_filt_vectd[INDI_NUM_ACT]
float angular_acceleration[3]
void stabilization_indi_attitude_run(struct Int32Quat quat_sp, bool in_flight)
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Butterworth2LowPass estimation_output_lowpass_filters[3]
static float Wv[INDI_OUTPUTS]
#define QUAT_BFP_OF_REAL(_qi, _qf)
float du_estimation[INDI_NUM_ACT]
float g1g2_trans_mult[INDI_OUTPUTS][INDI_OUTPUTS]
#define QUAT1_FLOAT_OF_BFP(_qi)
static void float_vect_smul(float *o, const float *a, const float s, const int n)
o = a * s
struct FloatVect3 body_accel_f
void stabilization_indi_set_earth_cmd_i(struct Int32Vect2 *cmd, int32_t heading)
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.
#define STABILIZATION_INDI_FILT_CUTOFF
float g2_init[INDI_NUM_ACT]
float g1g2inv[INDI_OUTPUTS][INDI_OUTPUTS]
bool act_is_servo[INDI_NUM_ACT]
void init_filters(void)
Function that resets the filters to zeros.
static struct Int32Vect3 * stateGetAccelBody_i(void)
Get acceleration in Body coordinates (int).
void stabilization_indi_read_rc(bool in_flight, bool in_carefree, bool coordinated_turn)
float actuator_state_filt_vect[INDI_NUM_ACT]
float actuator_state[INDI_NUM_ACT]
float act_dyn[INDI_NUM_ACT]
float g1g2_pseudo_inv[INDI_NUM_ACT][INDI_OUTPUTS]
float indi_u[INDI_NUM_ACT]
int32_t stabilization_cmd[COMMANDS_NB]
Stabilization commands.
static void float_vect_scale(float *a, const float s, const int n)
a *= s
float g1_init[INDI_OUTPUTS][INDI_NUM_ACT]
struct HorizontalGuidance guidance_h
float g1[INDI_OUTPUTS][INDI_NUM_ACT]
float du_max[INDI_NUM_ACT]
static void float_vect_copy(float *a, const float *b, const int n)
a = b
#define ACCELS_FLOAT_OF_BFP(_ef, _ei)
static void init_butterworth_2_low_pass(Butterworth2LowPass *filter, float tau, float sample_time, float value)
Init a second order Butterworth filter.
Butterworth2LowPass measurement_lowpass_filters[3]
static struct Int32Eulers * stateGetNedToBodyEulers_i(void)
Get vehicle body attitude euler angles (int).
struct Int32Eulers stab_att_sp_euler
with INT32_ANGLE_FRAC
#define GUIDANCE_H_MODE_NAV
static void rpm_cb(uint8_t sender_id, uint16_t *rpm, uint8_t num_act)
static void thrust_cb(uint8_t sender_id, float thrust_increment)
#define DefaultPeriodic
Set default periodic telemetry.
struct FloatRates angular_accel_ref
static void calc_g2_element(float dx_error, int8_t j, float mu_extra)
static void get_actuator_state(void)
Function that tries to get actuator feedback.
#define STABILIZATION_INDI_ESTIMATION_FILT_CUTOFF
static void float_vect_sum(float *o, const float *a, const float *b, const int n)
o = a + b
Simple first order low pass filter with bilinear transform.
static void lms_estimation(void)
Function that estimates the control effectiveness of each actuator online.
#define PPRZ_ITRIG_SIN(_s, _a)