18 #ifndef __se3_crba_hxx__ 19 #define __se3_crba_hxx__ 21 #include "pinocchio/multibody/visitor.hpp" 22 #include "pinocchio/spatial/act-on-set.hpp" 23 #include "pinocchio/algorithm/kinematics.hpp" 24 #include "pinocchio/algorithm/check.hpp" 32 typedef boost::fusion::vector<
const se3::Model&,
34 const Eigen::VectorXd &
39 template<
typename Jo
intModel>
42 const se3::Model & model,
44 const Eigen::VectorXd & q)
46 const Model::JointIndex & i = (Model::JointIndex) jmodel.id();
47 jmodel.calc(jdata.derived(),q);
57 typedef boost::fusion::vector<
const Model&,
62 template<
typename Jo
intModel>
75 typedef Data::Matrix6x::ColsBlockXpr Block;
76 const Model::JointIndex & i = (Model::JointIndex) jmodel.id();
80 jmodel.jointCols(data.
Fcrb[i]) = data.
Ycrb[i] * jdata.S();
83 data.
M.block(jmodel.idx_v(),jmodel.idx_v(),jmodel.nv(),data.
nvSubtree[i])
84 = jdata.S().transpose()*data.
Fcrb[i].middleCols(jmodel.idx_v(),data.
nvSubtree[i]);
86 const Model::JointIndex & parent = model.
parents[i];
94 = data.
Fcrb[parent].middleCols(jmodel.idx_v(),data.
nvSubtree[i]);
97 forceSet::se3Action(data.
liMi[i], iF, jF);
104 typedef boost::fusion::vector<
const se3::Model&,
106 const Eigen::VectorXd &
111 template<
typename Jo
intModel>
114 const se3::Model & model,
116 const Eigen::VectorXd & q)
118 const Model::JointIndex & i = (Model::JointIndex) jmodel.id();
119 jmodel.calc(jdata.derived(),q);
123 const Model::JointIndex & parent = model.
parents[i];
124 if (parent>0) data.
oMi[i] = data.
oMi[parent]*data.
liMi[i];
125 else data.
oMi[i] = data.
liMi[i];
127 jmodel.jointCols(data.
J) = data.
oMi[i].act(jdata.S());
136 typedef boost::fusion::vector<
const Model&,
141 template<
typename Jo
intModel>
148 const Model::JointIndex & i = (Model::JointIndex) jmodel.id();
151 jdata.U() = data.
Ycrb[i] * jdata.S();
152 ColsBlock jF = data.
Ag.middleCols<JointModel::NV>(jmodel.idx_v());
155 forceSet::se3Action(data.
oMi[i],jdata.U(),jF);
158 data.
M.block(jmodel.idx_v(),jmodel.idx_v(),jmodel.nv(),data.
nvSubtree[i]).noalias()
159 = jmodel.jointCols(data.
J).transpose()*data.
Ag.middleCols(jmodel.idx_v(),data.
nvSubtree[i]);
161 const Model::JointIndex & parent = model.
parents[i];
167 inline const Eigen::MatrixXd&
169 const Eigen::VectorXd & q)
171 assert(model.
check(data) &&
"data is not consistent with model.");
173 for( Model::JointIndex i=1;i<(Model::JointIndex)(model.
njoints);++i )
176 CrbaForwardStep::ArgsType(model,data,q));
179 for( Model::JointIndex i=(Model::JointIndex)(model.
njoints-1);i>0;--i )
182 CrbaBackwardStep::ArgsType(model,data));
188 inline const Eigen::MatrixXd &
190 const Eigen::VectorXd & q)
192 assert(model.
check(data) &&
"data is not consistent with model.");
194 for( Model::JointIndex i=1;i<(Model::JointIndex)(model.
njoints);++i )
196 CrbaForwardStepMinimal::run(model.
joints[i],data.
joints[i],
197 CrbaForwardStepMinimal::ArgsType(model,data,q));
200 for( Model::JointIndex i=(Model::JointIndex)(model.
njoints-1);i>0;--i )
202 CrbaBackwardStepMinimal::run(model.
joints[i],data.
joints[i],
203 CrbaBackwardStepMinimal::ArgsType(model,data));
209 data.
com[0] = data.
Ycrb[0].lever();
211 const Block3x Ag_lin = data.
Ag.middleRows<3>(Force::LINEAR);
212 Block3x Ag_ang = data.
Ag.middleRows<3>(Force::ANGULAR);
213 for(
long i = 0; i<model.
nv; ++i)
214 Ag_ang.col(i) += Ag_lin.col(i).cross(data.
com[0]);
225 inline bool isDescendant(
const Model& model,
const JointIndex j,
const JointIndex root)
227 if(
int(j)>=model.
njoints)
return false;
228 if(j==0)
return root==0;
229 return (j==root) || isDescendant(model,model.
parents[j],root);
233 inline bool CRBAChecker::checkModel_impl(
const Model& model )
const 239 for( JointIndex i=1; int(i)<model.
njoints-1; ++i )
242 while(internal::isDescendant(model,k,i)) ++k;
243 for( ; int(k)<model.
njoints; ++k )
244 if( internal::isDescendant(model,k,i) )
return false;
254 #endif // ifndef __se3_crba_hxx__ Matrix6x Ag
Centroidal Momentum Matrix.
int nv
Dimension of the velocity vector space.
container::aligned_vector< SE3 > jointPlacements
Placement (SE3) of the input of joint i regarding to the parent joint output li.
std::vector< int > nvSubtree
Dimension of the subtree motion space (for CRBA)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef Eigen::Matrix< double, 6, Eigen::Dynamic > Matrix6x
The 6d jacobian type (temporary)
JointModelVector joints
Model of joint i, encapsulated in a JointModelAccessor.
container::aligned_vector< Inertia > Ycrb
Vector of sub-tree composite rigid body inertias, i.e. the apparent inertia of the subtree supported ...
const Eigen::MatrixXd & crba(const Model &model, Data &data, const Eigen::VectorXd &q)
Computes the upper triangular part of the joint space inertia matrix M by using the Composite Rigid B...
Matrix6x J
Jacobian of joint placements.
std::vector< JointIndex > parents
Joint parent of joint i, denoted li (li==parents[i]).
container::aligned_vector< Matrix6x > Fcrb
Spatial forces set, used in CRBA and CCRBA.
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.
const Eigen::MatrixXd & crbaMinimal(const Model &model, Data &data, const Eigen::VectorXd &q)
Computes the upper triangular part of the joint space inertia matrix M by using the Composite Rigid B...
JointDataVector joints
Vector of se3::JointData associated to the se3::JointModel stored in model, encapsulated in JointData...
Eigen::MatrixXd M
The joint space inertia matrix (a square matrix of dim model.nv).
container::aligned_vector< SE3 > liMi
Vector of relative joint placements (wrt the body parent).
container::aligned_vector< SE3 > oMi
Vector of absolute joint placements (wrt the world).
bool check(const AlgorithmCheckerBase< D > &checker=AlgorithmCheckerBase< D >()) const
container::aligned_vector< Inertia > inertias
Spatial inertias of the body i expressed in the supporting joint frame i.
int njoints
Number of joints.