Browse Source

AP_Math: added calc_lowpass_alpha_dt()

used in several places
c415-sdk
Andrew Tridgell 4 years ago
parent
commit
cdcf32d22c
  1. 12
      libraries/AP_Math/AP_Math.cpp
  2. 5
      libraries/AP_Math/AP_Math.h

12
libraries/AP_Math/AP_Math.cpp

@ -382,6 +382,18 @@ Vector3f get_vel_correction_for_sensor_offset(const Vector3f &sensor_offset_bf, @@ -382,6 +382,18 @@ Vector3f get_vel_correction_for_sensor_offset(const Vector3f &sensor_offset_bf,
return rot_ef_to_bf.mul_transpose(vel_offset_body) * -1.0f;
}
/*
calculate a low pass filter alpha value
*/
float calc_lowpass_alpha_dt(float dt, float cutoff_freq)
{
if (dt <= 0.0f || cutoff_freq <= 0.0f) {
return 1.0;
}
float rc = 1.0f/(M_2PI*cutoff_freq);
return constrain_float(dt/(dt+rc), 0.0f, 1.0f);
}
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
// fill an array of float with NaN, used to invalidate memory in SITL
void fill_nanf(float *f, uint16_t count)

5
libraries/AP_Math/AP_Math.h

@ -290,6 +290,11 @@ bool rotation_equal(enum Rotation r1, enum Rotation r2) WARN_IF_UNUSED; @@ -290,6 +290,11 @@ bool rotation_equal(enum Rotation r1, enum Rotation r2) WARN_IF_UNUSED;
*/
Vector3f get_vel_correction_for_sensor_offset(const Vector3f &sensor_offset_bf, const Matrix3f &rot_ef_to_bf, const Vector3f &angular_rate);
/*
calculate a low pass filter alpha value
*/
float calc_lowpass_alpha_dt(float dt, float cutoff_freq);
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
// fill an array of float with NaN, used to invalidate memory in SITL
void fill_nanf(float *f, uint16_t count);

Loading…
Cancel
Save