 |
Paparazzi UAS
v6.1.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
51 #ifdef STABILIZATION_INDI_FILT_CUTOFF_P
52 #define STABILIZATION_INDI_FILTER_ROLL_RATE TRUE
54 #define STABILIZATION_INDI_FILT_CUTOFF_P 20.0
57 #ifdef STABILIZATION_INDI_FILT_CUTOFF_Q
58 #define STABILIZATION_INDI_FILTER_PITCH_RATE TRUE
60 #define STABILIZATION_INDI_FILT_CUTOFF_Q 20.0
63 #ifdef STABILIZATION_INDI_FILT_CUTOFF_R
64 #define STABILIZATION_INDI_FILTER_YAW_RATE TRUE
66 #define STABILIZATION_INDI_FILT_CUTOFF_R 20.0
86 STABILIZATION_INDI_REF_ERR_P,
87 STABILIZATION_INDI_REF_ERR_Q,
88 STABILIZATION_INDI_REF_ERR_R
91 STABILIZATION_INDI_REF_RATE_P,
92 STABILIZATION_INDI_REF_RATE_Q,
93 STABILIZATION_INDI_REF_RATE_R
97 #if STABILIZATION_INDI_USE_ADAPTIVE
103 #ifdef STABILIZATION_INDI_ACT_RATE_LIMIT
104 float act_rate_limit[INDI_NUM_ACT] = STABILIZATION_INDI_ACT_RATE_LIMIT;
107 #ifdef STABILIZATION_INDI_ACT_IS_SERVO
108 bool act_is_servo[INDI_NUM_ACT] = STABILIZATION_INDI_ACT_IS_SERVO;
113 #ifdef STABILIZATION_INDI_ACT_PREF
115 float act_pref[INDI_NUM_ACT] = STABILIZATION_INDI_ACT_PREF;
121 float act_dyn[INDI_NUM_ACT] = STABILIZATION_INDI_ACT_DYN;
123 #ifdef STABILIZATION_INDI_WLS_PRIORITIES
124 static float Wv[INDI_OUTPUTS] = STABILIZATION_INDI_WLS_PRIORITIES;
127 static float Wv[INDI_OUTPUTS] = {1000, 1000, 1, 100};
153 float mu1[INDI_OUTPUTS] = {0.00001, 0.00001, 0.000003, 0.000002};
175 float g2[INDI_NUM_ACT] = STABILIZATION_INDI_G2;
176 float g1[INDI_OUTPUTS][INDI_NUM_ACT] = {STABILIZATION_INDI_G1_ROLL,
177 STABILIZATION_INDI_G1_PITCH, STABILIZATION_INDI_G1_YAW, STABILIZATION_INDI_G1_THRUST
179 float g1g2[INDI_OUTPUTS][INDI_NUM_ACT];
180 float g1_est[INDI_OUTPUTS][INDI_NUM_ACT];
196 #if PERIODIC_TELEMETRY
200 pprz_msg_send_INDI_G(trans,
dev, AC_ID, INDI_NUM_ACT,
g1_est[0],
210 pprz_msg_send_AHRS_REF_QUAT(trans,
dev, AC_ID,
244 for (i = 0; i < INDI_OUTPUTS; i++) {
257 for (i = 0; i < INDI_NUM_ACT; i++) {
261 #if PERIODIC_TELEMETRY
292 float sample_time = 1.0 / PERIODIC_FREQUENCY;
295 for (i = 0; i < 3; i++) {
301 for (i = 0; i < INDI_NUM_ACT; i++) {
377 float rate_vect[3] = {body_rates->
p, body_rates->
q, body_rates->
r};
379 for (i = 0; i < 3; i++) {
397 #if STABILIZATION_INDI_FILTER_ROLL_RATE
400 rates_filt.
p = body_rates->
p;
402 #if STABILIZATION_INDI_FILTER_PITCH_RATE
405 rates_filt.
q = body_rates->
q;
407 #if STABILIZATION_INDI_FILTER_YAW_RATE
410 rates_filt.
r = body_rates->
r;
419 for (i = 0; i < INDI_NUM_ACT; i++) {
425 float v_thrust = 0.0;
431 for (i = 0; i < INDI_NUM_ACT; i++) {
438 for (i = 0; i < INDI_NUM_ACT; i++) {
450 #if STABILIZATION_INDI_ALLOCATION_PSEUDO_INVERSE
452 for (i = 0; i < INDI_NUM_ACT; i++) {
460 for (i = 0; i < INDI_NUM_ACT; i++) {
465 #ifdef GUIDANCE_INDI_MIN_THROTTLE
482 wls_alloc(
indi_du,
indi_v,
du_min,
du_max,
Bwls, 0, 0,
Wv, 0,
du_pref, 10000, 10);
489 for (i = 0; i < INDI_NUM_ACT; i++) {
505 for (i = 0; i < INDI_NUM_ACT; i++) {
522 for (i = 0; i < INDI_NUM_ACT; i++) {
558 att_fb.
x = att_err.
qx;
559 att_fb.
y = att_err.
qy;
560 att_fb.
z = att_err.
qz;
585 #if USE_EARTH_BOUND_RC_SETPOINT
602 #if INDI_RPM_FEEDBACK
607 float UNUSED prev_actuator_state;
608 for (i = 0; i < INDI_NUM_ACT; i++) {
614 #ifdef STABILIZATION_INDI_ACT_RATE_LIMIT
615 if ((
actuator_state[i] - prev_actuator_state) > act_rate_limit[i]) {
617 }
else if ((
actuator_state[i] - prev_actuator_state) < -act_rate_limit[i]) {
685 for (i = 0; i < INDI_OUTPUTS; i++) {
687 float ddx_error = - ddx_estimation[i];
689 for (j = 0; j < INDI_NUM_ACT; j++) {
699 for (j = 0; j < INDI_NUM_ACT; j++) {
704 if (fabs(indi_accel_d) > 60.0) {
710 for (j = 0; j < INDI_NUM_ACT; j++) {
722 #if STABILIZATION_INDI_ALLOCATION_PSEUDO_INVERSE
737 for (i = 0; i < INDI_OUTPUTS; i++) {
738 for (j = 0; j < INDI_NUM_ACT; j++) {
752 for (row = 0; row < INDI_OUTPUTS; row++) {
753 for (col = 0; col < INDI_OUTPUTS; col++) {
755 for (i = 0; i < INDI_NUM_ACT; i++) {
756 element = element +
g1g2[row][i] *
g1g2[col][i];
773 for (row = 0; row < INDI_NUM_ACT; row++) {
774 for (col = 0; col < INDI_OUTPUTS; col++) {
776 for (i = 0; i < INDI_OUTPUTS; i++) {
777 element = element +
g1g2[i][row] *
g1g2inv[col][i];
786 #if INDI_RPM_FEEDBACK
788 for (i = 0; i < num_act; i++) {
790 act_obs[i] *= (
MAX_PPRZ / (float)(get_servo_max(i) - get_servo_min(i)));
809 for (j = 0; j < INDI_NUM_ACT; j++) {
814 for (i = 0; i < INDI_OUTPUTS; i++) {
823 if (
g1_est[i][j] > max_limit) {
826 if (
g1_est[i][j] < min_limit) {
840 if (
g2_est[j] > max_limit) {
843 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.
signed char int8_t
Typedef defining 8 bit char type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
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]
#define STABILIZATION_INDI_FILT_CUTOFF_Q
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 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_first_order_low_pass(struct FirstOrderLowPass *filter, float value)
Update first order low pass filter state with a new value.
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]
static const struct usb_device_descriptor dev
float g2_est[INDI_NUM_ACT]
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]
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)
#define STABILIZATION_INDI_FILT_CUTOFF_P
#define STABILIZATION_INDI_FILT_CUTOFF_R
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)
short int16_t
Typedef defining 16 bit short type.
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
static struct FloatQuat * stateGetNedToBodyQuat_f(void)
Get vehicle body attitude quaternion (float).
float act_pref[INDI_NUM_ACT]
static float stateGetAirspeed_f(void)
Get airspeed (float).
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]
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
int int32_t
Typedef defining 32 bit int type.
float g2_init[INDI_NUM_ACT]
float g1g2inv[INDI_OUTPUTS][INDI_OUTPUTS]
bool act_is_servo[INDI_NUM_ACT]
void float_quat_tilt_twist(struct FloatQuat *tilt, struct FloatQuat *twist, struct FloatQuat *quat)
Tilt twist decomposition of a quaternion (z axis)
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]
#define QUAT_FLOAT_OF_BFP(_qf, _qi)
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
void float_quat_inv_comp_norm_shortest(struct FloatQuat *b2c, struct FloatQuat *a2b, struct FloatQuat *a2c)
Composition (multiplication) of two quaternions with normalization.
#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
static struct FirstOrderLowPass rates_filt_fo[3]
#define GUIDANCE_H_MODE_NAV
static void rpm_cb(uint8_t sender_id, uint16_t *rpm, uint8_t num_act)
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
static void thrust_cb(uint8_t sender_id, float thrust_increment)
First order low pass filter structure.
#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)