Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
optical_flow_landing.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016
3  *
4  * This file is part of Paparazzi.
5  *
6  * Paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * Paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Paparazzi; see the file COPYING. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
44 #ifndef OPTICAL_FLOW_LANDING_H_
45 #define OPTICAL_FLOW_LANDING_H_
46 
47 #include "std.h"
48 
49 // maximum number of samples to learn from for SSL:
50 #define MAX_SAMPLES_LEARNING 25000
51 
53  float agl;
54  float agl_lp;
55  float lp_const;
56  float vel;
58  float pgain;
59  float igain;
60  float dgain;
61  float divergence;
62  float previous_err;
63  float sum_err;
64  float d_err;
68  float cov_set_point;
69  float cov_limit;
78  float t_transition;
81  // Added features for SSL:
82  volatile bool
84  bool load_weights;
85  float close_to_edge;
86  bool use_bias;
87  bool snapshot;
89  float ramp_duration;
92  float roll_trim;
93  float pitch_trim;
94  float omega_LR;
95  float omega_FB;
98 };
99 
100 extern struct OpticalFlowLanding of_landing_ctrl;
101 
102 extern void optical_flow_landing_init(void);
103 
104 // FIXME Horizontal control have to be fixed before use
105 // Without optitrack set to: GUIDANCE_H_MODE_ATTITUDE
106 // With optitrack set to: GUIDANCE_H_MODE_HOVER / NAV (NAV is the common option in the experiments.)
107 
108 // Implement own loop:
109 extern void guidance_module_enter(void);
110 extern void guidance_module_run(bool in_flight);
111 
112 // SSL functions:
113 void save_texton_distribution(void);
114 void load_texton_distribution(void);
115 void fit_linear_model_OF(float *targets, float **samples, uint8_t D, uint16_t count, float *parameters,
116  float *fit_error);
117 void learn_from_file(void);
118 float predict_gain(float *distribution);
119 void save_weights(void);
120 void load_weights(void);
121 void recursive_least_squares_batch(float *targets, float **samples, uint8_t D, uint16_t count, float *params,
122  float *fit_error);
123 void recursive_least_squares(float target, float *sample, uint8_t length_sample, float *params);
124 
125 #endif /* OPTICAL_FLOW_LANDING_H_ */
float parameters[20]
Definition: ins_flow.c:235
void recursive_least_squares_batch(float *targets, float **samples, uint8_t D, uint16_t count, float *params, float *fit_error)
Recursively fit a linear model from samples to target values - batch mode, possibly for initializatio...
void learn_from_file(void)
float omega_LR
Set point for the left-right ventral flow.
float dgain_adaptive
D-gain for adaptive gain control.
float roll_trim
Roll trim angle in degrees.
float igain
I-gain for constant divergence control.
float pitch_trim
Pitch trim angle in degrees.
float igain_adaptive
I-gain for adaptive gain control.
float omega_FB
Set point for the front-back ventral flow.
float cov_set_point
for adaptive gain control, setpoint of the covariance (oscillations)
float dgain
D-gain for constant divergence control.
float cov_limit
for fixed gain control, what is the cov limit triggering the landing
float pgain
P-gain for constant divergence control (from divergence error to thrust)
float front_div_threshold
Threshold when the front div gets above this value, it will command a horizontal stop.
float reduction_factor_elc
reduction factor - after oscillation, how much to reduce the gain...
void recursive_least_squares(float target, float *sample, uint8_t length_sample, float *params)
float ramp_duration
ramp duration in seconds for when the divergence setpoint changes
float vel
vertical velocity as determined with sonar (only used when using "fake" divergence)
float divergence_setpoint
setpoint for constant divergence approach
void optical_flow_landing_init(void)
Initialize the optical flow landing module.
float pgain_adaptive
P-gain for adaptive gain control.
bool elc_oscillate
Whether or not to oscillate at beginning of elc to find optimum gain.
float t_transition
how many seconds the drone has to be oscillating in order to transition to the hover phase with reduc...
void guidance_module_enter(void)
Entering the module (user switched to module)
uint32_t VISION_METHOD
whether to use vision (1) or Optitrack / sonar (0)
void save_texton_distribution(void)
bool snapshot
if true, besides storing a texton distribution, an image will also be stored (when unstable)
bool load_weights
load the weights that were learned before
void guidance_module_run(bool in_flight)
Main guidance loop.
float lp_const
low-pass value for divergence
float d_err
difference of error for the D-gain
void fit_linear_model_OF(float *targets, float **samples, uint8_t D, uint16_t count, float *parameters, float *fit_error)
Fit a linear model from samples to target values.
float divergence
Divergence estimate.
volatile bool learn_gains
set to true if the robot needs to learn a mapping from texton distributions to the p-gain
uint32_t active_motion
Method for actively inducing motion.
float lp_factor_prediction
low-pass value for the predicted P-value
float sum_err
integration of the error for I-gain
float igain_horizontal_factor
factor multiplied with the vertical I-gain for horizontal ventral-flow-based control
float agl_lp
low-pass version of agl
float predict_gain(float *distribution)
struct OpticalFlowLanding of_landing_ctrl
float lp_cov_div_factor
low-pass factor for the covariance of divergence in order to trigger the second landing phase in the ...
void load_texton_distribution(void)
void load_weights(void)
uint32_t CONTROL_METHOD
type of divergence control: 0 = fixed gain, 1 = adaptive gain, 2 = exponential time landing control....
float nominal_thrust
nominal thrust around which the PID-control operates
uint32_t COV_METHOD
method to calculate the covariance: between thrust and div (0) or div and div past (1)
float previous_err
Previous divergence tracking error.
uint32_t delay_steps
number of delay steps for div past
float agl
agl = height from sonar (only used when using "fake" divergence)
void save_weights(void)
bool use_bias
if true, a bias 1.0f will be added to the feature vector (texton distribution) - this typically leads...
uint32_t window_size
number of time steps in "window" used for getting the covariance
float p_land_threshold
if during the exponential landing the gain reaches this value, the final landing procedure is trigger...
float pgain_horizontal_factor
factor multiplied with the vertical P-gain for horizontal ventral-flow-based control
float close_to_edge
if abs(cov_div - reference cov_div) < close_to_edge, then texton distributions and gains are stored f...
struct target_t target
Definition: target_pos.c:65
static float D
Definition: trilateration.c:35
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98