Paparazzi UAS
v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
|
#include "optical_flow_hover.h"
#include "optical_flow_functions.h"
#include "generated/airframe.h"
#include "autopilot.h"
#include "paparazzi.h"
#include "modules/core/abi.h"
#include "firmwares/rotorcraft/stabilization.h"
#include "firmwares/rotorcraft/stabilization/stabilization_attitude.h"
#include "firmwares/rotorcraft/guidance/guidance_v.h"
#include "modules/energy/electrical.h"
#include <stdio.h>
#include "modules/datalink/telemetry.h"
#include "mcu_periph/sys_time.h"
#include "math/pprz_stat.h"
Go to the source code of this file.
Macros | |
#define | OFH_OPTICAL_FLOW_ID ABI_BROADCAST |
#define | OFH_HOVER_METHOD 1 |
#define | XY_SYMMETRICAL 0 |
#define | OFH_COV_METHOD 0 |
#define | COV_WINDOW_SIZE (10*30) |
#define | OF_COV_DELAY_STEPS COV_WINDOW_SIZE/2 |
#define | OF_LP_CONST 0.5 |
#define | OFH_OSCPHI 1 |
#define | OFH_OSCTHETA 1 |
#define | OFH_PGAINZ 0.4 |
#define | OFH_IGAINZ 0.f |
#define | OFH_DGAINZ 0.0 |
#define | OFH_RAMPZ 0.15 |
#define | OFH_REDUCTIONZ 0.45 |
#define | OFH_COVDIV_SETPOINT -0.02 |
#define | OFH_PGAINX 0.f |
#define | OFH_IGAINX 0.00002 |
#define | OFH_DGAINX 0.f |
#define | OFH_PGAINY 0.f |
#define | OFH_IGAINY 0.00002 |
#define | OFH_DGAINY 0.f |
#define | OFH_RAMPXY 0.0008 |
#define | OFH_REDUCTIONXY 0.3 |
#define | OFH_COVFLOW_SETPOINT -500.f |
#define | OFH_VER_SLOPE_A 0.5 |
#define | OFH_VER_SLOPE_B 0.25 |
#define | OFH_HOR_X_SLOPE_A 2.f |
#define | OFH_HOR_X_SLOPE_B 0.5 |
#define | OFH_HOR_Y_SLOPE_A OFH_HOR_X_SLOPE_A |
#define | OFH_HOR_Y_SLOPE_B OFH_HOR_X_SLOPE_B |
#define | GH_GAIN_SCALE 2 |
#define | MAX_POS_ERR POS_BFP_OF_REAL(16.) |
#define | MAX_SPEED_ERR SPEED_BFP_OF_REAL(16.) |
Functions | |
void | ofh_optical_flow_cb (uint8_t sender_id, uint32_t stamp, int32_t flow_x, int32_t flow_y, int32_t flow_der_x, int32_t flow_der_y, float quality, float size_div) |
Function definitions. More... | |
static void | reset_horizontal_vars (void) |
Reset all horizontal variables: More... | |
static void | reset_vertical_vars (void) |
Reset all vertical variables: More... | |
void | vertical_ctrl_module_run (void) |
Run the vertical optical flow hover module. More... | |
void | horizontal_ctrl_module_run (void) |
Run the horizontal optical flow hover module. More... | |
void | computeOptiTrack (bool phi, bool theta, struct Int32Eulers *opti_sp_eu) |
Get the desired Euler angles for optitrack stabilization. More... | |
static void | send_optical_flow_hover (struct transport_tx *trans, struct link_device *dev) |
void | optical_flow_hover_init () |
void | guidance_module_enter (void) |
Entering the module (user switched to module) More... | |
void | guidance_module_run (bool in_flight) |
#define COV_WINDOW_SIZE (10*30) |
Definition at line 65 of file optical_flow_hover.c.
#define GH_GAIN_SCALE 2 |
Definition at line 233 of file optical_flow_hover.c.
#define MAX_POS_ERR POS_BFP_OF_REAL(16.) |
Definition at line 236 of file optical_flow_hover.c.
#define MAX_SPEED_ERR SPEED_BFP_OF_REAL(16.) |
Definition at line 239 of file optical_flow_hover.c.
#define OF_COV_DELAY_STEPS COV_WINDOW_SIZE/2 |
Definition at line 70 of file optical_flow_hover.c.
#define OF_LP_CONST 0.5 |
Definition at line 75 of file optical_flow_hover.c.
#define OFH_COV_METHOD 0 |
Definition at line 60 of file optical_flow_hover.c.
#define OFH_COVDIV_SETPOINT -0.02 |
Definition at line 113 of file optical_flow_hover.c.
#define OFH_COVFLOW_SETPOINT -500.f |
Definition at line 153 of file optical_flow_hover.c.
#define OFH_DGAINX 0.f |
Definition at line 126 of file optical_flow_hover.c.
#define OFH_DGAINY 0.f |
Definition at line 138 of file optical_flow_hover.c.
#define OFH_DGAINZ 0.0 |
Definition at line 98 of file optical_flow_hover.c.
#define OFH_HOR_X_SLOPE_A 2.f |
Definition at line 166 of file optical_flow_hover.c.
#define OFH_HOR_X_SLOPE_B 0.5 |
Definition at line 170 of file optical_flow_hover.c.
#define OFH_HOR_Y_SLOPE_A OFH_HOR_X_SLOPE_A |
Definition at line 174 of file optical_flow_hover.c.
#define OFH_HOR_Y_SLOPE_B OFH_HOR_X_SLOPE_B |
Definition at line 178 of file optical_flow_hover.c.
#define OFH_HOVER_METHOD 1 |
Definition at line 50 of file optical_flow_hover.c.
#define OFH_IGAINX 0.00002 |
Definition at line 122 of file optical_flow_hover.c.
#define OFH_IGAINY 0.00002 |
Definition at line 134 of file optical_flow_hover.c.
#define OFH_IGAINZ 0.f |
Definition at line 94 of file optical_flow_hover.c.
#define OFH_OPTICAL_FLOW_ID ABI_BROADCAST |
Definition at line 44 of file optical_flow_hover.c.
#define OFH_OSCPHI 1 |
Definition at line 80 of file optical_flow_hover.c.
#define OFH_OSCTHETA 1 |
Definition at line 85 of file optical_flow_hover.c.
#define OFH_PGAINX 0.f |
Definition at line 118 of file optical_flow_hover.c.
#define OFH_PGAINY 0.f |
Definition at line 130 of file optical_flow_hover.c.
#define OFH_PGAINZ 0.4 |
Definition at line 90 of file optical_flow_hover.c.
#define OFH_RAMPXY 0.0008 |
Definition at line 143 of file optical_flow_hover.c.
#define OFH_RAMPZ 0.15 |
Definition at line 103 of file optical_flow_hover.c.
#define OFH_REDUCTIONXY 0.3 |
Definition at line 148 of file optical_flow_hover.c.
#define OFH_REDUCTIONZ 0.45 |
Definition at line 108 of file optical_flow_hover.c.
#define OFH_VER_SLOPE_A 0.5 |
Definition at line 158 of file optical_flow_hover.c.
#define OFH_VER_SLOPE_B 0.25 |
Definition at line 162 of file optical_flow_hover.c.
#define XY_SYMMETRICAL 0 |
Definition at line 55 of file optical_flow_hover.c.
void computeOptiTrack | ( | bool | phi, |
bool | theta, | ||
struct Int32Eulers * | opti_sp_eu | ||
) |
Get the desired Euler angles for optitrack stabilization.
[in] | Boolean | whether to Phi or not |
[in] | Boolean | whether to Theta or not |
[out] | The | desired Euler angles |
Definition at line 636 of file optical_flow_hover.c.
References BFP_OF_REAL, GH_GAIN_SCALE, GUIDANCE_H_MAX_BANK, INT32_ANGLE_FRAC, INT32_POS_FRAC, INT32_SPEED_FRAC, INT32_TRIG_FRAC, MAX_POS_ERR, MAX_SPEED_ERR, Min, of_hover_cmd_earth, of_hover_pos_err, of_hover_ref_pos, of_hover_speed_err, of_hover_trim_att_integrator, Int32Eulers::phi, PPRZ_ITRIG_COS, PPRZ_ITRIG_SIN, Int32Eulers::psi, stateGetNedToBodyEulers_i(), stateGetPositionNed_i(), stateGetSpeedNed_i(), Int32Eulers::theta, VECT2_DIFF, VECT2_STRIM, Int32Vect2::x, and Int32Vect2::y.
Referenced by horizontal_ctrl_module_run().
void guidance_module_enter | ( | void | ) |
Entering the module (user switched to module)
Definition at line 600 of file optical_flow_hover.c.
References Stabilization::cmd, des_inputs, MAX_PPRZ, OpticalFlowHoverControl::nominal_value, of_hover_ctrl_Z, of_hover_ref_pos, ofh_sp_eu, Int32Eulers::psi, reset_horizontal_vars(), reset_vertical_vars(), stabilization, stateGetNedToBodyEulers_i(), stateGetPositionNed_i(), DesiredInputs::thrust, and VECT2_COPY.
void guidance_module_run | ( | bool | in_flight | ) |
Definition at line 616 of file optical_flow_hover.c.
References AP_MODE_NAV, autopilot_set_mode(), Electrical::bat_low, Stabilization::cmd, des_inputs, electrical, horizontal_ctrl_module_run(), ofh_sp_eu, StabilizationSetpoint::sp, ThrustSetpoint::sp, stab_sp_from_eulers_i(), stabilization, stabilization_attitude_run(), th_sp_from_thrust_i(), DesiredInputs::thrust, THRUST_AXIS_Z, and vertical_ctrl_module_run().
void horizontal_ctrl_module_run | ( | void | ) |
Run the horizontal optical flow hover module.
Definition at line 409 of file optical_flow_hover.c.
References BFP_OF_REAL, computeOptiTrack(), cov_method, OpticalFlowHoverControl::cov_setpoint, covariances, des_inputs, GainsPID::err, OpticalFlowHover::flowX, flowX, OpticalFlowHover::flowY, flowY, historyX, historyY, hover_method, INT32_ANGLE_FRAC, lp_factor, OpticalFlowHoverControl::nominal_value, of_hover, of_hover_ctrl_X, of_hover_ctrl_Y, OF_LP_CONST, OFH_PGAINY, ofh_sp_eu, oscillatingX, oscillatingY, oscphi, osctheta, GainsPID::P, Int32Eulers::phi, DesiredInputs::phi, OpticalFlowHoverControl::PID, PID_flow_control(), prev_vision_timeXY, OpticalFlowHoverControl::ramp, OpticalFlowHoverControl::reduction_factor, set_cov_flow(), OpticalFlowHoverControl::setpoint, Int32Eulers::theta, DesiredInputs::theta, vision_time, FloatVect3::x, XY_SYMMETRICAL, and FloatVect3::y.
Referenced by guidance_module_run().
void ofh_optical_flow_cb | ( | uint8_t sender_id | UNUSED, |
uint32_t | stamp, | ||
int32_t | flow_x, | ||
int32_t | flow_y, | ||
int32_t | flow_der_x, | ||
int32_t | flow_der_y, | ||
float quality | UNUSED, | ||
float | size_div | ||
) |
Function definitions.
Definition at line 578 of file optical_flow_hover.c.
References derotated, divergence_vision, flowX, flowY, and vision_time.
Referenced by optical_flow_hover_init().
void optical_flow_hover_init | ( | void | ) |
Definition at line 259 of file optical_flow_hover.c.
References cov_method, OpticalFlowHoverControl::cov_setpoint, GainsPID::D, DefaultPeriodic, hover_method, GainsPID::I, of_hover_ctrl_X, of_hover_ctrl_Y, of_hover_ctrl_Z, OFH_COV_METHOD, OFH_COVDIV_SETPOINT, OFH_COVFLOW_SETPOINT, OFH_DGAINX, OFH_DGAINY, OFH_DGAINZ, OFH_HOVER_METHOD, OFH_IGAINX, OFH_IGAINY, OFH_IGAINZ, ofh_optical_flow_cb(), OFH_OPTICAL_FLOW_ID, OFH_OSCPHI, OFH_OSCTHETA, OFH_PGAINX, OFH_PGAINY, OFH_PGAINZ, OFH_RAMPXY, OFH_RAMPZ, OFH_REDUCTIONXY, OFH_REDUCTIONZ, optical_flow_ev, oscphi, osctheta, GainsPID::P, OpticalFlowHoverControl::PID, OpticalFlowHoverControl::ramp, OpticalFlowHoverControl::reduction_factor, register_periodic_telemetry(), reset_horizontal_vars(), reset_vertical_vars(), send_optical_flow_hover(), and OpticalFlowHoverControl::setpoint.
|
static |
Reset all horizontal variables:
Definition at line 304 of file optical_flow_hover.c.
References cov_array_filledXY, COV_WINDOW_SIZE, covariances, GainsPID::d_err, des_inputs, FLOAT_OF_BFP, OpticalFlowHover::flowX, flowX, OpticalFlowHover::flowY, flowY, get_sys_time_float(), historyX, historyY, hover_method, GainsPID::I, ind_histXY, OFhistory::input, INT32_ANGLE_FRAC, OpticalFlowHoverControl::nominal_value, OFhistory::OF, of_hover, of_hover_ctrl_X, of_hover_ctrl_Y, OFH_IGAINX, OFH_IGAINY, OFH_PGAINX, OFH_PGAINY, ofh_sp_eu, oscillatingX, oscillatingY, GainsPID::P, OFhistory::past_OF, Int32Eulers::phi, DesiredInputs::phi, OpticalFlowHoverControl::PID, prev_vision_timeXY, GainsPID::previous_err, Stabilization::sp, stab_sp_to_eulers_i(), stabilization, GainsPID::sum_err, Int32Eulers::theta, DesiredInputs::theta, vision_time, FloatVect3::x, and FloatVect3::y.
Referenced by guidance_module_enter(), and optical_flow_hover_init().
|
static |
Reset all vertical variables:
Definition at line 377 of file optical_flow_hover.c.
References cov_array_filledZ, COV_WINDOW_SIZE, covariances, GainsPID::d_err, OpticalFlowHover::divergence, divergence_vision, get_sys_time_float(), historyZ, ind_histZ, OFhistory::input, OFhistory::OF, of_hover, of_hover_ctrl_Z, OFH_PGAINZ, oscillatingZ, GainsPID::P, OFhistory::past_OF, OpticalFlowHoverControl::PID, prev_vision_timeZ, GainsPID::previous_err, GainsPID::sum_err, vision_time, and FloatVect3::z.
Referenced by guidance_module_enter(), and optical_flow_hover_init().
|
static |
Definition at line 249 of file optical_flow_hover.c.
References covariances, des_inputs, dev, OpticalFlowHover::divergence, OpticalFlowHover::flowX, OpticalFlowHover::flowY, of_hover, of_hover_ctrl_X, of_hover_ctrl_Y, of_hover_ctrl_Z, GainsPID::P, DesiredInputs::phi, OpticalFlowHoverControl::PID, GainsPID::sum_err, DesiredInputs::theta, DesiredInputs::thrust, FloatVect3::x, FloatVect3::y, and FloatVect3::z.
Referenced by optical_flow_hover_init().
void vertical_ctrl_module_run | ( | void | ) |
Run the vertical optical flow hover module.
Definition at line 499 of file optical_flow_hover.c.
References cov_method, OpticalFlowHoverControl::cov_setpoint, covariances, des_inputs, OpticalFlowHover::divergence, divergence_vision, GainsPID::err, historyZ, hover_method, GainsPID::I, lp_factor, of_hover, of_hover_ctrl_X, of_hover_ctrl_Y, of_hover_ctrl_Z, OF_LP_CONST, OFH_HOR_X_SLOPE_A, OFH_HOR_X_SLOPE_B, OFH_HOR_Y_SLOPE_A, OFH_HOR_Y_SLOPE_B, OFH_IGAINX, OFH_IGAINY, OFH_PGAINX, OFH_REDUCTIONXY, OFH_VER_SLOPE_A, OFH_VER_SLOPE_B, oscillatingX, oscillatingZ, GainsPID::P, OpticalFlowHoverControl::PID, PID_divergence_control(), prev_vision_timeZ, OpticalFlowHoverControl::ramp, OpticalFlowHoverControl::reduction_factor, set_cov_div(), OpticalFlowHoverControl::setpoint, GainsPID::sum_err, DesiredInputs::thrust, vision_time, and FloatVect3::z.
Referenced by guidance_module_run().
bool cov_method |
method to calculate the covariance: between thrust and div / angle and flow (0) or div and div past / flow and past flow(1)
Definition at line 215 of file optical_flow_hover.c.
Referenced by horizontal_ctrl_module_run(), optical_flow_hover_init(), set_cov_div(), set_cov_flow(), and vertical_ctrl_module_run().
struct FloatVect3 covariances |
Definition at line 1 of file optical_flow_hover.c.
Referenced by horizontal_ctrl_module_run(), reset_horizontal_vars(), reset_vertical_vars(), send_optical_flow_hover(), and vertical_ctrl_module_run().
bool derotated |
Definition at line 214 of file optical_flow_hover.c.
Referenced by ofh_optical_flow_cb().
struct DesiredInputs des_inputs |
Definition at line 1 of file optical_flow_hover.c.
Referenced by guidance_module_enter(), guidance_module_run(), horizontal_ctrl_module_run(), reset_horizontal_vars(), send_optical_flow_hover(), and vertical_ctrl_module_run().
float divergence_vision |
Definition at line 199 of file optical_flow_hover.c.
Referenced by ofh_optical_flow_cb(), reset_vertical_vars(), and vertical_ctrl_module_run().
int32_t flowX |
Definition at line 190 of file optical_flow_hover.c.
Referenced by horizontal_ctrl_module_run(), ofh_optical_flow_cb(), and reset_horizontal_vars().
int32_t flowY |
Definition at line 191 of file optical_flow_hover.c.
Referenced by horizontal_ctrl_module_run(), ofh_optical_flow_cb(), and reset_horizontal_vars().
struct OFhistory historyX |
Definition at line 191 of file optical_flow_hover.c.
Referenced by horizontal_ctrl_module_run(), reset_horizontal_vars(), and set_cov_flow().
struct OFhistory historyY |
Definition at line 191 of file optical_flow_hover.c.
Referenced by horizontal_ctrl_module_run(), reset_horizontal_vars(), and set_cov_flow().
struct OFhistory historyZ |
Definition at line 199 of file optical_flow_hover.c.
Referenced by reset_vertical_vars(), and vertical_ctrl_module_run().
uint8_t hover_method |
Method used to hover 0 = All axis after each other; 1 = all axis at the same time; 2 = vertical only, use relation to set horizontal.
Definition at line 216 of file optical_flow_hover.c.
Referenced by horizontal_ctrl_module_run(), optical_flow_hover_init(), reset_horizontal_vars(), and vertical_ctrl_module_run().
struct Int32Vect2 of_hover_cmd_earth |
Definition at line 231 of file optical_flow_hover.c.
Referenced by computeOptiTrack().
struct OpticalFlowHoverControl of_hover_ctrl_X |
Definition at line 204 of file optical_flow_hover.c.
Referenced by horizontal_ctrl_module_run(), optical_flow_hover_init(), reset_horizontal_vars(), send_optical_flow_hover(), and vertical_ctrl_module_run().
struct OpticalFlowHoverControl of_hover_ctrl_Y |
Definition at line 204 of file optical_flow_hover.c.
Referenced by horizontal_ctrl_module_run(), optical_flow_hover_init(), reset_horizontal_vars(), send_optical_flow_hover(), and vertical_ctrl_module_run().
struct OpticalFlowHoverControl of_hover_ctrl_Z |
Definition at line 204 of file optical_flow_hover.c.
Referenced by guidance_module_enter(), optical_flow_hover_init(), reset_vertical_vars(), send_optical_flow_hover(), and vertical_ctrl_module_run().
struct Int32Vect2 of_hover_pos_err |
Definition at line 231 of file optical_flow_hover.c.
Referenced by computeOptiTrack().
struct Int32Vect2 of_hover_ref_pos |
Definition at line 231 of file optical_flow_hover.c.
Referenced by computeOptiTrack(), and guidance_module_enter().
struct Int32Vect2 of_hover_speed_err |
Definition at line 231 of file optical_flow_hover.c.
Referenced by computeOptiTrack().
struct Int32Vect2 of_hover_trim_att_integrator |
Definition at line 231 of file optical_flow_hover.c.
Referenced by computeOptiTrack().
struct Int32Eulers ofh_sp_eu |
Definition at line 191 of file optical_flow_hover.c.
Referenced by guidance_module_enter(), guidance_module_run(), horizontal_ctrl_module_run(), and reset_horizontal_vars().
|
static |
Definition at line 204 of file optical_flow_hover.c.
Referenced by optical_flow_hover_init().
bool oscillatingX |
Definition at line 188 of file optical_flow_hover.c.
Referenced by horizontal_ctrl_module_run(), reset_horizontal_vars(), and vertical_ctrl_module_run().
bool oscillatingY |
Definition at line 189 of file optical_flow_hover.c.
Referenced by horizontal_ctrl_module_run(), and reset_horizontal_vars().
bool oscillatingZ |
Definition at line 198 of file optical_flow_hover.c.
Referenced by reset_vertical_vars(), and vertical_ctrl_module_run().
bool oscphi |
Definition at line 212 of file optical_flow_hover.c.
Referenced by horizontal_ctrl_module_run(), and optical_flow_hover_init().
bool osctheta |
Definition at line 213 of file optical_flow_hover.c.
Referenced by horizontal_ctrl_module_run(), and optical_flow_hover_init().
float prev_vision_timeXY |
Definition at line 186 of file optical_flow_hover.c.
Referenced by horizontal_ctrl_module_run(), and reset_horizontal_vars().
float prev_vision_timeZ |
Definition at line 186 of file optical_flow_hover.c.
Referenced by reset_vertical_vars(), and vertical_ctrl_module_run().
float vision_time |
Definition at line 186 of file optical_flow_hover.c.
Referenced by horizontal_ctrl_module_run(), ofh_optical_flow_cb(), reset_horizontal_vars(), reset_vertical_vars(), and vertical_ctrl_module_run().