state-observation 1.7.0
General implementation of observers.
Loading...
Searching...
No Matches
imu-elastic-local-frame-dynamical-system.hpp
1/*
2 * imu-elastic-local-frame-dynamical-system.hpp
3 *
4 * Created on: 19 mai 2014
5 * Author: alexis
6 */
7
8#ifndef DYNAMICAL_SYSTEM_HPP_
9#define DYNAMICAL_SYSTEM_HPP_
10
11#include <vector>
12
13#include <state-observation/api.h>
14#include <state-observation/dynamical-system/dynamical-system-functor-base.hpp>
19
20#include <Eigen/Cholesky>
21
22namespace stateObservation
23{
24
25namespace flexibilityEstimation
26{
27
35{
36public:
37 struct input
38 {
40 static constexpr unsigned posCom = 0;
41 static constexpr unsigned velCom = 3;
42 static constexpr unsigned accCom = 6;
43 static constexpr unsigned inertia = 9;
44 static constexpr unsigned angMoment = 15;
45 static constexpr unsigned dotInertia = 18;
46 static constexpr unsigned dotAngMoment = 24;
47 static constexpr unsigned posIMU = 27;
48 static constexpr unsigned oriIMU = 30;
49 static constexpr unsigned linVelIMU = 33;
50 static constexpr unsigned angVelIMU = 36;
51 static constexpr unsigned linAccIMU = 39;
52 static constexpr unsigned additionalForces = 42;
53 static constexpr unsigned contacts = 48;
54
55 static constexpr unsigned sizeBase = 48;
56 };
57
58 struct state
59 {
60 static constexpr unsigned pos = 0;
61 static constexpr unsigned ori = 3;
62 static constexpr unsigned linVel = 6;
63 static constexpr unsigned angVel = 9;
64 static constexpr unsigned fc = 12;
65 static constexpr unsigned unmodeledForces = 24;
66 static constexpr unsigned comBias = 30;
67 static constexpr unsigned drift = 32;
68
69 static constexpr unsigned size = 35;
70 };
71
73 {
75 static constexpr unsigned elasticContact = 1;
76 static constexpr unsigned pendulum = 2;
77 static constexpr unsigned none = 0;
78 };
79
80 typedef Eigen::LLT<Matrix3> LLTMatrix3;
81
84
87
88 void test();
89
90 // Get the contact wrench
91 void computeContactWrench(const Matrix3 & orientation,
92 const Vector3 & position,
93 const IndexedVectorArray & contactPosV,
94 const IndexedVectorArray & contactOriV,
95 const Vector & fc,
96 const Vector & tc,
97 const Vector3 & fm,
98 const Vector3 & tm,
99 const Vector3 & addForce,
100 const Vector3 & addMoment);
101
102 stateObservation::Vector computeAccelerations(const Vector & x, const Vector & u);
103
104 // computation of the acceleration linear
105 virtual void computeAccelerations(const Vector3 & positionCom,
106 const Vector3 & velocityCom,
107 const Vector3 & accelerationCom,
108 const Vector3 & AngMomentum,
109 const Vector3 & dotAngMomentum,
110 const Matrix3 & Inertia,
111 const Matrix3 & dotInertia,
112 const IndexedVectorArray & contactPos,
113 const IndexedVectorArray & contactOri,
114 const Vector3 & position,
115 const Vector3 & linVelocity,
116 Vector3 & linearAcceleration,
117 const Vector3 & oriVector,
118 const Matrix3 & orientation,
119 const Vector3 & angularVel,
120 Vector3 & angularAcceleration,
121 const Vector & fc,
122 const Vector & tc,
123 const Vector3 & fm,
124 const Vector3 & tm,
125 const Vector3 & addForces,
126 const Vector3 & addMoments);
127
130 const stateObservation::Vector & u,
131 TimeIndex k);
132
135
138 const stateObservation::Vector & u,
139 TimeIndex k);
140
143
146 const stateObservation::Vector & u,
147 TimeIndex k);
148
151
154 const stateObservation::Vector & u,
155 TimeIndex k);
156
159
161 virtual void resetProcessNoise();
162
165
168
170 virtual void resetMeasurementNoise();
171
174
176 virtual void setSamplingPeriod(double dt);
177
179 virtual Index getStateSize() const;
180
182 virtual Index getInputSize() const;
183
185 virtual void setInputSize(Index i);
186
189
191
193 virtual Index getMeasurementSize() const;
194
196 virtual void setContactsNumber(unsigned);
197
198 virtual void setPe(stateObservation::Vector3 Pe)
199 {
200 pe = Pe;
201 }
202
204 inline unsigned getContactsNumber(void) const
205 {
206 return nbContacts_;
207 }
208
209 virtual void setContactModel(unsigned nb);
210
211 virtual void setPrinted(bool b)
212 {
213 printed_ = b;
214 }
215
216 virtual void computeElastContactForcesAndMoments(const IndexedVectorArray & contactPosArray,
217 const IndexedVectorArray & contactOriArray,
218 const IndexedVectorArray & contactVelArray,
219 const IndexedVectorArray & contactAngVelArray,
220 const Vector3 & position,
221 const Vector3 & linVelocity,
222 const Vector3 & oriVector,
223 const Matrix3 & orientation,
224 const Vector3 & angVel,
225 Vector & fc,
226 Vector & tc);
227
228 virtual void computeElastPendulumForcesAndMoments(const IndexedVectorArray & PrArray,
229 const Vector3 & position,
230 const Vector3 & linVelocity,
231 const Vector3 & oriVector,
232 const Matrix3 & orientation,
233 const Vector3 & angVel,
234 Vector & forces,
235 Vector & moments);
236
237 void computeForcesAndMoments(const IndexedVectorArray & position1,
238 const IndexedVectorArray & position2,
239 const IndexedVectorArray & velocity1,
240 const IndexedVectorArray & velocity2,
241 const Vector3 & position,
242 const Vector3 & linVelocity,
243 const Vector3 & oriVector,
244 const Matrix3 & orientation,
245 const Vector3 & angVel,
246 Vector & fc,
247 Vector & tc);
248
249 virtual void computeForcesAndMoments(const Vector & x, const Vector & u);
250
251 virtual Vector getForcesAndMoments();
252
253 virtual Vector getForcesAndMoments(const Vector & x, const Vector & u);
254
255 virtual Vector getMomentaDotFromForces(const Vector & x, const Vector & u);
256 virtual Vector getMomentaDotFromKinematics(const Vector & x, const Vector & u);
257
258 virtual void iterateDynamicsEuler(const Vector3 & positionCom,
259 const Vector3 & velocityCom,
260 const Vector3 & accelerationCom,
261 const Vector3 & AngMomentum,
262 const Vector3 & dotAngMomentum,
263 const Matrix3 & Inertia,
264 const Matrix3 & dotInertia,
265 const IndexedVectorArray & contactPos,
266 const IndexedVectorArray & contactOri,
267 Vector3 & position,
268 Vector3 & linVelocity,
269 Vector & fc1,
270 Vector3 & oriVector,
271 Vector3 & angularVel,
272 Vector & fc2,
273 const Vector3 & fm,
274 const Vector3 & tm,
275 const Vector3 & addForces,
276 const Vector3 & addMoments,
277 double dt);
278
279 virtual void iterateDynamicsRK4(const Vector3 & positionCom,
280 const Vector3 & velocityCom,
281 const Vector3 & accelerationCom,
282 const Vector3 & AngMomentum,
283 const Vector3 & dotAngMomentum,
284 const Matrix3 & Inertia,
285 const Matrix3 & dotInertia,
286 const IndexedVectorArray & contactPos,
287 const IndexedVectorArray & contactOri,
288 Vector3 & position,
289 Vector3 & linVelocity,
290 Vector & fc1,
291 Vector3 & oriVector,
292 Vector3 & angularVel,
293 Vector & fc2,
294 const Vector3 & fm,
295 const Vector3 & tm,
296 const Vector3 & addForces,
297 const Vector3 & addMoments,
298 double dt);
299
300 virtual void setWithForceMeasurements(bool b);
301 virtual bool getWithForceMeasurements() const;
302 virtual void setWithComBias(bool b);
303 virtual bool getWithComBias() const;
304 virtual void setWithAbsolutePosition(bool b);
305 virtual bool getWithAbsolutePosition() const;
306 void setWithUnmodeledForces(bool b);
307
308 virtual void setKfe(const Matrix3 & m);
309 virtual void setKfv(const Matrix3 & m);
310 virtual void setKte(const Matrix3 & m);
311 virtual void setKtv(const Matrix3 & m);
312
313 virtual void setKfeRopes(const Matrix3 & m);
314 virtual void setKfvRopes(const Matrix3 & m);
315 virtual void setKteRopes(const Matrix3 & m);
316 virtual void setKtvRopes(const Matrix3 & m);
317
318 virtual Matrix getKfe() const;
319 virtual Matrix getKfv() const;
320 virtual Matrix getKte() const;
321 virtual Matrix getKtv() const;
322
323 virtual void setRobotMass(double d);
324
325 virtual double getRobotMass() const;
326
327protected:
328 bool printed_;
329
331
332 stateObservation::NoiseBase * processNoise_;
333
334 void updateMeasurementSize_();
335
336 double dt_;
337
338 double robotMass_;
339 double robotMassInv_;
340
341 Matrix3 & computeRotation_(const Vector3 & x, int i);
342
343 static constexpr Index stateSize_ = state::size;
344 Index inputSize_;
345 static constexpr Index measurementSizeBase_ = 6;
346 unsigned nbContacts_;
347 unsigned contactModel_;
348
349 Vector fc_;
350 Vector tc_;
351
352 Vector dx_;
353
354 Vector xk1_;
355 Vector xk_;
356 Vector uk_;
357
358 Vector xk_fory_;
359 Vector yk_;
360 Vector uk_fory_;
361
362 Index measurementSize_;
363
364 std::vector<Vector3, Eigen::aligned_allocator<Vector3>> contactPositions_;
365
366 Matrix3 Kfe_, Kte_, Kfv_, Ktv_;
367 Matrix3 KfeRopes_, KteRopes_, KfvRopes_, KtvRopes_;
368
369 TimeIndex kcurrent_;
370
371 bool withForceMeasurements_;
372 bool withComBias_;
373 bool withAbsolutePos_;
374 bool withUnmodeledForces_;
375
377
378 double marginalStabilityFactor_;
379 // a scaling factor a=1-epsilon to avoid the natural marginal stability of
380 // the dynamics x_{k+1}=x_k we replace it with x_{k+1}=a*x_k
381
382 unsigned index_;
383
384 struct Optimization
385 {
386
387 Vector6 momentaDot;
388
389 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
390
391 Vector3 positionFlex;
392 Vector3 velocityFlex;
393 Vector3 accelerationFlex;
394 Vector3 orientationFlexV;
395 Vector3 angularVelocityFlex;
396 Vector3 angularAccelerationFlex;
397 Vector3 positionComBias;
398
399 Matrix3 rFlex;
400 Matrix3 rFlexT;
401
402 Vector3 drift;
403 Vector3 pdrift;
404 Matrix3 rdrift;
405
406 double cy, sy;
407
408 AngleAxis orientationAA;
409
410 Vector xk1;
411 Vector xk;
412 Vector xk1dx;
413
414 Vector xdx;
415
416 Vector xk_fory;
417 Vector yk;
418 Vector ykdy;
419
420 TimeIndex k_fory;
421
422 Matrix3 orinertia;
423
424 LLTMatrix3 invinertia;
425
426 Matrix3 rtotal;
427 Vector3 ptotal;
428 AngleAxis aatotal;
429 Vector3 oritotal;
430
431 Matrix Jx;
432 Matrix Jy;
433
434 Matrix3 rimu;
435 Vector3 imuAcc;
436 Vector3 imuOmega;
437 Vector sensorState;
438
439 Vector3 positionCom;
440 Vector3 velocityCom;
441 Vector3 accelerationCom;
442 Vector3 AngMomentum;
443 Vector3 dotAngMomentum;
444
445 Vector3 positionControl;
446 Vector3 velocityControl;
447 Vector3 accelerationControl;
448 Vector3 orientationControlV;
449 Vector3 angularVelocityControl;
450
451 Matrix3 rControl;
452
453 IndexedVectorArray contactPosV;
454 IndexedVectorArray contactOriV;
455 IndexedVectorArray contactVelArray;
456 IndexedVectorArray contactAngVelArray;
457
458 Matrix3 inertia;
459 Matrix3 dotInertia;
460
461 IndexedVectorArray efforts;
462
463 Vector3 f, fi;
464 Vector3 t;
465
466 // unmodelled and unmeasured forces
467 Vector3 fm;
468 Vector3 tm;
469
470 Vector3 linearAcceleration;
471 Vector3 angularAcceleration;
472
473 Vector3 vf;
474 Vector3 vt;
475
476 Vector3 crosstempV;
477 Matrix3 crosstempM;
478
479 // elastic contact forces and moments
480 Matrix3 Rci; // rotation of contact i
481 Matrix3 Rcit; // transpose of previous
482 Vector3 contactPos; //
483 Vector3 contactVel;
484 Vector3 RciContactPos;
485 Vector3 globalContactPos;
486 Matrix3 Rt;
487
488 Vector3 forcei;
489 Vector3 momenti;
490
491 // additional forces and moments
492 Vector3 addForce;
493 Vector3 addMoment;
494
495 Matrix3 skewV;
496 Matrix3 skewV2;
497 Matrix3 skewVR;
498 Matrix3 skewV2R;
499 Matrix3 RIRT;
500 Vector3 wx2Rc;
501 Vector3 _2wxRv;
502 Vector3 Ra;
503 Vector3 Rc;
504 Vector3 Rcp;
505
506 // optimization of orientation transformation between vector3 to rotation matrix
507
508 Matrix3 curRotation0;
509 Vector3 orientationVector0;
510 Matrix3 curRotation1;
511 Vector3 orientationVector1;
512 Matrix3 curRotation2;
513 Vector3 orientationVector2;
514 Matrix3 curRotation3;
515 Vector3 orientationVector3;
516
517 Optimization()
518 : curRotation0(Matrix3::Identity()), orientationVector0(Vector3::Zero()), curRotation1(Matrix3::Identity()),
519 orientationVector1(Vector3::Zero()), curRotation2(Matrix3::Identity()), orientationVector2(Vector3::Zero()),
520 curRotation3(Matrix3::Identity()), orientationVector3(Vector3::Zero())
521 {
522 }
523
524 inline Vector3 & orientationVector(int i)
525 {
526 if(i == 0) return orientationVector0;
527 if(i == 1) return orientationVector1;
528 if(i == 2) return orientationVector2;
529
530 return orientationVector3;
531 }
532
533 inline Matrix3 & curRotation(int i)
534 {
535 if(i == 0) return curRotation0;
536 if(i == 1) return curRotation1;
537 if(i == 2) return curRotation2;
538
539 return curRotation3;
540 }
541
542 } op_;
543
544public:
545 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
546};
547} // namespace flexibilityEstimation
548} // namespace stateObservation
549
550#endif /* DYNAMICAL_SYSTEM_HPP_ */
Implements the accelerometer-gyrometer inertial measuremen.
Implements the accelerometer-gyrometer measurements.
This is the base class of any functor that describes the dynamics of the state and the measurement....
virtual void resetMeasurementNoise()
Removes the measurement noise.
stateObservation::Matrix measureDynamicsJacobian()
compute the Jacobien of the measurements dynamics at the last computed value
stateObservation::Matrix stateDynamicsJacobian()
compute the jacobien of the state dynamics at the last computed value
virtual void setContactsNumber(unsigned)
Sets the number of contacts.
virtual stateObservation::Vector stateDynamics(const stateObservation::Vector &x, const stateObservation::Vector &u, TimeIndex k)
Description of the state dynamics.
stateObservation::Matrix stateDynamicsJacobian(const stateObservation::Vector &x, const stateObservation::Vector &u, TimeIndex k)
compute the jacobien of the state dynamics at a given state
virtual void setProcessNoise(stateObservation::NoiseBase *)
Sets a noise which disturbs the state dynamics.
virtual stateObservation::NoiseBase * getProcessNoise() const
Gets the process noise.
virtual void setSamplingPeriod(double dt)
Set the period of the time discretization.
virtual stateObservation::Vector measureDynamics(const stateObservation::Vector &x, const stateObservation::Vector &u, TimeIndex k)
Description of the sensor's dynamics.
virtual stateObservation::NoiseBase * getMeasurementNoise() const
Gets a pointer on the measurement noise.
virtual Index getMeasurementSize() const
Gets the contacts position.
stateObservation::Matrix measureDynamicsJacobian(const stateObservation::Vector &x, const stateObservation::Vector &u, TimeIndex k)
compute the Jacobien of the measurements dynamics at a given state value
void setFDstep(const stateObservation::Vector &dx)
sets the finite differences derivation step vector
virtual void setMeasurementNoise(stateObservation::NoiseBase *)
Sets a noise which disturbs the measurements.
Definitions of Hrp2 constants.
Filtering of divergent component of motion (DCM) and estimation of a bias betweeen the DCM and the co...
Eigen::AngleAxis< double > AngleAxis
Euler Axis/Angle representation of orientation.
Eigen::Vector3d Vector3
3D vector
Eigen::Matrix3d Matrix3
3x3 Scalar Matrix
Eigen::MatrixXd Matrix
Dynamic sized Matrix.
Eigen::Matrix< double, 6, 1 > Vector6
6D vector
Eigen::VectorXd Vector
Dynamic sized scalar vector.
Implements integrators for the kinematics, in terms or rotations and translations.
static constexpr unsigned elasticContact
indices of the different components of a vector of the input state
static constexpr unsigned posCom
indices of the different components of a vector of the input state