Skip to content

Commit

Permalink
local position acceleration: use mean value between two publications (#…
Browse files Browse the repository at this point in the history
…24105)

To avoid aliasing on the ned acceleration, add an accumulation of acceleration to improve the downsampling
  • Loading branch information
NicolasM0 authored Jan 3, 2025
1 parent c1589dd commit 4fe6d69
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/modules/ekf2/EKF/estimator_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,10 @@ class EstimatorInterface
const matrix::Quatf &getQuaternion() const { return _output_predictor.getQuaternion(); }
float getUnaidedYaw() const { return _output_predictor.getUnaidedYaw(); }
Vector3f getVelocity() const { return _output_predictor.getVelocity(); }
const Vector3f &getVelocityDerivative() const { return _output_predictor.getVelocityDerivative(); }

// get the mean velocity derivative in earth frame since last reset (see `resetVelocityDerivativeAccumulation()`)
Vector3f getVelocityDerivative() const { return _output_predictor.getVelocityDerivative(); }
void resetVelocityDerivativeAccumulation() { return _output_predictor.resetVelocityDerivativeAccumulation(); }
float getVerticalPositionDerivative() const { return _output_predictor.getVerticalPositionDerivative(); }
Vector3f getPosition() const;
LatLonAlt getLatLonAlt() const { return _output_predictor.getLatLonAlt(); }
Expand Down
24 changes: 20 additions & 4 deletions src/modules/ekf2/EKF/output_predictor/output_predictor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ void OutputPredictor::reset()

_R_to_earth_now.setIdentity();
_vel_imu_rel_body_ned.setZero();
_vel_deriv.setZero();
_delta_vel_sum.setZero();
_delta_vel_dt = 0.f;

_delta_angle_corr.setZero();

Expand Down Expand Up @@ -210,9 +211,8 @@ void OutputPredictor::calculateOutputStates(const uint64_t time_us, const Vector
delta_vel_earth(2) += CONSTANTS_ONE_G * delta_velocity_dt;

// calculate the earth frame velocity derivatives
if (delta_velocity_dt > 0.001f) {
_vel_deriv = delta_vel_earth / delta_velocity_dt;
}
_delta_vel_sum += delta_vel_earth;
_delta_vel_dt += delta_velocity_dt;

// save the previous velocity so we can use trapezoidal integration
const Vector3f vel_last(_output_new.vel);
Expand Down Expand Up @@ -389,3 +389,19 @@ void OutputPredictor::applyCorrectionToOutputBuffer(const Vector3f &vel_correcti
// update output state to corrected values
_output_new = _output_buffer.get_newest();
}

matrix::Vector3f OutputPredictor::getVelocityDerivative() const
{
if (_delta_vel_dt > FLT_EPSILON) {
return _delta_vel_sum / _delta_vel_dt;

} else {
return matrix::Vector3f(0.f, 0.f, 0.f);
}
}

void OutputPredictor::resetVelocityDerivativeAccumulation()
{
_delta_vel_dt = 0.f;
_delta_vel_sum.setZero();
}
9 changes: 6 additions & 3 deletions src/modules/ekf2/EKF/output_predictor/output_predictor.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ class OutputPredictor
// get the velocity of the body frame origin in local NED earth frame
matrix::Vector3f getVelocity() const { return _output_new.vel - _vel_imu_rel_body_ned; }

// get the velocity derivative in earth frame
const matrix::Vector3f &getVelocityDerivative() const { return _vel_deriv; }
// get the mean velocity derivative in earth frame since reset (see `resetVelocityDerivativeAccumulation()`)
matrix::Vector3f getVelocityDerivative() const;

void resetVelocityDerivativeAccumulation();

// get the derivative of the vertical position of the body frame origin in local NED earth frame
float getVerticalPositionDerivative() const { return _output_vert_new.vert_vel - _vel_imu_rel_body_ned(2); }
Expand Down Expand Up @@ -178,7 +180,8 @@ class OutputPredictor
outputVert _output_vert_new{}; // vertical filter output on the non-delayed time horizon
matrix::Matrix3f _R_to_earth_now{}; // rotation matrix from body to earth frame at current time
matrix::Vector3f _vel_imu_rel_body_ned{}; // velocity of IMU relative to body origin in NED earth frame
matrix::Vector3f _vel_deriv{}; // velocity derivative at the IMU in NED earth frame (m/s/s)
matrix::Vector3f _delta_vel_sum{}; // accumulation of delta velocity at the IMU in NED earth frame (m/s/s)
float _delta_vel_dt{}; // duration of delta velocity integration (s)

// output predictor states
matrix::Vector3f _delta_angle_corr{}; ///< delta angle correction vector (rad)
Expand Down
1 change: 1 addition & 0 deletions src/modules/ekf2/EKF2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1556,6 +1556,7 @@ void EKF2::PublishLocalPosition(const hrt_abstime &timestamp)

// Acceleration of body origin in local frame
const Vector3f vel_deriv{_ekf.getVelocityDerivative()};
_ekf.resetVelocityDerivativeAccumulation();
lpos.ax = vel_deriv(0);
lpos.ay = vel_deriv(1);
lpos.az = vel_deriv(2);
Expand Down

0 comments on commit 4fe6d69

Please sign in to comment.