24 #include "generated/airframe.h"
43 #ifndef OFH_OPTICAL_FLOW_ID
44 #define OFH_OPTICAL_FLOW_ID ABI_BROADCAST
49 #ifndef OFH_HOVER_METHOD
50 #define OFH_HOVER_METHOD 1
54 #ifndef XY_SYMMETRICAL
55 #define XY_SYMMETRICAL 0
59 #ifndef OFH_COV_METHOD
60 #define OFH_COV_METHOD 0
64 #ifndef COV_WINDOW_SIZE
65 #define COV_WINDOW_SIZE (10*30)
69 #ifndef OF_COV_DELAY_STEPS
70 #define OF_COV_DELAY_STEPS COV_WINDOW_SIZE/2
75 #define OF_LP_CONST 0.5
85 #define OFH_OSCTHETA 1
90 #define OFH_PGAINZ 0.4
94 #define OFH_IGAINZ 0.f
98 #define OFH_DGAINZ 0.0
103 #define OFH_RAMPZ 0.15
107 #ifndef OFH_REDUCTIONZ
108 #define OFH_REDUCTIONZ 0.45
112 #ifndef OFH_COVDIV_SETPOINT
113 #define OFH_COVDIV_SETPOINT -0.02
118 #define OFH_PGAINX 0.f
122 #define OFH_IGAINX 0.00002
126 #define OFH_DGAINX 0.f
130 #define OFH_PGAINY 0.f
134 #define OFH_IGAINY 0.00002
138 #define OFH_DGAINY 0.f
143 #define OFH_RAMPXY 0.0008
147 #ifndef OFH_REDUCTIONXY
148 #define OFH_REDUCTIONXY 0.3
152 #ifndef OFH_COVFLOW_SETPOINT
153 #define OFH_COVFLOW_SETPOINT -500.f
157 #ifndef OFH_VER_SLOPE_A
158 #define OFH_VER_SLOPE_A 0.5
161 #ifndef OFH_VER_SLOPE_B
162 #define OFH_VER_SLOPE_B 0.25
165 #ifndef OFH_HOR_X_SLOPE_A
166 #define OFH_HOR_X_SLOPE_A 2.f
169 #ifndef OFH_HOR_X_SLOPE_B
170 #define OFH_HOR_X_SLOPE_B 0.5
173 #ifndef OFH_HOR_Y_SLOPE_A
174 #define OFH_HOR_Y_SLOPE_A OFH_HOR_X_SLOPE_A
177 #ifndef OFH_HOR_Y_SLOPE_B
178 #define OFH_HOR_Y_SLOPE_B OFH_HOR_X_SLOPE_B
222 int32_t flow_der_x,
int32_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.)
414 float ventral_factor = -1.28f;
430 float new_flowX = (
flowX * ventral_factor) / dt;
431 float new_flowY = (
flowY * ventral_factor) / dt;
526 static const float max_div_dt = 0.20f;
Main include for ABI (AirBorneInterface).
Event structure to store callbacks in a linked list.
bool autopilot_set_mode(uint8_t new_autopilot_mode)
set autopilot mode
Core autopilot interface common to all firmwares.
struct Electrical electrical
Interface for electrical status: supply voltage, current, battery status, etc.
bool bat_low
battery low status
#define VECT2_DIFF(_c, _a, _b)
#define VECT2_STRIM(_v, _min, _max)
#define VECT2_COPY(_a, _b)
int32_t phi
in rad with INT32_ANGLE_FRAC
int32_t psi
in rad with INT32_ANGLE_FRAC
int32_t theta
in rad with INT32_ANGLE_FRAC
#define FLOAT_OF_BFP(_vbfp, _frac)
#define BFP_OF_REAL(_vr, _frac)
vector in North East Down coordinates
static struct Int32Eulers * stateGetNedToBodyEulers_i(void)
Get vehicle body attitude euler angles (int).
static struct NedCoor_i * stateGetPositionNed_i(void)
Get position in local NED coordinates (int).
static struct NedCoor_i * stateGetSpeedNed_i(void)
Get ground speed in local NED coordinates (int).
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
uint8_t cov_array_filledXY
int32_t PID_divergence_control(float dt, struct OpticalFlowHoverControl *of_hover_ctrl)
Determine and set the thrust for constant divergence control.
struct OpticalFlowHover of_hover
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...
float PID_flow_control(float dt, struct OpticalFlowHoverControl *of_hover_ctrl)
Determine and set the desired angle for constant flow control.
uint8_t cov_array_filledZ
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...
float cov_setpoint
for adaptive gain control, setpoint of the covariance (oscillations)
float d_err
difference of error for the D-gain
float P
P-gain for control.
float divergence
Divergence estimate.
struct GainsPID PID
The struct with the PID gains.
float flowX
Flow estimate in X direction.
float previous_err
Previous tracking error.
float I
I-gain for control.
float input[COV_WINDOW_SIZE]
float reduction_factor
Reduce the gain by this factor when oscillating.
float sum_err
integration of the error for I-gain
float past_OF[COV_WINDOW_SIZE]
float setpoint
setpoint for constant divergence/flow
float D
D-gain for control.
float flowY
Flow estimate in Y direction.
float nominal_value
The nominal value of thrust, phi or theta depending on Z, Y, X.
float OF[COV_WINDOW_SIZE]
float err
Current tracking error.
float ramp
The ramp pused is increased with per dt.
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.
static void reset_horizontal_vars(void)
Reset all horizontal variables:
void computeOptiTrack(bool phi, bool theta, struct Int32Eulers *opti_sp_eu)
Get the desired Euler angles for optitrack stabilization.
static abi_event optical_flow_ev
static void send_optical_flow_hover(struct transport_tx *trans, struct link_device *dev)
void horizontal_ctrl_module_run(void)
Run the horizontal optical flow hover module.
struct OpticalFlowHoverControl of_hover_ctrl_Y
struct FloatVect3 covariances
struct Int32Vect2 of_hover_pos_err
struct Int32Vect2 of_hover_cmd_earth
struct DesiredInputs des_inputs
uint8_t hover_method
Method used to hover 0 = All axis after each other; 1 = all axis at the same time; 2 = vertical only,...
struct OpticalFlowHoverControl of_hover_ctrl_Z
#define OFH_HOR_X_SLOPE_B
#define OFH_HOR_X_SLOPE_A
struct OFhistory historyZ
#define OFH_OPTICAL_FLOW_ID
void guidance_module_enter(void)
Entering the module (user switched to module)
void guidance_module_run(bool in_flight)
struct OFhistory historyX
#define OFH_COVFLOW_SETPOINT
static void reset_vertical_vars(void)
Reset all vertical variables:
void optical_flow_hover_init()
struct Int32Vect2 of_hover_ref_pos
struct OFhistory historyY
bool cov_method
method to calculate the covariance: between thrust and div / angle and flow (0) or div and div past /...
#define OFH_COVDIV_SETPOINT
struct Int32Vect2 of_hover_speed_err
struct OpticalFlowHoverControl of_hover_ctrl_X
struct Int32Eulers ofh_sp_eu
void vertical_ctrl_module_run(void)
Run the vertical optical flow hover module.
struct Int32Vect2 of_hover_trim_att_integrator
#define OFH_HOR_Y_SLOPE_B
#define OFH_HOR_Y_SLOPE_A
#define PPRZ_ITRIG_SIN(_s, _a)
#define PPRZ_ITRIG_COS(_c, _a)
#define GUIDANCE_H_MAX_BANK
Max bank controlled by guidance.
Vertical guidance for rotorcrafts.
General attitude stabilization interface for rotorcrafts.
void stabilization_attitude_run(bool in_flight, struct StabilizationSetpoint *sp, struct ThrustSetpoint *thrust, int32_t *cmd)
Attitude control run function.
struct Stabilization stabilization
struct StabilizationSetpoint stab_sp_from_eulers_i(struct Int32Eulers *eulers)
struct Int32Eulers stab_sp_to_eulers_i(struct StabilizationSetpoint *sp)
struct ThrustSetpoint th_sp_from_thrust_i(int32_t thrust, uint8_t axis)
General stabilization interface for rotorcrafts.
struct StabilizationSetpoint sp
current attitude setpoint (store for messages)
int32_t cmd[COMMANDS_NB]
output command vector, range from [-MAX_PPRZ:MAX_PPRZ] (store for messages)
static const struct usb_device_descriptor dev
union StabilizationSetpoint::@278 sp
Thrust setpoint // TODO to a setpoint header Structure to store the desired thrust vector with differ...
union ThrustSetpoint::@284 sp
Architecture independent timing functions.
static float get_sys_time_float(void)
Get the time in seconds since startup.
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.