25 #ifndef INCLUDED_EigenFilters_h_GUID_ECD959BF_587B_4ABB_30B3_E881B4520AC8 26 #define INCLUDED_EigenFilters_h_GUID_ECD959BF_587B_4ABB_30B3_E881B4520AC8 46 template <
typename Derived>
50 Derived ret = alpha * x + (1 - alpha) * hatx;
54 template <
typename Derived>
59 Derived ret = hatx.slerp(alpha, x).normalized();
72 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
76 value_type
const &
filter(value_type
const &x, scalar alpha) {
82 if (std::isfinite(alpha)) {
83 m_hatx = computeStep(hatx(), x, alpha);
88 value_type
const &hatx()
const {
return m_hatx; }
92 bool m_firstTime =
true;
105 auto tau =
T(1) / (
T(2) * M_PI * cutoff);
106 return T(1) / (
T(1) + tau / dt);
122 Params() : minCutoff(1), beta(0), derivativeCutoff(1) {}
123 Params(
double minCut,
double b = 0.5,
double dCut = 1)
124 : minCutoff(minCut), beta(b), derivativeCutoff(dCut) {}
141 dx = DerivativeType::Zero();
145 return (curr - prev) / dt;
155 using DerivativeType = Eigen::Vector3d;
156 static void setIdentity(DerivativeType &dx) {
157 dx = DerivativeType::Zero();
162 return util::quat_ln(curr * prev.
conjugate()) / dt;
164 static double computeMagnitude(DerivativeType
const &dx) {
186 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
191 auto dx = deriv_type{};
194 deriv::setIdentity(dx);
196 dx = deriv::compute(m_xFilter.hatx(), x, dt);
199 m_dxFilter.filter(dx, detail::computeAlpha<scalar>(
200 dt, m_params.derivativeCutoff));
202 auto dxMag = deriv::computeMagnitude(m_dxFilter.hatx());
204 auto cutoff = m_params.minCutoff + m_params.beta * dxMag;
207 return m_xFilter.filter(
208 x, detail::computeAlpha<scalar>(dt, cutoff));
211 value_type const &getState()
const {
return m_xFilter.hatx(); }
212 scalar getDerivativeMagnitude()
const {
213 return deriv::computeMagnitude(m_dxFilter.hatx());
217 bool m_firstTime =
true;
236 : m_positionFilter(positionFilterParams),
237 m_orientationFilter(oriFilterParams){};
240 Quat const &orientation) {
241 if (dt <= scalar(0)) {
245 m_positionFilter.filter(dt, position);
246 m_orientationFilter.filter(dt, orientation);
249 Vec3 const &getPosition()
const {
250 return m_positionFilter.getState();
253 scalar getLinearVelocityMagnitude()
const {
254 return m_positionFilter.getDerivativeMagnitude();
257 Quat const &getOrientation()
const {
258 return m_orientationFilter.getState();
261 scalar getAngularVelocityMagnitude()
const {
262 return m_orientationFilter.getDerivativeMagnitude();
284 #endif // INCLUDED_EigenFilters_h_GUID_ECD959BF_587B_4ABB_30B3_E881B4520AC8 Definition: RunLoopManager.h:42
Low pass filter (designed for use within the One Euro filter) that works with Eigen types...
Definition: EigenFilters.h:68
Parameters needed for the one-euro filter.
Definition: EigenFilters.h:121
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: TestIMU_Common.h:87
double minCutoff
Minimum cutoff frequency (in Hz) at "0" speed.
Definition: EigenFilters.h:127
Header wrapping include of <Eigen/Core> and <Eigen/Geometry> for warning quieting.
EIGEN_MAKE_ALIGNED_OPERATOR_NEW value_type const & filter(value_type const &x, scalar alpha)
Feeds in new data with the specified alpha.
Definition: EigenFilters.h:76
Definition: ForwardDeclarations.h:236
double derivativeCutoff
Cutoff frequency used for the low-pass filter applied to the derivative, in Hz.
Definition: EigenFilters.h:133
Default derivative traits: assumes derivative is same datatype as main data, identity is zeros...
Definition: EigenFilters.h:138
Definition: newuoa.h:1888
Filters for use with Eigen datatypes.
Definition: EigenFilters.h:43
double beta
Slope of cutoff frequency with respect to speed.
Definition: EigenFilters.h:129
Quaternion conjugate(void) const
Definition: Quaternion.h:395
Definition: ForwardDeclarations.h:233
Definition: Quaternion.h:47
Isometry3< typename Derived1::Scalar > makeIsometry(Eigen::MatrixBase< Derived1 > const &translation, Eigen::RotationBase< Derived2, 3 > const &rotation)
A simpler, functional-style alternative to .fromPositionOrientationScale when no scaling is performed...
Definition: EigenExtras.h:93
T computeAlpha(T dt, T cutoff)
Computing the alpha value for a step in the one euro filter for any scalar type.
Definition: EigenFilters.h:104
void filter(scalar dt, Vec3 const &position, Quat const &orientation)
Definition: EigenFilters.h:239
Combines a one-euro filter for position and a one-euro filter for orientation for the common use case...
Definition: EigenFilters.h:226
Quaternion< double > Quaterniond
double precision quaternion type
Definition: Quaternion.h:211
A simple filter designed for human input sources: high accuracy at low velocity, low latency at high ...
Definition: EigenFilters.h:180
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:127
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
double Scalar
Common scalar type.
Definition: FlexibleKalmanBase.h:48