24 #include "generated/airframe.h"
41 #ifndef OFH_OPTICAL_FLOW_ID
42 #define OFH_OPTICAL_FLOW_ID ABI_BROADCAST
47 #ifndef OFH_HOVER_METHOD
48 #define OFH_HOVER_METHOD 1
52 #ifndef XY_SYMMETRICAL
53 #define XY_SYMMETRICAL 0
57 #ifndef OFH_COV_METHOD
58 #define OFH_COV_METHOD 0
62 #ifndef COV_WINDOW_SIZE
63 #define COV_WINDOW_SIZE (10*30)
67 #ifndef OF_COV_DELAY_STEPS
68 #define OF_COV_DELAY_STEPS COV_WINDOW_SIZE/2
73 #define OF_LP_CONST 0.5
83 #define OFH_OSCTHETA 1
88 #define OFH_PGAINZ 0.4
92 #define OFH_IGAINZ 0.f
96 #define OFH_DGAINZ 0.0
101 #define OFH_RAMPZ 0.15
105 #ifndef OFH_REDUCTIONZ
106 #define OFH_REDUCTIONZ 0.45
110 #ifndef OFH_COVDIV_SETPOINT
111 #define OFH_COVDIV_SETPOINT -0.02
116 #define OFH_PGAINX 0.f
120 #define OFH_IGAINX 0.00002
124 #define OFH_DGAINX 0.f
128 #define OFH_PGAINY 0.f
132 #define OFH_IGAINY 0.00002
136 #define OFH_DGAINY 0.f
141 #define OFH_RAMPXY 0.0008
145 #ifndef OFH_REDUCTIONXY
146 #define OFH_REDUCTIONXY 0.3
150 #ifndef OFH_COVFLOW_SETPOINT
151 #define OFH_COVFLOW_SETPOINT -500.f
155 #ifndef OFH_VER_SLOPE_A
156 #define OFH_VER_SLOPE_A 0.5
159 #ifndef OFH_VER_SLOPE_B
160 #define OFH_VER_SLOPE_B 0.25
163 #ifndef OFH_HOR_X_SLOPE_A
164 #define OFH_HOR_X_SLOPE_A 2.f
167 #ifndef OFH_HOR_X_SLOPE_B
168 #define OFH_HOR_X_SLOPE_B 0.5
171 #ifndef OFH_HOR_Y_SLOPE_A
172 #define OFH_HOR_Y_SLOPE_A OFH_HOR_X_SLOPE_A
175 #ifndef OFH_HOR_Y_SLOPE_B
176 #define OFH_HOR_Y_SLOPE_B OFH_HOR_X_SLOPE_B
220 int16_t flow_der_x,
int16_t flow_der_y,
float quality,
float size_div);
232 #ifndef GH_GAIN_SCALE
233 #define GH_GAIN_SCALE 2
236 #define MAX_POS_ERR POS_BFP_OF_REAL(16.)
238 #ifndef MAX_SPEED_ERR
239 #define MAX_SPEED_ERR SPEED_BFP_OF_REAL(16.)
399 divergence_vision = 0;
434 float ventral_factor = -1.28f;
448 Bound(lp_factor, 0.f, 1.f);
450 float new_flowX = (flowX * ventral_factor) / dt;
451 float new_flowY = (flowY * ventral_factor) / dt;
492 if (hover_method == 0) {
541 Bound(lp_factor, 0.f, 1.f);
545 float new_divergence = (divergence_vision * div_factor) / dt;
548 static const float max_div_dt = 0.20f;
579 if (hover_method == 0) {
584 }
else if (hover_method == 2) {
602 int16_t flow_der_x,
int16_t flow_der_y,
float quality,
float size_div)
612 divergence_vision = size_div;
614 vision_time = ((float)stamp) / 1e6;
int32_t psi
in rad with INT32_ANGLE_FRAC
void guidance_h_module_run(bool in_flight)
Event structure to store callbacks in a linked list.
void ofh_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_div)
Function definitions.
struct OpticalFlowHoverControl of_hover_ctrl_Z
float ramp
The ramp pused is increased with per dt.
#define GUIDANCE_H_MAX_BANK
Periodic telemetry system header (includes downlink utility and generated code).
General attitude stabilization interface for rotorcrafts.
void vertical_ctrl_module_run(bool in_flight)
Run the vertical optical flow hover module.
#define OFH_HOR_X_SLOPE_B
int32_t theta
in rad with INT32_ANGLE_FRAC
float past_OF[COV_WINDOW_SIZE]
void guidance_v_module_init(void)
#define VECT2_STRIM(_v, _min, _max)
struct OpticalFlowHoverControl of_hover_ctrl_X
float previous_err
Previous tracking error.
#define OFH_HOR_Y_SLOPE_A
Main include for ABI (AirBorneInterface).
#define VECT2_COPY(_a, _b)
struct Int32Eulers ofh_sp_eu
struct Int32Vect2 of_hover_trim_att_integrator
#define VECT2_DIFF(_c, _a, _b)
struct OFhistory historyZ
void stabilization_attitude_run(bool in_flight)
#define FLOAT_OF_BFP(_vbfp, _frac)
#define OFH_HOR_Y_SLOPE_B
struct GainsPID PID
The struct with the PID gains.
float I
I-gain for control.
static float get_sys_time_float(void)
Get the time in seconds since startup.
#define GUIDANCE_V_MODE_MODULE_SETTING
void optical_flow_hover_init()
void guidance_h_module_enter(void)
Entering the horizontal module (user switched to module)
struct Int32Quat stab_att_sp_quat
with INT32_QUAT_FRAC
void autopilot_static_set_mode(uint8_t new_autopilot_mode)
struct OpticalFlowHover of_hover
float cov_setpoint
for adaptive gain control, setpoint of the covariance (oscillations)
#define BFP_OF_REAL(_vr, _frac)
#define PPRZ_ITRIG_SIN(_s, _a)
static struct NedCoor_i * stateGetSpeedNed_i(void)
Get ground speed in local NED coordinates (int).
#define GUIDANCE_V_MODE_MODULE
float sum_err
integration of the error for I-gain
Interface for electrical status: supply voltage, current, battery status, etc.
Architecture independent timing functions.
void horizontal_ctrl_module_init(void)
Initialize the horizontal optical flow hover module.
bool cov_method
method to calculate the covariance: between thrust and div / angle and flow (0) or div and div past /...
#define OFH_COVFLOW_SETPOINT
void stabilization_attitude_set_rpy_setpoint_i(struct Int32Eulers *rpy)
#define OFH_HOR_X_SLOPE_A
struct Int32Vect2 of_hover_speed_err
uint8_t hover_method
Method used to hover 0 = All axis after each other; 1 = all axis at the same time; 2 = vertical only...
#define OFH_OPTICAL_FLOW_ID
float flowY
Flow estimate in Y direction.
#define DefaultPeriodic
Set default periodic telemetry.
struct DesiredInputs des_inputs
void guidance_h_module_read_rc(void)
float reduction_factor
Reduce the gain by this factor when oscillating.
void guidance_v_module_run(bool in_flight)
float input[COV_WINDOW_SIZE]
float err
Current tracking error.
bool bat_low
battery low status
struct FloatVect3 covariances
struct OpticalFlowHoverControl of_hover_ctrl_Y
#define OFH_COVDIV_SETPOINT
struct Int32Vect2 of_hover_pos_err
static const struct usb_device_descriptor dev
float flowX
Flow estimate in X direction.
void int32_eulers_of_quat(struct Int32Eulers *e, struct Int32Quat *q)
float setpoint
setpoint for constant divergence/flow
float nominal_value
The nominal value of thrust, phi or theta depending on Z, Y, X.
float P
P-gain for control.
float OF[COV_WINDOW_SIZE]
int32_t phi
in rad with INT32_ANGLE_FRAC
uint8_t cov_array_filledZ
vector in North East Down coordinates
void guidance_h_module_init(void)
struct Int32Vect2 of_hover_cmd_earth
void computeOptiTrack(bool phi, bool theta, struct Int32Eulers *opti_sp_eu)
Get the desired Euler angles for optitrack stabilization.
int32_t PID_divergence_control(float dt, struct OpticalFlowHoverControl *of_hover_ctrl)
Determine and set the thrust for constant divergence control.
float set_cov_div(bool cov_method, struct OFhistory *history, struct DesiredInputs *inputs)
Set the covariance of the divergence and the thrust / past divergence This funciton should only be ca...
void set_cov_flow(bool cov_method, struct OFhistory *historyX, struct OFhistory *historyY, struct DesiredInputs *inputs, struct FloatVect3 *covs)
Set the covariance of the flow and past flow / desired angle This funciton should only be called once...
General stabilization interface for rotorcrafts.
static void reset_vertical_vars(void)
Reset all vertical variables:
float d_err
difference of error for the D-gain
int32_t stabilization_cmd[COMMANDS_NB]
Stabilization commands.
struct Int32Vect2 of_hover_ref_pos
struct Electrical electrical
struct OFhistory historyX
static struct NedCoor_i * stateGetPositionNed_i(void)
Get position in local NED coordinates (int).
static void reset_horizontal_vars(void)
Reset all horizontal variables:
static struct Int32Eulers * stateGetNedToBodyEulers_i(void)
Get vehicle body attitude euler angles (int).
float D
D-gain for control.
void vertical_ctrl_module_init(void)
Initialize the vertical optical flow hover module.
void horizontal_ctrl_module_run(bool in_flight)
Run the horizontal optical flow hover module.
float divergence
Divergence estimate.
static abi_event optical_flow_ev
void guidance_v_module_enter(void)
Entering the vertical module (user switched to module)
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
uint8_t cov_array_filledXY
static void send_optical_flow_hover(struct transport_tx *trans, struct link_device *dev)
#define PPRZ_ITRIG_COS(_c, _a)
struct OFhistory historyY
float PID_flow_control(float dt, struct OpticalFlowHoverControl *of_hover_ctrl)
Determine and set the desired angle for constant flow control.