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
105 #if PERIODIC_TELEMETRY
108 static void send_gh(
struct transport_tx *trans,
struct link_device *
dev)
111 pprz_msg_send_GUIDANCE_H_INT(trans, dev, AC_ID,
114 &(pos->
x), &(pos->
y));
122 pprz_msg_send_HOVER_LOOP(trans, dev, AC_ID,
125 &(pos->
x), &(pos->
y),
126 &(speed->
x), &(speed->
y),
127 &(accel->
x), &(accel->
y),
139 static void send_href(
struct transport_tx *trans,
struct link_device *
dev)
141 pprz_msg_send_GUIDANCE_H_REF_INT(trans, dev, AC_ID,
152 pprz_msg_send_ROTORCRAFT_TUNE_HOVER(trans, dev, AC_ID,
184 transition_percentage = 0;
185 transition_theta_offset = 0;
189 #if GUIDANCE_H_MODE_MODULE_SETTING == GUIDANCE_H_MODE_MODULE
193 #if PERIODIC_TELEMETRY
219 #if HYBRID_NAVIGATION
228 #if USE_STABILIZATION_RATE
238 #if NO_ATTITUDE_RESET_ON_MODE_CHANGE
253 #if NO_ATTITUDE_RESET_ON_MODE_CHANGE
262 #if GUIDANCE_H_MODE_MODULE_SETTING == GUIDANCE_H_MODE_MODULE
270 #if NO_ATTITUDE_RESET_ON_MODE_CHANGE
301 #if USE_STABILIZATION_RATE
303 #if SWITCH_STICKS_FOR_RATE_CONTROL
322 #if GUIDANCE_H_USE_SPEED_REF
329 #if GUIDANCE_H_MODE_MODULE_SETTING == GUIDANCE_H_MODE_MODULE
359 #if USE_STABILIZATION_RATE
390 #if GUIDANCE_H_MODE_MODULE_SETTING == GUIDANCE_H_MODE_MODULE
409 #if GUIDANCE_H_USE_REF
429 #if GUIDANCE_H_USE_SPEED_REF
442 #define MAX_POS_ERR POS_BFP_OF_REAL(16.)
443 #define MAX_SPEED_ERR SPEED_BFP_OF_REAL(16.)
445 #ifndef GUIDANCE_H_THRUST_CMD_FILTER
446 #define GUIDANCE_H_THRUST_CMD_FILTER 10
451 #define GH_GAIN_SCALE 2
510 static int32_t thrust_cmd_filt;
579 #if HYBRID_NAVIGATION
585 #if HYBRID_NAVIGATION
623 #ifdef TRANSITION_MAX_OFFSET
714 float newvx = cosf(-psi) * vx + sinf(-psi) * vy;
715 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
#define FLOAT_ANGLE_NORMALIZE(_a)
int32_t transition_percentage
void guidance_indi_enter(void)
Call upon entering indi guidance.
void gh_set_ref(struct Int32Vect2 pos, struct Int32Vect2 speed, struct Int32Vect2 accel)
void guidance_h_init(void)
#define GUIDANCE_H_MODE_GUIDED
void gh_update_ref_from_speed_sp(struct Int32Vect2 speed_sp)
void guidance_h_read_rc(bool in_flight)
#define GUIDANCE_H_MAX_BANK
void stabilization_none_run(bool in_flight)
bool guidance_h_set_guided_heading_rate(float rate)
Set heading rate setpoint in GUIDED mode.
#define GUIDANCE_H_MODE_CARE_FREE
struct Int32Vect2 pos
horizontal position setpoint in NED.
struct Int32Vect2 guidance_h_cmd_earth
horizontal guidance command.
Rotorcraft navigation functions.
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
const struct Int32Vect2 * guidance_h_get_pos_err(void)
Gets the position error.
#define INT32_PERCENTAGE_FRAC
Dummy stabilization for rotorcrafts.
Periodic telemetry system header (includes downlink utility and generated code).
General attitude stabilization interface for rotorcrafts.
void guidance_h_run(bool in_flight)
struct GuidanceHRef gh_ref
void stabilization_rate_enter(void)
int32_t theta
in rad with INT32_ANGLE_FRAC
#define FLOAT_EULERS_ZERO(_e)
#define VECT2_STRIM(_v, _min, _max)
#define POS_BFP_OF_REAL(_af)
#define GUIDANCE_H_APPROX_FORCE_BY_THRUST
Open Loop guidance for making a flip.
static void reset_guidance_reference_from_current_position(void)
Read an attitude setpoint from the RC.
bool approx_force_by_thrust
#define GUIDANCE_H_MODE_HOVER
#define VECT2_COPY(_a, _b)
bool guidance_h_set_guided_pos(float x, float y)
Set horizontal position setpoint in GUIDED mode.
Vertical guidance for rotorcrafts.
#define VECT2_DIFF(_c, _a, _b)
bool guidance_h_set_guided_body_vel(float vx, float vy)
Set body relative horizontal velocity setpoint in GUIDED mode.
void stabilization_attitude_run(bool in_flight)
struct Int32Vect2 guidance_h_trim_att_integrator
void stabilization_attitude_enter(void)
#define GUIDANCE_H_MODE_ATTITUDE
void stabilization_attitude_reset_care_free_heading(void)
reset the heading for care-free mode to current heading
struct HorizontalGuidanceReference ref
reference calculated from setpoints
struct EnuCoor_i navigation_target
void guidance_h_set_igain(uint32_t igain)
Guidance controllers (horizontal and vertical) for Hybrid UAV configurations.
void guidance_hybrid_run(void)
Runs the Hybrid Guidance main functions.
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
struct HorizontalGuidanceGains gains
#define GUIDANCE_H_REF_MAX_SPEED
Default speed saturation.
struct EnuCoor_i navigation_carrot
struct Int64Vect2 pos
Reference model position.
#define ANGLE_FLOAT_OF_BFP(_ai)
void guidance_h_hover_enter(void)
static void send_hover_loop(struct transport_tx *trans, struct link_device *dev)
#define GUIDANCE_H_MODE_FLIP
Rate stabilization for rotorcrafts.
#define BFP_OF_REAL(_vr, _frac)
void stabilization_none_enter(void)
#define PPRZ_ITRIG_SIN(_s, _a)
void guidance_h_module_enter(void)
uint8_t mask
bit 5: vx & vy, bit 6: vz, bit 7: vyaw
static struct NedCoor_i * stateGetSpeedNed_i(void)
Get ground speed in local NED coordinates (int).
#define GUIDANCE_H_THRUST_CMD_FILTER
static void guidance_h_update_reference(void)
struct Int32Vect2 speed
with INT32_SPEED_FRAC
int32_t transition_theta_offset
struct Int32Vect2 guidance_h_pos_err
void guidance_indi_run(bool in_flight, float heading_sp)
void stabilization_rate_read_rc(void)
struct Int32Vect2 speed
only used in HOVER mode if GUIDANCE_H_USE_SPEED_REF or in GUIDED mode
void guidance_h_module_read_rc(void)
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)
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 transition_run(bool to_forward)
void stabilization_none_read_rc(void)
struct RadioControl radio_control
struct HorizontalGuidance guidance_h
#define GH_SPEED_REF_FRAC
void guidance_h_mode_changed(uint8_t new_mode)
int32_t guidance_hybrid_norm_ref_airspeed
#define GUIDANCE_H_MODE_FORWARD
static void read_rc_setpoint_speed_i(struct Int32Vect2 *speed_sp, bool in_flight)
read speed setpoint from RC
void guidance_h_nav_enter(void)
void guidance_h_module_init(void)
static void send_tune_hover(struct transport_tx *trans, struct link_device *dev)
#define ANGLE_BFP_OF_REAL(_af)
static const struct usb_device_descriptor dev
#define GH_ACCEL_REF_FRAC
struct Int32Vect2 pos
with INT32_POS_FRAC
void guidance_h_from_nav(bool in_flight)
Set horizontal guidance from NAV and run control loop.
bool guidance_h_set_guided_vel(float vx, float vy)
Set horizontal velocity setpoint in GUIDED mode.
static void guidance_h_traj_run(bool in_flight)
int32_t phi
in rad with INT32_ANGLE_FRAC
API to get/set the generic vehicle states.
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
#define GUIDANCE_H_USE_REF
Use horizontal guidance reference trajectory.
#define GUIDANCE_H_MODE_NAV
General stabilization interface for rotorcrafts.
void guidance_flip_run(void)
int32_t stabilization_cmd[COMMANDS_NB]
Stabilization commands.
#define HORIZONTAL_MODE_MANUAL
void stabilization_rate_run(bool in_flight)
#define HORIZONTAL_MODE_ATTITUDE
struct Int32Vect2 guidance_h_speed_err
#define INT_VECT2_ZERO(_v)
void stabilization_attitude_read_rc_setpoint_eulers_f(struct FloatEulers *sp, bool in_flight, bool in_carefree, bool coordinated_turn)
struct Int32Vect2 accel
with INT32_ACCEL_FRAC
Guidance in a module file.
struct Int32Vect2 accel
Reference model acceleration.
void guidance_h_module_run(bool in_flight)
#define SPEED_BFP_OF_REAL(_af)
bool guidance_h_set_guided_heading(float heading)
Set heading setpoint in GUIDED mode.
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).
Horizontal guidance for rotorcrafts.
#define INT32_VECT2_RSHIFT(_o, _i, _r)
#define INT32_VECT2_LSHIFT(_o, _i, _l)
static struct Int32Eulers * stateGetNedToBodyEulers_i(void)
Get vehicle body attitude euler angles (int).
int32_t nav_heading
with INT32_ANGLE_FRAC
#define GUIDANCE_H_MODE_RATE
void guidance_h_guided_run(bool in_flight)
Run GUIDED mode control.
#define GUIDANCE_H_USE_SPEED_REF
Use horizontal guidance speed reference.
static void send_gh(struct transport_tx *trans, struct link_device *dev)
struct HorizontalGuidanceSetpoint sp
setpoints
A guidance mode based on Incremental Nonlinear Dynamic Inversion Come to ICRA2016 to learn more! ...
static void send_href(struct transport_tx *trans, struct link_device *dev)
#define GUIDANCE_H_MODE_KILL
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
static struct NedCoor_i * stateGetAccelNed_i(void)
Get acceleration in NED coordinates (int).
#define PPRZ_ITRIG_COS(_c, _a)
#define GUIDANCE_H_MODE_MODULE
#define GUIDANCE_H_MODE_RC_DIRECT