27 #include "generated/airframe.h"
41 #if (GUIDANCE_V_HOVER_KP < 0) || \
42 (GUIDANCE_V_HOVER_KD < 0) || \
43 (GUIDANCE_V_HOVER_KI < 0)
44 #error "ALL control gains must be positive!!!"
52 #ifdef GUIDANCE_V_NOMINAL_HOVER_THROTTLE
53 # ifndef GUIDANCE_V_ADAPT_THROTTLE_ENABLED
54 # define GUIDANCE_V_ADAPT_THROTTLE_ENABLED FALSE
57 # define GUIDANCE_V_NOMINAL_HOVER_THROTTLE 0.4
58 # ifndef GUIDANCE_V_ADAPT_THROTTLE_ENABLED
59 # define GUIDANCE_V_ADAPT_THROTTLE_ENABLED TRUE
66 #ifndef GUIDANCE_V_CLIMB_RC_DEADBAND
67 #define GUIDANCE_V_CLIMB_RC_DEADBAND MAX_PPRZ/10
70 #ifndef GUIDANCE_V_MAX_RC_CLIMB_SPEED
71 #define GUIDANCE_V_MAX_RC_CLIMB_SPEED GUIDANCE_V_REF_MIN_ZD
74 #ifndef GUIDANCE_V_MAX_RC_DESCENT_SPEED
75 #define GUIDANCE_V_MAX_RC_DESCENT_SPEED GUIDANCE_V_REF_MAX_ZD
78 #ifndef GUIDANCE_V_MIN_ERR_Z
79 #define GUIDANCE_V_MIN_ERR_Z POS_BFP_OF_REAL(-10.)
82 #ifndef GUIDANCE_V_MAX_ERR_Z
83 #define GUIDANCE_V_MAX_ERR_Z POS_BFP_OF_REAL(10.)
86 #ifndef GUIDANCE_V_MIN_ERR_ZD
87 #define GUIDANCE_V_MIN_ERR_ZD SPEED_BFP_OF_REAL(-10.)
90 #ifndef GUIDANCE_V_MAX_ERR_ZD
91 #define GUIDANCE_V_MAX_ERR_ZD SPEED_BFP_OF_REAL(10.)
94 #ifndef GUIDANCE_V_MAX_SUM_ERR
95 #define GUIDANCE_V_MAX_SUM_ERR 2000000
133 #define GuidanceVSetRef(_pos, _speed, _accel) { \
134 gv_set_ref(_pos, _speed, _accel); \
135 guidance_v_z_ref = _pos; \
136 guidance_v_zd_ref = _speed; \
137 guidance_v_zdd_ref = _accel; \
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;
190 #if GUIDANCE_V_MODE_MODULE_SETTING == GUIDANCE_V_MODE_MODULE
194 #if PERIODIC_TELEMETRY
216 if (guidance_v_rc_zd_sp > 0) {
217 guidance_v_rc_zd_sp *= descent_scale;
219 guidance_v_rc_zd_sp *= climb_scale;
226 if (new_mode == guidance_v_mode) {
234 guidance_v_z_sum_err = 0;
240 guidance_v_zd_sp = 0;
242 guidance_v_z_sum_err = 0;
246 #if GUIDANCE_V_MODE_MODULE_SETTING == GUIDANCE_V_MODE_MODULE
260 guidance_v_mode = new_mode;
286 switch (guidance_v_mode) {
303 #if !NO_RC_THRUST_LIMIT
314 guidance_v_zd_sp = 0;
317 #if !NO_RC_THRUST_LIMIT
326 #if GUIDANCE_V_MODE_MODULE_SETTING == GUIDANCE_V_MODE_MODULE
335 guidance_v_zd_sp = 0;
347 guidance_v_z_sum_err = 0;
350 #if !NO_RC_THRUST_LIMIT
390 if (coef < max_bank_coef) {
391 coef = max_bank_coef;
397 #define FF_CMD_FRAC 18
404 guidance_v_z_ref = (
int32_t)tmp;
414 guidance_v_z_sum_err += err_z;
417 guidance_v_z_sum_err = 0;
422 if (guidance_v_adapt_throttle_enabled) {
432 guidance_v_ff_cmd = g_m_zdd / inv_m;
434 guidance_v_ff_cmd = (guidance_v_ff_cmd <<
INT32_TRIG_FRAC) / guidance_v_thrust_coeff;
437 Bound(guidance_v_ff_cmd, 0, 8640);
442 guidance_v_fb_cmd = ((-guidance_v_kp * err_z) >> 7) +
443 ((-guidance_v_kd * err_zd) >> 16) +
449 Bound(guidance_v_delta_t, 0,
MAX_PPRZ);
int32_t guidance_v_z_sp
altitude setpoint in meters (input).
#define VERTICAL_MODE_ALT
#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
#define GUIDANCE_V_NOMINAL_HOVER_THROTTLE
#define GV_Z_REF_FRAC
number of bits for the fractional part of gv_z_ref
Generic transmission transport header.
Rotorcraft navigation functions.
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).
int32_t guidance_v_delta_t
thrust command.
void guidance_v_run(bool_t in_flight)
int32_t guidance_v_kp
vertical control P-gain
#define VERTICAL_MODE_CLIMB
void guidance_v_init(void)
#define POS_BFP_OF_REAL(_af)
void guidance_v_notify_in_flight(bool_t in_flight)
#define GUIDANCE_V_MIN_ERR_Z
void guidance_v_mode_changed(uint8_t new_mode)
float guidance_v_nominal_throttle
nominal throttle for hover.
Vertical guidance for rotorcrafts.
static void run_hover_loop(bool_t in_flight)
#define GV_ZDD_REF_FRAC
number of bits for the fractional part of gv_zdd_ref
bool_t guidance_v_adapt_throttle_enabled
Use adaptive throttle command estimation.
bool_t guidance_v_set_guided_z(float z)
Set z setpoint in GUIDED mode.
int32_t guidance_v_z_sum_err
accumulator for I-gain
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
#define GUIDANCE_V_MODE_KILL
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
void guidance_v_module_init(void)
#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 ...
void guidance_v_module_run(UNUSED bool_t in_flight)
#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 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.
#define GuidanceVSetRef(_pos, _speed, _accel)
static const struct usb_device_descriptor dev
#define GUIDANCE_V_CLIMB_RC_DEADBAND
uint32_t nav_throttle
direct throttle from 0:MAX_PPRZ, used in VERTICAL_MODE_MANUAL
#define GUIDANCE_V_ADAPT_THROTTLE_ENABLED
#define VERTICAL_MODE_MANUAL
void guidance_v_module_enter(void)
API to get/set the generic vehicle states.
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)
int32_t stabilization_cmd[COMMANDS_NB]
Stabilization commands.
#define GUIDANCE_V_MAX_ERR_ZD
#define GUIDANCE_V_MODE_FLIP
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.
#define SPEED_BFP_OF_REAL(_af)
int32_t guidance_v_ff_cmd
feed-forward command
int32_t nav_flight_altitude
#define GUIDANCE_V_MODE_RC_CLIMB
static struct NedCoor_i * stateGetPositionNed_i(void)
Get position in local NED coordinates (int).
#define GUIDANCE_V_MODE_RC_DIRECT
int32_t gv_adapt_X
State of the estimator.
#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.
static struct NedCoor_i * stateGetAccelNed_i(void)
Get acceleration in NED coordinates (int).
Paparazzi fixed point algebra.