27 #include "generated/airframe.h"
42 #if (GUIDANCE_V_HOVER_KP < 0) || \
43 (GUIDANCE_V_HOVER_KD < 0) || \
44 (GUIDANCE_V_HOVER_KI < 0)
45 #error "ALL control gains must be positive!!!"
53 #ifdef GUIDANCE_V_NOMINAL_HOVER_THROTTLE
54 # ifndef GUIDANCE_V_ADAPT_THROTTLE_ENABLED
55 # define GUIDANCE_V_ADAPT_THROTTLE_ENABLED FALSE
58 # define GUIDANCE_V_NOMINAL_HOVER_THROTTLE 0.4
59 # ifndef GUIDANCE_V_ADAPT_THROTTLE_ENABLED
60 # define GUIDANCE_V_ADAPT_THROTTLE_ENABLED TRUE
67 #ifndef GUIDANCE_V_CLIMB_RC_DEADBAND
68 #define GUIDANCE_V_CLIMB_RC_DEADBAND MAX_PPRZ/10
71 #ifndef GUIDANCE_V_MAX_RC_CLIMB_SPEED
72 #define GUIDANCE_V_MAX_RC_CLIMB_SPEED GUIDANCE_V_REF_MIN_ZD
75 #ifndef GUIDANCE_V_MAX_RC_DESCENT_SPEED
76 #define GUIDANCE_V_MAX_RC_DESCENT_SPEED GUIDANCE_V_REF_MAX_ZD
79 #ifndef GUIDANCE_V_MIN_ERR_Z
80 #define GUIDANCE_V_MIN_ERR_Z POS_BFP_OF_REAL(-10.)
83 #ifndef GUIDANCE_V_MAX_ERR_Z
84 #define GUIDANCE_V_MAX_ERR_Z POS_BFP_OF_REAL(10.)
87 #ifndef GUIDANCE_V_MIN_ERR_ZD
88 #define GUIDANCE_V_MIN_ERR_ZD SPEED_BFP_OF_REAL(-10.)
91 #ifndef GUIDANCE_V_MAX_ERR_ZD
92 #define GUIDANCE_V_MAX_ERR_ZD SPEED_BFP_OF_REAL(10.)
95 #ifndef GUIDANCE_V_MAX_SUM_ERR
96 #define GUIDANCE_V_MAX_SUM_ERR 2000000
108 #define GUIDANCE_V_GUIDED_MODE_ZHOLD 0
109 #define GUIDANCE_V_GUIDED_MODE_CLIMB 1
110 #define GUIDANCE_V_GUIDED_MODE_THROTTLE 2
143 #if PERIODIC_TELEMETRY
148 pprz_msg_send_VERT_LOOP(trans, dev, AC_ID,
149 &guidance_v_z_sp, &guidance_v_zd_sp,
153 &guidance_v_z_ref, &guidance_v_zd_ref,
158 &guidance_v_z_sum_err,
161 &guidance_v_delta_t);
166 pprz_msg_send_TUNE_VERT(trans, dev, AC_ID,
179 guidance_v_kp = GUIDANCE_V_HOVER_KP;
180 guidance_v_kd = GUIDANCE_V_HOVER_KD;
181 guidance_v_ki = GUIDANCE_V_HOVER_KI;
183 guidance_v_z_sum_err = 0;
187 desired_zd_updated =
false;
194 #if GUIDANCE_V_MODE_MODULE_SETTING == GUIDANCE_V_MODE_MODULE
198 #if PERIODIC_TELEMETRY
220 if (guidance_v_rc_zd_sp > 0) {
221 guidance_v_rc_zd_sp *= descent_scale;
223 guidance_v_rc_zd_sp *= climb_scale;
230 if (new_mode == guidance_v_mode) {
242 guidance_v_zd_sp = 0;
245 guidance_v_z_sum_err = 0;
249 #if GUIDANCE_V_MODE_MODULE_SETTING == GUIDANCE_V_MODE_MODULE
263 guidance_v_mode = new_mode;
285 if (desired_zd_updated) {
300 desired_zd_updated =
false;
302 switch (guidance_v_mode) {
319 #if !NO_RC_THRUST_LIMIT
335 #if GUIDANCE_V_MODE_MODULE_SETTING == GUIDANCE_V_MODE_MODULE
361 guidance_v_z_sum_err = 0;
365 guidance_v_zd_sp = 0;
371 guidance_v_z_ref = pos;
372 guidance_v_zd_ref = speed;
373 guidance_v_zdd_ref = accel;
399 if (coef < max_bank_coef) {
400 coef = max_bank_coef;
406 #define FF_CMD_FRAC 18
413 guidance_v_z_ref = (
int32_t)tmp;
417 desired_zd_updated =
true;
425 guidance_v_z_sum_err += err_z;
428 guidance_v_z_sum_err = 0;
433 if (guidance_v_adapt_throttle_enabled) {
443 guidance_v_ff_cmd = g_m_zdd / inv_m;
445 guidance_v_ff_cmd = (guidance_v_ff_cmd <<
INT32_TRIG_FRAC) / guidance_v_thrust_coeff;
447 #if HYBRID_NAVIGATION
449 guidance_v_ff_cmd = guidance_v_nominal_throttle *
MAX_PPRZ;
453 Bound(guidance_v_ff_cmd, 0, 8640);
458 guidance_v_fb_cmd = ((-guidance_v_kp * err_z) >> 7) +
459 ((-guidance_v_kd * err_zd) >> 16) +
465 Bound(guidance_v_delta_t, 0, MAX_PPRZ);
473 guidance_v_zd_sp = 0;
485 guidance_v_z_sum_err = 0;
488 #if HYBRID_NAVIGATION
491 #if !NO_RC_THRUST_LIMIT
508 guidance_v_zd_sp = 0;
511 guidance_v_z_sum_err = 0;
517 switch(guidance_v_guided_mode)
521 guidance_v_zd_sp = 0;
538 #if !NO_RC_THRUST_LIMIT
557 guidance_v_zd_sp = 0;
560 guidance_v_z_sum_err = 0;
592 Bound(guidance_v_th_sp, 0,
MAX_PPRZ);
bool guidance_v_set_guided_z(float z)
Set z setpoint in GUIDED mode.
int32_t guidance_v_z_sp
altitude setpoint in meters (input).
bool guidance_v_set_guided_th(float th)
void guidance_v_guided_run(bool in_flight)
Run GUIDED mode control.
void guidance_hybrid_vertical(void)
Description.
#define GV_ZD_REF_FRAC
number of bits for the fractional part of gv_zd_ref
int32_t guidance_v_kd
vertical control D-gain
#define GUIDANCE_V_MODE_NAV
static void send_vert_loop(struct transport_tx *trans, struct link_device *dev)
bool guidance_v_set_guided_vz(float vz)
Set z velocity setpoint in GUIDED mode.
#define GUIDANCE_V_NOMINAL_HOVER_THROTTLE
#define GV_Z_REF_FRAC
number of bits for the fractional part of gv_z_ref
int32_t guidance_v_fb_cmd
feed-back command
Periodic telemetry system header (includes downlink utility and generated code).
static struct Int32RMat * stateGetNedToBodyRMat_i(void)
Get vehicle body attitude rotation matrix (int).
void guidance_v_set_ref(int32_t pos, int32_t speed, int32_t accel)
Set guidance ref parameters.
int32_t guidance_v_delta_t
thrust command.
#define GUIDANCE_V_GUIDED_MODE_ZHOLD
int32_t guidance_v_kp
vertical control P-gain
void guidance_v_init(void)
#define POS_BFP_OF_REAL(_af)
bool guidance_v_adapt_throttle_enabled
Use adaptive throttle command estimation.
#define GUIDANCE_V_MIN_ERR_Z
int32_t nav_flight_altitude
void guidance_v_mode_changed(uint8_t new_mode)
float guidance_v_nominal_throttle
nominal throttle for hover.
Vertical guidance for rotorcrafts.
void guidance_v_z_enter(void)
#define GV_ZDD_REF_FRAC
number of bits for the fractional part of gv_zdd_ref
void guidance_v_run(bool in_flight)
int32_t guidance_v_z_sum_err
accumulator for I-gain
void guidance_v_notify_in_flight(bool in_flight)
Guidance controllers (horizontal and vertical) for Hybrid UAV configurations.
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
#define GUIDANCE_V_MODE_KILL
void run_hover_loop(bool in_flight)
int32_t guidance_v_rc_zd_sp
Vertical speed setpoint from radio control.
#define BFP_OF_REAL(_vr, _frac)
void gv_update_ref_from_z_sp(int32_t z_sp)
static struct NedCoor_i * stateGetSpeedNed_i(void)
Get ground speed in local NED coordinates (int).
int32_t guidance_v_ki
vertical control I-gain
#define GUIDANCE_V_MODE_MODULE
#define GUIDANCE_V_MAX_RC_DESCENT_SPEED
#define GUIDANCE_V_MODE_CLIMB
int32_t gv_zd_ref
reference model vertical speed in meters/sec (output) fixed point representation with GV_ZD_REF_FRAC ...
#define DefaultPeriodic
Set default periodic telemetry.
int32_t guidance_v_zdd_ref
vertical acceleration reference in meter/s^2.
#define GUIDANCE_V_MAX_ERR_Z
#define GUIDANCE_V_MODE_HOVER
struct RadioControl radio_control
void gv_adapt_run(int32_t zdd_meas, int32_t thrust_applied, int32_t zd_ref)
Adaptation function.
#define GUIDANCE_V_MAX_RC_CLIMB_SPEED
int32_t guidance_v_z_ref
altitude reference in meters.
void guidance_v_module_run(UNUSED bool in_flight)
void gv_update_ref_from_zd_sp(int32_t zd_sp, int32_t z_pos)
update vertical reference from speed setpoint.
int32_t guidance_v_zd_ref
vertical speed reference in meter/s.
int32_t gv_adapt_P
Covariance.
void guidance_v_guided_enter(void)
Enter GUIDED mode control.
static const struct usb_device_descriptor dev
void gv_set_ref(int32_t alt, int32_t speed, int32_t accel)
#define GUIDANCE_V_CLIMB_RC_DEADBAND
#define GUIDANCE_V_GUIDED_MODE_CLIMB
Rotorcraft navigation functions.
#define GUIDANCE_V_ADAPT_THROTTLE_ENABLED
API to get/set the generic vehicle states.
void guidance_v_module_init(void)
int32_t gv_adapt_Xmeas
Measurement.
int32_t guidance_v_thrust_coeff
#define GUIDANCE_V_MIN_ERR_ZD
int64_t gv_z_ref
reference model altitude in meters (output) fixed point representation with GV_Z_REF_FRAC Q37...
static int32_t get_vertical_thrust_coeff(void)
get the cosine of the angle between thrust vector and gravity vector
General stabilization interface for rotorcrafts.
void guidance_v_read_rc(void)
#define GUIDANCE_V_GUIDED_MODE_THROTTLE
void guidance_v_module_enter(void)
int32_t stabilization_cmd[COMMANDS_NB]
Stabilization commands.
#define GUIDANCE_V_MAX_ERR_ZD
#define VERTICAL_MODE_ALT
#define GUIDANCE_V_MODE_FLIP
static void send_tune_vert(struct transport_tx *trans, struct link_device *dev)
Guidance in a module file.
int32_t guidance_v_zd_sp
vertical speed setpoint in meter/s (input).
#define GUIDANCE_V_MAX_SUM_ERR
int32_t guidance_v_rc_delta_t
Direct throttle from radio control.
uint32_t nav_throttle
direct throttle from 0:MAX_PPRZ, used in VERTICAL_MODE_MANUAL
static bool desired_zd_updated
#define SPEED_BFP_OF_REAL(_af)
int32_t guidance_v_ff_cmd
feed-forward command
#define GUIDANCE_V_MODE_RC_CLIMB
static struct NedCoor_i * stateGetPositionNed_i(void)
Get position in local NED coordinates (int).
#define VERTICAL_MODE_CLIMB
void guidance_v_thrust_adapt(bool in_flight)
#define GUIDANCE_V_MODE_RC_DIRECT
int32_t gv_adapt_X
State of the estimator.
#define VERTICAL_MODE_MANUAL
#define GUIDANCE_V_MODE_GUIDED
int32_t gv_zdd_ref
reference model vertical accel in meters/s^2 (output) fixed point representation with GV_ZDD_REF_FRAC...
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
int guidance_v_guided_mode
static struct NedCoor_i * stateGetAccelNed_i(void)
Get acceleration in NED coordinates (int).
Paparazzi fixed point algebra.
void guidance_v_from_nav(bool in_flight)
Set guidance setpoint from NAV and run hover loop.