5 #include "pinocchio/algorithm/crba.hpp" 6 #include "pinocchio/algorithm/centroidal.hpp" 7 #include "pinocchio/algorithm/rnea.hpp" 8 #include "pinocchio/algorithm/jacobian.hpp" 9 #include "pinocchio/algorithm/center-of-mass.hpp" 10 #include "pinocchio/algorithm/joint-configuration.hpp" 12 #include "pinocchio/parsers/sample-models.hpp" 14 #include "pinocchio/utils/timer.hpp" 18 #include <boost/test/unit_test.hpp> 19 #include <boost/utility/binary.hpp> 21 template<
typename Jo
intModel>
24 const std::string & parent_name,
25 const std::string &
name,
27 bool setRandomLimits =
true)
30 typedef typename JointModel::ConfigVector_t CV;
31 typedef typename JointModel::TangentVector_t TV;
39 TV::Random() + TV::Constant(1),
40 TV::Random() + TV::Constant(1),
41 CV::Random() - CV::Constant(1),
42 CV::Random() + CV::Constant(1)
54 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
67 crba(model,data_ref,q);
68 data_ref.
M.triangularView<Eigen::StrictlyLower>() = data_ref.
M.transpose().triangularView<Eigen::StrictlyLower>();
69 data_ref.Ycrb[0] = data_ref.liMi[1].act(data_ref.Ycrb[1]);
75 BOOST_CHECK(
data.oYcrb[0].matrix().isApprox(data_ref.Ycrb[0].matrix(),1e-12));
78 BOOST_CHECK(
data.Ig.matrix().isApprox(Ig_ref.matrix(),1e-12));
84 BOOST_CHECK(
data.Ag.isApprox(Ag_ref,1e-12));
99 ccrba(model,data_ref,q,v);
101 BOOST_CHECK(
data.J.isApprox(data_ref.
J));
102 BOOST_CHECK(
data.Ag.isApprox(data_ref.
Ag));
106 BOOST_CHECK(
data.J.isApprox(data_ref.
J));
125 rnea(model,data_ref,q,v,a);
127 crba(model,data_ref,q);
128 data_ref.
M.triangularView<Eigen::StrictlyLower>() = data_ref.
M.transpose().triangularView<Eigen::StrictlyLower>();
133 SE3 oM1 (data_ref.liMi[1]);
139 ccrba(model,data_ref,q,v);
141 BOOST_CHECK(
data.Ag.isApprox(Ag_ref));
142 BOOST_CHECK(
data.Ag.isApprox(data_ref.
Ag));
143 BOOST_CHECK(
data.hg.isApprox(data_ref.
hg));
146 BOOST_CHECK(data_ref.vcom[0].isApprox(
data.hg.linear()/data_ref.
M(0,0)));
147 BOOST_CHECK(data_ref.vcom[0].isApprox(
data.vcom[0]));
148 BOOST_CHECK(data_ref.acom[0].isApprox(hdot_ref.linear()/data_ref.
M(0,0)));
151 BOOST_CHECK(hdot.
isApprox(hdot_ref));
154 BOOST_CHECK(
data.dAg.isZero());
159 Data data_ref(model), data_ref_plus(model),
data(model);
161 const double alpha = 1e-8;
166 crba(model,data_ref,q);
167 crba(model,data_ref_plus,q_plus);
171 for(
size_t i = 1;
i < (size_t)model.
njoints; ++
i)
173 Inertia::Matrix6 dYcrb = (data_ref_plus.oMi[
i].act(data_ref_plus.Ycrb[
i]).matrix() -
174 data_ref.oMi[
i].act(data_ref.Ycrb[
i]).matrix())/alpha;
175 BOOST_CHECK(data.doYcrb[
i].isApprox(dYcrb,sqrt(alpha)));
181 ccrba(model,data_ref,q,v);
185 crba(model,data_ref,q);
186 const Data::Matrix6x Ag_ref_from_M = data_ref.oMi[1].toDualActionMatrix() * data_ref.
M.topRows<6>();
188 const double alpha = 1e-8;
191 ccrba(model,data_ref,q_plus,v);
195 crba(model,data_ref,q_plus);
196 const Data::Matrix6x Ag_plus_ref_from_M = data_ref.oMi[1].toDualActionMatrix() * data_ref.
M.topRows<6>();
198 const Data::Matrix6x dAg_ref_from_M = (Ag_plus_ref_from_M - Ag_ref_from_M)/alpha;
200 dccrba(model, data, q, v);
205 BOOST_CHECK(dAg.isApprox(dAg_ref,sqrt(alpha)));
206 BOOST_CHECK(dAg.isApprox(dAg_ref_from_M,sqrt(alpha)));
211 std::vector<Data::Matrix6x> dAgdq((
size_t)model.
nv,Data::Matrix6x::Zero(6,model.
nv));
214 ccrba(model,data_fd,q,v);
223 const double alpha = 1e-8;
226 for(
int k = 0; k < model.
nv; ++k)
230 ccrba(model,data_fd,q_plus,v);
234 hg_fd = oMc_fd.
act(data_fd.
hg);
235 dAgdq[(size_t)k] = (Ag_fd - Ag0)/alpha;
236 dhdq.col(k) = (hg_fd - hg0).toVector()/alpha;
241 for(
int k = 0; k < model.
nv; ++k)
243 dAg_ref += dAgdq[(size_t)k] * v[k];
247 for(
int k = 0; k < model.
nv; ++k)
249 dAg_ref_bis.col(k) = dAgdq[(size_t)k] * v;
256 BOOST_CHECK(dAg.isApprox(dAg_ref,sqrt(alpha)));
257 BOOST_CHECK(dhdq.isApprox(dAg_ref_bis,sqrt(alpha)));
258 BOOST_CHECK((dAg*v).isApprox(dhdq*v,sqrt(alpha)));
275 dccrba(model,data_ref,q,v);
277 BOOST_CHECK(
data.J.isApprox(data_ref.
J));
278 BOOST_CHECK(
data.dJ.isApprox(data_ref.
dJ));
279 BOOST_CHECK(
data.Ag.isApprox(data_ref.
Ag));
280 BOOST_CHECK(
data.dAg.isApprox(data_ref.
dAg));
284 BOOST_CHECK(
data.J.isApprox(data_ref.
J));
285 BOOST_CHECK(
data.dJ.isApprox(data_ref.
dJ));
294 Data data(model), data_fk1(model), data_fk2(model), data_ref(model);
303 ccrba(model,data_ref,q,v);
308 BOOST_CHECK(
data.mass[0] == data_ref.
mass[0]);
309 BOOST_CHECK(
data.com[0].isApprox(data_ref.com[0]));
310 BOOST_CHECK(
data.hg.isApprox(data_ref.
hg));
311 for(
size_t k = 1; k < (size_t)model.
njoints; ++k)
313 BOOST_CHECK(
data.mass[k] == data_ref.
mass[k]);
314 BOOST_CHECK(
data.com[k].isApprox(data_ref.com[k]));
315 BOOST_CHECK(
data.v[k].isApprox(data_ref.v[k]));
322 BOOST_CHECK(data_fk1.hg.isApprox(
data.hg));
326 rnea(model,data_ref,q,v,a);
327 dccrba(model,data_ref,q,v);
328 const Force hgdot(data_ref.
Ag * a + data_ref.
dAg * v);
330 BOOST_CHECK(
data.mass[0] == data_ref.
mass[0]);
331 BOOST_CHECK(
data.com[0].isApprox(data_ref.com[0]));
332 BOOST_CHECK(
data.hg.isApprox(data_ref.
hg));
333 BOOST_CHECK(
data.dhg.isApprox(hgdot));
334 for(
size_t k = 1; k < (size_t)model.
njoints; ++k)
336 BOOST_CHECK(
data.mass[k] == data_ref.
mass[k]);
337 BOOST_CHECK(
data.com[k].isApprox(data_ref.com[k]));
338 BOOST_CHECK(
data.v[k].isApprox(data_ref.v[k]));
339 BOOST_CHECK(
data.a[k].isApprox(data_ref.a_gf[k]));
340 BOOST_CHECK(
data.f[k].isApprox(data_ref.f[k]));
347 BOOST_CHECK(data_fk2.hg.isApprox(
data.hg));
348 BOOST_CHECK(data_fk2.dhg.isApprox(
data.dhg));
352 const double eps = 1e-8;
363 Force dhg_ref = (transform.
act(hg_plus) - hg)/eps;
365 BOOST_CHECK(
data.dhg.isApprox(dhg_ref,sqrt(eps)));
368 BOOST_AUTO_TEST_SUITE_END()
Matrix6x dJ
Derivative of the Jacobian with respect to the time.
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorType > const Eigen::MatrixBase< TangentVectorType > & v
TangentVectorType tau
Vector of joint torques (dim model.nv).
const DataTpl< Scalar, Options, JointCollectionTpl >::Matrix6x & computeCentroidalMapTimeVariation(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVectorType > &v)
Computes the Centroidal Momentum Matrix time derivative.
const DataTpl< Scalar, Options, JointCollectionTpl >::Matrix6x & computeCentroidalMap(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q)
Computes the Centroidal Momentum Matrix,.
void addJointAndBody(Model &model, const JointModelBase< D > &jmodel, const Model::JointIndex parent_id, const SE3 &joint_placement, const std::string &name, const Inertia &Y)
const DataTpl< Scalar, Options, JointCollectionTpl >::MatrixXs & crba(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q)
Computes the upper triangular part of the joint space inertia matrix M by using the Composite Rigid B...
FrameIndex addJointFrame(const JointIndex &joint_index, int previous_frame_index=-1)
Add a joint to the frame tree.
bool isApprox(const Derived &other, const Scalar &prec=Eigen::NumTraits< Scalar >::dummy_precision()) const
Matrix6x J
Jacobian of joint placements.
void rnea(const int num_threads, ModelPoolTpl< Scalar, Options, JointCollectionTpl > &pool, const Eigen::MatrixBase< ConfigVectorPool > &q, const Eigen::MatrixBase< TangentVectorPool1 > &v, const Eigen::MatrixBase< TangentVectorPool2 > &a, const Eigen::MatrixBase< TangentVectorPool3 > &tau)
The Recursive Newton-Euler algorithm. It computes the inverse dynamics, aka the joint torques accordi...
void integrate(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVectorType > &v, const Eigen::MatrixBase< ReturnType > &qout)
Integrate a configuration vector for the specified model for a tangent vector during one unit time...
static InertiaTpl Random()
bool isApprox(const ForceDense< M2 > &f, const Scalar &prec=Eigen::NumTraits< Scalar >::dummy_precision()) const
int njoints
Number of joints.
ConfigVectorType lowerPositionLimit
Lower joint configuration limit.
BOOST_AUTO_TEST_CASE(test_ccrba)
void randomConfiguration(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorIn1 > &lowerLimits, const Eigen::MatrixBase< ConfigVectorIn2 > &upperLimits, const Eigen::MatrixBase< ReturnType > &qout)
Generate a configuration vector uniformly sampled among provided limits.
const DataTpl< Scalar, Options, JointCollectionTpl >::Vector3 & getComFromCrba(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data)
Extracts the center of mass position from the joint space inertia matrix (also called the mass matrix...
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorType > & q
const DataTpl< Scalar, Options, JointCollectionTpl >::Force & computeCentroidalMomentumTimeVariation(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data)
Computes the Centroidal momemtum and its time derivatives, a.k.a. the total momenta of the system and...
const DataTpl< Scalar, Options, JointCollectionTpl >::Force & computeCentroidalMomentum(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data)
Computes the Centroidal momentum, a.k.a. the total momenta of the system expressed around the center ...
void forwardKinematics(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q)
Update the joint placements according to the current joint configuration.
const DataTpl< Scalar, Options, JointCollectionTpl >::Matrix6x & dccrba(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVectorType > &v)
Computes the time derivative of the Centroidal Momentum Matrix according to the current configuration...
const DataTpl< Scalar, Options, JointCollectionTpl >::Matrix6x & ccrba(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVectorType > &v)
Computes the Centroidal Momentum Matrix, the Composite Ridig Body Inertia as well as the centroidal m...
ActionMatrixType toActionMatrix() const
The action matrix of .
static void addJointAndBody(pinocchio::Model &model, const pinocchio::JointModelBase< JointModel > &joint, const std::string &parent_name, const std::string &name, const pinocchio::SE3 placement=pinocchio::SE3::Random(), bool setRandomLimits=true)
JointIndex addJoint(const JointIndex parent, const JointModel &joint_model, const SE3 &joint_placement, const std::string &joint_name)
Add a joint to the kinematic tree with infinite bounds.
ActionMatrixType toDualActionMatrix() const
SE3Tpl inverse() const
aXb = bXa.inverse()
MatrixXs M
The joint space inertia matrix (a square matrix of dim model.nv).
pinocchio::JointIndex JointIndex
const DataTpl< Scalar, Options, JointCollectionTpl >::Matrix6x & computeJointJacobiansTimeVariation(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVectorType > &v)
Computes the full model Jacobian variations with respect to time. It corresponds to dJ/dt which depen...
Matrix6x dAg
Centroidal Momentum Matrix Time Variation.
Motion gravity
Spatial gravity of the model.
ConstLinearRef translation() const
SE3GroupAction< D >::ReturnType act(const D &d) const
ay = aXb.act(by)
traits< SE3Tpl >::Vector3 Vector3
Main pinocchio namespace.
JointModelSphericalTpl< double > JointModelSpherical
const DataTpl< Scalar, Options, JointCollectionTpl >::Matrix6x & computeJointJacobians(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q)
Computes the full model Jacobian, i.e. the stack of all motion subspace expressed in the world frame...
Matrix6x Ag
Centroidal Momentum Matrix.
int nv
Dimension of the velocity vector space.
JointIndex getJointId(const std::string &name) const
Return the index of a joint given by its name.
const DataTpl< Scalar, Options, JointCollectionTpl >::Vector3 & centerOfMass(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const bool computeSubtreeComs=true)
Computes the center of mass position of a given model according to a particular joint configuration...
ConfigVectorType upperPositionLimit
Upper joint configuration limit.
void appendBodyToJoint(const JointIndex joint_index, const Inertia &Y, const SE3 &body_placement=SE3::Identity())
Append a body to a given joint of the kinematic tree.
Force hg
Centroidal momentum quantity.
void humanoidRandom(ModelTpl< Scalar, Options, JointCollectionTpl > &model, bool usingFF=true)
Create a humanoid kinematic tree with 6-DOF limbs and random joint placements.
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > VectorXd
Eigen::Matrix< Scalar, 6, Eigen::Dynamic, Options > Matrix6x
The 6d jacobian type (temporary)
JointCollectionTpl & model
int nq
Dimension of the configuration vector representation.
std::vector< Scalar > mass
Vector of subtree mass. In other words, mass[j] is the mass of the subtree supported by joint ...
FrameIndex addBodyFrame(const std::string &body_name, const JointIndex &parentJoint, const SE3 &body_placement=SE3::Identity(), int previousFrame=-1)
Add a body to the frame tree.
void fill(Eigen::Ref< MatType > mat, const typename MatType::Scalar &value)