32 #include "generated/airframe.h"
39 #ifndef STABILIZATION_ATTITUDE_HELI_INDI_USE_NOTCHFILTER
40 #define STABILIZATION_ATTITUDE_HELI_INDI_USE_NOTCHFILTER 0
42 #if STABILIZATION_ATTITUDE_HELI_INDI_USE_NOTCHFILTER
43 #ifndef RPM_PWM_CHANNEL
44 #error notch filter requires module rpm_sensor.xml
50 #ifndef STABILIZATION_ATTITUDE_HELI_INDI_STEADY_STATE_ROLL
51 #define STABILIZATION_ATTITUDE_HELI_INDI_STEADY_STATE_ROLL 4.5
53 #ifndef STABILIZATION_ATTITUDE_HELI_INDI_STEADY_STATE_PITCH
54 #define STABILIZATION_ATTITUDE_HELI_INDI_STEADY_STATE_PITCH 0
56 #ifndef STABILIZATION_ATTITUDE_HELI_INDI_ROLL_P
57 #define STABILIZATION_ATTITUDE_HELI_INDI_ROLL_P 12
59 #ifndef STABILIZATION_ATTITUDE_HELI_INDI_PITCH_P
60 #define STABILIZATION_ATTITUDE_HELI_INDI_PITCH_P 8
62 #ifndef STABILIZATION_ATTITUDE_HELI_INDI_YAW_P
63 #define STABILIZATION_ATTITUDE_HELI_INDI_YAW_P 10
65 #ifndef STABILIZATION_ATTITUDE_HELI_INDI_YAW_D
66 #define STABILIZATION_ATTITUDE_HELI_INDI_YAW_D 30
68 #ifndef STABILIZATION_ATTITUDE_HELI_INDI_GINV_ROLL_TO_ROLL
69 #define STABILIZATION_ATTITUDE_HELI_INDI_GINV_ROLL_TO_ROLL 11681
71 #ifndef STABILIZATION_ATTITUDE_HELI_INDI_GINV_PITCH_TO_PITCH
72 #define STABILIZATION_ATTITUDE_HELI_INDI_GINV_PITCH_TO_PITCH 13873
74 #ifndef STABILIZATION_ATTITUDE_HELI_INDI_GINV_YAW_TO_YAW
75 #define STABILIZATION_ATTITUDE_HELI_INDI_GINV_YAW_TO_YAW 730
77 #ifndef STABILIZATION_ATTITUDE_HELI_INDI_ROLL_COMMAND_ROTATION
78 #define STABILIZATION_ATTITUDE_HELI_INDI_ROLL_COMMAND_ROTATION 11.0
80 #ifndef STABILIZATION_ATTITUDE_HELI_INDI_PITCH_COMMAND_ROTATION
81 #define STABILIZATION_ATTITUDE_HELI_INDI_PITCH_COMMAND_ROTATION -30.0
83 #ifndef STABILIZATION_ATTITUDE_HELI_INDI_NOTCHFILT_BW_DEFAULT
84 #define STABILIZATION_ATTITUDE_HELI_INDI_NOTCHFILT_BW_DEFAULT 10.0
86 #ifndef STABILIZATION_ATTITUDE_HELI_INDI_NOTCHFILT_BW_ROLL
87 #define STABILIZATION_ATTITUDE_HELI_INDI_NOTCHFILT_BW_ROLL STABILIZATION_ATTITUDE_HELI_INDI_NOTCHFILT_BW_DEFAULT
89 #ifndef STABILIZATION_ATTITUDE_HELI_INDI_NOTCHFILT_BW_PITCH
90 #define STABILIZATION_ATTITUDE_HELI_INDI_NOTCHFILT_BW_PITCH STABILIZATION_ATTITUDE_HELI_INDI_NOTCHFILT_BW_DEFAULT
92 #ifndef STABILIZATION_ATTITUDE_HELI_INDI_NOTCHFILT_BW_YAW
93 #define STABILIZATION_ATTITUDE_HELI_INDI_NOTCHFILT_BW_YAW STABILIZATION_ATTITUDE_HELI_INDI_NOTCHFILT_BW_DEFAULT
95 #ifndef STABILIZATION_ATTITUDE_HELI_INDI_NOTCHFILT_BW_THRUST
96 #define STABILIZATION_ATTITUDE_HELI_INDI_NOTCHFILT_BW_THRUST STABILIZATION_ATTITUDE_HELI_INDI_NOTCHFILT_BW_DEFAULT
98 #ifndef STABILIZATION_ATTITUDE_HELI_INDI_BUTTERW_CUTOFF_DEFAULT
99 #define STABILIZATION_ATTITUDE_HELI_INDI_BUTTERW_CUTOFF_DEFAULT 40.0
101 #ifndef STABILIZATION_ATTITUDE_HELI_INDI_BUTTERW_CUTOFF_ROLL
102 #define STABILIZATION_ATTITUDE_HELI_INDI_BUTTERW_CUTOFF_ROLL STABILIZATION_ATTITUDE_HELI_INDI_BUTTERW_CUTOFF_DEFAULT
104 #ifndef STABILIZATION_ATTITUDE_HELI_INDI_BUTTERW_CUTOFF_PITCH
105 #define STABILIZATION_ATTITUDE_HELI_INDI_BUTTERW_CUTOFF_PITCH STABILIZATION_ATTITUDE_HELI_INDI_BUTTERW_CUTOFF_DEFAULT
107 #ifndef STABILIZATION_ATTITUDE_HELI_INDI_BUTTERW_CUTOFF_YAW
108 #define STABILIZATION_ATTITUDE_HELI_INDI_BUTTERW_CUTOFF_YAW STABILIZATION_ATTITUDE_HELI_INDI_BUTTERW_CUTOFF_DEFAULT
110 #ifndef STABILIZATION_ATTITUDE_HELI_INDI_BUTTERW_CUTOFF_THRUST
111 #define STABILIZATION_ATTITUDE_HELI_INDI_BUTTERW_CUTOFF_THRUST STABILIZATION_ATTITUDE_HELI_INDI_BUTTERW_CUTOFF_DEFAULT
113 #ifndef STABILIZATION_ATTITUDE_HELI_INDI_NOTCH_MIN_RPM
114 #define STABILIZATION_ATTITUDE_HELI_INDI_NOTCH_MIN_RPM 1500
116 #define INDI_NOTCH_MIN_RPM STABILIZATION_ATTITUDE_HELI_INDI_NOTCH_MIN_RPM
119 #define INVG_00 STABILIZATION_ATTITUDE_HELI_INDI_GINV_ROLL_TO_ROLL
120 #define INVG_11 STABILIZATION_ATTITUDE_HELI_INDI_GINV_PITCH_TO_PITCH
121 #define INVG_22 STABILIZATION_ATTITUDE_HELI_INDI_GINV_YAW_TO_YAW
122 #define INVG_33 -50000
123 #define INT32_INVG_FRAC 16
148 #if STABILIZATION_ATTITUDE_HELI_INDI_USE_FAST_DYN_FILTERS
179 #if STABILIZATION_ATTITUDE_HELI_INDI_USE_FAST_DYN_FILTERS
208 _out[
INDI_YAW] = yaw_output_buffer[buf_idx];
209 yaw_output_buffer[buf_idx] = _in[
INDI_YAW];
221 static int32_t prev_thrust_out = 0;
340 #if STABILIZATION_ATTITUDE_HELI_INDI_USE_NOTCHFILTER
367 (PERIODIC_FREQUENCY + 13);
405 #if STABILIZATION_ATTITUDE_HELI_INDI_USE_FAST_DYN_FILTERS
408 STABILIZATION_ATTITUDE_HELI_INDI_FAST_DYN_ROLL_BW, 0,
MAX_PPRZ, PERIODIC_FREQUENCY);
410 STABILIZATION_ATTITUDE_HELI_INDI_FAST_DYN_PITCH_BW, 0,
MAX_PPRZ, PERIODIC_FREQUENCY);
435 ltp_accel.
x = ltp_accel_nedcoor->
x;
436 ltp_accel.
y = ltp_accel_nedcoor->
y;
437 ltp_accel.
z = ltp_accel_nedcoor->
z;
465 #if STABILIZATION_ATTITUDE_HELI_INDI_USE_NOTCHFILTER
494 static int32_t previous_filt_yawrate = 0;
496 previous_filt_yawrate);
553 cmd[COMMAND_YAW] = 0;
bool autopilot_get_motors_on(void)
get motors status
Core autopilot interface common to all firmwares.
static void delayed_first_order_lowpass_initialize(struct delayed_first_order_lowpass_filter_t *f, uint32_t omega, uint8_t delay, uint16_t max_inc, uint16_t sample_frequency)
delayed_first_order_lowpass_initialize
static int32_t delayed_first_order_lowpass_propagate(struct delayed_first_order_lowpass_filter_t *f, int32_t input)
delayed_first_order_lowpass_propagate
int32_t buffer[DELAYED_FIRST_ORDER_LOWPASS_FILTER_BUFFER_SIZE]
#define DELAYED_FIRST_ORDER_LOWPASS_FILTER_FILTER_ALPHA_SHIFT
void float_quat_of_orientation_vect(struct FloatQuat *q, const struct FloatVect3 *ov)
Quaternion from orientation vector.
#define QUAT_BFP_OF_REAL(_qi, _qf)
int32_t p
in rad/s with INT32_RATE_FRAC
int32_t r
in rad/s with INT32_RATE_FRAC
int32_t q
in rad/s with INT32_RATE_FRAC
static void int32_quat_normalize(struct Int32Quat *q)
normalize a quaternion inplace
static void int32_vect_sum(int32_t *o, const int32_t *a, const int32_t *b, const int n)
o = a + b
#define ANGLE_BFP_OF_REAL(_af)
void int32_quat_comp_inv(struct Int32Quat *a2b, struct Int32Quat *a2c, struct Int32Quat *b2c)
Composition (multiplication) of two quaternions.
void int32_rmat_vmult(struct Int32Vect3 *vb, struct Int32RMat *m_a2b, struct Int32Vect3 *va)
rotate 3D vector by rotation matrix.
static void int32_quat_wrap_shortest(struct Int32Quat *q)
static void int32_vect_diff(int32_t *o, const int32_t *a, const int32_t *b, const int n)
o = a - b
static void int32_vect_copy(int32_t *a, const int32_t *b, const int n)
a = b
void int32_quat_inv_comp(struct Int32Quat *b2c, struct Int32Quat *a2b, struct Int32Quat *a2c)
Composition (multiplication) of two quaternions.
vector in North East Down coordinates
static struct NedCoor_i * stateGetAccelNed_i(void)
Get acceleration in NED coordinates (int).
static struct Int32Quat * stateGetNedToBodyQuat_i(void)
Get vehicle body attitude quaternion (int).
static struct Int32RMat * stateGetNedToBodyRMat_i(void)
Get vehicle body attitude rotation matrix (int).
static struct Int32Rates * stateGetBodyRates_i(void)
Get vehicle body angular rate (int).
Simple first order low pass filter with bilinear transform.
static void init_butterworth_2_low_pass_int(Butterworth2LowPass_int *filter, float cut_off, float sample_time, int32_t value)
Init a second order Butterworth filter.
static int32_t update_butterworth_2_low_pass_int(Butterworth2LowPass_int *filter, int32_t value)
Update second order Butterworth low pass filter state with a new value(fixed point version).
static void notch_filter_update(struct SecondOrderNotchFilter *filter, int32_t *input_signal, int32_t *output_signal)
Notch filter propagate.
static void notch_filter_set_filter_frequency(struct SecondOrderNotchFilter *filter, float frequency)
Set notch filter frequency in Hz.
static void notch_filter_init(struct SecondOrderNotchFilter *filter, float cutoff_frequency, float bandwidth, uint16_t sample_frequency)
Initialize second order notch filter.
Paparazzi floating point algebra.
Paparazzi fixed point algebra.
Simple matrix helper macros.
#define MAT_MUL_VECT(_n, o, a, b)
o = a * b
int32_t pprz_itrig_cos(int32_t angle)
int32_t pprz_itrig_sin(int32_t angle)
uint16_t rpm_sensor_get_rpm(void)
struct Int32Quat stab_sp_to_quat_i(struct StabilizationSetpoint *sp)
struct Int32Eulers stab_sp_to_eulers_i(struct StabilizationSetpoint *sp)
int32_t th_sp_to_thrust_i(struct ThrustSetpoint *th, int32_t thrust, uint8_t axis)
#define STABILIZATION_ATTITUDE_HELI_INDI_NOTCHFILT_BW_PITCH
void indi_apply_measurement_notch_filters(int32_t _out[], int32_t _in[])
void stabilization_attitude_run(bool in_flight, struct StabilizationSetpoint *sp, struct ThrustSetpoint *thrust, int32_t *cmd)
Attitude control run function.
struct delayed_first_order_lowpass_filter_t actuator_model[INDI_DOF]
#define STABILIZATION_ATTITUDE_HELI_INDI_NOTCHFILT_BW_ROLL
#define STABILIZATION_ATTITUDE_HELI_INDI_ROLL_P
void indi_apply_measurement_butterworth_filters(int32_t _out[], int32_t _in[])
void stabilization_attitude_heli_indi_set_steadystate_roll(float roll)
stabilization_attitude_heli_indi_set_steadystate_roll
void stabilization_attitude_enter(void)
Attitude control enter function.
struct SecondOrderNotchFilter actuator_notchfilter[INDI_DOF]
#define STABILIZATION_ATTITUDE_HELI_INDI_BUTTERW_CUTOFF_YAW
#define STABILIZATION_ATTITUDE_HELI_INDI_PITCH_COMMAND_ROTATION
static void indi_apply_actuator_models(int32_t _out[], int32_t _in[])
void stabilization_attitude_heli_indi_set_steadystate_pitch(float pitch)
stabilization_attitude_heli_indi_set_steadystate_pitch
#define STABILIZATION_ATTITUDE_HELI_INDI_BUTTERW_CUTOFF_PITCH
#define INDI_NOTCH_MIN_RPM
static struct Int32Eulers stab_att_sp_euler
Butterworth2LowPass_int measurement_lowpass_filters[INDI_DOF]
#define STABILIZATION_ATTITUDE_HELI_INDI_NOTCHFILT_BW_THRUST
static struct Int32Quat sp_offset
#define STABILIZATION_ATTITUDE_HELI_INDI_STEADY_STATE_PITCH
static void indi_apply_compensator_filters(int32_t _out[], int32_t _in[])
The main idea of this function is to slow down a certain actuator, so that the actuator dynamics filt...
static struct IndiController_int heli_indi_ctl
Butterworth2LowPass_int actuator_lowpass_filters[INDI_DOF]
void stabilization_attitude_heli_indi_set_steadystate_pitchroll()
stabilization_attitude_heli_indi_set_steadystate_pitchroll
#define STABILIZATION_ATTITUDE_HELI_INDI_PITCH_P
#define STABILIZATION_ATTITUDE_HELI_INDI_STEADY_STATE_ROLL
#define STABILIZATION_ATTITUDE_HELI_INDI_YAW_P
#define STABILIZATION_ATTITUDE_HELI_INDI_ROLL_COMMAND_ROTATION
#define STABILIZATION_ATTITUDE_HELI_INDI_BUTTERW_CUTOFF_THRUST
struct SecondOrderNotchFilter measurement_notchfilter[INDI_DOF]
void stabilization_attitude_heli_indi_init(void)
stabilization_attitude_heli_indi_init
struct HeliIndiGains heli_indi_gains
void indi_apply_actuator_butterworth_filters(int32_t _out[], int32_t _in[])
#define STABILIZATION_ATTITUDE_HELI_INDI_YAW_D
static struct Int32Quat stab_att_sp_quat
#define STABILIZATION_ATTITUDE_HELI_INDI_NOTCHFILT_BW_YAW
void indi_apply_actuator_notch_filters(int32_t _out[], int32_t _in[])
static void indi_apply_notch_filters(struct SecondOrderNotchFilter *filter, int32_t _out[], int32_t _in[])
#define STABILIZATION_ATTITUDE_HELI_INDI_BUTTERW_CUTOFF_ROLL
#define INDI_YAW_BUFFER_SIZE
API to get/set the generic vehicle states.
int32_t reference[INDI_DOF]
Range -MAX_PPRZ:MAX_PPRZ.
float sp_offset_pitch
Neutral pitch angle [deg].
int32_t command_out[2][INDI_DOF]
Command and command from previous measurement.
int32_t filtered_measurement[INDI_NR_FILTERS][INDI_DOF]
Filtered measurement.
int32_t measurement[INDI_DOF]
Raw measurement.
int32_t error[INDI_DOF]
virtual control minus measurement
float sp_offset_roll
Neutral roll angle [deg].
int32_t actuator_out[INDI_DOF]
Actuator position.
void(* apply_compensator_filters)(int32_t _out[], int32_t _in[])
void(* apply_actuator_filters[INDI_NR_FILTERS])(int32_t _out[], int32_t _in[])
int32_t du[INDI_DOF]
Actuator commanded increment.
int32_t pitch_comp_angle
Angle to rotate pitch/roll commands with INT32_ANGLE_FRAC.
int32_t roll_comp_angle
Angle to rotate pitch/roll commands with INT32_ANGLE_FRAC.
int32_t invG[INDI_DOF][INDI_DOF]
Inverse control effectiveness matrix.
bool enable_notch
Use notch filters.
void(* apply_actuator_models)(int32_t _out[], int32_t _in[])
int16_t motor_rpm
RPM of the main motor.
int32_t u_setpoint[INDI_DOF]
Actuator setpoint without compensator.
int32_t filtered_actuator[INDI_NR_FILTERS][INDI_DOF]
Filtered actuator position.
void(* apply_measurement_filters[INDI_NR_FILTERS])(int32_t _out[], int32_t _in[])
Thrust setpoint // TODO to a setpoint header Structure to store the desired thrust vector with differ...
int int32_t
Typedef defining 32 bit int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.