Skip to content

Commit

Permalink
EKF: split delta velocity accumulztation get and reset functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Martin committed Dec 16, 2024
1 parent 44e4393 commit 5c1a6bc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/modules/ekf2/EKF/estimator_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,9 @@ class EstimatorInterface
float getUnaidedYaw() const { return _output_predictor.getUnaidedYaw(); }
Vector3f getVelocity() const { return _output_predictor.getVelocity(); }

// get the mean velocity derivative in earth frame since last call
Vector3f getVelocityDerivative() { 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
14 changes: 8 additions & 6 deletions src/modules/ekf2/EKF/output_predictor/output_predictor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,16 +390,18 @@ void OutputPredictor::applyCorrectionToOutputBuffer(const Vector3f &vel_correcti
_output_new = _output_buffer.get_newest();
}

matrix::Vector3f OutputPredictor::getVelocityDerivative()
matrix::Vector3f OutputPredictor::getVelocityDerivative() const
{
matrix::Vector3f vel_deriv(0.f, 0.f, 0.f);

if (_delta_vel_dt > FLT_EPSILON) {
vel_deriv = _delta_vel_sum / _delta_vel_dt;
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();

return vel_deriv;
}
7 changes: 5 additions & 2 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,11 @@ 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 mean velocity derivative in earth frame since last call
matrix::Vector3f getVelocityDerivative();
// get the mean velocity derivative in earth frame since reset (see `resetVelocityDerivativeAccumulation()`)
matrix::Vector3f getVelocityDerivative() const;

// reset the velocity derivative accumulation
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
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 5c1a6bc

Please sign in to comment.