state-observation 1.7.0
General implementation of observers.
Loading...
Searching...
No Matches
zmp-tracking-gain-estimator.hpp
1
12#ifndef ZMPTRACKINGGAINESTIMATOR_HPP
13#define ZMPTRACKINGGAINESTIMATOR_HPP
14
15#include <state-observation/api.h>
19
20namespace stateObservation
21{
22
26
27class STATE_OBSERVATION_DLLAPI ZmpTrackingGainEstimator
28{
29private:
30 constexpr static double defaultDt_ = 0.005;
31 constexpr static double defaultGain_ = 1;
32
33public:
35 constexpr static double defaultGainDriftSecond = 0.002;
36
38 constexpr static double defaultZmpProcessErrorStd = 0.005;
39
41 constexpr static double defaultZmpMeasurementErrorStd = 0.005;
42
45 constexpr static double defaultGainMinimum = .01;
46
48 constexpr static double defaultZmpUncertainty = 0.005;
49
51 constexpr static double defaultGainUncertainty = 20;
52
69 ZmpTrackingGainEstimator(double dt = defaultDt_,
70 const Vector2 & zmpMeasureErrorStd = Vector2::Constant(defaultZmpMeasurementErrorStd),
71 const Vector3 & gainDriftPerSecond = Vector3::Constant(defaultGainDriftSecond),
72 const Vector2 & zmpProcessErrorStd = Vector2::Constant(defaultZmpProcessErrorStd),
73 double minimumGain = defaultGainMinimum,
74 const Vector2 & initZMP = Vector2::Zero(),
75 const Vector3 & initGain = Vector3::Zero(),
76 const Vector2 & initZMPUncertainty = Vector2::Constant(defaultZmpUncertainty),
77 const Vector3 & initGainUncertainty = Vector3::Constant(defaultGainUncertainty));
78
88 void resetWithMeasurements(const Vector2 & initZMP = Vector2::Zero(),
89 const Vector3 & initGain = Vector3::Zero(),
90 const Matrix2 & yaw = Matrix2::Identity(),
91 const Vector2 & initZMPUncertainty = Vector2::Constant(defaultZmpUncertainty),
92 const Vector3 & initGainUncertainty = Vector3::Constant(defaultGainUncertainty));
93
103 inline void resetWithMeasurements(const Vector2 & initZMP,
104 const Vector3 & initGain,
105 double yaw,
106 const Vector2 & initZMPUncertainty = Vector2::Constant(defaultZmpUncertainty),
107 const Vector3 & initGainUncertainty = Vector3::Constant(defaultGainUncertainty))
108 {
109 resetWithMeasurements(initZMP, initGain, Rotation2D(yaw).toRotationMatrix(), initZMPUncertainty,
110 initGainUncertainty);
111 }
112
124 inline void resetWithMeasurements(const Vector2 & initZMP,
125 const Vector3 & initGain,
126 const Matrix3 & rotation,
127 const Vector2 & initZMPUncertainty = Vector2::Constant(defaultZmpUncertainty),
128 const Vector3 & initGainUncertainty = Vector3::Constant(defaultGainUncertainty))
129 {
130 resetWithMeasurements(initZMP, initGain, kine::rotationMatrixToYawAxisAgnostic(rotation), initZMPUncertainty,
131 initGainUncertainty);
132 }
133
136
140 void setSamplingTime(double dt);
141
146 void setGain(const Vector3 & gain);
147
151 void setGain(const Vector3 & gain, const Vector3 & uncertainty);
152
158
162 void setMinimumGain(const double & minGain);
163
168
172
182 inline void setInputs(const Vector2 & zmpErr, const Vector2 & zmp, const Matrix3 & orientation)
183 {
184 setInputs(zmpErr, zmp, kine::rotationMatrixToYawAxisAgnostic(orientation));
185 }
186
193 inline void setInputs(const Vector2 & zmpErr, const Vector2 & zmp, double yaw)
194 {
195 setInputs(zmpErr, zmp, Rotation2D(yaw).toRotationMatrix());
196 }
197
203 void setInputs(const Vector2 & zmpErr, const Vector2 & zmp, const Matrix2 & R = Matrix2::Identity());
204
208 void update();
209
215 {
217 return (previousOrientation_ * getEstimatedLocalGain().triangularView<Eigen::Upper>()
218 * previousOrientation_.transpose())
219 .selfadjointView<Eigen::Upper>();
220 }
221
226
231 {
232 return filter_;
233 }
234
237 inline const LinearKalmanFilter & getFilter() const
238 {
239 return filter_;
240 }
241
242protected:
243 typedef Eigen::Matrix<double, 2, 5> Matrix25;
244 typedef Eigen::Matrix<double, 2, 3> Matrix23;
245
246 double dt_;
247
248 double minimumGain_;
249
250 Vector2 zmpMeasureErrorstd_;
251 Vector3 gainDriftPerSecondStd_;
252 Vector2 zmpProcessErrorStd_;
253
254 Matrix2 yaw_;
255
256 LinearKalmanFilter filter_;
257 Matrix4 A_;
259 Matrix25 C_;
260
263
266
267 Matrix2 previousOrientation_;
268
270 inline static Matrix2 Vec2ToSqDiag_(const Vector2 & v)
271 {
272 return Vector2(v.array().square()).asDiagonal();
273 }
274
276 inline static Matrix3 Vec3ToSqDiag_(const Vector3 & v)
277 {
278 return Vector3(v.array().square()).asDiagonal();
279 }
280
281 inline void updateR_()
282 {
283 R_ = Vec2ToSqDiag_(zmpMeasureErrorstd_);
284 filter_.setMeasurementCovariance(R_);
285 }
286
287 inline void updateQ_()
288 {
289 Q_.topLeftCorner<2, 2>() = Vec2ToSqDiag_(zmpProcessErrorStd_);
290 Q_.bottomRightCorner<3, 3>() = Vec3ToSqDiag_(gainDriftPerSecondStd_);
291 filter_.setProcessCovariance(Q_);
292 }
293
294public:
295 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
296};
297
298} // namespace stateObservation
299
300#endif
The class of a Linear Kalman filter.
~ZmpTrackingGainEstimator()
Destroy the Lipm Dcm Bias Estimator object.
void setGain(const Vector3 &gain, const Vector3 &uncertainty)
Set the Gain from a guess.
void setInputs(const Vector2 &zmpErr, const Vector2 &zmp, const Matrix2 &R=Matrix2::Identity())
Set the Inputs of the estimator.
void setGainDriftPerSecond(const Vector3 &)
Set the Gain Drift Per Second.
static constexpr double defaultZmpMeasurementErrorStd
default error in the measurements of the zmp
void update()
Runs the estimation. Needs to be called every timestep.
static constexpr double defaultGainUncertainty
default value for the uncertainty of the Gain
void resetWithMeasurements(const Vector2 &initZMP=Vector2::Zero(), const Vector3 &initGain=Vector3::Zero(), const Matrix2 &yaw=Matrix2::Identity(), const Vector2 &initZMPUncertainty=Vector2::Constant(defaultZmpUncertainty), const Vector3 &initGainUncertainty=Vector3::Constant(defaultGainUncertainty))
Resets the estimator.
void setGain(const Vector3 &gain)
Set the Gain from a guess.
Matrix2 getEstimatedGain() const
Get the Unbiased DCM filtered by the estimator.
void setZMPProcesError(const Vector2 &)
Set the covariance of the zmp process linear dynamics error.
static constexpr double defaultZmpUncertainty
default valu for the initial ZMP uncertainty. It should be quite low since this is supposed to be mea...
void setMinimumGain(const double &minGain)
Set the Gain Limit.
static constexpr double defaultGainDriftSecond
default expected drift of the bias every second
void resetWithMeasurements(const Vector2 &initZMP, const Vector3 &initGain, double yaw, const Vector2 &initZMPUncertainty=Vector2::Constant(defaultZmpUncertainty), const Vector3 &initGainUncertainty=Vector3::Constant(defaultGainUncertainty))
Resets the estimator.
void setSamplingTime(double dt)
Set the Sampling Time.
LinearKalmanFilter & getFilter()
Get the Kalman Filter object This can be used to run specific Advanced Kalman filter related funcions...
Matrix2 getEstimatedLocalGain() const
Get the estimated Bias expressed in the local frame of the robot.
ZmpTrackingGainEstimator(double dt=defaultDt_, const Vector2 &zmpMeasureErrorStd=Vector2::Constant(defaultZmpMeasurementErrorStd), const Vector3 &gainDriftPerSecond=Vector3::Constant(defaultGainDriftSecond), const Vector2 &zmpProcessErrorStd=Vector2::Constant(defaultZmpProcessErrorStd), double minimumGain=defaultGainMinimum, const Vector2 &initZMP=Vector2::Zero(), const Vector3 &initGain=Vector3::Zero(), const Vector2 &initZMPUncertainty=Vector2::Constant(defaultZmpUncertainty), const Vector3 &initGainUncertainty=Vector3::Constant(defaultGainUncertainty))
Construct a new ZMP Gain Estimator object.
void setInputs(const Vector2 &zmpErr, const Vector2 &zmp, const Matrix3 &orientation)
Set the Inputs of the estimator.
static constexpr double defaultZmpProcessErrorStd
default error in the process linear dynamics of the zmp (in meters)
static Matrix3 Vec3ToSqDiag_(const Vector3 &v)
builds a diagonal out of the square valued of the Vec3
void resetWithMeasurements(const Vector2 &initZMP, const Vector3 &initGain, const Matrix3 &rotation, const Vector2 &initZMPUncertainty=Vector2::Constant(defaultZmpUncertainty), const Vector3 &initGainUncertainty=Vector3::Constant(defaultGainUncertainty))
Resets the estimator with first measurements.
void setZmpMeasureErrorStd(const Vector2 &)
Set the Zmp Measurement Error Stamdard deviation.
void setInputs(const Vector2 &zmpErr, const Vector2 &zmp, double yaw)
Set the Inputs of the estimator.
static Matrix2 Vec2ToSqDiag_(const Vector2 &v)
builds a diagonal out of the square valued of the Vec2
const LinearKalmanFilter & getFilter() const
Get the Kalman Filter object This can be used to run specific Advanced Kalman filter related funcions...
Defines the class of a Linear Kalman filter.
Gathers many kinds of algorithms.
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::Vector3d Vector3
3D vector
Eigen::Matrix3d Matrix3
3x3 Scalar Matrix
Eigen::Matrix< double, 5, 5 > Matrix5
5x5 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