27 #include "generated/airframe.h"
37 #if GUIDANCE_INDI_HYBRID
52 #ifndef GUIDANCE_H_AGAIN
53 #define GUIDANCE_H_AGAIN 0
56 #ifndef GUIDANCE_H_VGAIN
57 #define GUIDANCE_H_VGAIN 0
61 #if (GUIDANCE_H_PGAIN < 0) || \
62 (GUIDANCE_H_DGAIN < 0) || \
63 (GUIDANCE_H_IGAIN < 0) || \
64 (GUIDANCE_H_AGAIN < 0) || \
65 (GUIDANCE_H_VGAIN < 0)
66 #error "ALL control gains have to be positive!!!"
69 #ifndef GUIDANCE_H_MAX_BANK
70 #define GUIDANCE_H_MAX_BANK RadOfDeg(20)
76 #ifndef GUIDANCE_H_APPROX_FORCE_BY_THRUST
77 #define GUIDANCE_H_APPROX_FORCE_BY_THRUST FALSE
81 #define GUIDANCE_INDI FALSE
86 #ifndef GUIDANCE_HEADING_IS_FREE
87 #define GUIDANCE_HEADING_IS_FREE TRUE
114 #if PERIODIC_TELEMETRY
117 static void send_gh(
struct transport_tx *trans,
struct link_device *
dev)
120 pprz_msg_send_GUIDANCE_H_INT(trans,
dev, AC_ID,
123 &(pos->
x), &(pos->
y));
131 pprz_msg_send_HOVER_LOOP(trans,
dev, AC_ID,
134 &(pos->
x), &(pos->
y),
135 &(speed->
x), &(speed->
y),
136 &(accel->
x), &(accel->
y),
148 static void send_href(
struct transport_tx *trans,
struct link_device *
dev)
150 pprz_msg_send_GUIDANCE_H_REF_INT(trans,
dev, AC_ID,
161 pprz_msg_send_ROTORCRAFT_TUNE_HOVER(trans,
dev, AC_ID,
198 #if GUIDANCE_H_MODE_MODULE_SETTING == GUIDANCE_H_MODE_MODULE
202 #if PERIODIC_TELEMETRY
234 #if HYBRID_NAVIGATION
243 #if USE_STABILIZATION_RATE
254 #if NO_ATTITUDE_RESET_ON_MODE_CHANGE
269 #if NO_ATTITUDE_RESET_ON_MODE_CHANGE
278 #if GUIDANCE_H_MODE_MODULE_SETTING == GUIDANCE_H_MODE_MODULE
289 #if NO_ATTITUDE_RESET_ON_MODE_CHANGE
320 #if USE_STABILIZATION_RATE
322 #if SWITCH_STICKS_FOR_RATE_CONTROL
341 #if GUIDANCE_H_USE_SPEED_REF
348 #if GUIDANCE_H_MODE_MODULE_SETTING == GUIDANCE_H_MODE_MODULE
378 #if USE_STABILIZATION_RATE
395 #if (STABILIZATION_FILTER_CMD_ROLL_PITCH || STABILIZATION_FILTER_CMD_YAW)
417 #if GUIDANCE_H_MODE_MODULE_SETTING == GUIDANCE_H_MODE_MODULE
436 #if GUIDANCE_H_USE_REF
461 #if GUIDANCE_H_USE_SPEED_REF
474 #define MAX_POS_ERR POS_BFP_OF_REAL(16.)
475 #define MAX_SPEED_ERR SPEED_BFP_OF_REAL(16.)
477 #ifndef GUIDANCE_H_THRUST_CMD_FILTER
478 #define GUIDANCE_H_THRUST_CMD_FILTER 10
483 #define GH_GAIN_SCALE 2
542 static int32_t thrust_cmd_filt;
604 #if HYBRID_NAVIGATION
612 #if HYBRID_NAVIGATION
622 #if GUIDANCE_HEADING_IS_FREE
653 #ifdef TRANSITION_MAX_OFFSET
736 float newvx = cosf(-
psi) * vx + sinf(-
psi) * vy;
737 float newvy = -sinf(-
psi) * vx + cosf(-
psi) * vy;
void guidance_h_module_read_rc(void)
void guidance_h_module_run(bool in_flight)
void guidance_h_module_init(void)
void guidance_h_module_enter(void)
#define FLOAT_ANGLE_NORMALIZE(_a)
#define FLOAT_EULERS_ZERO(_e)
#define FLOAT_VECT2_ZERO(_v)
#define VECT2_DIFF(_c, _a, _b)
#define VECT2_STRIM(_v, _min, _max)
#define VECT2_COPY(_a, _b)
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 INT32_PERCENTAGE_FRAC
#define ACCEL_BFP_OF_REAL(_af)
#define POS_FLOAT_OF_BFP(_ai)
#define SPEED_FLOAT_OF_BFP(_ai)
#define BFP_OF_REAL(_vr, _frac)
#define INT_VECT2_ZERO(_v)
#define ANGLE_FLOAT_OF_BFP(_ai)
#define INT32_VECT2_RSHIFT(_o, _i, _r)
#define POS_BFP_OF_REAL(_af)
#define SPEED_BFP_OF_REAL(_af)
#define INT32_VECT2_NED_OF_ENU(_o, _i)
vector in North East Down coordinates
static struct NedCoor_i * stateGetAccelNed_i(void)
Get acceleration in NED coordinates (int).
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 NedCoor_f * stateGetPositionNed_f(void)
Get position in local NED coordinates (float).
static struct NedCoor_i * stateGetPositionNed_i(void)
Get position in local NED coordinates (int).
static struct NedCoor_i * stateGetSpeedNed_i(void)
Get ground speed in local NED coordinates (int).
void guidance_flip_run(void)
void guidance_flip_enter(void)
Open Loop guidance for making a flip.
void gh_set_ref(struct Int32Vect2 pos, struct FloatVect2 speed, struct FloatVect2 accel)
void gh_update_ref_from_pos_sp(struct Int32Vect2 pos_sp)
void gh_update_ref_from_speed_sp(struct FloatVect2 speed_sp)
struct GuidanceHRef gh_ref
#define GH_POS_REF_FRAC
fixedpoint representation: Q26.37 will give a range of 67e3 km and a resolution of 1....
struct FloatVect2 accel
Reference model acceleration.
#define GUIDANCE_H_REF_MAX_SPEED
Default speed saturation.
struct Int64Vect2 pos
Reference model position.
struct FloatVect2 speed
Reference model speed.
int32_t guidance_hybrid_norm_ref_airspeed
void guidance_hybrid_reset_heading(struct Int32Eulers *sp_cmd)
Description.
void guidance_hybrid_run(void)
Runs the Hybrid Guidance main functions.
Guidance controllers (horizontal and vertical) for Hybrid UAV configurations.
struct FloatVect3 speed_sp
void guidance_indi_enter(void)
Call upon entering indi guidance.
void guidance_indi_run(float *heading_sp)
A guidance mode based on Incremental Nonlinear Dynamic Inversion.
A guidance mode based on Incremental Nonlinear Dynamic Inversion Come to ICRA2016 to learn more!
Guidance in a module file.
#define PPRZ_ITRIG_SIN(_s, _a)
#define PPRZ_ITRIG_COS(_c, _a)
struct RadioControl radio_control
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)
int32_t transition_percentage
void guidance_h_read_rc(bool in_flight)
void guidance_h_set_pos(float x, float y)
Set horizontal position setpoint.
static void send_hover_loop(struct transport_tx *trans, struct link_device *dev)
struct Int32Vect2 guidance_h_speed_err
void guidance_h_mode_changed(uint8_t new_mode)
static void send_href(struct transport_tx *trans, struct link_device *dev)
static void send_gh(struct transport_tx *trans, struct link_device *dev)
void guidance_h_hover_enter(void)
struct Int32Vect2 guidance_h_pos_err
static void send_tune_hover(struct transport_tx *trans, struct link_device *dev)
struct Int32Vect2 guidance_h_trim_att_integrator
void guidance_h_guided_run(bool in_flight)
Run GUIDED mode control.
void guidance_h_from_nav(bool in_flight)
Set horizontal guidance from NAV and run control loop.
void guidance_h_set_heading(float heading)
Set heading setpoint.
void guidance_h_init(void)
struct HorizontalGuidance guidance_h
static void guidance_h_traj_run(bool in_flight)
static void read_rc_setpoint_speed_i(struct Int32Vect2 *speed_sp, bool in_flight)
read speed setpoint from RC
struct Int32Vect2 guidance_h_cmd_earth
horizontal guidance command.
#define GUIDANCE_H_THRUST_CMD_FILTER
void guidance_h_nav_enter(void)
static void guidance_h_update_reference(void)
void guidance_h_set_vel(float vx, float vy)
Set horizontal velocity setpoint.
void guidance_h_set_body_vel(float vx, float vy)
Set body relative horizontal velocity setpoint.
#define GUIDANCE_H_APPROX_FORCE_BY_THRUST
static void reset_guidance_reference_from_current_position(void)
static void transition_run(bool to_forward)
const struct Int32Vect2 * guidance_h_get_pos_err(void)
Gets the position error.
void guidance_h_set_igain(uint32_t igain)
#define GUIDANCE_H_MAX_BANK
void guidance_h_set_heading_rate(float rate)
Set heading rate setpoint.
void guidance_h_run(bool in_flight)
Horizontal guidance for rotorcrafts.
#define GUIDANCE_H_MODE_FORWARD
#define GUIDANCE_H_MODE_NAV
#define GUIDANCE_H_USE_REF
Use horizontal guidance reference trajectory.
struct Int32Vect2 accel
with INT32_ACCEL_FRAC
uint8_t mask
bit 5: vx & vy, bit 6: vz, bit 7: vyaw
#define GUIDANCE_H_MODE_HOVER
bool approx_force_by_thrust
struct Int32Vect2 pos
horizontal position setpoint in NED.
struct Int32Vect2 speed
with INT32_SPEED_FRAC
struct HorizontalGuidanceGains gains
#define GUIDANCE_H_MODE_ATTITUDE
#define GUIDANCE_H_MODE_GUIDED
#define GUIDANCE_H_MODE_RC_DIRECT
struct Int32Vect2 pos
with INT32_POS_FRAC
struct HorizontalGuidanceReference ref
reference calculated from setpoints
#define GUIDANCE_H_USE_SPEED_REF
Use horizontal guidance speed reference.
#define GUIDANCE_H_MODE_CARE_FREE
struct Int32Vect2 speed
only used in HOVER mode if GUIDANCE_H_USE_SPEED_REF or in GUIDED mode
#define GUIDANCE_H_MODE_KILL
#define GUIDANCE_H_MODE_RATE
struct HorizontalGuidanceSetpoint sp
setpoints
#define GUIDANCE_H_MODE_FLIP
#define GUIDANCE_H_MODE_MODULE
int32_t guidance_v_thrust_coeff
Vertical guidance for rotorcrafts.
struct EnuCoor_i navigation_carrot
struct EnuCoor_i navigation_target
int32_t nav_heading
with INT32_ANGLE_FRAC
Rotorcraft navigation functions.
#define HORIZONTAL_MODE_ATTITUDE
#define HORIZONTAL_MODE_MANUAL
#define HORIZONTAL_MODE_GUIDED
General attitude stabilization interface for rotorcrafts.
void stabilization_attitude_enter(void)
void stabilization_attitude_set_rpy_setpoint_i(struct Int32Eulers *rpy)
void stabilization_attitude_read_rc(bool in_flight, bool in_carefree, bool coordinated_turn)
void stabilization_attitude_set_earth_cmd_i(struct Int32Vect2 *cmd, int32_t heading)
void stabilization_attitude_run(bool in_flight)
void stabilization_filter_commands(void)
int32_t stabilization_cmd[COMMANDS_NB]
Stabilization commands.
General stabilization interface for rotorcrafts.
void stabilization_attitude_reset_care_free_heading(void)
reset the heading for care-free mode to current heading
int32_t transition_theta_offset
void stabilization_attitude_read_rc_setpoint_eulers_f(struct FloatEulers *sp, bool in_flight, bool in_carefree, bool coordinated_turn)
Read an attitude setpoint from the RC.
void stabilization_none_read_rc(void)
void stabilization_none_enter(void)
void stabilization_none_run(bool in_flight)
Dummy stabilization for rotorcrafts.
void stabilization_rate_read_rc(void)
void stabilization_rate_enter(void)
void stabilization_rate_read_rc_switched_sticks(void)
void stabilization_rate_run(bool in_flight)
Rate stabilization for rotorcrafts.
API to get/set the generic vehicle states.
static const struct usb_device_descriptor dev
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.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.