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
50 #ifndef COORDINATED_TURN_AIRSPEED
51 #define COORDINATED_TURN_AIRSPEED 12.0
54 #define YAW_DEADBAND_EXCEEDED() \
55 (radio_control.values[RADIO_YAW] > STABILIZATION_ATTITUDE_DEADBAND_R || \
56 radio_control.values[RADIO_YAW] < -STABILIZATION_ATTITUDE_DEADBAND_R)
65 #if STABILIZATION_ATTITUDE_DEADBAND_A
77 #if STABILIZATION_ATTITUDE_DEADBAND_E
81 return pitch * max_rc_theta /
MAX_PPRZ;
89 DeadBand(yaw, STABILIZATION_ATTITUDE_DEADBAND_R);
90 return yaw * max_rc_r / (
MAX_PPRZ - STABILIZATION_ATTITUDE_DEADBAND_R);
96 #if STABILIZATION_ATTITUDE_DEADBAND_A
100 return roll * STABILIZATION_ATTITUDE_SP_MAX_PHI /
MAX_PPRZ;
107 #if STABILIZATION_ATTITUDE_DEADBAND_E
111 return pitch * STABILIZATION_ATTITUDE_SP_MAX_THETA /
MAX_PPRZ;
118 DeadBand(yaw, STABILIZATION_ATTITUDE_DEADBAND_R);
119 return yaw * STABILIZATION_ATTITUDE_SP_MAX_R / (
MAX_PPRZ - STABILIZATION_ATTITUDE_DEADBAND_R);
142 heading = att->
psi - att->
phi;
144 heading = att->
psi + att->
phi;
156 if (fabsf(att->
phi) < M_PI / 2) {
158 }
else if (att->
theta > 0) {
159 heading = att->
psi - att->
phi;
161 heading = att->
psi + att->
phi;
175 bool coordinated_turn)
194 if (coordinated_turn) {
199 if (abs(sp->
phi) < max_phi) {
205 sp->
psi += omega * dt;
207 #ifdef STABILIZATION_ATTITUDE_SP_PSI_DELTA_LIMIT
216 if (delta_psi > delta_limit) {
217 sp->
psi = heading + delta_limit;
218 }
else if (delta_psi < -delta_limit) {
219 sp->
psi = heading - delta_limit;
242 sp->
theta = temp_theta;
254 bool coordinated_turn)
273 if (coordinated_turn) {
277 const float max_phi = RadOfDeg(60.0);
278 if (fabsf(sp->
phi) < max_phi) {
284 sp->
psi += omega * dt;
286 #ifdef STABILIZATION_ATTITUDE_SP_PSI_DELTA_LIMIT
293 if (delta_psi > STABILIZATION_ATTITUDE_SP_PSI_DELTA_LIMIT) {
294 sp->
psi = heading + STABILIZATION_ATTITUDE_SP_PSI_DELTA_LIMIT;
295 }
else if (delta_psi < -STABILIZATION_ATTITUDE_SP_PSI_DELTA_LIMIT) {
296 sp->
psi = heading - STABILIZATION_ATTITUDE_SP_PSI_DELTA_LIMIT;
311 sin_psi = sinf(care_free_delta_psi_f);
312 cos_psi = cosf(care_free_delta_psi_f);
314 temp_theta = cos_psi * sp->
theta - sin_psi * sp->
phi;
317 sp->
theta = temp_theta;
352 float qx_roll = sinf(roll2);
353 float qi_roll = cosf(roll2);
358 float qy_pitch = sinf(pitch2);
359 float qi_pitch = cosf(pitch2);
362 q->
qi = qi_roll * qi_pitch;
363 q->
qx = qx_roll * qi_pitch;
364 q->
qy = qi_roll * qy_pitch;
365 q->
qz = qx_roll * qy_pitch;
376 bool coordinated_turn)
381 #if defined STABILIZATION_ATTITUDE_TYPE_INT
410 #if defined STABILIZATION_ATTITUDE_TYPE_INT
429 bool in_carefree,
bool coordinated_turn)
433 #if defined STABILIZATION_ATTITUDE_TYPE_INT
448 #if defined STABILIZATION_ATTITUDE_TYPE_INT
#define THROTTLE_STICK_DOWN()
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()
void stabilization_attitude_read_rc_setpoint_quat_f(struct FloatQuat *q_sp, bool in_flight, bool in_carefree, bool coordinated_turn)
Read attitude setpoint from RC as quaternion Interprets the stick positions as axes.
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.
static int32_t get_rc_pitch(void)
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.
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)
void stabilization_attitude_read_rc_setpoint_quat_earth_bound_f(struct FloatQuat *q_sp, bool in_flight, bool in_carefree, bool coordinated_turn)
struct FloatEulers stab_att_sp_euler
with INT32_ANGLE_FRAC
#define PPRZ_ITRIG_SIN(_s, _a)
Some helper functions to check RC sticks.
int32_t transition_theta_offset
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)
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.
#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.
void stabilization_attitude_read_rc_setpoint_eulers_f(struct FloatEulers *sp, bool in_flight, bool in_carefree, bool coordinated_turn)
static float get_rc_roll_f(void)
void stabilization_attitude_read_rc_setpoint_eulers(struct Int32Eulers *sp, bool in_flight, bool in_carefree, bool coordinated_turn)
Read attitude setpoint from RC as euler angles.
Horizontal guidance for rotorcrafts.
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).
#define COORDINATED_TURN_AIRSPEED
Airspeed that will be used in the turning speed calculation (m/s).
#define PPRZ_ITRIG_COS(_c, _a)