state-observation 1.7.0
General implementation of observers.
Loading...
Searching...
No Matches
lipm-dcm-estimator.hpp
Go to the documentation of this file.
1
12#ifndef LIPMDCMBIASESTIMATOR_HPP
13#define LIPMDCMBIASESTIMATOR_HPP
14
15#include <state-observation/api.h>
19
20namespace stateObservation
21{
22
70
71class STATE_OBSERVATION_DLLAPI LipmDcmEstimator
72{
73private:
74 constexpr static double defaultDt_ = 0.005;
75 constexpr static double defaultOmega_ = tools::sqrt(cst::gravityConstant);
76
77public:
79 constexpr static double defaultBiasDriftSecond = 0.002;
80
82 constexpr static double defaultZmpErrorStd = 0.005;
83 constexpr static double defaultDcmErrorStd = 0.01;
84
86 constexpr static double defaultDCMUncertainty = 0.01;
87 constexpr static double defaultBiasUncertainty = 0.01;
88
90 constexpr static double defaultBiasLimit = -1;
91
108 LipmDcmEstimator(double dt = defaultDt_,
109 double omega_0 = defaultOmega_,
110 double biasDriftPerSecondStd = defaultBiasDriftSecond,
111 double dcmMeasureErrorStd = defaultDcmErrorStd,
112 double zmpMeasureErrorStd = defaultZmpErrorStd,
113 const Vector2 & biasLimit = Vector2::Constant(defaultBiasLimit),
114 const Vector2 & initZMP = Vector2::Zero(),
115 const Vector2 & initDcm = Vector2::Zero(),
116 const Vector2 & initBias = Vector2::Zero(),
117 const Vector2 & initDcmUncertainty = Vector2::Constant(defaultDCMUncertainty),
118 const Vector2 & initBiasUncertainty = Vector2::Constant(defaultBiasUncertainty));
119
131 void resetWithMeasurements(const Vector2 & measuredDcm,
132 const Vector2 & measuredZMP,
133 const Matrix2 & yaw = Matrix2::Identity(),
134 bool measurementIsWithBias = true,
135 const Vector2 & initBias = Vector2::Constant(0),
136 const Vector2 & initBiasuncertainty = Vector2::Constant(defaultBiasUncertainty));
137
149 inline void resetWithMeasurements(const Vector2 & measuredDcm,
150 const Vector2 & measuredZMP,
151 double yaw,
152 bool measurementIsWithBias = true,
153 const Vector2 & initBias = Vector2::Constant(0),
154 const Vector2 & initBiasuncertainty = Vector2::Constant(defaultBiasUncertainty))
155 {
156 resetWithMeasurements(measuredDcm, measuredZMP, Rotation2D(yaw).toRotationMatrix(), measurementIsWithBias, initBias,
157 initBiasuncertainty);
158 }
159
172 inline void resetWithMeasurements(const Vector2 & measuredDcm,
173 const Vector2 & measuredZMP,
174 const Matrix3 & rotation,
175 bool measurementIsWithBias = true,
176 const Vector2 & initBias = Vector2::Constant(0),
177 const Vector2 & initBiasuncertainty = Vector2::Constant(defaultBiasUncertainty))
178 {
179 resetWithMeasurements(measuredDcm, measuredZMP, kine::rotationMatrixToYawAxisAgnostic(rotation),
180 measurementIsWithBias, initBias, initBiasuncertainty);
181 }
182
185
189 void setLipmNaturalFrequency(double omega_0);
190
194 inline double getLipmNaturalFrequency() const
195 {
196 return omega0_;
197 }
198
205 void setUnbiasedCoMOffset(const Vector2 & gamma);
206
212 {
213 return gamma_;
214 }
215
218 void setZMPCoef(double kappa);
219
222 double getZMPCoef() const
223 {
224 return kappa_;
225 }
226
230 void setSamplingTime(double dt);
231
235 void setBias(const Vector2 & bias);
236
240 void setBias(const Vector2 & bias, const Vector2 & uncertainty);
241
245 void setBiasDriftPerSecond(double driftPerSecond);
246
251 void setBiasLimit(const Vector2 & biasLimit);
252
256 void setUnbiasedDCM(const Vector2 & dcm);
257
261 void setUnbiasedDCM(const Vector2 & dcm, const Vector2 & uncertainty);
262
266
270
281 inline void setInputs(const Vector2 & dcm,
282 const Vector2 & zmp,
283 const Matrix3 & orientation,
284 const Vector2 & CoMOffset_gamma = Vector2::Zero(),
285 const double ZMPCoef_kappa = 1)
286 {
287 setInputs(dcm, zmp, kine::rotationMatrixToYawAxisAgnostic(orientation), CoMOffset_gamma, ZMPCoef_kappa);
288 }
289
298 inline void setInputs(const Vector2 & dcm,
299 const Vector2 & zmp,
300 double yaw,
301 const Vector2 & CoMOffset_gamma = Vector2::Zero(),
302 const double ZMPCoef_kappa = 1)
303 {
304 setInputs(dcm, zmp, Rotation2D(yaw).toRotationMatrix(), CoMOffset_gamma, ZMPCoef_kappa);
305 }
306
314 void setInputs(const Vector2 & dcm,
315 const Vector2 & zmp,
316 const Matrix2 & R = Matrix2::Identity(),
317 const Vector2 & CoMOffset_gamma = Vector2::Zero(),
318 const double ZMPCoef_kappa = 1);
319
323 void update();
324
330
335
339 inline Vector2 getLocalBias() const
340 {
341 return previousOrientation_.transpose() * getBias();
342 }
343
348 {
349 return filter_;
350 }
351
354 inline const LinearKalmanFilter & getFilter() const
355 {
356 return filter_;
357 }
358
359protected:
360 typedef Eigen::Matrix<double, 4, 2> Matrix42;
361 typedef Eigen::Matrix<double, 2, 4> Matrix24;
362
365
366 double omega0_;
367 Vector2 gamma_ = Vector2::Zero();
368 double kappa_ = 1;
369 double dt_;
370 double biasDriftStd_;
371 double zmpErrorStd_;
372
373 bool needUpdateMatrices_ = true;
374
375 Vector2 previousZmp_;
376
377 Vector2 biasLimit_;
378
379 LinearKalmanFilter filter_;
380 Matrix4 A_;
381 Matrix4 B_;
383 Matrix24 C_;
388
389 Matrix2 previousOrientation_;
390
392 inline static Matrix2 Vec2ToSqDiag_(const Vector2 & v)
393 {
394 return Vector2(v.array().square()).asDiagonal();
395 }
396
398 inline static Matrix2 dblToDiag_(const double & d)
399 {
400 return Vector2::Constant(d).asDiagonal();
401 }
402
404 inline static Matrix2 dblToSqDiag_(const double & d)
405 {
406 return dblToDiag_(d * d);
407 }
408
409public:
410 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
411};
412
413} // namespace stateObservation
414
415#endif
The class of a Linear Kalman filter.
void setZMPCoef(double kappa)
Set the ZMP oefficient.
void setBias(const Vector2 &bias)
Set the Bias object from a guess.
void setZmpMeasureErrorStd(double)
Set the Zmp Measurement Error Stamdard devbiation.
void setLipmNaturalFrequency(double omega_0)
Set the Lipm Natural Frequency.
static constexpr double defaultZmpErrorStd
default error in the estimation of the sensors
double getZMPCoef() const
get the ZMP Coefficient
static constexpr double defaultBiasLimit
default value for Bias limit (negative means limitless)
~LipmDcmEstimator()
Destroy the Lipm Dcm Bias Estimator object.
static Matrix2 dblToSqDiag_(const double &d)
builds a constant 2x2 diagonal from a square of a double
Matrix24 C_
this needs to be transposed
void setBiasLimit(const Vector2 &biasLimit)
Set the Bias Limit.
double getLipmNaturalFrequency() const
Get the Lipm Natural Frequency.
Vector2 getLocalBias() const
Get the estimated Bias expressed in the local frame of the robot.
LipmDcmEstimator(double dt=defaultDt_, double omega_0=defaultOmega_, double biasDriftPerSecondStd=defaultBiasDriftSecond, double dcmMeasureErrorStd=defaultDcmErrorStd, double zmpMeasureErrorStd=defaultZmpErrorStd, const Vector2 &biasLimit=Vector2::Constant(defaultBiasLimit), const Vector2 &initZMP=Vector2::Zero(), const Vector2 &initDcm=Vector2::Zero(), const Vector2 &initBias=Vector2::Zero(), const Vector2 &initDcmUncertainty=Vector2::Constant(defaultDCMUncertainty), const Vector2 &initBiasUncertainty=Vector2::Constant(defaultBiasUncertainty))
Construct a new Lipm Dcm Estimator object.
static Matrix2 dblToDiag_(const double &d)
builds a constant 2x2 diagonal from a double
Vector2 getUnbiasedDCM() const
Get the Unbiased DCM filtered by the estimator.
void setUnbiasedDCM(const Vector2 &dcm)
set the unbiased DCM position from a guess
void setUnbiasedCoMOffset(const Vector2 &gamma)
Set an offset on the CoM dynamics.
void update()
Runs the estimation. Needs to be called every timestep.
void setInputs(const Vector2 &dcm, const Vector2 &zmp, const Matrix3 &orientation, const Vector2 &CoMOffset_gamma=Vector2::Zero(), const double ZMPCoef_kappa=1)
Set the Inputs of the estimator.
static Matrix2 Vec2ToSqDiag_(const Vector2 &v)
builds a diagonal out of the square valued of the Vec2
static constexpr double defaultDCMUncertainty
default uncertainty in the initial values of DCM and Bias
void setBias(const Vector2 &bias, const Vector2 &uncertainty)
Set the Bias object from a guess.
void setInputs(const Vector2 &dcm, const Vector2 &zmp, const Matrix2 &R=Matrix2::Identity(), const Vector2 &CoMOffset_gamma=Vector2::Zero(), const double ZMPCoef_kappa=1)
Set the Inputs of the estimator.
void updateMatricesABQ_()
set Matrices: A, B, Q
Vector2 getBias() const
Get the estimated Bias.
void resetWithMeasurements(const Vector2 &measuredDcm, const Vector2 &measuredZMP, double yaw, bool measurementIsWithBias=true, const Vector2 &initBias=Vector2::Constant(0), const Vector2 &initBiasuncertainty=Vector2::Constant(defaultBiasUncertainty))
Resets the estimator with first measurements.
Vector2 getUnbiasedCoMOffset() const
Get the ubiased offset on the CoM dynamics.
void setUnbiasedDCM(const Vector2 &dcm, const Vector2 &uncertainty)
void resetWithMeasurements(const Vector2 &measuredDcm, const Vector2 &measuredZMP, const Matrix2 &yaw=Matrix2::Identity(), bool measurementIsWithBias=true, const Vector2 &initBias=Vector2::Constant(0), const Vector2 &initBiasuncertainty=Vector2::Constant(defaultBiasUncertainty))
Resets the estimator with first measurements.
void setInputs(const Vector2 &dcm, const Vector2 &zmp, double yaw, const Vector2 &CoMOffset_gamma=Vector2::Zero(), const double ZMPCoef_kappa=1)
Set the Inputs of the estimator.
const LinearKalmanFilter & getFilter() const
Get the Kalman Filter object This can be used to run specific Advanced Kalman filter related funcions...
void setDcmMeasureErrorStd(double)
Set the Dcm Measurement Error Standard.
LinearKalmanFilter & getFilter()
Get the Kalman Filter object This can be used to run specific Advanced Kalman filter related funcions...
void resetWithMeasurements(const Vector2 &measuredDcm, const Vector2 &measuredZMP, const Matrix3 &rotation, bool measurementIsWithBias=true, const Vector2 &initBias=Vector2::Constant(0), const Vector2 &initBiasuncertainty=Vector2::Constant(defaultBiasUncertainty))
Resets the estimator with first measurements.
static constexpr double defaultBiasDriftSecond
default expected drift of the bias every second
void setSamplingTime(double dt)
Set the Sampling Time.
void setBiasDriftPerSecond(double driftPerSecond)
Set the Bias Drift Per Second.
Defines the class of a Linear Kalman filter.
Gathers many kinds of algorithms.
double constexpr sqrt(double x)
Constexpr version of the square root.
Filtering of divergent component of motion (DCM) and estimation of a bias betweeen the DCM and the co...
Eigen::Matrix4d Matrix4
4x4 Scalar Matrix
Eigen::Rotation2D< double > Rotation2D
2D rotations
Eigen::Matrix2d Matrix2
2D scalar Matrix
Eigen::Matrix3d Matrix3
3x3 Scalar Matrix
Eigen::Matrix< double, 2, 1 > Vector2
2d Vector
Implements integrators for the kinematics, in terms or rotations and translations.
double rotationMatrixToYawAxisAgnostic(const Matrix3 &rotation)
take 3x3 matrix represeting a rotation and gives a corresponding angle around upward vertical axis