53 #define MINIMUM_GAIN 0.1
67 pprz_msg_send_DIVERGENCE(trans, dev, AC_ID,
73 #include "generated/airframe.h"
79 #ifndef OPTICAL_FLOW_LANDING_AGL_ID
80 #define OPTICAL_FLOW_LANDING_AGL_ID ABI_BROADCAST
85 #ifndef OPTICAL_FLOW_LANDING_OPTICAL_FLOW_ID
86 #define OPTICAL_FLOW_LANDING_OPTICAL_FLOW_ID ABI_BROADCAST
91 #ifndef OPTICAL_FLOW_LANDING_PGAIN
92 #define OPTICAL_FLOW_LANDING_PGAIN 1.0
95 #ifndef OPTICAL_FLOW_LANDING_IGAIN
96 #define OPTICAL_FLOW_LANDING_IGAIN 0.0
99 #ifndef OPTICAL_FLOW_LANDING_DGAIN
100 #define OPTICAL_FLOW_LANDING_DGAIN 0.0
103 #ifndef OPTICAL_FLOW_LANDING_VISION_METHOD
104 #define OPTICAL_FLOW_LANDING_VISION_METHOD 1
107 #ifndef OPTICAL_FLOW_LANDING_CONTROL_METHOD
108 #define OPTICAL_FLOW_LANDING_CONTROL_METHOD 0
111 #ifndef OPTICAL_FLOW_LANDING_COV_METHOD
112 #define OPTICAL_FLOW_LANDING_COV_METHOD 0
155 struct timespec spec;
156 clock_gettime(CLOCK_REALTIME, &spec);
208 struct timespec spec;
209 clock_gettime(CLOCK_REALTIME, &spec);
231 if (
dt < 0) {
dt = 0.0f; }
234 struct timespec spec;
235 clock_gettime(CLOCK_REALTIME, &spec);
236 long new_time = spec.tv_nsec / 1.0E6;
238 dt += ((float)delta_t) / 1000.0f;
243 previous_time = new_time;
302 if (fabs(new_divergence -
divergence) > 0.20) {
348 Bound(thrust, 0.8 * nominal_throttle, 0.75 *
MAX_PPRZ);
369 thrust = 0.90 * nominal_throttle;
421 Bound(thrust, 0.8 * nominal_throttle, 0.75 *
MAX_PPRZ);
427 int32_t thrust = 0.90 * nominal_throttle;
428 Bound(thrust, 0.6 * nominal_throttle, 0.9 *
MAX_PPRZ);
444 for (
unsigned int i = 0; i < n_elements; i++) {
459 float get_cov(
float *a,
float *b,
int n_elements)
467 for (
unsigned int i = 0; i < n_elements; i++) {
468 cov += (a[i] - mean_a) * (b[i] - mean_b);
515 struct timespec spec;
516 clock_gettime(CLOCK_REALTIME, &spec);
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[COV_WINDOW_SIZE]
float get_mean_array(float *a, int n_elements)
Get the mean value of an array.
void guidance_v_module_run(bool in_flight)
struct OpticalFlowLanding of_landing_ctrl
Periodic telemetry system header (includes downlink utility and generated code).
void reset_all_vars()
Reset all variables:
float dgain
D-gain for constant divergence control.
Main include for ABI (AirBorneInterface).
#define OPTICAL_FLOW_LANDING_OPTICAL_FLOW_ID
float lp_factor
low-pass factor in [0,1], with 0 purely using the current measurement
float agl
agl = height from sonar (only used when using "fake" divergence)
float igain_adaptive
I-gain for adaptive gain control.
int32_t alt
in millimeters above WGS84 reference ellipsoid
static abi_event agl_ev
The altitude ABI event.
#define OPTICAL_FLOW_LANDING_IGAIN
#define OPTICAL_FLOW_LANDING_VISION_METHOD
float pgain_adaptive
P-gain for adaptive gain control.
#define OPTICAL_FLOW_LANDING_DGAIN
float vel
vertical velocity as determined with sonar (only used when using "fake" divergence) ...
void vertical_ctrl_module_init(void)
Initialize the optical flow landing module.
#define OPTICAL_FLOW_LANDING_AGL_ID
#define OPTICAL_FLOW_LANDING_CONTROL_METHOD
float divergence_history[COV_WINDOW_SIZE]
float divergence_setpoint
setpoint for constant divergence approach
static void vertical_ctrl_agl_cb(uint8_t sender_id, float distance)
Callback function of the ground altitude.
#define DefaultPeriodic
Set default periodic telemetry.
int delay_steps
number of delay steps for div past
int COV_METHOD
method to calculate the covariance: between thrust and div (0) or div and div past (1) ...
void vertical_ctrl_module_run(bool in_flight)
Run the optical flow landing module.
static const struct usb_device_descriptor dev
static abi_event optical_flow_ev
int CONTROL_METHOD
type of divergence control: 0 = fixed gain, 1 = adaptive gain
float past_divergence_history[COV_WINDOW_SIZE]
void guidance_v_module_init(void)
int VISION_METHOD
whether to use vision (1) or Optitrack / sonar (0)
float agl_lp
low-pass version of agl
static void send_divergence(struct transport_tx *trans, struct link_device *dev)
General stabilization interface for rotorcrafts.
static 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, uint8_t quality, float size_divergence, float dist)
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
float divergence_vision_dt
float cov_set_point
for adaptive gain control, setpoint of the covariance (oscillations)
float get_cov(float *a, float *b, int n_elements)
Get the covariance of two arrays.
#define OPTICAL_FLOW_LANDING_PGAIN
float pgain
P-gain for constant divergence control (from divergence error to thrust)
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
#define OPTICAL_FLOW_LANDING_COV_METHOD
float sum_err
integration of the error for I-gain
float dgain_adaptive
D-gain for adaptive gain control.
struct GpsState gps
global GPS state
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
if(PrimarySpektrumState.SpektrumTimer)