state-observation 1.8.0
General implementation of observers.
Loading...
Searching...
No Matches
waiko-humanoid.hpp
Go to the documentation of this file.
1
11
12#ifndef WaikoHumanoidHPP
13#define WaikoHumanoidHPP
14
16#include <optional>
17#include <state-observation/observer/delayed-measurements-complem-filter.hpp>
19
20namespace stateObservation
21{
22
28
29class STATE_OBSERVATION_DLLAPI WaikoHumanoid : public ZeroDelayObserver
30{
31
32public:
33 struct InputWaiko : public InputBase
34 {
36 {
37 Vector3 pos_meas_from_contacts_ = Vector3::Zero();
38 std::vector<Vector3> pos_meas_;
39 std::vector<Vector3> jacobians_;
40 std::vector<double> lambdas_;
41 };
42
43 InputWaiko(double dt, const Vector3 & yv, const Vector3 & ya, const Vector3 & yg)
44 : dt_(dt), yv_(yv), ya_(ya), yg_(yg)
45 {
46 }
47 // sampling time
48 double dt_;
49
50 // local linear velocity measurement
51 Vector3 yv_;
52 // accelerometer measurement
53 Vector3 ya_;
54 // gyrometer measurement
55 Vector3 yg_;
56 // IMU position measurements coming from contacts
57 std::optional<ContactPosInput> contact_pos_input_;
58 // IMU position measurements
59 std::vector<Vector3> pos_inputs_;
60 // IMU orientation measurements measurements
61 std::vector<Matrix3> ori_inputs_;
62 };
63
64 inline static constexpr Index sizeX1 = 3;
65 inline static constexpr Index sizeX2 = 3;
66 inline static constexpr Index sizeOri = 4;
67 inline static constexpr Index sizePos = 3;
68
69 inline static constexpr Index sizeX1Tangent = 3;
70 inline static constexpr Index sizeX2Tangent = 3;
71 inline static constexpr Index sizeOriTangent = 3;
72 inline static constexpr Index sizePosTangent = 3;
73
74 inline static constexpr Index x1Index = 0;
75 inline static constexpr Index x2Index = sizeX1;
76 inline static constexpr Index posIndex = x2Index + sizeX2;
77
78 inline static constexpr Index x1IndexTangent = 0;
79 inline static constexpr Index x2IndexTangent = sizeX1Tangent;
80 inline static constexpr Index oriIndexTangent = x2IndexTangent + sizeX2Tangent;
81 inline static constexpr Index posIndexTangent = oriIndexTangent + sizeOriTangent;
82
83public:
95 WaikoHumanoid(double alpha, double beta, double gamma, double rho, double mu, double psi = 0.0);
96
99 virtual ~WaikoHumanoid();
100
106 void initEstimator(const Vector3 & x1, const Vector3 & x2, const Vector4 & ori, const Vector3 & pos);
107
120 void setInput(double dt,
121 const Vector3 & imuAnchorPos,
122 const Vector3 & imuAnchorLinVel,
123 const Vector3 & ya_k,
124 const Vector3 & yg_k,
125 TimeIndex k,
126 bool resetImuLocVelHat = false);
127
137 void setInput(double dt,
138 const Vector3 & yv_k,
139 const Vector3 & ya_k,
140 const Vector3 & yg_k,
141 TimeIndex k,
142 bool resetImuLocVelHat = false);
143
145 void addPosInput(const Vector3 & poseInput, TimeIndex k);
146 void addOriInput(const Matrix3 & oriInput, TimeIndex k);
147 void addPoseInput(const Matrix3 & oriInput, const Vector3 & posInput, TimeIndex k);
156 void addContactPosInput(const Vector3 & refPose, const Vector3 & imuContactPos, double lambda, TimeIndex k);
157
159
161 void setAlpha(const double alpha)
162 {
163 alpha_ = alpha;
164 }
165 double getAlpha()
166 {
167 return alpha_;
168 }
169
171 void setBeta(const double beta)
172 {
173 beta_ = beta;
174 }
175 double getBeta()
176 {
177 return beta_;
178 }
179
181 void setRho(const double rho)
182 {
183 rho_ = rho;
184 }
185 double getRho()
186 {
187 return rho_;
188 }
189
191 void setGamma(const double gamma)
192 {
193 gamma_ = gamma;
194 }
195 double getGamma()
196 {
197 return gamma_;
198 }
199
201 void setMu(const double mu)
202 {
203 mu_ = mu;
204 }
205 double getMu()
206 {
207 return mu_;
208 }
209
211 void setPsi(const double psi)
212 {
213 psi_ = psi;
214 }
215 double getPsi()
216 {
217 return psi_;
218 }
219
220 void setWithOriCorrectFromContactPos(bool withCorrection)
221 {
222 withOriCorrectFromContactPos_ = withCorrection;
223 }
224 bool getWithOriCorrectFromContactPos()
225 {
226 return withOriCorrectFromContactPos_;
227 }
228
229 const Eigen::VectorBlock<ObserverBase::StateVector, sizeX1> getEstimatedLocLinVel()
230 {
231 return x_().segment<sizeX1>(x1Index);
232 }
233 const Eigen::VectorBlock<ObserverBase::StateVector, sizeX2> getEstimatedTilt()
234 {
235 return x_().segment<sizeX2>(x2Index);
236 }
237 Matrix3 getEstimatedOrientation() const
238 {
239 return state_ori_.toMatrix3();
240 }
241 const Eigen::VectorBlock<ObserverBase::StateVector, sizePos> getEstimatedLocPosition()
242 {
243 return x_().segment<sizePos>(posIndex);
244 }
245 Vector3 getEstimatedWorldPosition()
246 {
247 return positionAnchor_ + state_ori_.toMatrix3() * x_().segment<sizePos>(posIndex);
248 }
249 const Vector3 & getPositionAnchor() const
250 {
251 return positionAnchor_;
252 }
253 void resetPositionAnchor(const Vector3 & newPositionAnchor);
254 double getLastPositionAnchorResetJump() const
255 {
256 return lastPositionAnchorResetJump_;
257 }
258 double getLastPositionAnchorResetLocalNormBefore() const
259 {
260 return lastPositionAnchorResetLocalNormBefore_;
261 }
262 double getLastPositionAnchorResetLocalNormAfter() const
263 {
264 return lastPositionAnchorResetLocalNormAfter_;
265 }
266 std::size_t getPositionAnchorResetCount() const
267 {
268 return positionAnchorResetCount_;
269 }
270
271 // correction of the position coming from the contact positions, passed as a
272 // local linear velocity.
273 inline const stateObservation::Vector3 & getPosCorrectionFromContactPos()
274 {
275 return posCorrFromContactPos_;
276 }
277 // correction of the orientation coming from the contact positions, passed as
278 // a local angular velocity.
279 inline const stateObservation::Vector3 & getOriCorrectionFromContactPos()
280 {
281 return oriCorrFromContactPos_;
282 }
283 // correction of the orientation coming from direct orientation measurements,
284 // passed as a local angular velocity.
285 inline const stateObservation::Vector3 & getOriCorrFromOriMeas()
286 {
287 return oriCorrFromOriMeas_;
288 }
289
290protected:
296
302
308
312 void startNewIteration_();
313
314protected:
324 double alpha_, beta_, gamma_, rho_, mu_, psi_;
325 Vector dx_hat_;
326 kine::Orientation state_ori_;
327 Vector3 positionAnchor_ = Vector3::Zero();
328 double lastPositionAnchorResetJump_ = 0.0;
329 double lastPositionAnchorResetLocalNormBefore_ = 0.0;
330 double lastPositionAnchorResetLocalNormAfter_ = 0.0;
331 std::size_t positionAnchorResetCount_ = 0;
332
333 // correction of the orientation coming from the contact orientations, passed
334 // as a local angular velocity.
335 Vector3 oriCorrFromOriMeas_ = Vector3::Zero();
336 // correction of the position coming from the contact positions, passed as a
337 // local linear velocity.
338 Vector3 posCorrFromContactPos_ = Vector3::Zero();
339 // correction of the orientation coming from the contact positions, passed as
340 // a local angular velocity.
341 Vector3 oriCorrFromContactPos_ = Vector3::Zero();
342
343 bool withOriCorrectFromContactPos_ = false;
344};
345
346} // namespace stateObservation
347
348#endif // WaikoHumanoidHPP
Vector StateVector
StateVector is the type of state vector.
void addPosInput(const Vector3 &poseInput, TimeIndex k)
set position, orientation, or pose inputs
StateVector & computeStateDynamics_()
Computes the dynamics of the state at the desired iteration.
void setGamma(const double gamma)
set lambda
virtual ~WaikoHumanoid()
Destroys the observer.
void setRho(const double rho)
set rho
void setAlpha(const double alpha)
set the gain of x1_hat variable
void setPsi(const double psi)
set psi
void initEstimator(const Vector3 &x1, const Vector3 &x2, const Vector4 &ori, const Vector3 &pos)
initializes the state vector.
void setBeta(const double beta)
set the gain of x2prime_hat variable
WaikoHumanoid(double alpha, double beta, double gamma, double rho, double mu, double psi=0.0)
void setMu(const double mu)
set mu
void integrateState_()
Integrates the computed state dynamics.
void setInput(double dt, const Vector3 &imuAnchorPos, const Vector3 &imuAnchorLinVel, const Vector3 &ya_k, const Vector3 &yg_k, TimeIndex k, bool resetImuLocVelHat=false)
sets the input
StateVector oneStepEstimation_() override
Runs one loop of the estimator.
void setInput(double dt, const Vector3 &yv_k, const Vector3 &ya_k, const Vector3 &yg_k, TimeIndex k, bool resetImuLocVelHat=false)
sets the input
void addCorrectionTerms()
Add the correction terms coming from the input to the computed state dynamics.
void addContactPosInput(const Vector3 &refPose, const Vector3 &imuContactPos, double lambda, TimeIndex k)
adds a position measurement coming from contacts
ZeroDelayObserver(Index n, Index m, const std::shared_ptr< IndexedInputArrayInterface > input)
virtual void setInput(const InputBase &u_k, TimeIndex k)
Filtering of divergent component of motion (DCM) and estimation of a bias betweeen the DCM and the co...
Eigen::Vector3d Vector3
3D vector
Eigen::Vector4d Vector4
4D vector
Eigen::Matrix3d Matrix3
3x3 Scalar Matrix
Eigen::VectorXd Vector
Dynamic sized scalar vector.
Implements integrators for the kinematics, in terms or rotations and translations.
Defines the base class of online zero delay observers. Zero delay observers are the classical state o...