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
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
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)
251#if GUIDANCE_INDI_HYBRID_USE_WLS
257 .gamma_sq = 100000.0,
259#ifdef GUIDANCE_INDI_WLS_PRIORITIES
262 .Wv = { 100.f, 100.f, 1.f },
264#ifdef GUIDANCE_INDI_WLS_WU
291#ifndef GUIDANCE_INDI_VEL_SP_ID
292#define GUIDANCE_INDI_VEL_SP_ID ABI_BROADCAST
301#if PERIODIC_TELEMETRY
327#if GUIDANCE_INDI_HYBRID_USE_WLS
348#ifdef GUIDANCE_INDI_SPECIFIC_FORCE_GAIN
349#ifdef GUIDANCE_INDI_THRUST_DYNAMICS
358 for(
int8_t i=0; i<3; i++) {
369#if GUIDANCE_INDI_HYBRID_USE_WLS
375#if PERIODIC_TELEMETRY
378#if GUIDANCE_INDI_HYBRID_USE_WLS
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!"
469#ifndef GUIDANCE_INDI_SPECIFIC_FORCE_GAIN
470#ifndef STABILIZATION_ATTITUDE_INDI_FULL
478#if GUIDANCE_INDI_HYBRID_USE_WLS
508#if GUIDANCE_INDI_ZERO_AIRSPEED
543#ifdef FWD_SIDESLIP_GAIN
569#ifdef STABILIZATION_ATTITUDE_SP_PSI_DELTA_LIMIT
585#ifdef GUIDANCE_INDI_SPECIFIC_FORCE_GAIN
590#if GUIDANCE_INDI_RC_DEBUG
600#if GUIDANCE_INDI_HYBRID_U > 3
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);
676 float dv =
bv *
bv - 4.0f *
av * cv;
715 if (airspeed > 10.f) {
739#ifdef ROTWING_FW_MIN_AIRSPEED
835#ifdef GUIDANCE_INDI_SPECIFIC_FORCE_GAIN
871 Bound(airspeed, 0.0f, 100.0f);
886 if (airspeed < 12.f) {
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
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
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)