18 #ifndef __se3_center_of_mass_hxx__ 19 #define __se3_center_of_mass_hxx__ 21 #include "pinocchio/algorithm/check.hpp" 27 inline const SE3::Vector3 &
29 const Eigen::VectorXd & q,
30 const bool computeSubtreeComs)
38 inline const SE3::Vector3 &
40 const Eigen::VectorXd & q,
41 const Eigen::VectorXd & v,
42 const bool computeSubtreeComs)
46 centerOfMass<true,true,false>(model,data,computeSubtreeComs);
50 inline const SE3::Vector3 &
52 const Eigen::VectorXd & q,
53 const Eigen::VectorXd & v,
54 const Eigen::VectorXd & a,
55 const bool computeSubtreeComs)
59 centerOfMass<true,true,true>(model,data,computeSubtreeComs);
63 template<
bool do_position,
bool do_velocity,
bool do_acceleration>
65 const bool computeSubtreeComs)
67 assert(model.
check(data) &&
"data is not consistent with model.");
72 data.
com[0].setZero ();
74 data.
vcom[0].setZero ();
76 data.
acom[0].setZero ();
79 for(Model::JointIndex i=1;i<(Model::JointIndex)(model.
njoints);++i)
81 const double mass = model.
inertias[i].mass();
82 const SE3::Vector3 & lever = model.
inertias[i].lever();
90 data.
com[i] = mass * lever;
93 data.
vcom[i] = mass * (v.angular().cross(lever) + v.linear());
96 data.
acom[i] = mass * (a.angular().cross(lever) + a.linear())
97 + v.angular().cross(data.
vcom[i]);
101 for(Model::JointIndex i=(Model::JointIndex)(model.
njoints-1); i>0; --i)
103 const Model::JointIndex & parent = model.
parents[i];
104 const SE3 & liMi = data.
liMi[i];
109 data.
com[parent] += (liMi.rotation()*data.
com[i]
110 + data.
mass[i] * liMi.translation());
113 data.
vcom[parent] += liMi.rotation()*data.
vcom[i];
114 data.
acom[parent] += liMi.rotation()*data.
acom[i];
116 if(computeSubtreeComs)
135 inline const SE3::Vector3 &
139 assert(model.
check(data) &&
"data is not consistent with model.");
141 return data.
com[0] = data.
liMi[1].act(data.
Ycrb[1].lever());
151 typedef boost::fusion::vector<
const se3::Model &,
158 template<
typename Jo
intModel>
161 const se3::Model& model,
163 const bool computeSubtreeComs )
165 const Model::JointIndex & i = (Model::JointIndex) jmodel.id();
166 const Model::JointIndex & parent = model.
parents[i];
168 data.
com[parent] += data.
com[i];
174 ColBlock Jcols = jmodel.jointCols(data.
J);
175 Jcols = data.
oMi[i].act(jdata.S());
177 if (JointModel::NV == -1)
179 if( jmodel.nv() ==1 )
181 data.
Jcom.col(jmodel.idx_v())
182 = data.
mass[i] * Jcols.template topLeftCorner<3,1>()
183 - data.
com[i].cross(Jcols.template bottomLeftCorner<3,1>()) ;
187 jmodel.jointCols(data.
Jcom)
188 = data.
mass[i] * Jcols.template topRows<3>()
189 -
skew(data.
com[i]) * Jcols.template bottomRows<3>();
194 if( JointModel::NV ==1 )
196 data.
Jcom.col(jmodel.idx_v())
197 = data.
mass[i] * Jcols.template topLeftCorner<3,1>()
198 - data.
com[i].cross(Jcols.template bottomLeftCorner<3,1>()) ;
202 jmodel.jointCols(data.
Jcom)
203 = data.
mass[i] * Jcols.template topRows<3>()
204 -
skew(data.
com[i]) * Jcols.template bottomRows<3>();
209 if(computeSubtreeComs)
217 const Eigen::VectorXd & q,
218 const bool computeSubtreeComs,
219 const bool updateKinematics)
221 assert(model.
check(data) &&
"data is not consistent with model.");
222 data.
com[0].setZero ();
226 if (updateKinematics)
229 for(Model::JointIndex i=1;i<(Model::JointIndex)(model.
njoints);++i)
231 const double mass = model.
inertias[i].mass();
232 const SE3::Vector3 & lever = model.
inertias[i].lever();
235 data.
com[i] = mass*data.
oMi[i].act(lever);
239 for( Model::JointIndex i= (Model::JointIndex) (model.
njoints-1);i>0;--i )
241 JacobianCenterOfMassBackwardStep
243 JacobianCenterOfMassBackwardStep::ArgsType(model,data,computeSubtreeComs));
255 assert(model.
check(data) &&
"data is not consistent with model.");
256 const SE3 & oM1 = data.
liMi[1];
259 data.
mass[0] = data.
M(0,0);
263 const SE3::Matrix3 oR1_over_m (oM1.rotation() / data.
M(0,0));
267 for (
long k=0; k<model.
nv;++k)
268 data.
Jcom.col(k) = oR1_over_m * data.
M.topRows<3> ().col(k);
276 #endif // ifndef __se3_center_of_mass_hxx__ container::aligned_vector< Motion > a
Vector of joint accelerations expressed at the centers of the joints.
Matrix3x Jcom
Jacobien of center of mass.
container::aligned_vector< Eigen::Vector3d > vcom
Vector of subtree center of mass linear velocities expressed in the root joint of the subtree...
int nv
Dimension of the velocity vector space.
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 ...
void skew(const Eigen::MatrixBase< Vector3 > &v, const Eigen::MatrixBase< Matrix3 > &M)
Computes the skew representation of a given 3d vector, i.e. the antisymmetric matrix representation o...
Matrix6x J
Jacobian of joint placements.
const SE3::Vector3 & getComFromCrba(const Model &model, Data &data)
Extracts the center of mass position from the joint space inertia matrix (also called the mass matrix...
container::aligned_vector< Eigen::Vector3d > acom
Vector of subtree center of mass linear accelerations expressed in the root joint of the subtree...
const Data::Matrix3x & getJacobianComFromCrba(const Model &model, Data &data)
Extracts both the jacobian of the center of mass (CoM), the total mass of the system and the CoM posi...
std::vector< JointIndex > parents
Joint parent of joint i, denoted li (li==parents[i]).
const Data::Matrix3x & jacobianCenterOfMass(const Model &model, Data &data, const Eigen::VectorXd &q, const bool computeSubtreeComs=true, const bool updateKinematics=true)
Computes both the jacobian and the the center of mass position of a given model according to a partic...
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.
JointDataVector joints
Vector of se3::JointData associated to the se3::JointModel stored in model, encapsulated in JointData...
void forwardKinematics(const Model &model, Data &data, const Eigen::VectorXd &q)
Update the joint placements according to the current joint configuration.
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).
const SE3::Vector3 & centerOfMass(const Model &model, Data &data, const Eigen::VectorXd &q, const bool computeSubtreeComs=true)
Computes the center of mass position of a given model according to a particular joint configuration...
container::aligned_vector< SE3 > oMi
Vector of absolute joint placements (wrt the world).
Eigen::Matrix< double, 3, Eigen::Dynamic > Matrix3x
The 3d jacobian type (temporary)
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.
container::aligned_vector< Motion > v
Vector of joint velocities expressed at the centers of the joints.
int njoints
Number of joints.
std::vector< double > mass
Vector of subtree mass. In other words, mass[j] is the mass of the subtree supported by joint ...