pinocchio  UNKNOWN
All Classes Namespaces Functions Variables Typedefs Enumerations Modules Pages
check.hxx
1 //
2 // Copyright (c) 2016-2018 CNRS
3 //
4 // This file is part of Pinocchio
5 // Pinocchio is free software: you can redistribute it
6 // and/or modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation, either version
8 // 3 of the License, or (at your option) any later version.
9 //
10 // Pinocchio is distributed in the hope that it will be
11 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Lesser Public License for more details. You should have
14 // received a copy of the GNU Lesser General Public License along with
15 // Pinocchio If not, see
16 // <http://www.gnu.org/licenses/>.
17 
18 #ifndef __se3_check_hxx__
19 #define __se3_check_hxx__
20 
21 #include <boost/fusion/algorithm.hpp>
22 #include <boost/foreach.hpp>
23 
24 namespace se3
25 {
26  namespace internal
27  {
28  // Dedicated structure for the fusion::accumulate algorithm: validate the check-algorithm
29  // for all elements in a fusion list of AlgoCheckers.
30  struct AlgoFusionChecker
31  {
32  typedef bool result_type;
33  const Model& model;
34 
35  AlgoFusionChecker(const Model&model) : model(model) {}
36 
37  inline bool operator()(const bool& accumul, const boost::fusion::void_ &) const
38  { return accumul; }
39 
40  template<typename T>
41  inline bool operator()(const bool& accumul, const AlgorithmCheckerBase<T> & t) const
42  { return accumul && t.checkModel(model); }
43  };
44  } // namespace internal
45 
46  // Check the validity of the kinematic tree defined by parents.
47  inline bool ParentChecker::checkModel_impl( const Model& model ) const
48  {
49  for( JointIndex j=1;(int)j<model.njoints;++j )
50  if( model.parents[j]>=j ) return false;
51 
52  return true;
53  }
54 
55 #if !defined(BOOST_FUSION_HAS_VARIADIC_LIST)
56  template<BOOST_PP_ENUM_PARAMS(PINOCCHIO_ALGO_CHECKER_LIST_MAX_LIST_SIZE,class T)>
57  bool AlgorithmCheckerList<BOOST_PP_ENUM_PARAMS(PINOCCHIO_ALGO_CHECKER_LIST_MAX_LIST_SIZE,T)>::checkModel_impl(const Model& model) const
58  {
59  return boost::fusion::accumulate(checkerList,true,internal::AlgoFusionChecker(model));
60  }
61 #else
62  template<class ...T>
63  bool AlgorithmCheckerList<T...>::checkModel_impl(const Model& model) const
64  {
65  return boost::fusion::accumulate(checkerList,true,internal::AlgoFusionChecker(model));
66  }
67 #endif
68 
69  inline bool checkData(const Model & model, const Data & data)
70  {
71 #define CHECK_DATA(a) if(!(a)) return false;
72 
73  // TODO JMinvJt,sDUiJt are never explicitly initialized.
74  // TODO impulse_c
75  // They are not check neither
76 
77  CHECK_DATA( (int)data.joints.size() == model.njoints );
78  CHECK_DATA( (int)data.a.size() == model.njoints );
79  CHECK_DATA( (int)data.a_gf.size() == model.njoints );
80  CHECK_DATA( (int)data.v.size() == model.njoints );
81  CHECK_DATA( (int)data.f.size() == model.njoints );
82  CHECK_DATA( (int)data.oMi.size() == model.njoints );
83  CHECK_DATA( (int)data.liMi.size() == model.njoints );
84  CHECK_DATA( (int)data.Ycrb.size() == model.njoints );
85  CHECK_DATA( (int)data.Yaba.size() == model.njoints );
86  CHECK_DATA( (int)data.Fcrb.size() == model.njoints );
87  BOOST_FOREACH(const Data::Matrix6x & F,data.Fcrb) CHECK_DATA( F.cols() == model.nv );
88  CHECK_DATA( (int)data.iMf.size() == model.njoints );
89  CHECK_DATA( (int)data.iMf.size() == model.njoints );
90  CHECK_DATA( (int)data.com.size() == model.njoints );
91  CHECK_DATA( (int)data.vcom.size() == model.njoints );
92  CHECK_DATA( (int)data.acom.size() == model.njoints );
93  CHECK_DATA( (int)data.mass.size() == model.njoints );
94 
95  CHECK_DATA( data.tau.size() == model.nv );
96  CHECK_DATA( data.nle.size() == model.nv );
97  CHECK_DATA( data.ddq.size() == model.nv );
98  CHECK_DATA( data.u.size() == model.nv );
99  CHECK_DATA( data.M.rows() == model.nv );
100  CHECK_DATA( data.M.cols() == model.nv );
101  CHECK_DATA( data.Ag.cols() == model.nv );
102  CHECK_DATA( data.U.cols() == model.nv );
103  CHECK_DATA( data.U.rows() == model.nv );
104  CHECK_DATA( data.D.size() == model.nv );
105  CHECK_DATA( data.tmp.size() == model.nv );
106  CHECK_DATA( data.J.cols() == model.nv );
107  CHECK_DATA( data.Jcom.cols() == model.nv );
108  CHECK_DATA( data.torque_residual.size() == model.nv );
109  CHECK_DATA( data.dq_after.size() == model.nv );
110  //CHECK_DATA( data.impulse_c.size()== model.nv );
111 
112  CHECK_DATA( (int)data.oMf.size() == model.nframes );
113 
114  CHECK_DATA( (int)data.lastChild.size() == model.njoints );
115  CHECK_DATA( (int)data.nvSubtree.size() == model.njoints );
116  CHECK_DATA( (int)data.parents_fromRow.size() == model.nv );
117  CHECK_DATA( (int)data.nvSubtree_fromRow.size() == model.nv );
118 
119  for( JointIndex j=1;int(j)<model.njoints;++j )
120  {
121  JointIndex c = (JointIndex)data.lastChild[j];
122  CHECK_DATA((int)c<model.njoints);
123  int nv=model.joints[j].nv();
124  for( JointIndex d=j+1;d<=c;++d ) // explore all descendant
125  {
126  CHECK_DATA( model.parents[d]>=j );
127  nv+=model.joints[d].nv();
128  }
129  CHECK_DATA(nv==data.nvSubtree[j]);
130 
131  for( JointIndex d=c+1;(int)d<model.njoints;++d)
132  CHECK_DATA( (model.parents[d]<j)||(model.parents[d]>c) );
133 
134  int row = model.joints[j].idx_v();
135  CHECK_DATA(data.nvSubtree[j] == data.nvSubtree_fromRow[(size_t)row]);
136 
137  const JointModel & jparent = model.joints[model.parents[j]];
138  if(row==0) { CHECK_DATA(data.parents_fromRow[(size_t)row]==-1); }
139  else { CHECK_DATA(jparent.idx_v()+jparent.nv()-1 == data.parents_fromRow[(size_t)row]); }
140  }
141 
142 #undef CHECK_DATA
143  return true;
144  }
145 
146  inline bool Model::check(const Data & data) const { return checkData(*this,data); }
147 
148 
149 } // namespace se3
150 
151 #endif // ifndef __se3_check_hxx__
Eigen::VectorXd tau
Vector of joint torques (dim model.nv).
Definition: data.hpp:93
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
Matrix3x Jcom
Jacobien of center of mass.
Definition: data.hpp:260
container::aligned_vector< Eigen::Vector3d > vcom
Vector of subtree center of mass linear velocities expressed in the root joint of the subtree...
Definition: data.hpp:250
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
container::aligned_vector< SE3 > iMf
Vector of joint placements wrt to algorithm end effector.
Definition: data.hpp:244
Eigen::VectorXd u
Intermediate quantity corresponding to apparent torque [ABA].
Definition: data.hpp:168
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef Eigen::Matrix< double, 6, Eigen::Dynamic > Matrix6x
The 6d jacobian type (temporary)
Definition: data.hpp:45
JointModelVector joints
Model of joint i, encapsulated in a JointModelAccessor.
Definition: model.hpp:70
container::aligned_vector< Inertia > Ycrb
Vector of sub-tree composite rigid body inertias, i.e. the apparent inertia of the subtree supported ...
Definition: data.hpp:110
Matrix6x J
Jacobian of joint placements.
Definition: data.hpp:217
bool checkData(const Model &model, const Data &data)
Definition: check.hxx:69
Eigen::VectorXd D
Diagonal of the joint space intertia matrix obtained by a Cholesky Decomposition. ...
Definition: data.hpp:201
container::aligned_vector< Eigen::Vector3d > acom
Vector of subtree center of mass linear accelerations expressed in the root joint of the subtree...
Definition: data.hpp:253
Eigen::VectorXd ddq
The joint accelerations computed from ABA.
Definition: data.hpp:161
Eigen::VectorXd torque_residual
Temporary corresponding to the residual torque .
Definition: data.hpp:284
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< Inertia::Matrix6 > Yaba
Inertia matrix of the subtree expressed as dense matrix [ABA].
Definition: data.hpp:165
bool check() const
Run check(fusion::list) with DEFAULT_CHECKERS as argument.
container::aligned_vector< Matrix6x > Fcrb
Spatial forces set, used in CRBA and CCRBA.
Definition: data.hpp:190
Eigen::VectorXd nle
Vector of Non Linear Effects (dim model.nv). It corresponds to concatenation of the Coriolis...
Definition: data.hpp:98
container::aligned_vector< Motion > a_gf
Vector of joint accelerations due to the gravity field.
Definition: data.hpp:64
container::aligned_vector< Eigen::Vector3d > com
Vector of subtree center of mass positions expressed in the root joint of the subtree. In other words, com[j] is the CoM position of the subtree supported by joint and expressed in the joint frame . The element com[0] corresponds to the center of mass position of the whole model and expressed in the global frame.
Definition: data.hpp:247
JointDataVector joints
Vector of se3::JointData associated to the se3::JointModel stored in model, encapsulated in JointData...
Definition: data.hpp:55
Eigen::VectorXd dq_after
Generalized velocity after impact.
Definition: data.hpp:287
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
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
Eigen::VectorXd tmp
Temporary of size NV used in Cholesky Decomposition.
Definition: data.hpp:207
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
std::vector< double > mass
Vector of subtree mass. In other words, mass[j] is the mass of the subtree supported by joint ...
Definition: data.hpp:256
std::vector< int > lastChild
Index of the last child (for CRBA)
Definition: data.hpp:193
int nframes
Number of operational frames.
Definition: model.hpp:61