46 #include "generated/airframe.h"
64 #define OFL_AGL_ID ABI_BROADCAST
69 #ifndef OFL_OPTICAL_FLOW_ID
70 #define OFL_OPTICAL_FLOW_ID ABI_BROADCAST
76 #define OFL_PGAIN 0.40
80 #define OFL_IGAIN 0.01
87 #ifndef OFL_VISION_METHOD
88 #define OFL_VISION_METHOD 1
91 #ifndef OFL_CONTROL_METHOD
92 #define OFL_CONTROL_METHOD 0
95 #ifndef OFL_COV_METHOD
96 #define OFL_COV_METHOD 0
100 #ifndef OFL_COV_WINDOW_SIZE
101 #define OFL_COV_WINDOW_SIZE 30
104 #ifndef OFL_COV_LANDING_LIMIT
105 #define OFL_COV_LANDING_LIMIT 2.2
108 #ifndef OFL_COV_SETPOINT
109 #define OFL_COV_SETPOINT -0.0075
113 #define OFL_LP_CONST 0.02
116 #ifndef OFL_P_LAND_THRESHOLD
117 #define OFL_P_LAND_THRESHOLD 0.15
120 #ifndef OFL_ELC_OSCILLATE
121 #define OFL_ELC_OSCILLATE true
127 #define MINIMUM_GAIN 0.1
130 #define INCREASE_GAIN_PER_SECOND 0.02
162 pprz_msg_send_DIVERGENCE(trans, dev, AC_ID,
251 previous_cov_err = 0.;
252 divergence_vision = 0.;
253 divergence_vision_dt = 0.;
254 divergence_setpoint = 0;
260 cov_array_filled = 0;
263 thrust_history[i] = 0;
264 divergence_history[i] = 0;
301 Bound(lp_factor, 0.f, 1.f);
326 divergence_vision_dt = (divergence_vision / dt);
327 if (fabsf(divergence_vision_dt) > 1e-5f) {
338 float new_divergence = (divergence_vision * div_factor) / dt;
341 static const float max_div_dt = 0.20f;
396 static const float phase_0_set_point = 0.0f;
397 if (elc_phase == 0) {
403 float gain_factor = pstate /
pused;
404 istate *= gain_factor;
405 dstate *= gain_factor;
437 }
else if (elc_phase == 1) {
446 if (t_interval < 0) { t_interval = 0.0f; }
458 }
else if (elc_phase == 2) {
463 if (t_interval < 0) { t_interval = 0.0f; }
467 pstate = elc_p_gain_start * gain_scaling;
468 istate = elc_i_gain_start * gain_scaling;
469 dstate = elc_d_gain_start * gain_scaling;
506 uint32_t thrust = 0.85 * nominal_throttle;
507 Bound(thrust, 0.6 * nominal_throttle, 0.9 *
MAX_PPRZ);
523 normalized_thrust = (float)(thrust / (
MAX_PPRZ / 100));
528 past_divergence_history[
ind_hist] = divergence_history[ind_past];
586 Bound(lp_factor, 0.f, 1.f);
602 int16_t flow_der_x UNUSED,
int16_t flow_der_y UNUSED,
float quality UNUSED,
float size_divergence)
604 divergence_vision = size_divergence;
605 vision_time = ((float)stamp) / 1e6;
float previous_err
Previous divergence tracking error.
float d_err
difference of error for the D-gain
Event structure to store callbacks in a linked list.
void guidance_v_module_enter(void)
Entering the module (user switched to module)
This module implements optical flow landings in which the divergence is kept constant.
float igain
I-gain for constant divergence control.
float thrust_history[OFL_COV_WINDOW_SIZE]
Adaptation block of the vertical guidance.
static void set_cov_div(int32_t thrust)
Set the covariance of the divergence and the thrust / past divergence This funciton should only be ca...
#define OFL_OPTICAL_FLOW_ID
float lp_const
low-pass filter constant
#define INCREASE_GAIN_PER_SECOND
void guidance_v_module_run(bool in_flight)
struct OpticalFlowLanding of_landing_ctrl
Periodic telemetry system header (includes downlink utility and generated code).
float t_transition
how many seconds the drone has to be oscillating in order to transition to the hover phase with reduc...
float dgain
D-gain for constant divergence control.
float divergence
Divergence estimate.
Main include for ABI (AirBorneInterface).
float guidance_v_nominal_throttle
nominal throttle for hover.
bool elc_oscillate
Whether or not to oscillate at beginning of elc to find optimum gain.
#define OFL_COV_LANDING_LIMIT
float agl
agl = height from sonar (only used when using "fake" divergence)
float igain_adaptive
I-gain for adaptive gain control.
static uint32_t final_landing_procedure(void)
Execute a final landing procedure.
#define OFL_VISION_METHOD
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
static float get_sys_time_float(void)
Get the time in seconds since startup.
float divergence_setpoint
float p_land_threshold
if during the exponential landing the gain reaches this value, the final landing procedure is trigger...
static abi_event agl_ev
The altitude ABI event.
#define OFL_ELC_OSCILLATE
float pgain_adaptive
P-gain for adaptive gain control.
uint32_t VISION_METHOD
whether to use vision (1) or Optitrack / sonar (0)
float past_divergence_history[OFL_COV_WINDOW_SIZE]
float vel
vertical velocity as determined with sonar (only used when using "fake" divergence) ...
static int32_t PID_divergence_control(float divergence_setpoint, float P, float I, float D, float dt)
Determine and set the thrust for constant divergence control.
static void update_errors(float error, float dt)
Updates the integral and differential errors for PID control and sets the previous error...
void vertical_ctrl_module_init(void)
Initialize the optical flow landing module.
Architecture independent timing functions.
void vertical_ctrl_optical_flow_cb(uint8_t sender_id, uint32_t stamp, int16_t flow_x, int16_t flow_y, int16_t flow_der_x, int16_t flow_der_y, float quality, float size_divergence)
static void reset_all_vars(void)
Reset all variables:
float reduction_factor_elc
reduction factor - after oscillation, how much to reduce the gain...
float divergence_setpoint
setpoint for constant divergence approach
void vertical_ctrl_agl_cb(uint8_t sender_id, float distance)
Function definitions Callback function of the ground altitude.
#define DefaultPeriodic
Set default periodic telemetry.
#define OFL_COV_WINDOW_SIZE
#define OFL_CONTROL_METHOD
void vertical_ctrl_module_run(bool in_flight)
Run the optical flow landing module.
static const struct usb_device_descriptor dev
float covariance_f(float *arr1, float *arr2, uint32_t n_elements)
Compute the covariance of two arrays V(X) = E[(X-E[X])(Y-E[Y])] = E[XY] - E[X]E[Y] where E[X] is the ...
Core autopilot interface common to all firmwares.
static abi_event optical_flow_ev
void guidance_v_module_init(void)
float agl_lp
low-pass version of agl
static void send_divergence(struct transport_tx *trans, struct link_device *dev)
uint32_t CONTROL_METHOD
type of divergence control: 0 = fixed gain, 1 = adaptive gain
static struct EnuCoor_f * stateGetSpeedEnu_f(void)
Get ground speed in local ENU coordinates (float).
float divergence_history[OFL_COV_WINDOW_SIZE]
General stabilization interface for rotorcrafts.
int32_t stabilization_cmd[COMMANDS_NB]
Stabilization commands.
Common flight_plan functions shared between fixedwing and rotorcraft.
float cov_limit
for fixed gain control, what is the cov limit triggering the landing
uint32_t COV_METHOD
method to calculate the covariance: between thrust and div (0) or div and div past (1) ...
float divergence_vision_dt
float cov_set_point
for adaptive gain control, setpoint of the covariance (oscillations)
uint32_t window_size
number of time steps in "window" used for getting the covariance
#define OFL_P_LAND_THRESHOLD
uint32_t delay_steps
number of delay steps for div past
float pgain
P-gain for constant divergence control (from divergence error to thrust)
float lp_cov_div_factor
low-pass factor for the covariance of divergence in order to trigger the second landing phase in the ...
float sum_err
integration of the error for I-gain
float dgain_adaptive
D-gain for adaptive gain control.
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
float nominal_thrust
nominal thrust around which the PID-control operates