27 #include "generated/airframe.h"
36 #ifndef STABILIZATION_ATTITUDE_DEADBAND_A
37 #define STABILIZATION_ATTITUDE_DEADBAND_A 0
40 #ifndef STABILIZATION_ATTITUDE_DEADBAND_E
41 #define STABILIZATION_ATTITUDE_DEADBAND_E 0
44 #define YAW_DEADBAND_EXCEEDED() \
45 (radio_control.values[RADIO_YAW] > STABILIZATION_ATTITUDE_DEADBAND_R || \
46 radio_control.values[RADIO_YAW] < -STABILIZATION_ATTITUDE_DEADBAND_R)
55 #if STABILIZATION_ATTITUDE_DEADBAND_A
67 #if STABILIZATION_ATTITUDE_DEADBAND_E
71 return pitch * max_rc_theta /
MAX_PPRZ;
79 DeadBand(yaw, STABILIZATION_ATTITUDE_DEADBAND_R);
80 return yaw * max_rc_r / (
MAX_PPRZ - STABILIZATION_ATTITUDE_DEADBAND_R);
86 #if STABILIZATION_ATTITUDE_DEADBAND_A
90 return roll * STABILIZATION_ATTITUDE_SP_MAX_PHI /
MAX_PPRZ;
97 #if STABILIZATION_ATTITUDE_DEADBAND_E
101 return pitch * STABILIZATION_ATTITUDE_SP_MAX_THETA /
MAX_PPRZ;
108 DeadBand(yaw, STABILIZATION_ATTITUDE_DEADBAND_R);
109 return yaw * STABILIZATION_ATTITUDE_SP_MAX_R / (
MAX_PPRZ - STABILIZATION_ATTITUDE_DEADBAND_R);
132 heading = att->
psi - att->
phi;
134 heading = att->
psi + att->
phi;
146 if (fabsf(att->
phi) < M_PI / 2) {
148 }
else if (att->
theta > 0) {
149 heading = att->
psi - att->
phi;
151 heading = att->
psi + att->
phi;
165 bool_t coordinated_turn)
168 static float last_ts = 0.f;
184 if (coordinated_turn) {
190 if (abs(sp->
phi) < max_phi) {
196 sp->
psi += omega * dt;
198 #ifdef STABILIZATION_ATTITUDE_SP_PSI_DELTA_LIMIT
207 if (delta_psi > delta_limit) {
208 sp->
psi = heading + delta_limit;
209 }
else if (delta_psi < -delta_limit) {
210 sp->
psi = heading - delta_limit;
233 sp->
theta = temp_theta;
245 bool_t coordinated_turn)
248 static float last_ts = 0.f;
264 if (coordinated_turn) {
269 const float max_phi = RadOfDeg(85.0);
270 if (fabsf(sp->
phi) < max_phi) {
271 omega = 1.3 * tanf(sp->
phi);
273 omega = 1.3 * 1.72305 * ((sp->
phi > 0) - (sp->
phi < 0));
276 sp->
psi += omega * dt;
278 #ifdef STABILIZATION_ATTITUDE_SP_PSI_DELTA_LIMIT
285 if (delta_psi > STABILIZATION_ATTITUDE_SP_PSI_DELTA_LIMIT) {
286 sp->
psi = heading + STABILIZATION_ATTITUDE_SP_PSI_DELTA_LIMIT;
287 }
else if (delta_psi < -STABILIZATION_ATTITUDE_SP_PSI_DELTA_LIMIT) {
288 sp->
psi = heading - STABILIZATION_ATTITUDE_SP_PSI_DELTA_LIMIT;
303 sin_psi = sinf(care_free_delta_psi_f);
304 cos_psi = cosf(care_free_delta_psi_f);
306 temp_theta = cos_psi * sp->
theta - sin_psi * sp->
phi;
309 sp->
theta = temp_theta;
344 float qx_roll = sinf(roll2);
345 float qi_roll = cosf(roll2);
350 float qy_pitch = sinf(pitch2);
351 float qi_pitch = cosf(pitch2);
354 q->
qi = qi_roll * qi_pitch;
355 q->
qx = qx_roll * qi_pitch;
356 q->
qy = qi_roll * qy_pitch;
357 q->
qz = qx_roll * qy_pitch;
368 bool_t coordinated_turn)
373 #if defined STABILIZATION_ATTITUDE_TYPE_INT
402 #if defined STABILIZATION_ATTITUDE_TYPE_INT
421 bool_t in_carefree, bool_t coordinated_turn)
425 #if defined STABILIZATION_ATTITUDE_TYPE_INT
440 #if defined STABILIZATION_ATTITUDE_TYPE_INT
int32_t psi
in rad with INT32_ANGLE_FRAC
#define FLOAT_ANGLE_NORMALIZE(_a)
void float_quat_comp_inv(struct FloatQuat *a2b, struct FloatQuat *a2c, struct FloatQuat *b2c)
Composition (multiplication) of two quaternions.
#define YAW_DEADBAND_EXCEEDED()
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
static float get_rc_yaw_f(void)
#define STABILIZATION_ATTITUDE_DEADBAND_A
void float_quat_comp(struct FloatQuat *a2c, struct FloatQuat *a2b, struct FloatQuat *b2c)
Composition (multiplication) of two quaternions.
General attitude stabilization interface for rotorcrafts.
int32_t theta
in rad with INT32_ANGLE_FRAC
static float get_rc_pitch_f(void)
static int32_t get_rc_roll(void)
int32_t stabilization_attitude_get_heading_i(void)
Read an attitude setpoint from the RC.
void stabilization_attitude_read_rc_setpoint_eulers_f(struct FloatEulers *sp, bool_t in_flight, bool_t in_carefree, bool_t coordinated_turn)
static int32_t get_rc_pitch(void)
void stabilization_attitude_read_rc_setpoint_eulers(struct Int32Eulers *sp, bool_t in_flight, bool_t in_carefree, bool_t coordinated_turn)
Read attitude setpoint from RC as euler angles.
void stabilization_attitude_reset_care_free_heading(void)
reset the heading for care-free mode to current heading
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
void stabilization_attitude_read_rc_roll_pitch_quat_f(struct FloatQuat *q)
Read roll/pitch command from RC as quaternion.
#define THROTTLE_STICK_DOWN()
static float get_sys_time_float(void)
Get the time in seconds since startup.
#define ANGLE_FLOAT_OF_BFP(_ai)
#define QUAT_COPY(_qo, _qi)
struct FloatEulers stab_att_sp_euler
with INT32_ANGLE_FRAC
#define PPRZ_ITRIG_SIN(_s, _a)
Architecture independent timing functions.
#define INT32_ANGLE_NORMALIZE(_a)
static void float_quat_normalize(struct FloatQuat *q)
struct RadioControl radio_control
#define STABILIZATION_ATTITUDE_DEADBAND_E
#define ANGLE_BFP_OF_REAL(_af)
Some helper functions to check RC sticks.
void stabilization_attitude_read_rc_roll_pitch_earth_quat_f(struct FloatQuat *q)
Read roll/pitch command from RC as quaternion.
int32_t phi
in rad with INT32_ANGLE_FRAC
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.
#define INT_MULT_RSHIFT(_a, _b, _r)
void float_quat_of_orientation_vect(struct FloatQuat *q, const struct FloatVect3 *ov)
Quaternion from orientation vector.
void float_quat_of_axis_angle(struct FloatQuat *q, const struct FloatVect3 *uv, float angle)
Quaternion from unit vector and angle.
void float_quat_comp_norm_shortest(struct FloatQuat *a2c, struct FloatQuat *a2b, struct FloatQuat *b2c)
Composition (multiplication) of two quaternions with normalization.
int32_t transition_theta_offset
Horizontal guidance for rotorcrafts.
static float get_rc_roll_f(void)
float stabilization_attitude_get_heading_f(void)
static int32_t get_rc_yaw(void)
static struct Int32Eulers * stateGetNedToBodyEulers_i(void)
Get vehicle body attitude euler angles (int).
void stabilization_attitude_read_rc_setpoint_quat_earth_bound_f(struct FloatQuat *q_sp, bool_t in_flight, bool_t in_carefree, bool_t coordinated_turn)
#define PPRZ_ITRIG_COS(_c, _a)