26 #include "generated/airframe.h"
55 static const float phi_pgain[] = STABILIZATION_ATTITUDE_PHI_PGAIN;
56 static const float theta_pgain[] = STABILIZATION_ATTITUDE_THETA_PGAIN;
57 static const float psi_pgain[] = STABILIZATION_ATTITUDE_PSI_PGAIN;
59 static const float phi_dgain[] = STABILIZATION_ATTITUDE_PHI_DGAIN;
60 static const float theta_dgain[] = STABILIZATION_ATTITUDE_THETA_DGAIN;
61 static const float psi_dgain[] = STABILIZATION_ATTITUDE_PSI_DGAIN;
63 static const float phi_igain[] = STABILIZATION_ATTITUDE_PHI_IGAIN;
64 static const float theta_igain[] = STABILIZATION_ATTITUDE_THETA_IGAIN;
65 static const float psi_igain[] = STABILIZATION_ATTITUDE_PSI_IGAIN;
67 static const float phi_ddgain[] = STABILIZATION_ATTITUDE_PHI_DDGAIN;
68 static const float theta_ddgain[] = STABILIZATION_ATTITUDE_THETA_DDGAIN;
69 static const float psi_ddgain[] = STABILIZATION_ATTITUDE_PSI_DDGAIN;
71 static const float phi_dgain_d[] = STABILIZATION_ATTITUDE_PHI_DGAIN_D;
72 static const float theta_dgain_d[] = STABILIZATION_ATTITUDE_THETA_DGAIN_D;
73 static const float psi_dgain_d[] = STABILIZATION_ATTITUDE_PSI_DGAIN_D;
76 #if defined COMMAND_ROLL_SURFACE && defined COMMAND_PITCH_SURFACE && defined COMMAND_YAW_SURFACE
77 #define HAS_SURFACE_COMMANDS 1
80 #ifdef HAS_SURFACE_COMMANDS
81 static const float phi_pgain_surface[] = STABILIZATION_ATTITUDE_PHI_PGAIN_SURFACE;
82 static const float theta_pgain_surface[] = STABILIZATION_ATTITUDE_THETA_PGAIN_SURFACE;
83 static const float psi_pgain_surface[] = STABILIZATION_ATTITUDE_PSI_PGAIN_SURFACE;
85 static const float phi_dgain_surface[] = STABILIZATION_ATTITUDE_PHI_DGAIN_SURFACE;
86 static const float theta_dgain_surface[] = STABILIZATION_ATTITUDE_THETA_DGAIN_SURFACE;
87 static const float psi_dgain_surface[] = STABILIZATION_ATTITUDE_PSI_DGAIN_SURFACE;
89 static const float phi_igain_surface[] = STABILIZATION_ATTITUDE_PHI_IGAIN_SURFACE;
90 static const float theta_igain_surface[] = STABILIZATION_ATTITUDE_THETA_IGAIN_SURFACE;
91 static const float psi_igain_surface[] = STABILIZATION_ATTITUDE_PSI_IGAIN_SURFACE;
93 static const float phi_ddgain_surface[] = STABILIZATION_ATTITUDE_PHI_DDGAIN_SURFACE;
94 static const float theta_ddgain_surface[] = STABILIZATION_ATTITUDE_THETA_DDGAIN_SURFACE;
95 static const float psi_ddgain_surface[] = STABILIZATION_ATTITUDE_PSI_DDGAIN_SURFACE;
98 #define IERROR_SCALE 1024
100 #if PERIODIC_TELEMETRY
107 pprz_msg_send_STAB_ATTITUDE_FLOAT(trans, dev, AC_ID,
108 &(body_rate->
p), &(body_rate->
q), &(body_rate->
r),
130 pprz_msg_send_STAB_ATTITUDE_REF_FLOAT(trans, dev, AC_ID,
161 #ifdef HAS_SURFACE_COMMANDS
173 #if PERIODIC_TELEMETRY
229 #ifndef GAIN_PRESCALER_FF
230 #define GAIN_PRESCALER_FF 1
239 #ifdef HAS_SURFACE_COMMANDS
246 #ifndef GAIN_PRESCALER_P
247 #define GAIN_PRESCALER_P 1
249 #ifndef GAIN_PRESCALER_D
250 #define GAIN_PRESCALER_D 1
252 #ifndef GAIN_PRESCALER_I
253 #define GAIN_PRESCALER_I 1
259 fb_commands[COMMAND_ROLL] =
265 fb_commands[COMMAND_PITCH] =
271 fb_commands[COMMAND_YAW] =
277 #ifdef HAS_SURFACE_COMMANDS
278 fb_commands[COMMAND_ROLL_SURFACE] =
283 fb_commands[COMMAND_PITCH_SURFACE] =
288 fb_commands[COMMAND_YAW_SURFACE] =
323 #define INTEGRATOR_BOUND 1.0
325 if (enable_integrator) {
346 #ifdef HAS_SURFACE_COMMANDS
348 stabilization_att_ff_cmd[COMMAND_ROLL_SURFACE];
350 stabilization_att_ff_cmd[COMMAND_PITCH_SURFACE];
352 stabilization_att_ff_cmd[COMMAND_YAW_SURFACE];
Attitude reference models and state/output (float)
void float_quat_of_eulers(struct FloatQuat *q, struct FloatEulers *e)
Quaternion from Euler angles.
struct FloatRates last_body_rate
struct FloatVect3 rates_d
static const float theta_dgain[]
static const float theta_ddgain[]
void attitude_ref_quat_float_enter(struct AttRefQuatFloat *ref, float psi)
Generic transmission transport header.
#define GAIN_PRESCALER_FF
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
void stabilization_attitude_read_rc(bool_t in_flight, bool_t in_carefree, bool_t coordinated_turn)
Periodic telemetry system header (includes downlink utility and generated code).
static const float phi_igain[]
General attitude stabilization interface for rotorcrafts.
void stabilization_attitude_set_earth_cmd_i(struct Int32Vect2 *cmd, int32_t heading)
#define FLOAT_EULERS_ZERO(_e)
static void float_quat_identity(struct FloatQuat *q)
initialises a quaternion to identity
static const float psi_dgain_d[]
#define VECT3_ASSIGN(_a, _x, _y, _z)
float stabilization_att_fb_cmd[COMMANDS_NB]
Read an attitude setpoint from the RC.
struct FloatVect3 surface_dd
#define FLOAT_RATES_ZERO(_r)
static const float phi_pgain[]
struct FloatRates body_rate_d
#define RATES_DIFF(_c, _a, _b)
void float_quat_inv_comp(struct FloatQuat *b2c, struct FloatQuat *a2b, struct FloatQuat *a2c)
Composition (multiplication) of two quaternions.
#define ANGLE_FLOAT_OF_BFP(_ai)
struct FloatAttitudeGains stabilization_gains[STABILIZATION_ATTITUDE_GAIN_NB]
static struct FloatQuat * stateGetNedToBodyQuat_f(void)
Get vehicle body attitude quaternion (float).
static void attitude_run_ff(float ff_commands[], struct FloatAttitudeGains *gains, struct FloatRates *ref_accel)
struct FloatVect3 surface_d
static const float phi_dgain_d[]
struct FloatEulers stab_att_sp_euler
with INT32_ANGLE_FRAC
void stabilization_attitude_gain_schedule(uint8_t idx)
void stabilization_attitude_enter(void)
Paparazzi floating point algebra.
static const float psi_dgain[]
static void attitude_run_fb(float fb_commands[], struct FloatAttitudeGains *gains, struct FloatQuat *att_err, struct FloatRates *rate_err, struct FloatRates *rate_err_d, struct FloatQuat *sum_err)
static const float psi_ddgain[]
static const float theta_dgain_d[]
static const float psi_pgain[]
void attitude_ref_quat_float_update(struct AttRefQuatFloat *ref, struct FloatQuat *sp_quat, float dt)
void stabilization_attitude_run(bool_t enable_integrator)
void stabilization_attitude_init(void)
#define DefaultPeriodic
Set default periodic telemetry.
void attitude_ref_quat_float_schedule(struct AttRefQuatFloat *ref, uint8_t idx)
static const float psi_igain[]
struct FloatQuat stab_att_sp_quat
with INT32_QUAT_FRAC
static const float theta_igain[]
void stabilization_attitude_set_rpy_setpoint_i(struct Int32Eulers *rpy)
static struct FloatRates * stateGetBodyRates_f(void)
Get vehicle body angular rate (float).
static const float phi_dgain[]
static const struct usb_device_descriptor dev
struct AttRefQuatFloat att_ref_quat_f
API to get/set the generic vehicle states.
void stabilization_attitude_read_rc_setpoint_quat_f(struct FloatQuat *q_sp, bool_t in_flight, bool_t in_carefree, bool_t coordinated_turn)
Read attitude setpoint from RC as quaternion Interprets the stick positions as axes.
static void float_quat_wrap_shortest(struct FloatQuat *q)
int32_t stabilization_cmd[COMMANDS_NB]
Stabilization commands.
#define PERIODIC_FREQUENCY
#define RATES_COPY(_a, _b)
float stabilization_att_ff_cmd[COMMANDS_NB]
float stabilization_attitude_get_heading_f(void)
#define STABILIZATION_ATTITUDE_GAIN_IDX_DEFAULT
static const float theta_pgain[]
static const float phi_ddgain[]
struct FloatQuat stabilization_att_sum_err_quat
struct FloatVect3 surface_p
void attitude_ref_quat_float_init(struct AttRefQuatFloat *ref)
void stabilization_attitude_set_failsafe_setpoint(void)
#define EULERS_FLOAT_OF_BFP(_ef, _ei)
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
struct FloatVect3 surface_i
Paparazzi fixed point algebra.
#define STABILIZATION_ATTITUDE_GAIN_NB