29 #include "generated/airframe.h"
35 #ifndef GUIDANCE_H_AGAIN
36 #define GUIDANCE_H_AGAIN 0
39 #ifndef GUIDANCE_H_VGAIN
40 #define GUIDANCE_H_VGAIN 0
44 #if (GUIDANCE_H_PGAIN < 0) || \
45 (GUIDANCE_H_DGAIN < 0) || \
46 (GUIDANCE_H_IGAIN < 0) || \
47 (GUIDANCE_H_AGAIN < 0) || \
48 (GUIDANCE_H_VGAIN < 0)
49 #error "ALL PID_H control gains have to be positive!!!"
52 #ifndef GUIDANCE_H_THRUST_CMD_FILTER
53 #define GUIDANCE_H_THRUST_CMD_FILTER 10
56 #ifndef GUIDANCE_H_APPROX_FORCE_BY_THRUST
57 #define GUIDANCE_H_APPROX_FORCE_BY_THRUST FALSE
61 #define MAX_POS_ERR POS_BFP_OF_REAL(16.)
62 #define MAX_SPEED_ERR SPEED_BFP_OF_REAL(16.)
67 #if (GUIDANCE_V_HOVER_KP < 0) || \
68 (GUIDANCE_V_HOVER_KD < 0) || \
69 (GUIDANCE_V_HOVER_KI < 0)
70 #error "ALL PID_V control gains must be positive!!!"
77 #ifdef GUIDANCE_V_NOMINAL_HOVER_THROTTLE
78 # ifndef GUIDANCE_V_ADAPT_THROTTLE_ENABLED
79 # define GUIDANCE_V_ADAPT_THROTTLE_ENABLED FALSE
82 # ifndef GUIDANCE_V_ADAPT_THROTTLE_ENABLED
83 # define GUIDANCE_V_ADAPT_THROTTLE_ENABLED TRUE
88 #ifndef GUIDANCE_V_MIN_ERR_Z
89 #define GUIDANCE_V_MIN_ERR_Z POS_BFP_OF_REAL(-10.)
92 #ifndef GUIDANCE_V_MAX_ERR_Z
93 #define GUIDANCE_V_MAX_ERR_Z POS_BFP_OF_REAL(10.)
96 #ifndef GUIDANCE_V_MIN_ERR_ZD
97 #define GUIDANCE_V_MIN_ERR_ZD SPEED_BFP_OF_REAL(-10.)
100 #ifndef GUIDANCE_V_MAX_ERR_ZD
101 #define GUIDANCE_V_MAX_ERR_ZD SPEED_BFP_OF_REAL(10.)
104 #ifndef GUIDANCE_V_MAX_SUM_ERR
105 #define GUIDANCE_V_MAX_SUM_ERR 2000000
108 #ifndef GUIDANCE_V_MAX_CMD
109 #define GUIDANCE_V_MAX_CMD 0.9*MAX_PPRZ
116 #ifndef GUIDANCE_PID_USE_AS_DEFAULT
117 #define GUIDANCE_PID_USE_AS_DEFAULT TRUE
139 #if PERIODIC_TELEMETRY
147 pprz_msg_send_HOVER_LOOP(trans,
dev, AC_ID,
150 &(pos->
x), &(pos->
y),
151 &(speed->
x), &(speed->
y),
152 &(accel->
x), &(accel->
y),
166 pprz_msg_send_VERT_LOOP(trans,
dev, AC_ID,
205 #if PERIODIC_TELEMETRY
213 #define GH_GAIN_SCALE 2
262 static int32_t thrust_cmd_filt;
319 #define FF_CMD_FRAC 18
422 #if GUIDANCE_PID_USE_AS_DEFAULT
#define VECT2_DIFF(_c, _a, _b)
#define VECT2_STRIM(_v, _min, _max)
#define ANGLE_BFP_OF_REAL(_af)
#define BFP_OF_REAL(_vr, _frac)
#define INT_VECT2_ZERO(_v)
vector in North East Down coordinates
static struct NedCoor_i * stateGetAccelNed_i(void)
Get acceleration in NED coordinates (int).
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (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_v_run_enter(void)
struct ThrustSetpoint guidance_v_run_pos(bool in_flight UNUSED, struct VerticalGuidance *gv)
struct ThrustSetpoint guidance_v_run_speed(bool in_flight UNUSED, struct VerticalGuidance *gv)
struct ThrustSetpoint guidance_v_run_accel(bool in_flight UNUSED, struct VerticalGuidance *gv)
void guidance_pid_set_h_igain(uint32_t igain)
settings handler
#define GUIDANCE_V_MAX_SUM_ERR
struct ThrustSetpoint guidance_pid_v_run_accel(bool in_flight UNUSED, struct VerticalGuidance *gv UNUSED)
void guidance_pid_init(void)
int32_t guidance_pid_v_ff_cmd
feed-forward command
struct StabilizationSetpoint guidance_pid_h_run_accel(bool in_flight UNUSED, struct HorizontalGuidance *gh UNUSED)
struct Int32Vect2 guidance_pid_trim_att_integrator
struct StabilizationSetpoint guidance_pid_h_run_pos(bool in_flight, struct HorizontalGuidance *gh)
static void send_hover_loop(struct transport_tx *trans, struct link_device *dev)
struct StabilizationSetpoint guidance_pid_h_run_speed(bool in_flight, struct HorizontalGuidance *gh)
int32_t guidance_pid_v_fb_cmd
feed-back command
struct ThrustSetpoint guidance_pid_v_run_pos(bool in_flight, struct VerticalGuidance *gv)
#define GUIDANCE_V_MIN_ERR_Z
static struct ThrustSetpoint guidance_pid_v_run(bool in_flight, struct VerticalGuidance *gv)
void guidance_pid_set_v_igain(uint32_t igain)
#define GUIDANCE_V_MAX_CMD
#define GUIDANCE_V_ADAPT_THROTTLE_ENABLED
#define FF_CMD_FRAC
run vertical control loop for position and speed control
struct ThrustSetpoint guidance_pid_v_run_speed(bool in_flight, struct VerticalGuidance *gv)
static void send_vert_loop(struct transport_tx *trans, struct link_device *dev)
static struct StabilizationSetpoint guidance_pid_h_run(bool in_flight, struct HorizontalGuidance *gh)
run horizontal control loop for position and speed control
struct GuidancePID guidance_pid
Guidance PID structyre.
#define GUIDANCE_H_THRUST_CMD_FILTER
#define GUIDANCE_V_MIN_ERR_ZD
#define GUIDANCE_V_MAX_ERR_ZD
int32_t guidance_pid_z_sum_err
accumulator for I-gain
struct Int32Vect2 guidance_pid_pos_err
#define GUIDANCE_H_APPROX_FORCE_BY_THRUST
const struct Int32Vect2 * guidance_pid_get_h_pos_err(void)
Gets the position error.
void guidance_pid_v_enter(void)
#define GUIDANCE_V_MAX_ERR_Z
struct Int32Vect2 guidance_pid_speed_err
void guidance_pid_h_enter(void)
Guidance controller with PID for rotorcrafts.
bool approx_force_by_thrust
bool adapt_throttle_enabled
struct Int32Vect2 cmd_earth
int32_t gv_adapt_P
Covariance.
int32_t gv_adapt_X
State of the estimator.
int32_t gv_adapt_Xmeas
Measurement.
Adaptation block of the vertical guidance.
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
struct HorizontalGuidance guidance_h
void guidance_h_run_enter(void)
struct StabilizationSetpoint guidance_h_run_pos(bool in_flight, struct HorizontalGuidance *gh)
struct StabilizationSetpoint guidance_h_run_speed(bool in_flight, struct HorizontalGuidance *gh)
struct StabilizationSetpoint guidance_h_run_accel(bool in_flight, struct HorizontalGuidance *gh)
#define GUIDANCE_H_MAX_BANK
Max bank controlled by guidance.
struct HorizontalGuidanceSetpoint sp
setpoints
struct VerticalGuidance guidance_v
int32_t z_sp
altitude setpoint in meters (input).
int32_t zd_sp
vertical speed setpoint in meter/s (input).
int32_t z_ref
altitude reference in meters.
int32_t zd_ref
vertical speed reference in meter/s.
int32_t zdd_ref
vertical acceleration reference in meter/s^2.
struct RotorcraftNavigation nav
float heading
heading setpoint (in radians)
struct Stabilization stabilization
struct StabilizationSetpoint stab_sp_from_ltp_i(struct Int32Vect2 *vect, int32_t heading)
struct ThrustSetpoint th_sp_from_thrust_i(int32_t thrust, uint8_t axis)
General stabilization interface for rotorcrafts.
#define THRUST_SP_SET_ZERO(_sp)
int32_t cmd[COMMANDS_NB]
output command vector, range from [-MAX_PPRZ:MAX_PPRZ] (store for messages)
API to get/set the generic vehicle states.
static const struct usb_device_descriptor dev
struct Int32Vect2 pos
horizontal position setpoint in NED.
union StabilizationSetpoint::@278 sp
Thrust setpoint // TODO to a setpoint header Structure to store the desired thrust vector with differ...
union ThrustSetpoint::@284 sp
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.