30 #include "generated/airframe.h"
47 #ifndef GUIDANCE_INDI_SPEED_GAIN
48 #define GUIDANCE_INDI_SPEED_GAIN 1.8
49 #define GUIDANCE_INDI_SPEED_GAINZ 1.8
52 #ifndef GUIDANCE_INDI_POS_GAIN
53 #define GUIDANCE_INDI_POS_GAIN 0.5
54 #define GUIDANCE_INDI_POS_GAINZ 0.5
57 #ifndef GUIDANCE_INDI_LIFTD_ASQ
58 #define GUIDANCE_INDI_LIFTD_ASQ 0.20
61 #ifndef GUIDANCE_INDI_MAX_PUSHER_INCREMENT
62 #define GUIDANCE_INDI_MAX_PUSHER_INCREMENT MAX_PPRZ
69 #ifndef GUIDANCE_INDI_LIFTD_P50
70 #define GUIDANCE_INDI_LIFTD_P80 (GUIDANCE_INDI_LIFTD_ASQ*12*12)
71 #define GUIDANCE_INDI_LIFTD_P50 (GUIDANCE_INDI_LIFTD_P80/2)
81 .heading_bank_gain = GUIDANCE_INDI_HEADING_BANK_GAIN,
87 #ifndef GUIDANCE_INDI_MAX_AIRSPEED
88 #error "You must have an airspeed sensor to use this guidance"
97 #if GUIDANCE_INDI_HYBRID_USE_WLS
98 #if GUIDANCE_INDI_HYBRID_U > WLS_N_U_MAX
99 #error Matrix-WLS_N_U_MAX too small: increase WLS_N_U_MAX in airframe file
102 #if GUIDANCE_INDI_HYBRID_V > WLS_N_V_MAX
103 #error Matrix-WLS_N_V_MAX too small: increase WLS_N_V_MAX in airframe file
110 #ifndef GUIDANCE_INDI_ZERO_AIRSPEED
111 #define GUIDANCE_INDI_ZERO_AIRSPEED FALSE
115 #ifndef TURN_AIRSPEED_TH
116 #define TURN_AIRSPEED_TH 10.0
128 #ifdef GUIDANCE_INDI_SPECIFIC_FORCE_GAIN
130 static void guidance_indi_filter_thrust(
void);
132 #ifdef GUIDANCE_INDI_THRUST_DYNAMICS
133 #warning GUIDANCE_INDI_THRUST_DYNAMICS is deprecated, use GUIDANCE_INDI_THRUST_DYNAMICS_FREQ instead.
134 #warning "The thrust dynamics are now specified in continuous time with the corner frequency of the first order model!"
135 #warning "define GUIDANCE_INDI_THRUST_DYNAMICS_FREQ in rad/s"
136 #warning "Use -ln(1 - old_number) * PERIODIC_FREQUENCY to compute it from the old value."
139 #ifndef GUIDANCE_INDI_THRUST_DYNAMICS_FREQ
140 #ifndef STABILIZATION_INDI_ACT_FREQ_P
141 #error "You need to define GUIDANCE_INDI_THRUST_DYNAMICS_FREQ to be able to use indi vertical control"
143 #define GUIDANCE_INDI_THRUST_DYNAMICS_FREQ STABILIZATION_INDI_ACT_FREQ_P
149 #ifndef GUIDANCE_INDI_FILTER_CUTOFF
150 #ifdef STABILIZATION_INDI_FILT_CUTOFF
151 #define GUIDANCE_INDI_FILTER_CUTOFF STABILIZATION_INDI_FILT_CUTOFF
153 #define GUIDANCE_INDI_FILTER_CUTOFF 3.0
157 #ifndef GUIDANCE_INDI_AIRSPEED_FILT_CUTOFF
158 #define GUIDANCE_INDI_AIRSPEED_FILT_CUTOFF 0.5
161 #ifndef GUIDANCE_INDI_CLIMB_SPEED_FWD
162 #define GUIDANCE_INDI_CLIMB_SPEED_FWD 4.0
165 #ifndef GUIDANCE_INDI_DESCEND_SPEED_FWD
166 #define GUIDANCE_INDI_DESCEND_SPEED_FWD -4.0
169 #ifndef GUIDANCE_INDI_MAX_LAT_ACCEL
170 #define GUIDANCE_INDI_MAX_LAT_ACCEL 9.81
196 float Ga[GUIDANCE_INDI_HYBRID_V][GUIDANCE_INDI_HYBRID_U];
201 #if GUIDANCE_INDI_HYBRID_USE_WLS
203 float *Bwls_gih[GUIDANCE_INDI_HYBRID_V];
204 struct WLS_t wls_guid_p = {
205 .
nu = GUIDANCE_INDI_HYBRID_U,
206 .nv = GUIDANCE_INDI_HYBRID_V,
207 .gamma_sq = 100000.0,
209 #ifdef GUIDANCE_INDI_WLS_PRIORITIES
210 .Wv = GUIDANCE_INDI_WLS_PRIORITIES,
212 .Wv = { 100.f, 100.f, 1.f },
214 #ifdef GUIDANCE_INDI_WLS_WU
215 .Wu = GUIDANCE_INDI_WLS_WU,
217 .Wu = {[0 ... GUIDANCE_INDI_HYBRID_U - 1] = 1.0},
241 #ifndef GUIDANCE_INDI_VEL_SP_ID
242 #define GUIDANCE_INDI_VEL_SP_ID ABI_BROADCAST
251 #if PERIODIC_TELEMETRY
255 pprz_msg_send_EFF_MAT_GUID(trans,
dev, AC_ID,
256 GUIDANCE_INDI_HYBRID_U,
Ga[0],
257 GUIDANCE_INDI_HYBRID_U,
Ga[1],
258 GUIDANCE_INDI_HYBRID_U,
Ga[2]);
262 pprz_msg_send_GUIDANCE_INDI_HYBRID(trans,
dev, AC_ID,
277 #if GUIDANCE_INDI_HYBRID_USE_WLS
278 static void send_wls_v_guid(
struct transport_tx *trans,
struct link_device *
dev)
282 static void send_wls_u_guid(
struct transport_tx *trans,
struct link_device *
dev)
298 #ifdef GUIDANCE_INDI_SPECIFIC_FORCE_GAIN
299 #ifdef GUIDANCE_INDI_THRUST_DYNAMICS
302 thrust_dyn = 1-exp(-GUIDANCE_INDI_THRUST_DYNAMICS_FREQ/PERIODIC_FREQUENCY);
307 float sample_time = 1.0/PERIODIC_FREQUENCY;
308 for(
int8_t i=0; i<3; i++) {
319 #if GUIDANCE_INDI_HYBRID_USE_WLS
320 for (
int8_t i = 0; i < GUIDANCE_INDI_HYBRID_V; i++) {
325 #if PERIODIC_TELEMETRY
328 #if GUIDANCE_INDI_HYBRID_USE_WLS
350 float sample_time = 1.0 / PERIODIC_FREQUENCY;
351 for (
int8_t i = 0; i < 3; i++) {
389 #if GUIDANCE_INDI_RC_DEBUG
390 #warning "GUIDANCE_INDI_RC_DEBUG lets you control the accelerations via RC, but disables autonomous flight!"
395 sp_accel.
x = cosf(psi) * rc_x - sinf(psi) * rc_y;
396 sp_accel.
y = sinf(psi) * rc_x + cosf(psi) * rc_y;
411 Bound(a_diff.x, -6.0, 6.0);
412 Bound(a_diff.y, -6.0, 6.0);
413 Bound(a_diff.z, -9.0, 9.0);
417 #ifndef GUIDANCE_INDI_SPECIFIC_FORCE_GAIN
418 #ifndef STABILIZATION_ATTITUDE_INDI_FULL
426 #if GUIDANCE_INDI_HYBRID_USE_WLS
431 float du_gih[GUIDANCE_INDI_HYBRID_U];
433 for (
int i = 0; i < GUIDANCE_INDI_HYBRID_V; i++) {
434 wls_guid_p.
v[i] =
v_gih[i];
436 wls_alloc(&wls_guid_p, Bwls_gih, 0, 0, 10);
437 for (
int i = 0; i < GUIDANCE_INDI_HYBRID_U; i++) {
455 const float max_phi = RadOfDeg(60.0f);
456 #if GUIDANCE_INDI_ZERO_AIRSPEED
457 float airspeed_turn = 0.f;
462 Bound(airspeed_turn, 10.0f, 30.0f);
485 if (fabsf(coordinated_turn_roll) < max_phi) {
486 omega = 9.81f / airspeed_turn * tanf(coordinated_turn_roll);
488 omega = 9.81f / airspeed_turn * 1.72305f * ((coordinated_turn_roll > 0.0f) - (coordinated_turn_roll < 0.0f));
491 #ifdef FWD_SIDESLIP_GAIN
502 ff_rates.
p = -sinf(euler_zyx->
theta) * omega;
503 ff_rates.q = cosf(euler_zyx->
theta) * sinf(euler_zyx->
phi) * omega;
504 ff_rates.r = cosf(euler_zyx->
theta) * cosf(euler_zyx->
phi) * omega;
517 #ifdef STABILIZATION_ATTITUDE_SP_PSI_DELTA_LIMIT
518 float delta_limit = STABILIZATION_ATTITUDE_SP_PSI_DELTA_LIMIT;
522 if (delta_psi > delta_limit) {
524 }
else if (delta_psi < -delta_limit) {
533 #ifdef GUIDANCE_INDI_SPECIFIC_FORCE_GAIN
534 guidance_indi_filter_thrust();
537 Bound(
thrust_in, GUIDANCE_INDI_MIN_THROTTLE, 9600);
538 #if GUIDANCE_INDI_RC_DEBUG
547 float thrust_vect[3];
548 #if GUIDANCE_INDI_HYBRID_U > 3
549 thrust_vect[0] =
du_gih[3];
573 struct FloatVect3 accel_sp = { 0.f, 0.f, 0.f };
579 float cpsi = cosf(psi);
580 float spsi = sinf(psi);
585 #if GUIDANCE_INDI_ZERO_AIRSPEED
586 float airspeed = 0.f;
594 struct FloatVect2 airspeed_v = { cpsi * airspeed, spsi * airspeed };
596 VECT2_DIFF(windspeed, *groundspeed, airspeed_v);
606 float groundspeed_factor = 0.0f;
614 float dv = bv * bv - 4.0f * av * cv;
620 float d_sqrt = sqrtf(dv);
622 groundspeed_factor = (-bv + d_sqrt) / (2.0f * av);
650 accel_sp.
x = cpsi * sp_accel_b.x - spsi * sp_accel_b.y;
651 accel_sp.
y = spsi * sp_accel_b.x + cpsi * sp_accel_b.y;
656 if (airspeed > 10.f) {
659 float speed_increment = speed_sp_b_x - groundspeed_x;
667 gi_speed_sp.
x = cpsi * speed_sp_b_x - spsi * speed_sp_b_y;
668 gi_speed_sp.
y = spsi * speed_sp_b_x + cpsi * speed_sp_b_y;
680 BoundAbs(accel_sp.
z, 3.0);
771 #ifdef GUIDANCE_INDI_SPECIFIC_FORCE_GAIN
775 void guidance_indi_filter_thrust(
void)
821 if (airspeed < 12.f) {
826 float pitch_interp = DegOfRad(theta);
827 const float min_pitch = -80.0f;
828 const float middle_pitch = -50.0f;
829 const float max_pitch = -20.0f;
831 Bound(pitch_interp, min_pitch, max_pitch);
832 if (pitch_interp > middle_pitch) {
833 float ratio = (pitch_interp - max_pitch)/(middle_pitch - max_pitch);
836 float ratio = (pitch_interp - middle_pitch)/(min_pitch - middle_pitch);
859 #if GUIDANCE_INDI_HYBRID_USE_AS_DEFAULT
Main include for ABI (AirBorneInterface).
Event structure to store callbacks in a linked list.
Core autopilot interface common to all firmwares.
static void float_quat_normalize(struct FloatQuat *q)
#define FLOAT_ANGLE_NORMALIZE(_a)
void float_mat3_mult(struct FloatVect3 *vect_out, float mat[3][3], struct FloatVect3 vect_in)
Multiply 3D matrix with vector.
void float_vect3_bound_in_2d(struct FloatVect3 *vect3, float bound)
void float_quat_of_eulers_zxy(struct FloatQuat *q, struct FloatEulers *e)
quat from euler rotation 'ZXY' This rotation order is useful if you need 90 deg pitch
void float_eulers_of_quat_zxy(struct FloatEulers *e, struct FloatQuat *q)
euler rotation 'ZXY' This rotation order is useful if you need 90 deg pitch
bool float_mat_inv_3d(float inv_out[3][3], float mat_in[3][3])
3x3 matrix inverse
#define FLOAT_VECT2_NORM(_v)
#define VECT2_DIFF(_c, _a, _b)
#define VECT3_DIFF(_c, _a, _b)
#define POS_FLOAT_OF_BFP(_ai)
#define SPEED_FLOAT_OF_BFP(_ai)
#define ACCEL_FLOAT_OF_BFP(_ai)
static struct NedCoor_f * stateGetAccelNed_f(void)
Get acceleration in NED coordinates (float).
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (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 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).
float guidance_indi_specific_force_gain
struct FloatVect3 indi_vel_sp
bool force_forward
forward flight for hybrid nav
Butterworth2LowPass accely_filt
static void vel_sp_cb(uint8_t sender_id, struct FloatVect3 *vel_sp)
ABI callback that obtains the velocity setpoint from a module.
Butterworth2LowPass roll_filt
#define GUIDANCE_INDI_SPEED_GAINZ
#define GUIDANCE_INDI_CLIMB_SPEED_FWD
struct guidance_indi_hybrid_params gih_params
#define GUIDANCE_INDI_MAX_LAT_ACCEL
struct FloatVect3 gi_speed_sp
float guidance_indi_min_pitch
float guidance_indi_max_bank
struct StabilizationSetpoint guidance_indi_run_mode(bool in_flight UNUSED, struct HorizontalGuidance *gh, struct VerticalGuidance *gv, enum GuidanceIndiHybrid_HMode h_mode, enum GuidanceIndiHybrid_VMode v_mode)
struct FloatVect3 sp_accel
struct FloatEulers guidance_euler_cmd
float guidance_indi_pitch_pref_deg
#define GUIDANCE_INDI_LIFTD_ASQ
float guidance_indi_airspeed_filt_cutoff
void guidance_indi_enter(void)
Call upon entering indi guidance.
Butterworth2LowPass guidance_indi_airspeed_filt
Butterworth2LowPass pitch_filt
#define GUIDANCE_INDI_POS_GAIN
bool take_heading_control
float guidance_indi_hybrid_heading_sp
float WEAK guidance_indi_get_liftd(float airspeed, float theta)
Get the derivative of lift w.r.t.
struct ThrustSetpoint thrust_sp
#define GUIDANCE_INDI_LIFTD_P50
static void send_guidance_indi_hybrid(struct transport_tx *trans, struct link_device *dev)
void guidance_indi_init(void)
Init function.
#define GUIDANCE_INDI_FILTER_CUTOFF
#define GUIDANCE_INDI_DESCEND_SPEED_FWD
#define GUIDANCE_INDI_MAX_PUSHER_INCREMENT
float Ga[GUIDANCE_INDI_HYBRID_V][GUIDANCE_INDI_HYBRID_U]
struct FloatVect3 euler_cmd
static float bound_vz_sp(float vz_sp)
struct FloatEulers eulers_zxy
state eulers in zxy order
Butterworth2LowPass filt_accel_ned[3]
#define GUIDANCE_INDI_AIRSPEED_FILT_CUTOFF
#define GUIDANCE_INDI_POS_GAINZ
float guidance_indi_max_airspeed
static void send_eff_mat_guid_indi_hybrid(struct transport_tx *trans, struct link_device *dev)
static struct FloatVect3 compute_accel_from_speed_sp(void)
#define GUIDANCE_INDI_VEL_SP_ID
struct StabilizationSetpoint guidance_indi_run(struct FloatVect3 *accel_sp, float heading_sp)
void guidance_indi_propagate_filters(void)
Low pass the accelerometer measurements to remove noise from vibrations.
bool guidance_indi_airspeed_filtering
#define GUIDANCE_INDI_LIFTD_P80
Butterworth2LowPass thrust_filt
#define GUIDANCE_INDI_SPEED_GAIN
float du_gih[GUIDANCE_INDI_HYBRID_U]
struct FloatVect2 desired_airspeed
A guidance mode based on Incremental Nonlinear Dynamic Inversion Come to ICRA2016 to learn more!
void guidance_indi_calcg_wing(float Gmat[GUIDANCE_INDI_HYBRID_V][GUIDANCE_INDI_HYBRID_U], struct FloatVect3 a_diff, float v_body[GUIDANCE_INDI_HYBRID_V])
Perform WLS.
@ GUIDANCE_INDI_HYBRID_V_POS
@ GUIDANCE_INDI_HYBRID_V_SPEED
@ GUIDANCE_INDI_HYBRID_V_ACCEL
@ GUIDANCE_INDI_HYBRID_H_SPEED
@ GUIDANCE_INDI_HYBRID_H_ACCEL
@ GUIDANCE_INDI_HYBRID_H_POS
void WEAK guidance_indi_hybrid_set_wls_settings(float body_v[3], float roll_angle, float pitch_angle)
#define GUIDANCE_INDI_MAX_PITCH
#define GUIDANCE_INDI_MIN_PITCH
static enum GuidanceOneloop_VMode _v_mode
void guidance_v_run_enter(void)
static struct VerticalGuidance * _gv
struct ThrustSetpoint guidance_v_run_pos(bool in_flight UNUSED, struct VerticalGuidance *gv)
struct ThrustSetpoint guidance_v_run_speed(bool in_flight UNUSED, struct VerticalGuidance *gv)
struct ThrustSetpoint guidance_v_run_accel(bool in_flight UNUSED, struct VerticalGuidance *gv)
Simple first order low pass filter with bilinear transform.
static void init_butterworth_2_low_pass(Butterworth2LowPass *filter, float tau, float sample_time, float value)
Init a second order Butterworth filter.
static float update_butterworth_2_low_pass(Butterworth2LowPass *filter, float value)
Update second order Butterworth low pass filter state with a new value.
Second order low pass filter structure.
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]
#define RADIO_ROLL
Redefining RADIO_* Do not use with radio.h (ppm rc)
Some helper functions to check RC sticks.
void guidance_h_run_enter(void)
struct StabilizationSetpoint guidance_h_run_pos(bool in_flight, struct HorizontalGuidance *gh)
struct StabilizationSetpoint guidance_h_run_speed(bool in_flight, struct HorizontalGuidance *gh)
struct StabilizationSetpoint guidance_h_run_accel(bool in_flight, struct HorizontalGuidance *gh)
#define GUIDANCE_H_MAX_BANK
Max bank controlled by guidance.
struct VerticalGuidance guidance_v
int32_t z_ref
altitude reference in meters.
int32_t zd_ref
vertical speed reference in meter/s.
int32_t zdd_ref
vertical acceleration reference in meter/s^2.
struct RotorcraftNavigation nav
Rotorcraft navigation functions.
float descend_vspeed
descend speed setting, mostly used in flight plans
float heading
heading setpoint (in radians)
float climb_vspeed
climb speed setting, mostly used in flight plans
struct Stabilization stabilization
struct ThrustSetpoint th_sp_from_incr_vect_f(float th_increment[3])
struct StabilizationSetpoint stab_sp_from_quat_ff_rates_f(struct FloatQuat *quat, struct FloatRates *rates)
struct ThrustSetpoint th_sp_from_thrust_i(int32_t thrust, uint8_t axis)
float transition_ratio
transition percentage for hybrids (0.: hover; 1.: forward)
int32_t cmd[COMMANDS_NB]
output command vector, range from [-MAX_PPRZ:MAX_PPRZ] (store for messages)
float stabilization_attitude_get_heading_f(void)
Get attitude heading as float (avoiding jumps)
float g1g2[INDI_OUTPUTS][INDI_NUM_ACT]
API to get/set the generic vehicle states.
static const struct usb_device_descriptor dev
union StabilizationSetpoint::@278 sp
Thrust setpoint // TODO to a setpoint header Structure to store the desired thrust vector with differ...
Architecture independent timing functions.
static float get_sys_time_float(void)
Get the time in seconds since startup.
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_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.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
signed char int8_t
Typedef defining 8 bit char type.
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)