34 #include "generated/airframe.h"
55 #ifdef GUIDANCE_INDI_POS_GAIN
61 #ifdef GUIDANCE_INDI_SPEED_GAIN
67 #ifndef GUIDANCE_INDI_ACCEL_SP_ID
68 #define GUIDANCE_INDI_ACCEL_SP_ID ABI_BROADCAST
77 #ifdef GUIDANCE_INDI_SPECIFIC_FORCE_GAIN
78 float thrust_in_specific_force_gain = GUIDANCE_INDI_SPECIFIC_FORCE_GAIN;
79 static void guidance_indi_filter_thrust(
void);
81 #ifndef GUIDANCE_INDI_THRUST_DYNAMICS
82 #ifndef STABILIZATION_INDI_ACT_DYN_P
83 #error "You need to define GUIDANCE_INDI_THRUST_DYNAMICS to be able to use indi vertical control"
84 #else // assume that the same actuators are used for thrust as for roll (e.g. quadrotor)
85 #define GUIDANCE_INDI_THRUST_DYNAMICS STABILIZATION_INDI_ACT_DYN_P
87 #endif //GUIDANCE_INDI_THRUST_DYNAMICS
89 #endif //GUIDANCE_INDI_SPECIFIC_FORCE_GAIN
91 #ifndef GUIDANCE_INDI_FILTER_CUTOFF
92 #ifdef STABILIZATION_INDI_FILT_CUTOFF
93 #define GUIDANCE_INDI_FILTER_CUTOFF STABILIZATION_INDI_FILT_CUTOFF
95 #define GUIDANCE_INDI_FILTER_CUTOFF 3.0
140 float sample_time = 1.0 / PERIODIC_FREQUENCY;
141 for (
int8_t i = 0; i < 3; i++) {
174 sp_accel.
x = indi_accel_sp.
x;
175 sp_accel.
y = indi_accel_sp.
y;
184 sp_accel.
x = indi_accel_sp.
x;
185 sp_accel.
y = indi_accel_sp.
y;
186 sp_accel.
z = indi_accel_sp.
z;
198 #if GUIDANCE_INDI_RC_DEBUG
199 #warning "GUIDANCE_INDI_RC_DEBUG lets you control the accelerations via RC, but disables autonomous flight!"
204 sp_accel.
x = cosf(psi) * rc_x - sinf(psi) * rc_y;
205 sp_accel.
y = sinf(psi) * rc_x + cosf(psi) * rc_y;
217 struct FloatVect3 a_diff = { sp_accel.
x - filt_accel_ned[0].
o[0], sp_accel.
y - filt_accel_ned[1].
o[0], sp_accel.
z - filt_accel_ned[2].
o[0]};
220 Bound(a_diff.
x, -6.0, 6.0);
221 Bound(a_diff.
y, -6.0, 6.0);
222 Bound(a_diff.
z, -9.0, 9.0);
226 #ifndef GUIDANCE_INDI_SPECIFIC_FORCE_GAIN
227 #ifndef STABILIZATION_ATTITUDE_INDI_FULL
241 #ifdef GUIDANCE_INDI_SPECIFIC_FORCE_GAIN
242 guidance_indi_filter_thrust();
248 #if GUIDANCE_INDI_RC_DEBUG
268 #ifdef GUIDANCE_INDI_SPECIFIC_FORCE_GAIN
272 void guidance_indi_filter_thrust(
void)
308 float sphi = sinf(euler_yxz->
phi);
309 float cphi = cosf(euler_yxz->
phi);
310 float stheta = sinf(euler_yxz->
theta);
311 float ctheta = cosf(euler_yxz->
theta);
338 float sphi = sinf(euler->
phi);
339 float cphi = cosf(euler->
phi);
340 float stheta = sinf(euler->
theta);
341 float ctheta = cosf(euler->
theta);
342 float spsi = sinf(euler->
psi);
343 float cpsi = cosf(euler->
psi);
347 RMAT_ELMT(*Gmat, 0, 0) = (cphi * spsi - sphi * cpsi * stheta) * T;
348 RMAT_ELMT(*Gmat, 1, 0) = (-sphi * spsi * stheta - cpsi * cphi) * T;
350 RMAT_ELMT(*Gmat, 0, 1) = (cphi * cpsi * ctheta) * T;
351 RMAT_ELMT(*Gmat, 1, 1) = (cphi * spsi * ctheta) * T;
353 RMAT_ELMT(*Gmat, 0, 2) = sphi * spsi + cphi * cpsi * stheta;
354 RMAT_ELMT(*Gmat, 1, 2) = cphi * spsi * stheta - cpsi * sphi;
365 indi_accel_sp.
x = accel_sp->
x;
366 indi_accel_sp.
y = accel_sp->
y;
369 }
else if (flag == 1) {
370 indi_accel_sp.
x = accel_sp->
x;
371 indi_accel_sp.
y = accel_sp->
y;
372 indi_accel_sp.
z = accel_sp->
z;
Event structure to store callbacks in a linked list.
void guidance_indi_enter(void)
Call upon entering indi guidance.
static float update_butterworth_2_low_pass(Butterworth2LowPass *filter, float value)
Update second order Butterworth low pass filter state with a new value.
bool indi_accel_sp_set_2d
static void init_butterworth_2_low_pass(Butterworth2LowPass *filter, float tau, float sample_time, float value)
Init a second order Butterworth filter.
#define GUIDANCE_H_MAX_BANK
#define GUIDANCE_INDI_ACCEL_SP_ID
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
General attitude stabilization interface for rotorcrafts.
struct FloatVect3 sp_accel
Simple first order low pass filter with bilinear transform.
static void accel_sp_cb(uint8_t sender_id, uint8_t flag, struct FloatVect3 *accel_sp)
ABI callback that obtains the acceleration setpoint from telemetry flag: 0 -> 2D, 1 -> 3D...
void guidance_indi_init(void)
Init function.
Main include for ABI (AirBorneInterface).
static void guidance_indi_calcG(struct FloatMat33 *Gmat)
Vertical guidance for rotorcrafts.
struct HorizontalGuidanceReference ref
reference calculated from setpoints
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
float time_of_accel_sp_2d
#define GUIDANCE_INDI_FILTER_CUTOFF
static float get_sys_time_float(void)
Get the time in seconds since startup.
Butterworth2LowPass filt_accel_ned[3]
struct Int32Quat stab_att_sp_quat
with INT32_QUAT_FRAC
static struct FloatQuat * stateGetNedToBodyQuat_f(void)
Get vehicle body attitude quaternion (float).
float time_of_accel_sp_3d
void guidance_indi_run(float heading_sp)
Butterworth2LowPass pitch_filt
Some helper functions to check RC sticks.
vector in North East Down coordinates Units: meters
static struct NedCoor_f * stateGetSpeedNed_f(void)
Get ground speed in local NED coordinates (float).
Architecture independent timing functions.
float guidance_indi_pos_gain
static struct NedCoor_f * stateGetAccelNed_f(void)
Get acceleration in NED coordinates (float).
#define QUAT_BFP_OF_REAL(_qi, _qf)
struct RadioControl radio_control
struct HorizontalGuidance guidance_h
int32_t guidance_v_z_ref
altitude reference in meters.
struct FloatEulers guidance_euler_cmd
Inertial Measurement Unit interface.
float guidance_indi_speed_gain
float guidance_indi_max_bank
#define THRUST_INCREMENT_ID
Core autopilot interface common to all firmwares.
#define MAT33_VECT3_MUL(_vout, _mat, _vin)
struct Int32Vect2 pos
with INT32_POS_FRAC
API to get/set the generic vehicle states.
Butterworth2LowPass thrust_filt
struct FloatVect3 indi_accel_sp
struct FloatVect3 control_increment
#define RMAT_ELMT(_rm, _row, _col)
General stabilization interface for rotorcrafts.
int32_t stabilization_cmd[COMMANDS_NB]
Stabilization commands.
static void guidance_indi_propagate_filters(struct FloatEulers *eulers)
Low pass the accelerometer measurements to remove noise from vibrations.
#define POS_FLOAT_OF_BFP(_ai)
void float_eulers_of_quat_yxz(struct FloatEulers *e, struct FloatQuat *q)
euler rotation 'YXZ' This function calculates from a quaternion the Euler angles with the order YXZ...
Second order low pass filter structure.
static struct NedCoor_i * stateGetPositionNed_i(void)
Get position in local NED coordinates (int).
Horizontal guidance for rotorcrafts.
#define MAT33_INV(_minv, _m)
Butterworth2LowPass roll_filt
static struct NedCoor_f * stateGetPositionNed_f(void)
Get position in local NED coordinates (float).
static void guidance_indi_calcG_yxz(struct FloatMat33 *Gmat, struct FloatEulers *euler_yxz)
Rotorcraft attitude reference generation.
A guidance mode based on Incremental Nonlinear Dynamic Inversion.
void float_quat_of_eulers_yxz(struct FloatQuat *q, struct FloatEulers *e)
quat from euler rotation 'YXZ' This function calculates a quaternion from Euler angles with the order...
INS for rotorcrafts combining vertical and horizontal filters.
bool indi_accel_sp_set_3d