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)
74 #ifndef GUIDANCE_INDI_MAX_AIRSPEED
75 #error "You must have an airspeed sensor to use this guidance"
78 #ifndef GUIDANCE_INDI_MIN_AIRSPEED
79 #define GUIDANCE_INDI_MIN_AIRSPEED -10.f
85 #ifndef GUIDANCE_INDI_FWD_CLIMB_SPEED
86 #define GUIDANCE_INDI_FWD_CLIMB_SPEED 4.0
92 #ifndef GUIDANCE_INDI_FWD_DESCEND_SPEED
93 #define GUIDANCE_INDI_FWD_DESCEND_SPEED -4.0
99 #ifndef GUIDANCE_INDI_QUAD_CLIMB_SPEED
100 #define GUIDANCE_INDI_QUAD_CLIMB_SPEED 2.0
106 #ifndef GUIDANCE_INDI_QUAD_DESCEND_SPEED
107 #define GUIDANCE_INDI_QUAD_DESCEND_SPEED -2.0
117 .heading_bank_gain = GUIDANCE_INDI_HEADING_BANK_GAIN,
122 .max_airspeed = GUIDANCE_INDI_MAX_AIRSPEED,
123 .stall_protect_gain = 1.5,
135 #if GUIDANCE_INDI_HYBRID_USE_WLS
136 #if GUIDANCE_INDI_HYBRID_U > WLS_N_U_MAX
137 #error Matrix-WLS_N_U_MAX too small: increase WLS_N_U_MAX in airframe file
140 #if GUIDANCE_INDI_HYBRID_V > WLS_N_V_MAX
141 #error Matrix-WLS_N_V_MAX too small: increase WLS_N_V_MAX in airframe file
148 #ifndef GUIDANCE_INDI_ZERO_AIRSPEED
149 #define GUIDANCE_INDI_ZERO_AIRSPEED FALSE
153 #ifndef TURN_AIRSPEED_TH
154 #define TURN_AIRSPEED_TH 13.0
166 #ifdef GUIDANCE_INDI_SPECIFIC_FORCE_GAIN
168 static void guidance_indi_filter_thrust(
void);
170 #ifdef GUIDANCE_INDI_THRUST_DYNAMICS
171 #warning GUIDANCE_INDI_THRUST_DYNAMICS is deprecated, use GUIDANCE_INDI_THRUST_DYNAMICS_FREQ instead.
172 #warning "The thrust dynamics are now specified in continuous time with the corner frequency of the first order model!"
173 #warning "define GUIDANCE_INDI_THRUST_DYNAMICS_FREQ in rad/s"
174 #warning "Use -ln(1 - old_number) * PERIODIC_FREQUENCY to compute it from the old value."
177 #ifndef GUIDANCE_INDI_THRUST_DYNAMICS_FREQ
178 #ifndef STABILIZATION_INDI_ACT_FREQ_P
179 #error "You need to define GUIDANCE_INDI_THRUST_DYNAMICS_FREQ to be able to use indi vertical control"
181 #define GUIDANCE_INDI_THRUST_DYNAMICS_FREQ STABILIZATION_INDI_ACT_FREQ_P
187 #ifndef GUIDANCE_INDI_FILTER_CUTOFF
188 #ifdef STABILIZATION_INDI_FILT_CUTOFF
189 #define GUIDANCE_INDI_FILTER_CUTOFF STABILIZATION_INDI_FILT_CUTOFF
191 #define GUIDANCE_INDI_FILTER_CUTOFF 3.0
195 #ifndef GUIDANCE_INDI_AIRSPEED_FILT_CUTOFF
196 #define GUIDANCE_INDI_AIRSPEED_FILT_CUTOFF 0.5
199 #ifndef GUIDANCE_INDI_MAX_LAT_ACCEL
200 #define GUIDANCE_INDI_MAX_LAT_ACCEL 9.81
203 #ifndef GUIDANCE_INDI_COORDINATED_TURN_MIN_AIRSPEED
204 #define GUIDANCE_INDI_COORDINATED_TURN_MIN_AIRSPEED 10.0
207 #ifndef GUIDANCE_INDI_COORDINATED_TURN_MAX_AIRSPEED
208 #define GUIDANCE_INDI_COORDINATED_TURN_MAX_AIRSPEED 30.0
211 #ifndef GUIDANCE_INDI_COORDINATED_TURN_AIRSPEED_MARGIN
212 #define GUIDANCE_INDI_COORDINATED_TURN_AIRSPEED_MARGIN 0.0
221 #if defined(ROTWING_STATE_FW_MAX_AIRSPEED) && defined(ROTWING_STATE_QUAD_MAX_AIRSPEED)
246 float Ga[GUIDANCE_INDI_HYBRID_V][GUIDANCE_INDI_HYBRID_U];
251 #if GUIDANCE_INDI_HYBRID_USE_WLS
253 float *Bwls_gih[GUIDANCE_INDI_HYBRID_V];
254 struct WLS_t wls_guid_p = {
255 .
nu = GUIDANCE_INDI_HYBRID_U,
256 .nv = GUIDANCE_INDI_HYBRID_V,
257 .gamma_sq = 100000.0,
259 #ifdef GUIDANCE_INDI_WLS_PRIORITIES
260 .Wv = GUIDANCE_INDI_WLS_PRIORITIES,
262 .Wv = { 100.f, 100.f, 1.f },
264 #ifdef GUIDANCE_INDI_WLS_WU
265 .Wu = GUIDANCE_INDI_WLS_WU,
267 .Wu = {[0 ... GUIDANCE_INDI_HYBRID_U - 1] = 1.0},
291 #ifndef GUIDANCE_INDI_VEL_SP_ID
292 #define GUIDANCE_INDI_VEL_SP_ID ABI_BROADCAST
301 #if PERIODIC_TELEMETRY
305 pprz_msg_send_EFF_MAT_GUID(trans,
dev, AC_ID,
306 GUIDANCE_INDI_HYBRID_U,
Ga[0],
307 GUIDANCE_INDI_HYBRID_U,
Ga[1],
308 GUIDANCE_INDI_HYBRID_U,
Ga[2]);
312 pprz_msg_send_GUIDANCE_INDI_HYBRID(trans,
dev, AC_ID,
327 #if GUIDANCE_INDI_HYBRID_USE_WLS
328 static void send_wls_v_guid(
struct transport_tx *trans,
struct link_device *
dev)
332 static void send_wls_u_guid(
struct transport_tx *trans,
struct link_device *
dev)
348 #ifdef GUIDANCE_INDI_SPECIFIC_FORCE_GAIN
349 #ifdef GUIDANCE_INDI_THRUST_DYNAMICS
352 thrust_dyn = 1-exp(-GUIDANCE_INDI_THRUST_DYNAMICS_FREQ/PERIODIC_FREQUENCY);
357 float sample_time = 1.0/PERIODIC_FREQUENCY;
358 for(
int8_t i=0; i<3; i++) {
369 #if GUIDANCE_INDI_HYBRID_USE_WLS
370 for (
int8_t i = 0; i < GUIDANCE_INDI_HYBRID_V; i++) {
375 #if PERIODIC_TELEMETRY
378 #if GUIDANCE_INDI_HYBRID_USE_WLS
400 float sample_time = 1.0 / PERIODIC_FREQUENCY;
401 for (
int8_t i = 0; i < 3; i++) {
441 #if GUIDANCE_INDI_RC_DEBUG
442 #warning "GUIDANCE_INDI_RC_DEBUG lets you control the accelerations via RC, but disables autonomous flight!"
447 sp_accel.
x = cosf(psi) * rc_x - sinf(psi) * rc_y;
448 sp_accel.
y = sinf(psi) * rc_x + cosf(psi) * rc_y;
463 Bound(a_diff.x, -6.0, 6.0);
464 Bound(a_diff.y, -6.0, 6.0);
465 Bound(a_diff.z, -9.0, 9.0);
469 #ifndef GUIDANCE_INDI_SPECIFIC_FORCE_GAIN
470 #ifndef STABILIZATION_ATTITUDE_INDI_FULL
478 #if GUIDANCE_INDI_HYBRID_USE_WLS
483 float du_gih[GUIDANCE_INDI_HYBRID_U];
485 for (
int i = 0; i < GUIDANCE_INDI_HYBRID_V; i++) {
486 wls_guid_p.
v[i] =
v_gih[i];
488 wls_alloc(&wls_guid_p, Bwls_gih, 0, 0, 10);
489 for (
int i = 0; i < GUIDANCE_INDI_HYBRID_U; i++) {
507 const float max_phi = RadOfDeg(60.0f);
508 #if GUIDANCE_INDI_ZERO_AIRSPEED
509 float airspeed_turn = 0.f;
537 if (fabsf(coordinated_turn_roll) < max_phi) {
538 omega = 9.81f / airspeed_turn * tanf(coordinated_turn_roll);
540 omega = 9.81f / airspeed_turn * 1.72305f * ((coordinated_turn_roll > 0.0f) - (coordinated_turn_roll < 0.0f));
543 #ifdef FWD_SIDESLIP_GAIN
554 ff_rates.
p = -sinf(euler_zyx->
theta) * omega;
555 ff_rates.q = cosf(euler_zyx->
theta) * sinf(euler_zyx->
phi) * omega;
556 ff_rates.r = cosf(euler_zyx->
theta) * cosf(euler_zyx->
phi) * omega;
569 #ifdef STABILIZATION_ATTITUDE_SP_PSI_DELTA_LIMIT
570 float delta_limit = STABILIZATION_ATTITUDE_SP_PSI_DELTA_LIMIT;
574 if (delta_psi > delta_limit) {
576 }
else if (delta_psi < -delta_limit) {
585 #ifdef GUIDANCE_INDI_SPECIFIC_FORCE_GAIN
586 guidance_indi_filter_thrust();
589 Bound(
thrust_in, GUIDANCE_INDI_MIN_THROTTLE, 9600);
590 #if GUIDANCE_INDI_RC_DEBUG
599 float thrust_vect[3];
600 #if GUIDANCE_INDI_HYBRID_U > 3
601 thrust_vect[0] =
du_gih[3];
625 struct FloatVect3 accel_sp = { 0.f, 0.f, 0.f };
631 float cpsi = cosf(psi);
632 float spsi = sinf(psi);
637 #if GUIDANCE_INDI_ZERO_AIRSPEED
638 float airspeed = 0.f;
641 Bound(airspeed, 0.0f, 100.0f);
647 struct FloatVect2 airspeed_v = { cpsi * airspeed, spsi * airspeed };
649 VECT2_DIFF(windspeed, *groundspeed, airspeed_v);
661 float gi_airspeed_sp = norm_des_as;
668 float groundspeed_factor = 0.0f;
676 float dv = bv * bv - 4.0f * av * cv;
682 float d_sqrt = sqrtf(dv);
684 groundspeed_factor = (-bv + d_sqrt) / (2.0f * av);
709 accel_sp.
x = cpsi * sp_accel_b.x - spsi * sp_accel_b.y;
710 accel_sp.
y = spsi * sp_accel_b.x + cpsi * sp_accel_b.y;
715 if (airspeed > 10.f) {
718 float speed_increment = speed_sp_b_x - groundspeed_x;
726 gi_speed_sp.
x = cpsi * speed_sp_b_x - spsi * speed_sp_b_y;
727 gi_speed_sp.
y = spsi * speed_sp_b_x + cpsi * speed_sp_b_y;
737 BoundAbs(accel_sp.
z, 3.0);
739 #ifdef ROTWING_FW_MIN_AIRSPEED
742 BoundAbs(accel_sp.
z, 5.0);
835 #ifdef GUIDANCE_INDI_SPECIFIC_FORCE_GAIN
839 void guidance_indi_filter_thrust(
void)
871 Bound(airspeed, 0.0f, 100.0f);
886 if (airspeed < 12.f) {
891 float pitch_interp = DegOfRad(theta);
892 const float min_pitch = -80.0f;
893 const float middle_pitch = -50.0f;
894 const float max_pitch = -20.0f;
896 Bound(pitch_interp, min_pitch, max_pitch);
897 if (pitch_interp > middle_pitch) {
898 float ratio = (pitch_interp - max_pitch)/(middle_pitch - max_pitch);
901 float ratio = (pitch_interp - middle_pitch)/(min_pitch - middle_pitch);
924 #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
#define GUIDANCE_INDI_COORDINATED_TURN_AIRSPEED_MARGIN
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_QUAD_DESCEND_SPEED
Descend speed when navigation is doing direct lines.
#define GUIDANCE_INDI_SPEED_GAINZ
#define GUIDANCE_INDI_COORDINATED_TURN_MIN_AIRSPEED
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
#define GUIDANCE_INDI_MIN_AIRSPEED
float gih_coordinated_turn_min_airspeed
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)
#define GUIDANCE_INDI_FWD_DESCEND_SPEED
Descend speed when navigation is making turns instead of direct lines.
float gih_coordinated_turn_max_airspeed
struct FloatVect3 sp_accel
struct FloatEulers guidance_euler_cmd
float guidance_indi_pitch_pref_deg
#define GUIDANCE_INDI_LIFTD_ASQ
#define GUIDANCE_INDI_QUAD_CLIMB_SPEED
Climb speed when navigation is doing direct lines.
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
#define GUIDANCE_INDI_COORDINATED_TURN_MAX_AIRSPEED
#define GUIDANCE_INDI_FWD_CLIMB_SPEED
Climb speed when navigation is making turns instead of direct lines.
bool take_heading_control
void guidance_set_min_max_airspeed(float min_airspeed, float max_airspeed)
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_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]
float gi_unbounded_airspeed_sp
#define GUIDANCE_INDI_AIRSPEED_FILT_CUTOFF
#define GUIDANCE_INDI_POS_GAINZ
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)
bool coordinated_turn_use_accel
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.
float descend_vspeed_quad
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 heading
heading setpoint (in radians)
bool rotwing_state_pusher_motor_running(void)
bool rotwing_state_hover_motors_running(void)
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)