27 #include "generated/airframe.h"
48 #ifndef GUIDANCE_H_AGAIN
49 #define GUIDANCE_H_AGAIN 0
52 #ifndef GUIDANCE_H_VGAIN
53 #define GUIDANCE_H_VGAIN 0
57 #if (GUIDANCE_H_PGAIN < 0) || \
58 (GUIDANCE_H_DGAIN < 0) || \
59 (GUIDANCE_H_IGAIN < 0) || \
60 (GUIDANCE_H_AGAIN < 0) || \
61 (GUIDANCE_H_VGAIN < 0)
62 #error "ALL control gains have to be positive!!!"
65 #ifndef GUIDANCE_H_MAX_BANK
66 #define GUIDANCE_H_MAX_BANK RadOfDeg(20)
72 #ifndef GUIDANCE_H_APPROX_FORCE_BY_THRUST
73 #define GUIDANCE_H_APPROX_FORCE_BY_THRUST FALSE
77 #define GUIDANCE_INDI FALSE
107 #if PERIODIC_TELEMETRY
110 static void send_gh(
struct transport_tx *trans,
struct link_device *
dev)
113 pprz_msg_send_GUIDANCE_H_INT(trans, dev, AC_ID,
116 &(pos->
x), &(pos->
y));
124 pprz_msg_send_HOVER_LOOP(trans, dev, AC_ID,
127 &(pos->
x), &(pos->
y),
128 &(speed->
x), &(speed->
y),
129 &(accel->
x), &(accel->
y),
141 static void send_href(
struct transport_tx *trans,
struct link_device *
dev)
143 pprz_msg_send_GUIDANCE_H_REF_INT(trans, dev, AC_ID,
154 pprz_msg_send_ROTORCRAFT_TUNE_HOVER(trans, dev, AC_ID,
186 transition_percentage = 0;
187 transition_theta_offset = 0;
191 #if GUIDANCE_H_MODE_MODULE_SETTING == GUIDANCE_H_MODE_MODULE
195 #if PERIODIC_TELEMETRY
206 #if HYBRID_NAVIGATION
229 transition_percentage = 0;
230 transition_theta_offset = 0;
233 #if HYBRID_NAVIGATION
242 #if USE_STABILIZATION_RATE
252 #if NO_ATTITUDE_RESET_ON_MODE_CHANGE
267 #if NO_ATTITUDE_RESET_ON_MODE_CHANGE
276 #if GUIDANCE_H_MODE_MODULE_SETTING == GUIDANCE_H_MODE_MODULE
284 #if NO_ATTITUDE_RESET_ON_MODE_CHANGE
315 #if USE_STABILIZATION_RATE
317 #if SWITCH_STICKS_FOR_RATE_CONTROL
336 #if GUIDANCE_H_USE_SPEED_REF
343 #if GUIDANCE_H_MODE_MODULE_SETTING == GUIDANCE_H_MODE_MODULE
373 #if USE_STABILIZATION_RATE
429 #if HYBRID_NAVIGATION
435 #if HYBRID_NAVIGATION
462 #if GUIDANCE_H_MODE_MODULE_SETTING == GUIDANCE_H_MODE_MODULE
481 #if GUIDANCE_H_USE_REF
501 #if GUIDANCE_H_USE_SPEED_REF
514 #define MAX_POS_ERR POS_BFP_OF_REAL(16.)
515 #define MAX_SPEED_ERR SPEED_BFP_OF_REAL(16.)
517 #ifndef GUIDANCE_H_THRUST_CMD_FILTER
518 #define GUIDANCE_H_THRUST_CMD_FILTER 10
523 #define GH_GAIN_SCALE 2
582 static int32_t thrust_cmd_filt;
637 #ifdef TRANSITION_MAX_OFFSET
706 float newvx = cosf(-psi) * vx + sinf(-psi) * vy;
707 float newvy = -sinf(-psi) * vx + cosf(-psi) * vy;
void guidance_flip_enter(void)
void gh_update_ref_from_pos_sp(struct Int32Vect2 pos_sp)
int32_t psi
in rad with INT32_ANGLE_FRAC
int32_t heading_rate
with INT32_RATE_FRAC
void guidance_indi_enter(void)
Call upon entering indi guidance.
void gh_set_ref(struct Int32Vect2 pos, struct Int32Vect2 speed, struct Int32Vect2 accel)
struct Int32Vect2 guidance_h_cmd_earth
horizontal guidance command.
uint8_t mask
bit 5: vx & vy, bit 6: vz, bit 7: vyaw
void gh_update_ref_from_speed_sp(struct Int32Vect2 speed_sp)
#define GUIDANCE_H_MODE_RC_DIRECT
void stabilization_none_run(bool in_flight)
struct Int32Eulers rc_sp
with INT32_ANGLE_FRAC
Rotorcraft navigation functions.
#define GUIDANCE_H_MODE_MODULE
#define GUIDANCE_H_MODE_CARE_FREE
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
void guidance_h_read_rc(bool in_flight)
void guidance_h_set_igain(uint32_t igain)
#define INT32_PERCENTAGE_FRAC
Dummy stabilization for rotorcrafts.
Periodic telemetry system header (includes downlink utility and generated code).
General attitude stabilization interface for rotorcrafts.
struct GuidanceHRef gh_ref
void stabilization_rate_enter(void)
void guidance_h_run(bool in_flight)
int32_t theta
in rad with INT32_ANGLE_FRAC
void guidance_hybrid_init(void)
Hybrid Guidance Initialization function.
#define VECT2_STRIM(_v, _min, _max)
#define POS_BFP_OF_REAL(_af)
Open Loop guidance for making a flip.
Read an attitude setpoint from the RC.
#define GUIDANCE_H_MODE_ATTITUDE
#define VECT2_COPY(_a, _b)
Vertical guidance for rotorcrafts.
bool guidance_h_set_guided_body_vel(float vx, float vy)
Set body relative horizontal velocity setpoint in GUIDED mode.
#define VECT2_DIFF(_c, _a, _b)
static void transition_run(void)
void stabilization_attitude_run(bool in_flight)
struct HorizontalGuidanceReference ref
reference calculated from setpoints
void stabilization_attitude_enter(void)
static void reset_guidance_reference_from_current_position(void)
int32_t transition_percentage
void stabilization_attitude_reset_care_free_heading(void)
reset the heading for care-free mode to current heading
struct EnuCoor_i navigation_target
static void send_tune_hover(struct transport_tx *trans, struct link_device *dev)
Guidance controllers (horizontal and vertical) for Hybrid UAV configurations.
void guidance_hybrid_run(void)
Runs the Hybrid Guidance main functions.
struct HorizontalGuidance guidance_h
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
#define GUIDANCE_H_REF_MAX_SPEED
Default speed saturation.
struct HorizontalGuidanceSetpoint sp
setpoints
struct EnuCoor_i navigation_carrot
struct Int32Vect2 accel
with INT32_ACCEL_FRAC
struct Int64Vect2 pos
Reference model position.
#define GUIDANCE_H_USE_SPEED_REF
Use horizontal guidance speed reference.
Rate stabilization for rotorcrafts.
static void guidance_h_nav_enter(void)
static void guidance_h_traj_run(bool in_flight)
#define BFP_OF_REAL(_vr, _frac)
void stabilization_none_enter(void)
#define PPRZ_ITRIG_SIN(_s, _a)
void guidance_h_module_enter(void)
static struct NedCoor_i * stateGetSpeedNed_i(void)
Get ground speed in local NED coordinates (int).
bool guidance_h_set_guided_heading(float heading)
Set heading setpoint in GUIDED mode.
#define GUIDANCE_H_MODE_HOVER
static void send_href(struct transport_tx *trans, struct link_device *dev)
struct Int32Vect2 guidance_h_speed_err
static void read_rc_setpoint_speed_i(struct Int32Vect2 *speed_sp, bool in_flight)
read speed setpoint from RC
void stabilization_rate_read_rc(void)
void guidance_h_module_read_rc(void)
bool guidance_h_set_guided_pos(float x, float y)
Set horizontal position setpoint in GUIDED mode.
struct Int32Vect2 speed
with INT32_SPEED_FRAC
#define GUIDANCE_H_APPROX_FORCE_BY_THRUST
void stabilization_rate_read_rc_switched_sticks(void)
void stabilization_attitude_set_rpy_setpoint_i(struct Int32Eulers *rpy)
#define INT32_VECT2_NED_OF_ENU(_o, _i)
#define INT32_ANGLE_NORMALIZE(_a)
void stabilization_attitude_set_earth_cmd_i(struct Int32Vect2 *cmd, int32_t heading)
void guidance_hybrid_reset_heading(struct Int32Eulers *sp_cmd)
Description.
#define DefaultPeriodic
Set default periodic telemetry.
static void send_hover_loop(struct transport_tx *trans, struct link_device *dev)
void stabilization_none_read_rc(void)
struct RadioControl radio_control
#define GH_SPEED_REF_FRAC
#define GUIDANCE_H_MODE_NAV
#define GUIDANCE_H_MAX_BANK
int32_t guidance_hybrid_norm_ref_airspeed
#define GUIDANCE_H_MODE_KILL
static void send_gh(struct transport_tx *trans, struct link_device *dev)
bool guidance_h_set_guided_heading_rate(float rate)
Set heading rate setpoint in GUIDED mode.
void guidance_h_module_init(void)
#define ANGLE_BFP_OF_REAL(_af)
static const struct usb_device_descriptor dev
#define GH_ACCEL_REF_FRAC
int32_t heading
with INT32_ANGLE_FRAC
int32_t phi
in rad with INT32_ANGLE_FRAC
#define INT_EULERS_ZERO(_e)
API to get/set the generic vehicle states.
struct HorizontalGuidanceGains gains
vector in North East Down coordinates
struct Int32Vect2 speed
Reference model speed.
#define INT_MULT_RSHIFT(_a, _b, _r)
float nav_pitch
with INT32_ANGLE_FRAC
int32_t guidance_v_thrust_coeff
static void guidance_h_update_reference(void)
void guidance_h_mode_changed(uint8_t new_mode)
int32_t transition_theta_offset
General stabilization interface for rotorcrafts.
Horizontal guidance for rotorcrafts.
void guidance_flip_run(void)
#define GUIDANCE_H_THRUST_CMD_FILTER
struct Int32Vect2 pos
with INT32_POS_FRAC
int32_t stabilization_cmd[COMMANDS_NB]
Stabilization commands.
#define HORIZONTAL_MODE_MANUAL
void stabilization_rate_run(bool in_flight)
#define HORIZONTAL_MODE_ATTITUDE
#define INT_VECT2_ZERO(_v)
Guidance in a module file.
struct Int32Vect2 accel
Reference model acceleration.
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.
bool approx_force_by_thrust
void guidance_h_module_run(bool in_flight)
#define SPEED_BFP_OF_REAL(_af)
struct Int32Vect2 guidance_h_pos_err
void stabilization_attitude_read_rc(bool in_flight, bool in_carefree, bool coordinated_turn)
static struct NedCoor_i * stateGetPositionNed_i(void)
Get position in local NED coordinates (int).
#define INT32_VECT2_RSHIFT(_o, _i, _r)
#define INT32_VECT2_LSHIFT(_o, _i, _l)
#define GUIDANCE_H_MODE_FORWARD
static struct Int32Eulers * stateGetNedToBodyEulers_i(void)
Get vehicle body attitude euler angles (int).
int32_t nav_heading
with INT32_ANGLE_FRAC
const struct Int32Vect2 * guidance_h_get_pos_err(void)
Gets the position error.
#define GUIDANCE_H_USE_REF
Use horizontal guidance reference trajectory.
#define GUIDANCE_H_MODE_RATE
#define GUIDANCE_H_MODE_FLIP
struct Int32Vect2 speed
only used in HOVER mode if GUIDANCE_H_USE_SPEED_REF or in GUIDED mode
void guidance_indi_run(bool in_flight, int32_t heading)
bool guidance_h_set_guided_vel(float vx, float vy)
Set horizontal velocity setpoint in GUIDED mode.
static void guidance_h_hover_enter(void)
void guidance_h_init(void)
A guidance mode based on Incremental Nonlinear Dynamic Inversion Come to ICRA2016 to learn more! ...
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
struct Int32Vect2 guidance_h_trim_att_integrator
static struct NedCoor_i * stateGetAccelNed_i(void)
Get acceleration in NED coordinates (int).
struct Int32Vect2 pos
horizontal position setpoint in NED.
#define PPRZ_ITRIG_COS(_c, _a)
#define GUIDANCE_H_MODE_GUIDED
#define RATE_BFP_OF_REAL(_af)