32 #include "generated/modules.h"
37 #error Only Chibios is supported
50 #define WE_UKF_ALPHA 0.5f
53 #define WE_UKF_BETA 2.f
56 #define WE_UKF_P0 0.2f
59 #define WE_UKF_R_GS 0.5f
62 #define WE_UKF_R_VA 0.5f
65 #define WE_UKF_R_AOA 0.002f
68 #define WE_UKF_R_SSA 0.002f
71 #define WE_UKF_Q_VA 0.1f
73 #ifndef WE_UKF_Q_VA_SCALE
74 #define WE_UKF_Q_VA_SCALE 0.0001f
77 #define WE_UKF_Q_WIND 0.001f
80 #ifndef SEND_WIND_ESTIMATOR
81 #define SEND_WIND_ESTIMATOR TRUE
91 pprz_msg_send_WIND_INFO_RET(trans,
dev, AC_ID,
99 #if PERIODIC_TELEMETRY
103 #ifndef LOG_WIND_ESTIMATOR
104 #define LOG_WIND_ESTIMATOR FALSE
107 #if LOG_WIND_ESTIMATOR
110 #define PrintLog sdLogWriteLog
111 #define LogFileIsOpen() (pprzLogFile != -1)
114 #define PrintLog fprintf
115 #define LogFileIsOpen() (pprzLogFile != NULL)
118 static bool log_we_started;
122 #define MAT_EL(_m, _l, _c, _n) _m[_l + _c * _n]
208 #if LOG_WIND_ESTIMATOR
209 if (LogFileIsOpen()) {
210 if (!log_we_started) {
215 for (i = 0; i < 7; i++)
219 for (i = 0; i < 5; i++)
226 PrintLog(
pprzLogFile,
"p q r ax ay az q1 q2 q3 q4 vkx vky vkz va aoa ssa u v w wx wy wz vas t\n");
227 log_we_started =
true;
229 PrintLog(
pprzLogFile,
"%.5f %.5f %.5f %.3f %.3f %.3f %.4f %.4f %.4f %.4f %.5f %.5f %.5f %.5f %.5f %.5f ",
272 #if LOG_WIND_ESTIMATOR
273 if (log_we_started) {
274 PrintLog(
pprzLogFile,
"%.3f %.3f %.3f %.3f %.3f %.3f %.3f %d\n",
297 if (chMtxTryLock(&we_ukf_mtx)) {
325 struct FloatVect3 gravity_ned = { 0.f, 0.f, 9.81f };
326 struct FloatVect3 gravity_body = { 0.f, 0.f, 0.f };
333 accel_body.
x += -9.81*sinf(b2i_e->
theta);
334 accel_body.
y += 9.81*cosf(b2i_e->
theta)*sinf(b2i_e->
phi);
335 accel_body.
z += 9.81*cosf(b2i_e->
theta)*cosf(b2i_e->
phi);
399 chMtxUnlock(&we_ukf_mtx);
401 chSemSignal(&we_ukf_sem);
415 if (chMtxTryLock(&we_ukf_mtx)) {
426 #if SEND_WIND_ESTIMATOR
433 chMtxUnlock(&we_ukf_mtx);
446 chRegSetThreadName(
"wind estimation");
450 chSemWait(&we_ukf_sem);
452 chMtxLock(&we_ukf_mtx);
456 chMtxUnlock(&we_ukf_mtx);
468 #if LOG_WIND_ESTIMATOR
469 log_we_started =
false;
475 snprintf(filename, 512,
"%s/we_ukf_%05d.csv", STRINGIFY(WE_LOG_PATH),
counter);
479 snprintf(filename, 512,
"%s/we_ukf_%05d.csv", STRINGIFY(WE_LOG_PATH), ++
counter);
483 printf(
"Failed to open WE log file '%s'\n",filename);
485 printf(
"Opening WE log file '%s'\n",filename);
492 chThdCreateStatic(wa_thd_windestimation,
sizeof(wa_thd_windestimation),
496 #if PERIODIC_TELEMETRY
void UKF_Wind_Estimator_initialize(void)
void UKF_Wind_Estimator_step(void)
ukf_params_type ukf_params
uint32_t get_sys_time_msec(void)
Get the time in milliseconds since startup.
Common code for AP and FBW telemetry.
static float float_vect3_norm(struct FloatVect3 *v)
void float_rmat_vmult(struct FloatVect3 *vb, struct FloatRMat *m_a2b, struct FloatVect3 *va)
rotate 3D vector by rotation matrix.
#define VECT3_ADD(_a, _b)
#define ACCELS_FLOAT_OF_BFP(_ef, _ei)
static struct NedCoor_f * stateGetAccelNed_f(void)
Get acceleration in NED coordinates (float).
static struct FloatRMat * stateGetNedToBodyRMat_f(void)
Get vehicle body attitude rotation matrix (float).
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
static struct FloatQuat * stateGetNedToBodyQuat_f(void)
Get vehicle body attitude quaternion (float).
static struct FloatRates * stateGetBodyRates_f(void)
Get vehicle body angular rate (float).
static struct NedCoor_f * stateGetSpeedNed_f(void)
Get ground speed in local NED coordinates (float).
static struct Int32Vect3 * stateGetAccelBody_i(void)
Get acceleration in Body coordinates (int).
static float stateGetSideslip_f(void)
Get sideslip (float).
static void stateSetVerticalWindspeed_f(uint16_t id, float v_windspeed)
Set vertical windspeed (float).
static float stateGetAirspeed_f(void)
Get airspeed (float).
static float stateGetAngleOfAttack_f(void)
Get angle of attack (float).
static void stateSetHorizontalWindspeed_f(uint16_t id, struct FloatVect2 *h_windspeed)
Set horizontal windspeed (float).
uint8_t msg[10]
Buffer used for general comunication over SPI (out buffer)
Inertial Measurement Unit interface.
Paparazzi floating point algebra.
Paparazzi floating point math for geodetic calculations.
API to get/set the generic vehicle states.
static const struct usb_device_descriptor dev
Architecture independent timing functions.
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 int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
void wind_estimator_periodic(void)
void wind_estimator_Set_Q_WIND(float _v)
static MUTEX_DECL(we_ukf_mtx)
void wind_estimator_Set_R_AOA(float _v)
#define MAT_EL(_m, _l, _c, _n)
static SEMAPHORE_DECL(we_ukf_sem, 0)
static void send_wind_estimator(struct transport_tx *trans, struct link_device *dev)
#define WE_UKF_KI
Default parameters.
void wind_estimator_Set_Q_VA_SCALE(float _v)
static void thd_windestimate(void *arg)
void wind_estimator_Set_R_SSA(float _v)
void init_calculator(void)
void wind_estimator_Set_R_VA(float _v)
void wind_estimator_Set_R_GS(float _v)
static THD_WORKING_AREA(wa_thd_windestimation, 8 *1024)
static void wind_estimator_step(void)
void wind_estimator_Set_Q_VA(float _v)
struct WindEstimator wind_estimator
#define WE_UKF_Q_VA_SCALE
void wind_estimator_init(void)
static uint32_t time_step_before
void wind_estimator_event(void)
Wind Estimator based on generated library from Matlab.
float q_va
noise associated to airspeed vector model
struct FloatVect3 wind
wind vector in NED frame
float r_va
noise associated to airspeed norm measurement
float q_wind
noise associated to wind vector model
bool data_available
new data available
bool reset
reset filter flag
float r_ssa
noise associated to sideslip angle measurement
float q_va_scale
noise associated to airspeed scale factor model
struct FloatVect3 airspeed
airspeed vector in body frame
float r_gs
noise associated to ground speed measurement
float r_aoa
noise associated to angle of attack measurement