pinocchio  UNKNOWN
data.hxx
1 //
2 // Copyright (c) 2015-2018 CNRS
3 // Copyright (c) 2015 Wandercraft, 86 rue de Paris 91400 Orsay, France.
4 //
5 // This file is part of Pinocchio
6 // Pinocchio is free software: you can redistribute it
7 // and/or modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation, either version
9 // 3 of the License, or (at your option) any later version.
10 //
11 // Pinocchio is distributed in the hope that it will be
12 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Lesser Public License for more details. You should have
15 // received a copy of the GNU Lesser General Public License along with
16 // Pinocchio If not, see
17 // <http://www.gnu.org/licenses/>.
18 
19 #ifndef __se3_data_hxx__
20 #define __se3_data_hxx__
21 
22 #include "pinocchio/spatial/fwd.hpp"
23 #include "pinocchio/multibody/model.hpp"
24 #include "pinocchio/utils/string-generator.hpp"
25 #include "pinocchio/multibody/liegroup/liegroup-algo.hpp"
26 
27 #include <boost/bind.hpp>
28 #include <boost/utility.hpp>
29 
31 
32 namespace se3
33 {
34 
35  inline Data::Data(const Model & model)
36  : joints(0)
37  , a((std::size_t)model.njoints)
38  , oa((std::size_t)model.njoints)
39  , a_gf((std::size_t)model.njoints)
40  , v((std::size_t)model.njoints)
41  , ov((std::size_t)model.njoints)
42  , f((std::size_t)model.njoints)
43  , of((std::size_t)model.njoints)
44  , h((std::size_t)model.njoints)
45  , oh((std::size_t)model.njoints)
46  , oMi((std::size_t)model.njoints)
47  , liMi((std::size_t)model.njoints)
48  , tau(model.nv)
49  , nle(model.nv)
50  , g(model.nv)
51  , oMf((std::size_t)model.nframes)
52  , Ycrb((std::size_t)model.njoints)
53  , dYcrb((std::size_t)model.njoints)
54  , M(model.nv,model.nv)
55  , Minv(model.nv,model.nv)
56  , C(model.nv,model.nv)
57  , dFdq(6,model.nv)
58  , dFdv(6,model.nv)
59  , dFda(6,model.nv)
60  , SDinv(6,model.nv)
61  , UDinv(6,model.nv)
62  , IS(6,model.nv)
63  , vxI((std::size_t)model.njoints)
64  , Ivx((std::size_t)model.njoints)
65  , oYcrb((std::size_t)model.njoints)
66  , doYcrb((std::size_t)model.njoints)
67  , ddq(model.nv)
68  , Yaba((std::size_t)model.njoints)
69  , u(model.nv)
70  , Ag(6,model.nv)
71  , dAg(6,model.nv)
72  , Fcrb((std::size_t)model.njoints)
73  , lastChild((std::size_t)model.njoints)
74  , nvSubtree((std::size_t)model.njoints)
75  , U(model.nv,model.nv)
76  , D(model.nv)
77  , Dinv(model.nv)
78  , tmp(model.nv)
79  , parents_fromRow((std::size_t)model.nv)
80  , nvSubtree_fromRow((std::size_t)model.nv)
81  , J(6,model.nv)
82  , dJ(6,model.nv)
83  , dVdq(6,model.nv)
84  , dAdq(6,model.nv)
85  , dAdv(6,model.nv)
86  , dtau_dq(Eigen::MatrixXd::Zero(model.nv,model.nv))
87  , dtau_dv(Eigen::MatrixXd::Zero(model.nv,model.nv))
88  , ddq_dq(Eigen::MatrixXd::Zero(model.nv,model.nv))
89  , ddq_dv(Eigen::MatrixXd::Zero(model.nv,model.nv))
90  , iMf((std::size_t)model.njoints)
91  , com((std::size_t)model.njoints)
92  , vcom((std::size_t)model.njoints)
93  , acom((std::size_t)model.njoints)
94  , mass((std::size_t)model.njoints)
95  , Jcom(3,model.nv)
96  , JMinvJt()
97  , llt_JMinvJt()
98  , lambda_c()
99  , sDUiJt(model.nv,model.nv)
100  , torque_residual(model.nv)
101  , dq_after(model.nv)
102  , impulse_c()
103  , staticRegressor(3,4*(model.njoints-1))
104  {
105  /* Create data strcture associated to the joints */
106  for(Model::Index i=0;i<(Model::JointIndex)(model.njoints);++i)
107  joints.push_back(CreateJointData::run(model.joints[i]));
108 
109  /* Init for CRBA */
110  M.fill(0); Minv.setZero();
111  for(Model::Index i=0;i<(Model::Index)(model.njoints);++i ) { Fcrb[i].resize(6,model.nv); }
112  computeLastChild(model);
113 
114  /* Init for Coriolis */
115  C.fill(0.);
116 
117  /* Init for Cholesky */
118  U.setIdentity();
119  computeParents_fromRow(model);
120 
121  /* Init Jacobian */
122  J.setZero();
123  Ag.setZero();
124 
125  /* Init universe states relatively to itself */
126 
127  a[0].setZero();
128  oa[0].setZero();
129  v[0].setZero();
130  ov[0].setZero();
131  a_gf[0] = -model.gravity;
132  f[0].setZero();
133  h[0].setZero();
134  oMi[0].setIdentity();
135  liMi[0].setIdentity();
136  oMf[0].setIdentity();
137  }
138 
139  inline void Data::computeLastChild(const Model & model)
140  {
141  typedef Model::Index Index;
142  std::fill(lastChild.begin(),lastChild.end(),-1);
143  for( int i=model.njoints-1;i>=0;--i )
144  {
145  if(lastChild[(Index)i] == -1) lastChild[(Index)i] = i;
146  const Index & parent = model.parents[(Index)i];
147  lastChild[parent] = std::max(lastChild[(Index)i],lastChild[parent]);
148 
149  nvSubtree[(Index)i]
150  = idx_v(model.joints[(Index)lastChild[(Index)i]]) + nv(model.joints[(Index)lastChild[(Index)i]])
151  - idx_v(model.joints[(Index)i]);
152  }
153  }
154 
155  inline void Data::computeParents_fromRow(const Model & model)
156  {
157  for( Model::Index joint=1;joint<(Model::Index)(model.njoints);joint++)
158  {
159  const Model::Index & parent = model.parents[joint];
160  const int nvj = nv (model.joints[joint]);
161  const int idx_vj = idx_v(model.joints[joint]);
162 
163  if(parent>0) parents_fromRow[(Model::Index)idx_vj] = idx_v(model.joints[parent])+nv(model.joints[parent])-1;
164  else parents_fromRow[(Model::Index)idx_vj] = -1;
165  nvSubtree_fromRow[(Model::Index)idx_vj] = nvSubtree[joint];
166 
167  for(int row=1;row<nvj;++row)
168  {
169  parents_fromRow[(Model::Index)(idx_vj+row)] = idx_vj+row-1;
170  nvSubtree_fromRow[(Model::Index)(idx_vj+row)] = nvSubtree[joint]-row;
171  }
172  }
173  }
174 
175 } // namespace se3
176 
178 
179 #endif // ifndef __se3_data_hxx__
Matrix6x Ag
Centroidal Momentum Matrix.
Definition: data.hpp:173
container::aligned_vector< Motion > a
Vector of joint accelerations expressed at the centers of the joints.
Definition: data.hpp:58
int nv
Dimension of the velocity vector space.
Definition: model.hpp:52
std::vector< int > nvSubtree
Dimension of the subtree motion space (for CRBA)
Definition: data.hpp:195
Data(const Model &model)
Default constructor of se3::Data from a se3::Model.
Definition: data.hxx:35
STL namespace.
JointModelVector joints
Model of joint i, encapsulated in a JointModelAccessor.
Definition: model.hpp:70
Matrix6x J
Jacobian of joint placements.
Definition: data.hpp:217
container::aligned_vector< Motion > oa
Vector of joint accelerations expressed at the origin.
Definition: data.hpp:61
std::vector< int > nvSubtree_fromRow
Subtree of the current row index (used in Cholesky Decomposition).
Definition: data.hpp:213
std::vector< JointIndex > parents
Joint parent of joint i, denoted li (li==parents[i]).
Definition: model.hpp:73
int nv(const JointModelVariant &jmodel)
Visit a JointModelVariant through JointNvVisitor to get the dimension of the joint tangent space...
container::aligned_vector< Motion > ov
Vector of joint velocities expressed at the origin.
Definition: data.hpp:70
container::aligned_vector< Matrix6x > Fcrb
Spatial forces set, used in CRBA and CCRBA.
Definition: data.hpp:190
container::aligned_vector< Motion > a_gf
Vector of joint accelerations due to the gravity field.
Definition: data.hpp:64
JointDataVector joints
Vector of se3::JointData associated to the se3::JointModel stored in model, encapsulated in JointData...
Definition: data.hpp:55
Motion gravity
Spatial gravity of the model.
Definition: model.hpp:106
Eigen::MatrixXd M
The joint space inertia matrix (a square matrix of dim model.nv).
Definition: data.hpp:116
Eigen::MatrixXd U
Joint space intertia matrix square root (upper trianglular part) computed with a Cholesky Decompositi...
Definition: data.hpp:198
container::aligned_vector< SE3 > oMf
Vector of absolute operationnel frame placements (wrt the world).
Definition: data.hpp:106
container::aligned_vector< SE3 > liMi
Vector of relative joint placements (wrt the body parent).
Definition: data.hpp:90
container::aligned_vector< SE3 > oMi
Vector of absolute joint placements (wrt the world).
Definition: data.hpp:87
int idx_v(const JointModelVariant &jmodel)
Visit a JointModelVariant through JointIdxVVisitor to get the index in the full model tangent space c...
RowMatrixXd Minv
The inverse of the joint space inertia matrix (a square matrix of dim model.nv).
Definition: data.hpp:119
container::aligned_vector< Force > f
Vector of body forces expressed in the local frame of the joint. For each body, the force represents ...
Definition: data.hpp:74
std::vector< int > parents_fromRow
First previous non-zero row in M (used in Cholesky Decomposition).
Definition: data.hpp:210
container::aligned_vector< Motion > v
Vector of joint velocities expressed at the centers of the joints.
Definition: data.hpp:67
int njoints
Number of joints.
Definition: model.hpp:55
container::aligned_vector< Force > h
Vector of spatial momenta expressed in the local frame of the joint.
Definition: data.hpp:81
Eigen::MatrixXd C
The Coriolis matrix (a square matrix of dim model.nv).
Definition: data.hpp:122
std::vector< int > lastChild
Index of the last child (for CRBA)
Definition: data.hpp:193