Ravelin
CRBAlgorithm.h
1 /****************************************************************************
2  * Copyright 2006 Evan Drumwright
3  * This library is distributed under the terms of the Apache V2.0
4  * License (obtainable from http://www.apache.org/licenses/LICENSE-2.0).
5  ****************************************************************************/
6 
7 #ifndef CRB_ALGORITHM
8 #error This class is not to be included by the user directly. Use CRBAlgorithmd.h or CRBAlgorithmf.h instead.
9 #endif
10 
13 {
14  friend class RC_ARTICULATED_BODY;
15 
16  public:
17  CRB_ALGORITHM();
18  ~CRB_ALGORITHM() {}
19  boost::shared_ptr<RC_ARTICULATED_BODY> get_body() const { return boost::shared_ptr<RC_ARTICULATED_BODY>(_body); }
20  void set_body(boost::shared_ptr<RC_ARTICULATED_BODY> body) { _body = body; setup_parent_array(); }
21  void calc_fwd_dyn();
22  void apply_impulse(const SMOMENTUM& w, boost::shared_ptr<RIGIDBODY> link);
24  void calc_generalized_inertia(SHAREDMATRIXN& M, boost::shared_ptr<const POSE3> P);
27  bool factorize_cholesky(MATRIXN& M);
28  VECTORN& M_solve(VECTORN& xb);
30  MATRIXN& M_solve(MATRIXN& XB);
32 
33  private:
34  void calc_fwd_dyn_special();
35  static boost::shared_ptr<const POSE3> get_computation_frame(boost::shared_ptr<RC_ARTICULATED_BODY> body);
36  std::vector<unsigned> _lambda;
37  void setup_parent_array();
38 
40  boost::weak_ptr<RC_ARTICULATED_BODY> _body;
41 
43  SACCEL _a0;
44 
46  VECTORN _qdd;
47 
49  MATRIXN _M;
50 
52  MATRIXN _fM;
53 
55  bool _rank_deficient;
56 
57  void calc_joint_space_inertia(boost::shared_ptr<RC_ARTICULATED_BODY> body, MATRIXN& H, std::vector<SPATIAL_RB_INERTIA>& Ic);
58  void apply_coulomb_joint_friction(boost::shared_ptr<RC_ARTICULATED_BODY> body);
59  void precalc(boost::shared_ptr<RC_ARTICULATED_BODY> body);
60  void calc_generalized_inertia(boost::shared_ptr<RC_ARTICULATED_BODY> body);
61  void calc_fwd_dyn_fixed_base(boost::shared_ptr<RC_ARTICULATED_BODY> body);
62  void calc_fwd_dyn_floating_base(boost::shared_ptr<RC_ARTICULATED_BODY> body);
63  void update_link_accelerations(boost::shared_ptr<RC_ARTICULATED_BODY> body);
64  static void to_spatial7_inertia(const SPATIAL_RB_INERTIA& I, const QUAT& q, MATRIXN& I7);
65  VECTORN& M_solve_noprecalc(VECTORN& xb);
66  MATRIXN& M_solve_noprecalc(MATRIXN& XB);
67  SHAREDVECTORN& M_solve_noprecalc(SHAREDVECTORN& xb);
68  SHAREDMATRIXN& M_solve_noprecalc(SHAREDMATRIXN& XB);
69  void transform_and_mult(boost::shared_ptr<const POSE3> P, const SPATIAL_RB_INERTIA& I, const std::vector<SVELOCITY>& s, std::vector<SMOMENTUM>& Is);
70 
71  private:
72  // temporaries for transform_and_transpose_mult() functions
73  std::vector<SFORCE> _tandt_fx;
74  std::vector<SMOMENTUM> _tandt_wx, _Isprime;
75  std::vector<SVELOCITY> _tandt_tx;
76 
77  // temporary for calc_fwd_dyn()
78  std::vector<SACCEL> _a;
79 
80  // temporary for calc_generalized_forces()
81  std::vector<SFORCE> _w;
82 
83  // temporary spatial axes
84  std::vector<SVELOCITY> _sprime;
85 
86  // temporaries for solving and linear algebra
87  boost::shared_ptr<LINALG> _LA;
88  MATRIXN _uM, _vM;
89  VECTORN _sM;
90 
91  // temporaries for calc_generalized_inertia()
92  MATRIXN _H;
93  VECTORN _rowi;
94  std::vector<SPATIAL_RB_INERTIA> _Ic;
95  std::vector<SMOMENTUM> _Is;
96 
97  // temporaries for calc_joint_space_inertia()
98  MATRIXN _workM, _sub;
99  std::vector<std::vector<bool> > _supports;
100  std::vector<std::vector<SMOMENTUM> > _momenta;
101 
102  // temporaries for calc_fwd_dyn_fixed_base(), calc_fwd_dyn_floating_base()
103  VECTORN _C, _Q, _b, _augV;
104 
105  // temporaries for applying impulse
106  VECTORN _workv;
107  std::vector<SVELOCITY> _J;
108 
109  // precalc
110  VECTORN _gc_last;
111 
112  #include "CRBAlgorithm.inl"
113 }; // end class
114 
VECTORN & M_solve(VECTORN &xb)
Solves for acceleration using the body inertia matrix.
Definition: CRBAlgorithm.cpp:636
Computes forward dynamics using composite-rigid body method.
Definition: CRBAlgorithm.h:12
boost::shared_ptr< LINALG > _LA
Linear algebra object.
Definition: RCArticulatedBody.h:139
Quaternion class used for orientation.
Definition: Quat.h:21
void calc_generalized_forces_noinertial(SFORCE &f0, VECTORN &C)
Computes the vector "C", w/o inertial forces, using the recursive Newton-Euler algorithm.
Definition: CRBAlgorithm.cpp:1107
void calc_generalized_forces(SFORCE &f0, VECTORN &C)
Computes the vector "C", used for forward dynamics computation, using the recursive Newton-Euler algo...
Definition: CRBAlgorithm.cpp:884
A spatial (six dimensional) momentum.
Definition: SMomentum.h:12
A generic, possibly non-square matrix.
Definition: MatrixN.h:18
void calc_fwd_dyn()
Executes the composite rigid-body method.
Definition: CRBAlgorithm.cpp:597
virtual void apply_impulse(const SMOMENTUM &w, boost::shared_ptr< RIGIDBODY > link)
Abstract method for applying an impulse to this articulated body.
A generic, possibly non-square matrix using shared data.
Definition: SharedMatrixN.h:59
Defines an articulated body for use with reduced-coordinate dynamics algorithms.
Definition: RCArticulatedBody.h:29
A generic N-dimensional floating point vector.
Definition: SharedVectorN.h:15
bool factorize_cholesky(MATRIXN &M)
Factorizes (Cholesky) the generalized inertia matrix, exploiting sparsity.
Definition: CRBAlgorithm.cpp:60
A 6x6 spatial algebra matrix used for dynamics calculations.
Definition: SpatialRBInertia.h:25
A spatial (six dimensional) acceleration.
Definition: SAccel.h:14
A generic N-dimensional floating point vector.
Definition: VectorN.h:16
A spatial force (a wrench)
Definition: SForce.h:14
void calc_generalized_inertia(SHAREDMATRIXN &M)
Calculates the generalized inertia matrix for the given representation.
Definition: CRBAlgorithm.cpp:486