83#include "generated/airframe.h"
92#ifndef ONELOOP_NB_SIMPLE_QUAD
110#ifndef ONELOOP_NB_DEBUG_MODE
111#define ONELOOP_NB_DEBUG_MODE FALSE
116static float g = 9.81;
118#define IDX_aD RW_aD - 2
119#define IDX_ap RW_ap - 2
120#define IDX_aq RW_aq - 2
121#define IDX_ar RW_ar - 2
127#ifdef ONELOOP_NB_FILT_CUTOFF
133#ifdef ONELOOP_NB_FILT_CUTOFF_ACC
139#ifdef ONELOOP_NB_FILT_CUTOFF_VEL
145#ifdef ONELOOP_NB_FILT_CUTOFF_P
146#define ONELOOP_NB_FILTER_ROLL_RATE TRUE
152#ifdef ONELOOP_NB_FILT_CUTOFF_Q
153#define ONELOOP_NB_FILTER_PITCH_RATE TRUE
159#ifdef ONELOOP_NB_FILT_CUTOFF_R
160#define ONELOOP_NB_FILTER_YAW_RATE TRUE
166PRINT_CONFIG_MSG(
"============================================================")
174PRINT_CONFIG_MSG("============================================================")
175PRINT_CONFIG_MSG("============================================================")
181PRINT_CONFIG_MSG("============================================================")
197#ifndef ONELOOP_NB_NUM_THRUSTERS
203#ifdef ONELOOP_NB_ACT_IS_SERVO
209#ifdef ONELOOP_NB_ACT_DYN
213#error "You must specify the actuator dynamics"
218#ifdef ONELOOP_NB_ACT_MAX
224#ifdef ONELOOP_NB_ACT_MIN
230#ifdef ONELOOP_NB_ACT_MAX_NORM
236#ifdef ONELOOP_NB_ACT_MIN_NORM
242#ifdef ONELOOP_NB_NU_NORM_MAX
248#ifdef ONELOOP_NB_U_PREF
254PRINT_CONFIG_MSG(
"============================================================")
259PRINT_CONFIG_MSG("============================================================")
261#ifdef ONELOOP_NB_MAX_BANK
267#ifdef ONELOOP_NB_MAX_PHI
273#ifdef ONELOOP_NB_MAX_THETA
279#ifndef ONELOOP_THETA_PREF_MAX
285PRINT_CONFIG_MSG(
"============================================================")
289PRINT_CONFIG_MSG("============================================================")
291#if ANDI_NUM_ACT_TOT != WLS_N_U_MAX
292#error Matrix-WLS_N_U_MAX is not equal to the number of actuators: define WLS_N_U_MAX == ANDI_NUM_ACT_TOT in airframe file
293#define WLS_N_U_MAX == ANDI_NUM_ACT_TOT
295#if ANDI_OUTPUTS != WLS_N_V_MAX
296#error Matrix-WLS_N_V_MAX is not equal to the number of controlled axis: define WLS_N_V_MAX == ANDI_OUTPUTS in airframe file
297#define WLS_N_V_MAX == ANDI_OUTPUTS
309#ifndef ONELOOP_NB_MAX_FAULT_MOT
310#define ONELOOP_NB_MAX_FAULT_MOT 3000.0
313 "ONELOOP_NB_MAX_FAULT_MOT must be in [0, 9600] pprz");
324#ifdef ONELOOP_NB_YAW_DISTURBANCE_LIMIT
330#if ONELOOP_NB_HEADING_MANUAL
336#if ONELOOP_NB_YAW_STICK_IN_AUTO
344#ifdef ONELOOP_NB_MAX_ANGULAR_JERK
352#ifdef ONELOOP_NB_MAX_ANGULAR_JERK_YAW
358#ifdef ONELOOP_NB_MAX_ANGULAR_ACCEL
366#ifdef ONELOOP_NB_MAX_ANGULAR_ACCEL_YAW
372#ifdef ONELOOP_NB_MAX_ANGULAR_VEL
380#ifdef ONELOOP_NB_MAX_ANGULAR_VEL_YAW
394#ifndef ONELOOP_NB_AIRSPEED_SWITCH_THRESHOLD
395#define ONELOOP_NB_AIRSPEED_SWITCH_THRESHOLD 10.0
398#ifndef FWD_SIDESLIP_GAIN
404#ifdef NAV_HYBRID_MAX_DECELERATION
410#ifdef ONELOOP_NB_MAX_LINEAR_JERK
416#ifdef NAV_HYBRID_MAX_AIRSPEED
422#ifdef NAV_HYBRID_MAX_SPEED_V
428#define USE_ND_VELOCITIES
440#ifndef ONELOOP_NB_WU_QUAD_MOTORS_FWD
498#ifndef ONELOOP_NB_FAULT_AILERONS
499#define ONELOOP_NB_FAULT_AILERONS TRUE
521#ifdef ONELOOP_NB_DELTA_FAULT
530#ifndef ONELOOP_NB_SPIN_PROT_MAX_RATE
531#define ONELOOP_NB_SPIN_PROT_MAX_RATE 34.0
533#ifndef ONELOOP_NB_SPIN_PROT_START_RATE
534#define ONELOOP_NB_SPIN_PROT_START_RATE 28.0
536#ifndef ONELOOP_NB_SPIN_PROT_MAX_CMD
537#define ONELOOP_NB_SPIN_PROT_MAX_CMD 4800.0
547#ifndef ONELOOP_NB_SPIN_TRIM_ON
548#define ONELOOP_NB_SPIN_TRIM_ON TRUE
550#ifndef ONELOOP_NB_SPIN_TRIM_RATE
551#define ONELOOP_NB_SPIN_TRIM_RATE 1000.0
553#ifndef ONELOOP_NB_SPIN_TRIM_BLEED_RATE
554#define ONELOOP_NB_SPIN_TRIM_BLEED_RATE 1000.0
556#ifndef ONELOOP_NB_SPIN_TRIM_RELEASE_RATE
557#define ONELOOP_NB_SPIN_TRIM_RELEASE_RATE 24.0
564#ifndef ONELOOP_NB_SPIN_PROT_MIN_GAP
565#define ONELOOP_NB_SPIN_PROT_MIN_GAP 1.0
570 "ONELOOP_NB_SPIN_PROT_MIN_GAP must be in [0.1, 10] rad/s");
572 "ONELOOP_NB_SPIN_PROT_MAX_RATE must be <= 60 rad/s");
574 "ONELOOP_NB_SPIN_PROT_START_RATE must be at least SPIN_PROT_MIN_GAP below SPIN_PROT_MAX_RATE");
577 "ONELOOP_NB_SPIN_TRIM_RELEASE_RATE must be >= 0 and at least SPIN_PROT_MIN_GAP below SPIN_PROT_START_RATE");
579 "ONELOOP_NB_SPIN_PROT_MAX_CMD must be in [0, MAX_PPRZ]");
581 "ONELOOP_NB_SPIN_TRIM_RATE must be in [0, 1000] pprz/s");
583 "ONELOOP_NB_SPIN_TRIM_BLEED_RATE must be in [0, 1000] pprz/s");
585#ifndef ONELOOP_NB_SPIN_MAN_RAMP_RATE
586#define ONELOOP_NB_SPIN_MAN_RAMP_RATE 2.0
588#ifndef ONELOOP_NB_SPIN_MAN_BLEND_TIME
589#define ONELOOP_NB_SPIN_MAN_BLEND_TIME 1.0
591#ifndef ONELOOP_NB_SPIN_MAN_TRIM_RATE
592#define ONELOOP_NB_SPIN_MAN_TRIM_RATE 300.0
594#ifndef ONELOOP_NB_SPIN_MAN_DONE_RATE
595#define ONELOOP_NB_SPIN_MAN_DONE_RATE 0.5
597#define SPIN_MAN_PAIR_PITCH 0
598#define SPIN_MAN_PAIR_ROLL 1
599#ifndef ONELOOP_NB_SPIN_MAN_PAIR
600#define ONELOOP_NB_SPIN_MAN_PAIR SPIN_MAN_PAIR_PITCH
602#ifndef ONELOOP_NB_SPIN_MAN_PITCH_DIR
603#define ONELOOP_NB_SPIN_MAN_PITCH_DIR 1.0
606 "ONELOOP_NB_SPIN_MAN_PAIR must be 0 (pitch) or 1 (roll)");
608 "ONELOOP_NB_SPIN_MAN_PITCH_DIR must be 1 or -1");
610 "ONELOOP_NB_SPIN_MAN_RAMP_RATE must be in [0.1, 10] rad/s^2");
612 "ONELOOP_NB_SPIN_MAN_BLEND_TIME must be in [0.1, 5] s");
614 "ONELOOP_NB_SPIN_MAN_TRIM_RATE must be in [0, 1000] pprz/s");
616 "ONELOOP_NB_SPIN_MAN_DONE_RATE must be in [0.1, 5] rad/s");
618#ifndef ONELOOP_NB_EC_K3
619#define ONELOOP_NB_EC_K3 22.0
625#ifndef ONELOOP_NB_PID_A_MAX
626#define ONELOOP_NB_PID_A_MAX 0.6
628#ifndef ONELOOP_NB_PID_V_MAX_MANUAL
629#define ONELOOP_NB_PID_V_MAX_MANUAL 3.0
631#ifndef ONELOOP_NB_PID_V_MAX_NAV
632#define ONELOOP_NB_PID_V_MAX_NAV 3.0
636 "ONELOOP_NB_PID_V_MAX_MANUAL must be in [0.1, 10] m/s");
638 "ONELOOP_NB_PID_V_MAX_NAV must be in [0.1, 10] m/s");
669#ifdef ONELOOP_NB_SLOW_POLE
723void err_nd(
float err[],
float a[],
float b[],
float k[],
int n);
724void err_sum_nd(
float err[],
float a[],
float b[],
float k[],
float c[],
int n);
731void rm_3rd_attitude(
float dt,
float x_ref[3],
float x_d_ref[3],
float x_2d_ref[3],
float x_3d_ref[3],
float x_des[3],
bool ow_psi,
float psi_overwrite[4],
float k1_rm[3],
float k2_rm[3],
float k3_rm[3], struct
OneloopStabilizationRef bounds);
732void rm_3rd_pos(
float dt,
float x_ref[],
float x_d_ref[],
float x_2d_ref[],
float x_3d_ref[],
float x_des[],
float k1_rm[],
float k2_rm[],
float k3_rm[],
float x_d_bound,
float x_2d_bound,
float x_3d_bound,
int n);
736void ec_3rd_att(
float y_4d[3],
float x_des[3],
float x_ref[3],
float x_d_ref[3],
float x_2d_ref[3],
float x_3d_ref[3],
float x[3],
float x_d[3],
float x_2d[3],
float k1_e[3],
float k2_e[3],
float k3_e[3], struct
OneloopStabilizationRef bounds,
float fb[3]);
737void ec_3rd_pos(
float y_4d[],
float x_des[],
float x_ref[],
float x_d_ref[],
float x_2d_ref[],
float x_3d_ref[],
float x[],
float x_d[],
float x_2d[],
float k1_e[],
float k2_e[],
float k3_e[],
float x_d_bound,
float x_2d_bound,
float fb[],
int n);
740void chirp_pos(
float time_elapsed,
float f0,
float f1,
float t_chirp,
float A,
int8_t n,
float psi,
float p_ref[],
float v_ref[],
float a_ref[],
float j_ref[],
float p_ref_0[]);
741void chirp_call(
bool*
chirp_on,
bool*
chirp_first_call,
float*
t_0_chirp,
float*
time_elapsed,
float f0,
float f1,
float t_chirp,
float A,
int8_t n,
float psi,
float p_ref[],
float v_ref[],
float a_ref[],
float j_ref[],
float p_ref_0[]);
751float cos_2n(
float psi,
float xi,
int n);
758#if PERIODIC_TELEMETRY
872#ifdef PPRZ_MSG_ID_PUSH_NB
1118void err_nd(
float err[],
float a[],
float b[],
float k[],
int n)
1121 for (i = 0; i < n; i++)
1123 err[i] = k[i] * (a[i] -
b[i]);
1127void err_sum_nd(
float err[],
float a[],
float b[],
float k[],
float c[],
int n)
1130 for (i = 0; i < n; i++)
1132 err[i] = k[i] * (a[i] -
b[i]);
1139 err[0] = (a[0] -
b[0]);
1140 err[1] = (a[1] -
b[1]);
1141 err[2] = (a[2] -
b[2]);
1148 for (i = 0; i < n; i++)
1150 a[i] = a[i] + dt *
a_dot[i];
1162 for (i = 0; i < n; i++)
1176 return (omega_n * omega_n * p1) / (omega_n * omega_n + omega_n * p1 * zeta * 2.0);
1183 return (omega_n * omega_n + omega_n * p1 * zeta * 2.0) / (p1 + omega_n * zeta * 2.0);
1190 return p1 + omega_n * zeta * 2.0;
1239 const float u_sat[3],
1244 const float eps = 1e-6f;
1276 const float x_dot[3],
1280 static float prev_vel[3] = {0.f, 0.f, 0.f};
1281 static float integral[3] = {0.f, 0.f, 0.f};
1285 const float I_MAX = 0.4f;
1297 for (
int i = 0; i < 3; i++)
1335 const float x_dot[3],
1339 static float prev_vel[3] = {0.f, 0.f, 0.f};
1340 static float integral[3] = {0.f, 0.f, 0.f};
1344 const float I_MAX = 0.4f;
1356 for (
int i = 0; i < 3; i++)
1362 for (
int i = 0; i < 3; i++)
1408 float spsi =
sinf(psi);
1409 float cpsi =
cosf(psi);
1410 float aX = cpsi * a[0] + spsi * a[1];
1411 float aY = -spsi * a[0] + cpsi * a[1];
1441 float sphi =
sinf(e[0]);
1442 float cphi =
cosf(e[0]);
1443 float stheta =
sinf(e[1]);
1444 float ctheta =
cosf(e[1]);
1445 r[0] = ctheta *
edot[0] - stheta * cphi *
edot[2];
1447 r[2] = stheta *
edot[0] + ctheta * cphi *
edot[2];
1469 float sphi =
sinf(e[0]);
1470 float cphi =
cosf(e[0]);
1471 float stheta =
sinf(e[1]);
1472 float ctheta =
cosf(e[1]);
1473 float spsi =
sinf(e[2]);
1474 float cpsi =
cosf(e[2]);
1480 edot[0] = r[0] + spsi * stheta / ctheta * r[1] + cpsi * stheta / ctheta * r[2];
1481 edot[1] = cphi * r[1] - sphi * r[2];
1482 edot[2] = sphi * r[1] + cphi * r[2];
1490 float v[2] = {vect->
x, vect->
y};
1491 float sign_v0 = (
v[0] > 0.f) ? 1.f : (
v[0] < 0.f) ? -1.f
1493 float sign_v1 = (
v[1] > 0.f) ? 1.f : (
v[1] < 0.f) ? -1.f
1559void rm_3rd_attitude(
float dt,
float x_ref[3],
float x_d_ref[3],
float x_2d_ref[3],
float x_3d_ref[3],
float x_des[3],
bool ow_psi,
float psi_overwrite[4],
float k1_rm[3],
float k2_rm[3],
float k3_rm[3],
struct OneloopStabilizationRef bounds)
1635void rm_3rd_pos(
float dt,
float x_ref[],
float x_d_ref[],
float x_2d_ref[],
float x_3d_ref[],
float x_des[],
float k1_rm[],
float k2_rm[],
float k3_rm[],
float x_d_bound,
float x_2d_bound,
float x_3d_bound,
int n)
1714void ec_3rd_pos(
float y_4d[],
float x_des[],
float x_ref[],
float x_d_ref[],
float x_2d_ref[],
float x_3d_ref[],
float x[],
float x_d[],
float x_2d[],
float k1_e[],
float k2_e[],
float k3_e[],
float x_d_bound,
float x_2d_bound,
float fb[],
int n)
1746void ec_3rd_att(
float y_4d[3],
float x_des[3],
float x_ref[3],
float x_d_ref[3],
float x_2d_ref[3],
float x_3d_ref[3],
float x[3],
float x_d[3],
float x_2d[3],
float k1_e[3],
float k2_e[3],
float k3_e[3],
struct OneloopStabilizationRef bounds,
float fb[3])
2073 LP->tau = 1 / (2 *
M_PI *
LP->freq);
2076#elif defined(USE_BW2)
2078#elif defined(USE_YAW_LP4)
2084 LP->meas_prev = 0.0;
2092 LP->freq =
LP->freq_set;
2093 LP->tau = 1 / (2 *
M_PI *
LP->freq);
2102 LP->freq =
LP->freq_set;
2103 LP->tau = 1 / (2 *
M_PI *
LP->freq);
2163 for (
int i = 0; i < 3; i++)
2182 float tau_r = 1.0 / (5.0);
2187 for (
int i = 0; i < 3; i++)
2200 for (
int i = 0; i < 3; i++)
2215#ifdef USE_ND_VELOCITIES
2328#if PERIODIC_TELEMETRY
2335#ifdef PPRZ_MSG_ID_PUSH_NB
2420#ifdef ROTWING_EFF_SCHED_MP_dFdu
2557#ifdef ROTWING_EFF_SCHED_MP_dFdu
2569#ifdef ROTWING_EFF_SCHED_MP_dFdu
2626#define OVERRIDE_ATT_RM
2627#ifdef OVERRIDE_ATT_RM
2636 static float psi_vec[4] = {0.0, 0.0, 0.0, 0.0};
2637 rm_3rd_attitude(
dt_1l,
oneloop_nB.
sta_ref.
att,
oneloop_nB.
sta_ref.
att_d,
oneloop_nB.
sta_ref.
att_2d,
oneloop_nB.
sta_ref.
att_3d,
att_des,
false,
psi_vec,
k_att_rm.
k1,
k_att_rm.
k2,
k_att_rm.
k3,
sta_bounds);
2729 float nu_stab[3] = {0.0, 0.0, 0.0};
2736 float dummy1[3] = {1.0, 1.0, 1.0};
2737 float dummy0[3] = {0.0, 0.0, 0.0};
2745 ec_3rd_att(
att_jerk_des,
att_des,
oneloop_nB.
sta_ref.
att,
oneloop_nB.
sta_ref.
att_d,
oneloop_nB.
sta_ref.
att_2d,
oneloop_nB.
sta_ref.
att_3d,
oneloop_nB.
sta_state.
att,
oneloop_nB.
sta_state.
att_d,
oneloop_nB.
sta_state.
att_2d,
k_att_e.
k1,
k_att_e.
k2,
k_att_e.
k3,
sta_bounds,
ctrl_effort_model_att);
2753 ec_3rd_att(
att_jerk_des,
att_des,
oneloop_nB.
sta_ref.
att,
oneloop_nB.
sta_ref.
att_d,
oneloop_nB.
sta_ref.
att_2d,
dummy0,
oneloop_nB.
sta_state.
att,
oneloop_nB.
sta_state.
att_d,
oneloop_nB.
sta_state.
att_2d,
k_att_e.
k1,
k_att_e.
k2,
dummy1,
sta_bounds,
ctrl_effort_model_att);
2760 ec_3rd_att(
att_jerk_des,
att_des,
oneloop_nB.
sta_ref.
att,
oneloop_nB.
sta_ref.
att_d,
oneloop_nB.
sta_ref.
att_2d,
oneloop_nB.
sta_ref.
att_3d,
oneloop_nB.
sta_state.
att,
oneloop_nB.
sta_state.
att_d,
oneloop_nB.
sta_state.
att_2d,
k_att_e.
k1,
k_att_e.
k2,
k_att_e.
k3,
sta_bounds,
ctrl_effort_model_att);
2769 ec_3rd_att(
att_jerk_des,
att_des,
oneloop_nB.
sta_ref.
att,
oneloop_nB.
sta_ref.
att_d,
oneloop_nB.
sta_ref.
att_2d,
dummy0,
oneloop_nB.
sta_state.
att,
oneloop_nB.
sta_state.
att_d,
oneloop_nB.
sta_state.
att_2d,
k_att_e.
k1,
k_att_e.
k2,
dummy1,
sta_bounds,
ctrl_effort_model_att);
2893 for (
int k = 0; k < 2; k++)
2906#if ONELOOP_NB_DEBUG_MODE
3031#ifdef COMMAND_AILERONS
3167#ifdef FWD_SIDESLIP_GAIN
3186 float cpsi =
cosf(psi);
3187 float spsi =
sinf(psi);
3216 float dv =
bv *
bv - 4.0f *
av * cv;
3358#ifdef COMMAND_AILERONS
3369#ifdef COMMAND_ROT_MECH
3797 float c =
cosf((psi -
xi) / 2.0f);
3800 for (
int i = 0; i < n; i++)
3810 float out = -
atan2f(r, w);
Main include for ABI (AirBorneInterface).
struct pprz_autopilot autopilot
Global autopilot structure.
bool autopilot_get_motors_on(void)
get motors status
pprz_t throttle
throttle level as will be displayed in GCS
Hardware independent code for commands handling.
static struct uart_periph * dev
float G2_RW[EFF_MAT_COLS_NB]
float EFF_MAT_RW[EFF_MAT_ROWS_NB][EFF_MAT_COLS_NB]
#define FLOAT_ANGLE_NORMALIZE(_a)
static void float_vect_sum(float *o, const float *a, const float *b, const int n)
o = a + b
static void float_vect_zero(float *a, const int n)
a = 0
void float_eulers_of_quat_zxy(struct FloatEulers *e, const struct FloatQuat *q)
euler rotation 'ZXY' This rotation order is useful if you need 90 deg pitch
#define FLOAT_VECT3_ZERO(_v)
void float_rmat_vmult(struct FloatVect3 *vb, const struct FloatRMat *m_a2b, const struct FloatVect3 *va)
rotate 3D vector by rotation matrix.
static void float_vect_copy(float *a, const float *b, const int n)
a = b
static void float_vect_diff(float *o, const float *a, const float *b, const int n)
o = a - b
static float float_vect_norm(const float *a, const int n)
||a||
#define FLOAT_VECT2_NORM(_v)
#define VECT2_DIFF(_c, _a, _b)
#define VECT3_SUB(_a, _b)
#define VECT3_ADD(_a, _b)
#define POS_FLOAT_OF_BFP(_ai)
#define SPEED_FLOAT_OF_BFP(_ai)
#define POS_BFP_OF_REAL(_af)
#define ACCEL_FLOAT_OF_BFP(_ai)
#define SPEED_BFP_OF_REAL(_af)
static struct NedCoor_f * stateGetAccelNed_f(void)
Get acceleration in NED coordinates (float).
static struct FloatRMat * stateGetNedToBodyRMat_f(void)
Get vehicle body attitude rotation matrix (float).
static struct FloatQuat * stateGetNedToBodyQuat_f(void)
Get vehicle body attitude quaternion (float).
static struct NedCoor_f * stateGetPositionNed_f(void)
Get position in local NED coordinates (float).
static struct FloatRates * stateGetBodyRates_f(void)
Get vehicle body angular rate (float).
static struct NedCoor_f * stateGetSpeedNed_f(void)
Get ground speed in local NED coordinates (float).
static struct Int32Vect3 * stateGetAccelBody_i(void)
Get acceleration in Body coordinates (int).
static float stateGetAirspeed_f(void)
Get airspeed (float).
bool force_forward
forward flight for hybrid nav
Integrated Navigation System interface.
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
Simple first order low pass filter with bilinear transform.
static void init_first_order_low_pass(struct FirstOrderLowPass *filter, float tau, const float sample_time, float value)
Init first order low pass filter.
static float update_first_order_low_pass(struct FirstOrderLowPass *filter, const float value)
Update first order low pass filter state with a new value.
static void init_butterworth_2_low_pass(Butterworth2LowPass *filter, const float tau, const float sample_time, const float value)
Init a second order Butterworth filter.
static float update_butterworth_2_low_pass(Butterworth2LowPass *filter, const float value)
Update second order Butterworth low pass filter state with a new value.
static float update_butterworth_4_low_pass(Butterworth4LowPass *filter, const float value)
Update fourth order Butterworth low pass filter state with a new value.
static void init_butterworth_4_low_pass(Butterworth4LowPass *filter, const float tau, const float sample_time, const float value)
Init a fourth order Butterworth filter.
Second order low pass filter structure.
Hardware independent API for actuators (servos, motor controllers).
#define NAV_HYBRID_MAX_AIRSPEED
float nav_hybrid_max_bank
float nav_max_acceleration_sp
float nav_hybrid_pos_gain
#define NAV_HYBRID_MAX_DECELERATION
Specific navigation functions for hybrid aircraft.
static void notch_filter_update(struct SecondOrderNotchFilter *filter, int32_t *input_signal, int32_t *output_signal)
Notch filter propagate.
static void notch_filter_init(struct SecondOrderNotchFilter *filter, float cutoff_frequency, float bandwidth, uint16_t sample_frequency)
Initialize second order notch filter.
#define ANDI_NUM_VIRTUAL_ACT
#define CTRL_ANDI
Control types.
void init_poles(void)
Initialize Position of Poles.
static void send_oneloop_nB_ctrl(struct transport_tx *trans, struct link_device *dev)
#define ONELOOP_NB_PID_V_MAX_NAV
float oneloop_nB_filt_cutoff
struct PolePlacement p_pos_e
#define ONELOOP_NB_SPIN_MAN_TRIM_RATE
static float Wv_backup[ANDI_OUTPUTS]
static void reinit_LP(struct LP_t *LP, bool reinit)
#define ONELOOP_NB_DEBUG_MODE
void chirp_pos(float time_elapsed, float f0, float f1, float t_chirp, float A, int8_t n, float psi, float p_ref[], float v_ref[], float a_ref[], float j_ref[], float p_ref_0[])
Reference Model Definition for 3rd order system specific to positioning with bounds.
static float spin_man_dir
static Butterworth2LowPass accely_filt
float act_dynamics[ANDI_NUM_ACT_TOT]
#define ONELOOP_NB_SPIN_MAN_RAMP_RATE
float ratio_u_un[ANDI_NUM_ACT_TOT]
static Butterworth2LowPass nB_filt[3]
static float Wu_backup[ANDI_NUM_ACT_TOT]
void init_filter(void)
Initialize the filters.
float spin_man_blend_time
float ctrl_effort_model[ANDI_OUTPUTS]
void reinit_controller(void)
Re-Init function of controller variables.
static bool vec3_saturated(const float u_unsat[3], const float u_sat[3], float eps)
struct PolePlacement p_head_rm
void oneloop_calc_model_disturbance(bool in_flight)
Function that calculates the model disturbance (Control Effort) The control effort is equalt to : EFF...
static void update_filter_on_type(struct LP_t *filter, float input)
Update a filter based on its type.
static Butterworth2LowPass airspeed_filt
static void eul_of_acc(float a[3], float psi)
float n_array[ANDI_OUTPUTS]
static void init_all_LP(void)
Initialize all Low Pass Filters.
float act_max_norm[ANDI_NUM_ACT_TOT]
struct Gains3rdOrder k_att_rm
static void send_eff_mat_stab_oneloop_nB(struct transport_tx *trans, struct link_device *dev)
void float_euler_dot_of_rates_vec(float r[3], float e[3], float edot[3])
Attitude Euler to Rates Conversion Function ZYX.
static Butterworth2LowPass u_filt[ANDI_NUM_ACT_TOT]
void oneloop_nB_propagate_filters(void)
Propagate the filters.
float act_dyn_ctrl[ANDI_NUM_ACT_TOT]
struct FloatEulers eulers_zxy_des
struct PolePlacement p_att_rm
float pusher_cmd_fun(float aN_des, float aE_des, float r, float psi, float w, int n)
static void ARW_ClampVec3(const float err[3], const float u_unsat[3], const float u_sat[3], const float I_prev[3], const float I_cand[3], float I_next[3])
static float k_rm_3_3_f(float omega_n, float zeta, float p1)
static Butterworth2LowPass nB_2d_filt[3]
#define ONELOOP_NB_PID_V_MAX_MANUAL
bool safety_killer_trigger
void guidance_set_max_bank_angle(float max_bank)
Guidance limit setters called by rotwing_state (also implemented by guidance_indi_hybrid).
float xi_fun(float r, float w, float aN_des, float aE_des)
struct Gains3rdOrder k_att_e
#define ONELOOP_NB_SPIN_TRIM_BLEED_RATE
static float spin_man_u_last[ANDI_NUM_ACT]
float EFF_MAT_G[ANDI_OUTPUTS][ANDI_NUM_ACT_TOT]
float oneloop_nB_sideslip(void)
Function to calculate corrections for sideslip DEPRECIATED.
void rm_1st_pos(float dt, float x_2d_ref[], float x_3d_ref[], float x_2d_des[], float k3_rm[], float x_3d_bound, int n)
Reference Model Definition for 3rd order system specific to positioning with bounds.
void guidance_set_max_climb_speed(float max_climb_speed_quad, float max_climb_speed_fwd)
struct Gains3rdOrder k_pos_e
bool actuator_is_servo[ANDI_NUM_ACT_TOT]
void float_vect_diff_euler(float err[3], float a[3], float b[3])
Calculate Error between two 3D euler arrays with the psi normalized.
float num_thrusters_oneloop
static float act_dynamics_d[ANDI_NUM_ACT_TOT]
static void Vel_PID_ARW(float x_dot_des[3], const float x_dot[3], float k_P, float k_I, float k_D, float a_sp[3], float a_max, float v_max)
static void spin_man_set_pair(uint8_t pair)
Select the motors of a pair (pitch: FRONT/BACK, roll: RIGHT/LEFT) for the blend.
#define ONELOOP_NB_SPIN_MAN_PITCH_DIR
static float andi_u_n[ANDI_NUM_ACT_TOT]
float act_min_norm[ANDI_NUM_ACT_TOT]
#define ONELOOP_NB_SPIN_PROT_START_RATE
void rm_3rd_attitude(float dt, float x_ref[3], float x_d_ref[3], float x_2d_ref[3], float x_3d_ref[3], float x_des[3], bool ow_psi, float psi_overwrite[4], float k1_rm[3], float k2_rm[3], float k3_rm[3], struct OneloopStabilizationRef bounds)
Reference Model Definition for 3rd order system with attitude conversion functions.
static float ec_poles(float p_rm, float slow_pole, float k)
Calculate EC poles given RM poles.
static void send_wls_u_oneloop(struct transport_tx *trans, struct link_device *dev)
#define ONELOOP_NB_SPIN_PROT_MAX_RATE
float spin_trim_release_rate
static bool spin_man_rate_ctrl(void)
Yaw rate tracking is used by the manoeuvre (no fault active)
void nB_EC(struct FloatVect3 nB, struct FloatVect3 nB_d, struct FloatVect3 nB_2d, struct FloatVect3 mu_B, float k1_e[3], float k2_e[3], float k3_e[3], float dist[3], float nB_nu[3])
void oneloop_from_nav(bool in_flight)
Function that maps navigation inputs to the oneloop controller for the generated autopilot.
float phase_first_order(float r, float w)
float bound_v_from_a(float e_x, float v_bound, float a_bound)
Calculate velocity limit based on acceleration limit for a float From SUVAT we have that v^2 = u^2 + ...
struct PolePlacement p_alt_rm
static Butterworth2LowPass KPID_filt[3]
float cos_2n(float psi, float xi, int n)
void init_controller_gains(void)
Initialize Controller Gains FIXME: Calculate the gains dynamically for transition.
static uint8_t spin_man_mot[2]
static void reinit_all_LP(bool reinit)
Reinitialize all the Low Pass Filters.
static float positive_non_zero(float input)
Function to make sure that inputs are positive non zero vaues.
#define ONELOOP_NB_SPIN_MAN_DONE_RATE
float safety_killer_cutoff
#define ONELOOP_NB_SPIN_PROT_MIN_GAP
#define SPIN_MAN_PAIR_PITCH
void guidance_set_min_max_airspeed(float min_airspeed, float max_airspeed)
float andi_u[ANDI_NUM_ACT_TOT]
float oneloop_nB_filt_cutoff_q
void calc_normalization(void)
Calculate Normalization of actuators and discrete actuator dynamics
static void send_eff_mat_guid_oneloop_nB(struct transport_tx *trans, struct link_device *dev)
static void spin_man_update(bool in_flight, bool nb_ctrl)
Spin transition manoeuvre state machine.
void drop_axis(void)
Function that drops control along selected axes.
static void spin_man_start_blend(void)
Start a bumpless transfer of the selected pair from the average of its last applied commands,...
static void send_oneloop_nB(struct transport_tx *trans, struct link_device *dev)
struct Gains3rdOrder k_pos_e_indi
struct PolePlacement p_att_e
static void debug_vect(struct transport_tx *trans, struct link_device *dev, char *name, float *data, int datasize)
struct PolePlacement p_alt_e
float bound_v_from_a_vect(float e_x[], float v_bound, float a_bound, int n)
Calculate velocity limit based on acceleration limit for a vector From SUVAT we have that v^2 = u^2 +...
void rm_2nd_pos(float dt, float x_d_ref[], float x_2d_ref[], float x_3d_ref[], float x_d_des[], float k2_rm[], float k3_rm[], float x_2d_bound, float x_3d_bound, int n)
Reference Model Definition for 3rd order system specific to positioning with bounds.
void get_act_state_oneloop(void)
Function to reconstruct actuator state using first order dynamics.
struct PolePlacement p_roll_e
void ec_3rd_pos(float y_4d[], float x_des[], float x_ref[], float x_d_ref[], float x_2d_ref[], float x_3d_ref[], float x[], float x_d[], float x_2d[], float k1_e[], float k2_e[], float k3_e[], float x_d_bound, float x_2d_bound, float fb[], int n)
Error Controller Definition for 3rd order system.
struct PolePlacement p_head_e
#define SPIN_MAN_PAIR_ROLL
static void spin_prot_bound_params(void)
Enforce valid spin protection / spin trim parameters (they can be changed in flight from the settings...
static Butterworth2LowPass nB_3d_state_filt[2]
static void init_LP(struct LP_t *LP, float fc)
Initialize the Low Pass Filter Struct.
float andi_du[ANDI_NUM_ACT_TOT]
static float spin_man_alpha
float oneloop_nB_filt_cutoff_v
float spin_trim_bleed_rate
struct OneloopGeneral oneloop_nB
static void send_wls_v_oneloop(struct transport_tx *trans, struct link_device *dev)
static float nav_target[3]
void err_nd(float err[], float a[], float b[], float k[], int n)
Calculate Scaled Error between two 3D arrays.
void oneloop_nB_state_compensation(bool state_compensation_on)
Function that performs state compensation for gyroscopic effects.
#define ONELOOP_NB_FAULT_AILERONS
float oneloop_nB_yaw_dist_limit
static void init_filter_on_type(struct LP_t *filter, float x0)
Initialize a filter based on its type.
struct Gains3rdOrder k_pos_rm
bool autopilot_in_flight_end_detection(bool motors_on UNUSED)
Quadplanes can still be in-flight with COMMAND_THRUST==0 and can even soar not descending in updrafts...
void guidance_set_max_descend_speed(float max_descend_speed_quad, float max_descend_speed_fwd)
#define ONELOOP_NB_SPIN_PROT_MAX_CMD
static void reinit_LP_synchronous(struct LP_t *LP, struct LP_t *f, bool reinit)
Reinitialize Low Pass filter if new frequency setting or if forced.
static void spin_man_reset(void)
Stop the spin manoeuvre and clear its GCS triggers (fault flags are left as they are)
float m_array[ANDI_NUM_ACT_TOT]
bool state_compensation_on
static Butterworth2LowPass push_PID_vel[2]
void oneloop_nB_enter(bool half_loop_sp, int ctrl_type)
Function that resets important values upon engaging Oneloop ANDI.
static void Pos_KPID_ARW(const float x_des[3], const float x[3], const float x_dot[3], float k_K, float k_P, float k_I, float k_D, float a_sp[3], float a_max, float v_max)
void chirp_call(bool *chirp_on, bool *chirp_first_call, float *t_0_chirp, float *time_elapsed, float f0, float f1, float t_chirp, float A, int8_t n, float psi, float p_ref[], float v_ref[], float a_ref[], float j_ref[], float p_ref_0[])
void G1G2_oneloop(int ctrl_type)
Function that samples and scales the effectiveness matrix FIXME: make this function into a for loop t...
#define ONELOOP_NB_SPIN_TRIM_RELEASE_RATE
float act_max[ANDI_NUM_ACT_TOT]
#define ONELOOP_NB_SPIN_MAN_BLEND_TIME
static void spin_man_ramp_ref(float target)
Move the yaw rate reference towards target at spin_man_ramp_rate.
void set_WLS_settings(void)
Function that sets the WLS settings for oneloop controller.
void normalize_nu(void)
Function to normalize the pseudo control vector.
void rm_3rd_pos(float dt, float x_ref[], float x_d_ref[], float x_2d_ref[], float x_3d_ref[], float x_des[], float k1_rm[], float k2_rm[], float k3_rm[], float x_d_bound, float x_2d_bound, float x_3d_bound, int n)
Reference Model Definition for 3rd order system specific to positioning with bounds.
struct FloatEulers eulers_zxy
void float_rates_of_euler_dot_vec(float r[3], float e[3], float edot[3])
Attitude Rates to Euler Conversion Function ZYX.
void SpinQuad_overwrite(float gain, float ce_model, float *nu_stab_2)
static void send_eff_mat_stab_thrust_oneloop_nB(struct transport_tx *trans, struct link_device *dev)
#define ONELOOP_NB_SPIN_TRIM_ON
static Butterworth2LowPass push_PID_vel_d[2]
static float k_rm_1_3_f(float omega_n, float zeta, float p1)
Reference Model Gain Design.
float gi_unbounded_airspeed_sp
PRINT_CONFIG_VAR(ONELOOP_NB_FILT_CUTOFF)
struct OneloopStabilizationRef sta_bounds
void init_poles_att(void)
Initialize Position of Poles.
#define ONELOOP_NB_MAX_FAULT_MOT
void oneloop_nB_calc_nB_states(void)
Function which estimates the nB states.
struct PolePlacement p_pos_rm
float ratio_vn_v[ANDI_OUTPUTS]
void oneloop_nB_run(bool in_flight, bool half_loop, struct FloatVect3 PSA_des)
Main function that runs the controller and performs control allocation.
float actuator_state_1l[ANDI_NUM_ACT_TOT]
float oneloop_nB_filt_cutoff_a
void vect_bound_nd(float vect[], float bound, int n)
Scale a 3D array to within a 3D bound.
void err_sum_nd(float err[], float a[], float b[], float k[], float c[], int n)
Calculate Scaled Error between two 3D arrays.
#define ONELOOP_NB_AIRSPEED_SWITCH_THRESHOLD
void integrate_nd(float dt, float a[], float a_dot[], int n)
Integrate in time 3D array.
void rm_3rd_nI(float dt, struct FloatVect3 *x_ref, struct FloatVect3 *x_d_ref, struct FloatVect3 *x_2d_ref, struct FloatVect3 *x_3d_ref, const struct FloatVect3 *x_des, const float k1_rm[3], const float k2_rm[3], const float k3_rm[3])
struct Gains3rdOrder k_att_e_indi
static Butterworth2LowPass KPID_vel_filt[3]
static void send_oneloop_debug(struct transport_tx *trans, struct link_device *dev)
float act_min[ANDI_NUM_ACT_TOT]
static void send_guidance_oneloop_nB(struct transport_tx *trans, struct link_device *dev)
float oneloop_nB_filt_cutoff_p
void oneloop_nB_RM(bool half_loop, struct FloatVect3 PSA_des, bool in_flight_oneloop)
Function to generate the reference signals for the oneloop controller.
float oneloop_nB_filt_cutoff_r
static float spin_man_u_hold[2]
void acc_body_bound(struct FloatVect2 *vect, float bound)
Scale a 3D array to within a 3D bound.
float * bwls_1l[ANDI_OUTPUTS]
void init_poles_pos(void)
#define ONELOOP_NB_SPIN_TRIM_RATE
void skew_symmetric(struct FloatRMat *out, const struct FloatVect3 *in)
#define ONELOOP_NB_PID_A_MAX
static float k_rm_2_3_f(float omega_n, float zeta, float p1)
static float nav_target_new[3]
void ec_3rd_att(float y_4d[3], float x_des[3], float x_ref[3], float x_d_ref[3], float x_2d_ref[3], float x_3d_ref[3], float x[3], float x_d[3], float x_2d[3], float k1_e[3], float k2_e[3], float k3_e[3], struct OneloopStabilizationRef bounds, float fb[3])
Error Controller Definition for 3rd order system specific to attitude.
#define ONELOOP_NB_SPIN_MAN_PAIR
void calc_HB_matrix(float HB[3][3], struct FloatVect3 nB)
static float u_pref[ANDI_NUM_ACT_TOT]
float spin_prot_start_rate
void oneloop_nB_init(void)
Init function of Oneloop ANDI controller
static void shape_vector(float a[3])
struct OneloopGuidanceState gui_state
struct OneloopStabilizationState sta_state
union LP_t::@275 meas_filt
struct OneloopGuidanceRef gui_ref
struct OneloopStabilizationRef sta_ref
struct OneloopStabilizationnBState sta_nB_state
enum FilterType filter_type
struct OneloopPushnB push_nB
Paparazzi floating point algebra.
vector in North East Down coordinates Units: meters
struct RadioControl radio_control
Generic interface for radio control modules.
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
static pprz_t radio_control_get(uint8_t idx)
Get a radio control channel value.
#define RADIO_ROLL
Redefining RADIO_* Do not use with radio.h (ppm rc)
struct RotorcraftNavigation nav
Rotorcraft navigation functions.
struct EnuCoor_f speed
speed setpoint (in m/s)
float climb
climb setpoint (in m/s)
#define NAV_SETPOINT_MODE_SPEED
#define NAV_VERTICAL_MODE_CLIMB
float nav_altitude
current altitude setpoint (in meters): might differ from fp_altitude depending on altitude shift from...
#define NAV_VERTICAL_MODE_ALT
#define NAV_SETPOINT_MODE_POS
Nav setpoint modes these modes correspond to submodes defined by navigation routines to tell which se...
struct EnuCoor_f target
final target position (in meters)
static const ShellCommand commands[]
struct Stabilization stabilization
int32_t cmd[COMMANDS_NB]
output command vector, range from [-MAX_PPRZ:MAX_PPRZ] (store for messages)
API to get/set the generic vehicle states.
int16_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint16_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.
static const float scale[]
short int16_t
Typedef defining 16 bit short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
signed char int8_t
Typedef defining 8 bit char type.
uint16_t f
Camera baseline, in meters (i.e. horizontal distance between the two cameras of the stereo setup)
void send_wls_v(char *name, struct WLS_t *WLS_p, struct transport_tx *trans, struct link_device *dev)
void wls_alloc(struct WLS_t *WLS_p, float **B, float *u_guess, float *W_init, int imax)
active set algorithm for control allocation
void send_wls_u(char *name, struct WLS_t *WLS_p, struct transport_tx *trans, struct link_device *dev)
float u_pref[WLS_N_U_MAX]