29 #include "generated/airframe.h"
37 #ifndef USE_ATTITUDE_REF
38 #define USE_ATTITUDE_REF 1
42 #ifndef STABILIZATION_ATTITUDE_PHI_FFDGAIN
43 #define STABILIZATION_ATTITUDE_PHI_FFDGAIN 0
45 #ifndef STABILIZATION_ATTITUDE_THETA_FFDGAIN
46 #define STABILIZATION_ATTITUDE_THETA_FFDGAIN 0
48 #ifndef STABILIZATION_ATTITUDE_PSI_FFDGAIN
49 #define STABILIZATION_ATTITUDE_PSI_FFDGAIN 0
55 #if (STABILIZATION_ATTITUDE_PHI_PGAIN < 0) || \
56 (STABILIZATION_ATTITUDE_THETA_PGAIN < 0) || \
57 (STABILIZATION_ATTITUDE_PSI_PGAIN < 0) || \
58 (STABILIZATION_ATTITUDE_PHI_DGAIN < 0) || \
59 (STABILIZATION_ATTITUDE_THETA_DGAIN < 0) || \
60 (STABILIZATION_ATTITUDE_PSI_DGAIN < 0) || \
61 (STABILIZATION_ATTITUDE_PHI_IGAIN < 0) || \
62 (STABILIZATION_ATTITUDE_THETA_IGAIN < 0) || \
63 (STABILIZATION_ATTITUDE_PSI_IGAIN < 0)
64 #error "ALL control gains have to be positive!!!"
83 #if PERIODIC_TELEMETRY
86 static void send_att(
struct transport_tx *trans,
struct link_device *
dev)
90 pprz_msg_send_STAB_ATTITUDE_INT(trans,
dev, AC_ID,
91 &(body_rate->
p), &(body_rate->
q), &(body_rate->
r),
112 pprz_msg_send_STAB_ATTITUDE_REF_INT(trans,
dev, AC_ID,
137 STABILIZATION_ATTITUDE_PHI_PGAIN,
138 STABILIZATION_ATTITUDE_THETA_PGAIN,
139 STABILIZATION_ATTITUDE_PSI_PGAIN);
142 STABILIZATION_ATTITUDE_PHI_DGAIN,
143 STABILIZATION_ATTITUDE_THETA_DGAIN,
144 STABILIZATION_ATTITUDE_PSI_DGAIN);
147 STABILIZATION_ATTITUDE_PHI_IGAIN,
148 STABILIZATION_ATTITUDE_THETA_IGAIN,
149 STABILIZATION_ATTITUDE_PSI_IGAIN);
152 STABILIZATION_ATTITUDE_PHI_DDGAIN,
153 STABILIZATION_ATTITUDE_THETA_DDGAIN,
154 STABILIZATION_ATTITUDE_PSI_DDGAIN);
163 #if PERIODIC_TELEMETRY
175 #define OFFSET_AND_ROUND(_a, _b) (((_a)+(1<<((_b)-1)))>>(_b))
176 #define OFFSET_AND_ROUND2(_a, _b) (((_a)+(1<<((_b)-1))-((_a)<0?1:0))>>(_b))
178 #define MAX_SUM_ERR 4000000
225 EULERS_DIFF(att_err, att_ref_scaled, (*ltp_to_body_euler));
239 RATES_DIFF(rate_err, rate_ref_scaled, (*body_rate));
277 BoundAbs(cmd[COMMAND_ROLL],
MAX_PPRZ);
278 BoundAbs(cmd[COMMAND_PITCH],
MAX_PPRZ);
279 BoundAbs(cmd[COMMAND_YAW],
MAX_PPRZ);
280 BoundAbs(cmd[COMMAND_THRUST],
MAX_PPRZ);
#define EULERS_BOUND_CUBE(_v, _min, _max)
#define EULERS_DIFF(_c, _a, _b)
#define VECT3_ASSIGN(_a, _x, _y, _z)
#define EULERS_ADD(_a, _b)
#define RATES_DIFF(_c, _a, _b)
int32_t p
in rad/s with INT32_RATE_FRAC
int32_t r
in rad/s with INT32_RATE_FRAC
int32_t phi
in rad with INT32_ANGLE_FRAC
int32_t q
in rad/s with INT32_RATE_FRAC
int32_t psi
in rad with INT32_ANGLE_FRAC
int32_t theta
in rad with INT32_ANGLE_FRAC
#define INT_RATES_ZERO(_e)
#define INT32_EULERS_LSHIFT(_o, _i, _r)
#define INT_EULERS_ZERO(_e)
#define INT32_ANGLE_NORMALIZE(_a)
static struct Int32Eulers * stateGetNedToBodyEulers_i(void)
Get vehicle body attitude euler angles (int).
static struct Int32Rates * stateGetBodyRates_i(void)
Get vehicle body angular rate (int).
struct Stabilization stabilization
struct Int32Eulers stab_sp_to_eulers_i(struct StabilizationSetpoint *sp)
int32_t th_sp_to_thrust_i(struct ThrustSetpoint *th, int32_t thrust, uint8_t axis)
int32_t cmd[COMMANDS_NB]
output command vector, range from [-MAX_PPRZ:MAX_PPRZ] (store for messages)
void stabilization_attitude_run(bool in_flight, struct StabilizationSetpoint *sp, struct ThrustSetpoint *thrust, int32_t *cmd)
Attitude control run function.
#define OFFSET_AND_ROUND2(_a, _b)
void stabilization_attitude_enter(void)
Attitude control enter function.
int32_t stabilization_att_ff_cmd[COMMANDS_NB]
static void send_att_ref(struct transport_tx *trans, struct link_device *dev)
#define STABILIZATION_ATTITUDE_PSI_FFDGAIN
#define OFFSET_AND_ROUND(_a, _b)
static struct Int32Eulers stab_att_sp_euler
static void reset_psi_ref_from_body(void)
struct Int32AttitudeGains stabilization_gains
struct Int32Eulers stabilization_att_sum_err
int32_t stabilization_att_fb_cmd[COMMANDS_NB]
#define STABILIZATION_ATTITUDE_THETA_FFDGAIN
void stabilization_attitude_euler_int_init(void)
#define STABILIZATION_ATTITUDE_PHI_FFDGAIN
explicitly define to zero to disable feed-forward rate term by default
static struct AttRefEulerInt att_ref_euler_i
static void send_att(struct transport_tx *trans, struct link_device *dev)
void attitude_ref_euler_int_update(struct AttRefEulerInt *ref, struct Int32Eulers *sp_euler)
Propagate reference model.
void attitude_ref_euler_int_init(struct AttRefEulerInt *ref)
Rotorcraft attitude reference generation (euler int version)
struct Int32Rates accel
with REF_ACCEL_FRAC
struct Int32Rates rate
with REF_RATE_FRAC
struct Int32Eulers euler
with REF_ANGLE_FRAC
Attitude reference models and state/output (euler int)
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...
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.
int int32_t
Typedef defining 32 bit int type.