5 printf(
"beans 0x%lx\n", (uint64_t)
this);
6 printf(
"beans2 0x%lx\n", (uint64_t) & (this->_stateEstimatorData));
7 printf(
"beans3 0x%lx\n", (uint64_t)(this->_stateEstimatorData.parameters));
8 printf(
"beans4 0x%lx\n",
9 (uint64_t) & (this->_stateEstimatorData.parameters->controller_dt));
10 T dt = this->_stateEstimatorData.parameters->controller_dt;
11 printf(
"Initialize LinearKF State Estimator with dt = %.3f\n", dt);
16 _A.block(0, 0, 3, 3) = Eigen::Matrix<T, 3, 3>::Identity();
17 _A.block(0, 3, 3, 3) = dt * Eigen::Matrix<T, 3, 3>::Identity();
18 _A.block(3, 3, 3, 3) = Eigen::Matrix<T, 3, 3>::Identity();
19 _A.block(6, 6, 12, 12) = Eigen::Matrix<T, 12, 12>::Identity();
21 _B.block(3, 0, 3, 3) = dt * Eigen::Matrix<T, 3, 3>::Identity();
22 Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> C1(3, 6);
23 C1 << Eigen::Matrix<T, 3, 3>::Identity(), Eigen::Matrix<T, 3, 3>::Zero();
24 Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> C2(3, 6);
25 C2 << Eigen::Matrix<T, 3, 3>::Zero(), Eigen::Matrix<T, 3, 3>::Identity();
27 _C.block(0, 0, 3, 6) = C1;
28 _C.block(3, 0, 3, 6) = C1;
29 _C.block(6, 0, 3, 6) = C1;
30 _C.block(9, 0, 3, 6) = C1;
31 _C.block(0, 6, 12, 12) = T(-1) * Eigen::Matrix<T, 12, 12>::Identity();
32 _C.block(12, 0, 3, 6) = C2;
33 _C.block(15, 0, 3, 6) = C2;
34 _C.block(18, 0, 3, 6) = C2;
35 _C.block(21, 0, 3, 6) = C2;
43 _Q0.block(0, 0, 3, 3) = (dt / 20.f) * Eigen::Matrix<T, 3, 3>::Identity();
44 _Q0.block(3, 3, 3, 3) =
45 (dt * 9.8f / 20.f) * Eigen::Matrix<T, 3, 3>::Identity();
46 _Q0.block(6, 6, 12, 12) = dt * Eigen::Matrix<T, 12, 12>::Identity();
55 T process_noise_pimu =
56 this->_stateEstimatorData.parameters->imu_process_noise_position;
57 T process_noise_vimu =
58 this->_stateEstimatorData.parameters->imu_process_noise_velocity;
59 T process_noise_pfoot =
60 this->_stateEstimatorData.parameters->foot_process_noise_position;
61 T sensor_noise_pimu_rel_foot =
62 this->_stateEstimatorData.parameters->foot_sensor_noise_position;
63 T sensor_noise_vimu_rel_foot =
64 this->_stateEstimatorData.parameters->foot_sensor_noise_velocity;
65 T sensor_noise_zfoot =
66 this->_stateEstimatorData.parameters->foot_height_sensor_noise;
68 Eigen::Matrix<T, 18, 18> Q = Eigen::Matrix<T, 18, 18>::Identity();
69 Q.block(0, 0, 3, 3) = _Q0.block(0, 0, 3, 3) * process_noise_pimu;
70 Q.block(3, 3, 3, 3) = _Q0.block(3, 3, 3, 3) * process_noise_vimu;
71 Q.block(6, 6, 12, 12) = _Q0.block(6, 6, 12, 12) * process_noise_pfoot;
73 Eigen::Matrix<T, 28, 28> R = Eigen::Matrix<T, 28, 28>::Identity();
74 R.block(0, 0, 12, 12) = _R0.block(0, 0, 12, 12) * sensor_noise_pimu_rel_foot;
75 R.block(12, 12, 12, 12) =
76 _R0.block(12, 12, 12, 12) * sensor_noise_vimu_rel_foot;
77 R.block(24, 24, 4, 4) = _R0.block(24, 24, 4, 4) * sensor_noise_zfoot;
85 Mat3<T> Rbod = this->_stateEstimatorData.result->rBody.transpose();
86 Vec3<T> a = this->_stateEstimatorData.result->aWorld +
92 p0 << _xhat[0], _xhat[1], _xhat[2];
93 v0 << _xhat[3], _xhat[4], _xhat[5];
95 for (
int i = 0; i < 4; i++) {
98 *(this->_stateEstimatorData.legControllerData->quadruped);
100 Vec3<T> p_rel = ph + this->_stateEstimatorData.legControllerData[i]
102 Vec3<T> dp_rel = this->_stateEstimatorData.legControllerData[i]
107 (this->_stateEstimatorData.result->omegaBody.cross(p_rel) + dp_rel);
115 T phase = fmin(this->_stateEstimatorData.result->contactEstimate(i), T(1));
116 T trust_window = T(0.2);
118 if (phase < trust_window) {
119 trust = phase / trust_window;
120 }
else if (phase > (T(1) - trust_window)) {
121 trust = (T(1) - phase) / trust_window;
125 Q.block(qindex, qindex, 3, 3) =
126 (T(1) + (T(1) - trust) * T(100)) * Q.block(qindex, qindex, 3, 3);
127 R.block(rindex1, rindex1, 3, 3) = 1 * R.block(rindex1, rindex1, 3, 3);
128 R.block(rindex2, rindex2, 3, 3) =
129 (T(1) + (T(1) - trust) * 100.0
f) * R.block(rindex2, rindex2, 3, 3);
130 R(rindex3, rindex3) =
131 (T(1) + (T(1) - trust) * T(100)) * R(rindex3, rindex3);
135 _ps.segment(i1, 3) = -p_f;
136 _vs.segment(i1, 3) = (1.0f - trust) * v0 + trust * (-dp_f);
137 pzs(i) = (1.0f - trust) * (p0(2) + p_f(2));
141 Eigen::Matrix<T, 28, 1> y;
143 _xhat = _A * _xhat + _B * a;
144 Eigen::Matrix<T, 18, 18> At = _A.transpose();
145 Eigen::Matrix<T, 18, 18> Pm = _A * _P * At + Q;
146 Eigen::Matrix<T, 18, 28> Ct = _C.transpose();
147 Eigen::Matrix<T, 28, 1> yModel = _C * _xhat;
148 Eigen::Matrix<T, 28, 1> ey = y - yModel;
149 Eigen::Matrix<T, 28, 28> S = _C * Pm * Ct + R;
152 Eigen::Matrix<T, 28, 1> S_ey = S.lu().solve(ey);
153 _xhat += Pm * Ct * S_ey;
155 Eigen::Matrix<T, 28, 18> S_C = S.lu().solve(_C);
156 _P = (Eigen::Matrix<T, 18, 18>::Identity() - Pm * Ct * S_C) * Pm;
158 Eigen::Matrix<T, 18, 18> Pt = _P.transpose();
159 _P = (_P + Pt) / T(2);
161 if (_P.block(0, 0, 2, 2).determinant() > T(0.000001)) {
162 _P.block(0, 2, 2, 16).setZero();
163 _P.block(2, 0, 16, 2).setZero();
164 _P.block(0, 0, 2, 2) /= T(10);
167 this->_stateEstimatorData.result->position = _xhat.block(0, 0, 3, 1);
168 this->_stateEstimatorData.result->vWorld = _xhat.block(3, 0, 3, 1);
169 this->_stateEstimatorData.result->vBody =
170 this->_stateEstimatorData.result->rBody *
171 this->_stateEstimatorData.result->vWorld;
179 template <
typename T>
181 this->_stateEstimatorData.result->position = this->_stateEstimatorData.cheaterState->position.template cast<T>();
182 this->_stateEstimatorData.result->vWorld =
183 this->_stateEstimatorData.result->rBody.transpose().template cast<T>() * this->_stateEstimatorData.cheaterState->vBody.template cast<T>();
184 this->_stateEstimatorData.result->vBody = this->_stateEstimatorData.cheaterState->vBody.template cast<T>();
typename Eigen::Matrix< T, 3, 3 > Mat3
typename Eigen::Matrix< T, 3, 1 > Vec3
EIGEN_MAKE_ALIGNED_OPERATOR_NEW LinearKFPositionVelocityEstimator()
Vec3< T > getHipLocation(int leg)
typename Eigen::Matrix< T, 4, 1 > Vec4
All State Estimation Algorithms.
MX f(const MX &x, const MX &u)