27 #include "generated/airframe.h"
35 #ifndef STABILIZATION_ATTITUDE_DEADBAND_A
36 #define STABILIZATION_ATTITUDE_DEADBAND_A 0
39 #ifndef STABILIZATION_ATTITUDE_DEADBAND_E
40 #define STABILIZATION_ATTITUDE_DEADBAND_E 0
49 #ifndef COORDINATED_TURN_AIRSPEED
50 #define COORDINATED_TURN_AIRSPEED 12.0
53 #define YAW_DEADBAND_EXCEEDED(_rc) \
54 (rc->values[RADIO_YAW] > STABILIZATION_ATTITUDE_DEADBAND_R || \
55 rc->values[RADIO_YAW] < -STABILIZATION_ATTITUDE_DEADBAND_R)
77 DeadBand(yaw, STABILIZATION_ATTITUDE_DEADBAND_R);
78 return yaw * max_rc_r / (
MAX_PPRZ - STABILIZATION_ATTITUDE_DEADBAND_R);
98 DeadBand(yaw, STABILIZATION_ATTITUDE_DEADBAND_R);
99 return yaw * STABILIZATION_ATTITUDE_SP_MAX_R / (
MAX_PPRZ - STABILIZATION_ATTITUDE_DEADBAND_R);
170 bool in_carefree,
bool coordinated_turn,
struct RadioControl *rc)
235 if (fabsf(att->
phi) < M_PI / 2) {
237 }
else if (att->
theta > 0) {
256 bool in_carefree,
bool coordinated_turn,
struct RadioControl *rc)
275 if (coordinated_turn) {
280 if (abs(sp_i.phi) < max_phi) {
286 sp_i.psi += omega * dt;
288 #ifdef STABILIZATION_ATTITUDE_SP_PSI_DELTA_LIMIT
297 if (delta_psi > delta_limit) {
298 sp_i.psi =
heading + delta_limit;
299 }
else if (delta_psi < -delta_limit) {
300 sp_i.psi =
heading - delta_limit;
323 sp_i.theta = temp_theta;
346 bool in_carefree,
bool coordinated_turn,
struct RadioControl *rc)
362 if (coordinated_turn) {
366 const float max_phi = RadOfDeg(60.0);
367 if (fabsf(rc_sp->rc_eulers.
phi) < max_phi) {
373 rc_sp->rc_eulers.
psi += omega * dt;
375 #ifdef STABILIZATION_ATTITUDE_SP_PSI_DELTA_LIMIT
380 float delta_psi = rc_sp->rc_eulers.
psi -
heading;
382 if (delta_psi > STABILIZATION_ATTITUDE_SP_PSI_DELTA_LIMIT) {
383 rc_sp->rc_eulers.
psi =
heading + STABILIZATION_ATTITUDE_SP_PSI_DELTA_LIMIT;
384 }
else if (delta_psi < -STABILIZATION_ATTITUDE_SP_PSI_DELTA_LIMIT) {
385 rc_sp->rc_eulers.
psi =
heading - STABILIZATION_ATTITUDE_SP_PSI_DELTA_LIMIT;
396 float care_free_delta_psi_f = rc_sp->rc_eulers.
psi - rc_sp->care_free_heading;
400 sin_psi = sinf(care_free_delta_psi_f);
401 cos_psi = cosf(care_free_delta_psi_f);
403 temp_theta = cos_psi * rc_sp->rc_eulers.
theta - sin_psi * rc_sp->rc_eulers.
phi;
404 rc_sp->rc_eulers.
phi = cos_psi * rc_sp->rc_eulers.
phi - sin_psi * rc_sp->rc_eulers.
theta;
406 rc_sp->rc_eulers.
theta = temp_theta;
414 return rc_sp->rc_eulers;
445 float qx_roll = sinf(roll2);
446 float qi_roll = cosf(roll2);
451 float qy_pitch = sinf(pitch2);
452 float qi_pitch = cosf(pitch2);
455 q->
qi = qi_roll * qi_pitch;
456 q->
qx = qx_roll * qi_pitch;
457 q->
qy = qi_roll * qy_pitch;
458 q->
qz = qx_roll * qy_pitch;
static void float_quat_normalize(struct FloatQuat *q)
#define FLOAT_ANGLE_NORMALIZE(_a)
void float_quat_of_axis_angle(struct FloatQuat *q, const struct FloatVect3 *uv, float angle)
Quaternion from unit vector and angle.
static void float_quat_identity(struct FloatQuat *q)
initialises a quaternion to identity
void float_quat_comp_norm_shortest(struct FloatQuat *a2c, struct FloatQuat *a2b, struct FloatQuat *b2c)
Composition (multiplication) of two quaternions with normalization.
void float_quat_comp_inv(struct FloatQuat *a2b, struct FloatQuat *a2c, struct FloatQuat *b2c)
Composition (multiplication) of two quaternions.
#define FLOAT_EULERS_ZERO(_e)
void float_quat_of_orientation_vect(struct FloatQuat *q, const struct FloatVect3 *ov)
Quaternion from orientation vector.
void float_quat_comp(struct FloatQuat *a2c, struct FloatQuat *a2b, struct FloatQuat *b2c)
Composition (multiplication) of two quaternions.
#define EULERS_BFP_OF_REAL(_ei, _ef)
#define QUAT_COPY(_qo, _qi)
#define EULERS_FLOAT_OF_BFP(_ef, _ei)
int32_t phi
in rad with INT32_ANGLE_FRAC
int32_t psi
in rad with INT32_ANGLE_FRAC
int32_t theta
in rad with INT32_ANGLE_FRAC
#define INT_MULT_RSHIFT(_a, _b, _r)
#define ANGLE_BFP_OF_REAL(_af)
#define ANGLE_FLOAT_OF_BFP(_ai)
#define INT32_ANGLE_NORMALIZE(_a)
static struct Int32Eulers * stateGetNedToBodyEulers_i(void)
Get vehicle body attitude euler angles (int).
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).
#define PPRZ_ITRIG_SIN(_s, _a)
#define PPRZ_ITRIG_COS(_c, _a)
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.
#define THROTTLE_STICK_DOWN_FROM_RC(_rc)
General attitude stabilization interface for rotorcrafts.
void stabilization_attitude_reset_care_free_heading(struct AttitudeRCInput *rc_sp)
reset the heading for care-free mode to current heading
int32_t stabilization_attitude_get_heading_i(void)
Get attitude heading as int (avoiding jumps)
static int32_t get_rc_yaw(struct RadioControl *rc)
static float get_rc_pitch_f(struct RadioControl *rc)
#define COORDINATED_TURN_AIRSPEED
Airspeed that will be used in the turning speed calculation (m/s).
static int32_t get_rc_pitch(struct RadioControl *rc)
static int32_t get_rc_roll(struct RadioControl *rc)
void stabilization_attitude_reset_rc_setpoint(struct AttitudeRCInput *rc_sp)
reset to current state
void stabilization_attitude_rc_setpoint_init(struct AttitudeRCInput *rc_sp)
Init rc input.
void stabilization_attitude_read_rc_setpoint_earth_bound(struct AttitudeRCInput *rc_sp, bool in_flight, bool in_carefree, bool coordinated_turn, struct RadioControl *rc)
Read attitude setpoint from RC as quaternion in earth bound frame.
void stabilization_attitude_read_rc_roll_pitch_earth_quat_f(struct FloatQuat *q, float theta_offset, struct RadioControl *rc)
Read roll/pitch command from RC as quaternion.
void stabilization_attitude_read_rc_roll_pitch_quat_f(struct FloatQuat *q, struct RadioControl *rc)
Read roll/pitch command from RC as quaternion.
void stabilization_attitude_read_rc_setpoint(struct AttitudeRCInput *rc_sp, bool in_flight, bool in_carefree, bool coordinated_turn, struct RadioControl *rc)
Read attitude setpoint from RC as quaternion Interprets the stick positions as axes.
#define STABILIZATION_ATTITUDE_DEADBAND_A
#define STABILIZATION_ATTITUDE_DEADBAND_E
struct Int32Eulers stabilization_attitude_read_rc_setpoint_eulers(struct AttitudeRCInput *rc_sp, bool in_flight, bool in_carefree, bool coordinated_turn, struct RadioControl *rc)
Read attitude setpoint from RC as euler angles Only the euler format is updated and returned.
static float get_rc_roll_f(struct RadioControl *rc)
#define YAW_DEADBAND_EXCEEDED(_rc)
struct FloatEulers stabilization_attitude_read_rc_setpoint_eulers_f(struct AttitudeRCInput *rc_sp, bool in_flight, bool in_carefree, bool coordinated_turn, struct RadioControl *rc)
Read attitude setpoint from RC as float euler angles Only the euler format is updated and returned.
float stabilization_attitude_get_heading_f(void)
Get attitude heading as float (avoiding jumps)
static float get_rc_yaw_f(struct RadioControl *rc)
Read an attitude setpoint from the RC.
struct FloatEulers rc_eulers
RC input in eulers (needed even for quat for yaw integration)
struct FloatQuat rc_quat
RC input in quaternion.
float care_free_heading
care_free heading
float transition_theta_offset
pitch offset for hybrids, add when in forward mode
API to get/set the generic vehicle states.
Architecture independent timing functions.
static float get_sys_time_float(void)
Get the time in seconds since startup.
int int32_t
Typedef defining 32 bit int type.