49 gain_acc_(
Parameters::defaultImuFilterComplementaryGainAcc()),
50 bias_alpha_(
Parameters::defaultImuFilterComplementaryBiasAlpha()),
51 do_bias_estimation_(
Parameters::defaultImuFilterComplementaryDoBiasEstimation()),
52 do_adaptive_gain_(
Parameters::defaultImuFilterComplementaryDoAdpativeGain()),
55 q0_(1), q1_(0), q2_(0), q3_(0),
56 wx_prev_(0), wy_prev_(0), wz_prev_(0),
57 wx_bias_(0), wy_bias_(0), wz_bias_(0)
92 if (gain >= 0 && gain <= 1.0)
113 if (bias_alpha >= 0 && bias_alpha <= 1.0)
128 double qx,
double qy,
double qz,
double qw)
160 double gx,
double gy,
double gz,
161 double ax,
double ay,
double az,
175 UWARN(
"dt=%f <=0.0, orientation will not be updated!", dt);
184 double q0_pred, q1_pred, q2_pred, q3_pred;
186 q0_pred, q1_pred, q2_pred, q3_pred);
191 double dq0_acc, dq1_acc, dq2_acc, dq3_acc;
193 q0_pred, q1_pred, q2_pred, q3_pred,
194 dq0_acc, dq1_acc, dq2_acc, dq3_acc);
211 dq0_acc, dq1_acc, dq2_acc, dq3_acc,
218 double wx,
double wy,
double wz)
const 220 double acc_magnitude =
sqrt(ax*ax + ay*ay + az*az);
238 double wx,
double wy,
double wz)
255 double wx,
double wy,
double wz,
double dt,
256 double& q0_pred,
double& q1_pred,
double& q2_pred,
double& q3_pred)
const 262 q0_pred =
q0_ + 0.5*dt*( wx_unb*
q1_ + wy_unb*
q2_ + wz_unb*
q3_);
263 q1_pred =
q1_ + 0.5*dt*(-wx_unb*
q0_ - wy_unb*
q3_ + wz_unb*
q2_);
264 q2_pred =
q2_ + 0.5*dt*( wx_unb*
q3_ - wy_unb*
q0_ - wz_unb*
q1_);
265 q3_pred =
q3_ + 0.5*dt*(-wx_unb*
q2_ + wy_unb*
q1_ - wz_unb*
q0_);
271 double ax,
double ay,
double az,
272 double mx,
double my,
double mz,
273 double& q0_meas,
double& q1_meas,
double& q2_meas,
double& q3_meas)
278 double q0_acc, q1_acc, q2_acc, q3_acc;
284 q0_acc =
sqrt((az + 1) * 0.5);
285 q1_acc = -ay/(2.0 * q0_acc);
286 q2_acc = ax/(2.0 * q0_acc);
291 double X =
sqrt((1 - az) * 0.5);
292 q0_acc = -ay/(2.0 * X);
295 q3_acc = ax/(2.0 * X);
301 double lx = (q0_acc*q0_acc + q1_acc*q1_acc - q2_acc*q2_acc)*mx +
302 2.0 * (q1_acc*q2_acc)*my - 2.0 * (q0_acc*q2_acc)*mz;
303 double ly = 2.0 * (q1_acc*q2_acc)*mx + (q0_acc*q0_acc - q1_acc*q1_acc +
304 q2_acc*q2_acc)*my + 2.0 * (q0_acc*q1_acc)*mz;
308 double gamma = lx*lx + ly*ly;
309 double beta =
sqrt(gamma + lx*
sqrt(gamma));
310 double q0_mag = beta / (
sqrt(2.0 * gamma));
311 double q3_mag = ly / (
sqrt(2.0) * beta);
317 q0_mag, 0, 0, q3_mag,
318 q0_meas, q1_meas, q2_meas, q3_meas );
327 double ax,
double ay,
double az,
328 double& q0_meas,
double& q1_meas,
double& q2_meas,
double& q3_meas)
339 q0_meas =
sqrt((az + 1) * 0.5);
340 q1_meas = -ay/(2.0 * q0_meas);
341 q2_meas = ax/(2.0 * q0_meas);
346 double X =
sqrt((1 - az) * 0.5);
347 q0_meas = -ay/(2.0 * X);
350 q3_meas = ax/(2.0 * X);
355 double ax,
double ay,
double az,
356 double p0,
double p1,
double p2,
double p3,
357 double& dq0,
double& dq1,
double& dq2,
double& dq3)
370 dq0 =
sqrt((gz + 1) * 0.5);
371 dq1 = -gy/(2.0 * dq0);
372 dq2 = gx/(2.0 * dq0);
377 double& qx,
double& qy,
double& qz,
double& qw)
const 385 double a_mag =
sqrt(ax*ax + ay*ay + az*az);
390 double m = 1.0/(error1 - error2);
391 double b = 1.0 - m*error1;
394 else if (error < error2)
395 factor = m*error + b;
404 double norm =
sqrt(x*x + y*y + z*z);
413 double norm =
sqrt(q0*q0 + q1*q1 + q2*q2 + q3*q3);
421 double q0,
double q1,
double q2,
double q3,
422 double& q0_inv,
double& q1_inv,
double& q2_inv,
double& q3_inv)
433 double& dq0,
double& dq1,
double& dq2,
double& dq3)
439 double A =
sin(angle*(1.0 - gain))/
sin(angle);
440 double B =
sin(angle * gain)/
sin(angle);
449 dq0 = (1.0 - gain) + gain * dq0;
459 double p0,
double p1,
double p2,
double p3,
460 double q0,
double q1,
double q2,
double q3,
461 double& r0,
double& r1,
double& r2,
double& r3)
464 r0 = p0*q0 - p1*q1 - p2*q2 - p3*q3;
465 r1 = p0*q1 + p1*q0 + p2*q3 - p3*q2;
466 r2 = p0*q2 - p1*q3 + p2*q0 + p3*q1;
467 r3 = p0*q3 + p1*q2 - p2*q1 + p3*q0;
471 double x,
double y,
double z,
472 double q0,
double q1,
double q2,
double q3,
473 double& vx,
double& vy,
double& vz)
475 vx = (q0*q0 + q1*q1 - q2*q2 - q3*q3)*x + 2*(q1*q2 - q0*q3)*y + 2*(q1*q3 + q0*q2)*z;
476 vy = 2*(q1*q2 + q0*q3)*x + (q0*q0 - q1*q1 + q2*q2 - q3*q3)*y + 2*(q2*q3 - q0*q1)*z;
477 vz = 2*(q1*q3 - q0*q2)*x + 2*(q2*q3 + q0*q1)*y + (q0*q0 - q1*q1 - q2*q2 + q3*q3)*z;
void updateBiases(double ax, double ay, double az, double wx, double wy, double wz)
virtual void reset(double qx=0.0, double qy=0.0, double qz=0.0, double qw=1.0)
static bool parse(const ParametersMap ¶meters, const std::string &key, bool &value)
void invertQuaternion(double q0, double q1, double q2, double q3, double &q0_inv, double &q1_inv, double &q2_inv, double &q3_inv)
static const double kAccelerationThreshold
GLM_FUNC_DECL vecType< T, P > sqrt(vecType< T, P > const &x)
double getAngularVelocityBiasY() const
std::map< std::string, std::string > ParametersMap
double getAngularVelocityBiasZ() const
void normalizeQuaternion(double &q0, double &q1, double &q2, double &q3)
GLM_FUNC_DECL T angle(detail::tquat< T, P > const &x)
virtual void getOrientation(double &qx, double &qy, double &qz, double &qw) const
void getMeasurement(double ax, double ay, double az, double &q0_meas, double &q1_meas, double &q2_meas, double &q3_meas)
static const double gamma_
virtual void parseParameters(const ParametersMap ¶meters)
static const double kDeltaAngularVelocityThreshold
GLM_FUNC_DECL genType sin(genType const &angle)
void quaternionMultiplication(double p0, double p1, double p2, double p3, double q0, double q1, double q2, double q3, double &r0, double &r1, double &r2, double &r3)
bool getDoAdaptiveGain() const
double getBiasAlpha() const
void setDoAdaptiveGain(bool do_adaptive_gain)
bool checkState(double ax, double ay, double az, double wx, double wy, double wz) const
bool getSteadyState() const
bool setBiasAlpha(double bias_alpha)
void scaleQuaternion(double gain, double &dq0, double &dq1, double &dq2, double &dq3)
void normalizeVector(double &x, double &y, double &z)
bool setGainAcc(double gain)
virtual void updateImpl(double gx, double gy, double gz, double ax, double ay, double az, double dt)
ULogger class and convenient macros.
GLM_FUNC_DECL genType acos(genType const &x)
ComplementaryFilter(const ParametersMap ¶meters=ParametersMap())
double getGainAcc() const
bool getDoBiasEstimation() const
void rotateVectorByQuaternion(double x, double y, double z, double q0, double q1, double q2, double q3, double &vx, double &vy, double &vz)
double getAdaptiveGain(double alpha, double ax, double ay, double az)
double getAngularVelocityBiasX() const
void setDoBiasEstimation(bool do_bias_estimation)
void getPrediction(double wx, double wy, double wz, double dt, double &q0_pred, double &q1_pred, double &q2_pred, double &q3_pred) const
void getAccCorrection(double ax, double ay, double az, double p0, double p1, double p2, double p3, double &dq0, double &dq1, double &dq2, double &dq3)
static const double kGravity
static const double kAngularVelocityThreshold