5 #include "pinocchio/spatial/fwd.hpp" 6 #include "pinocchio/spatial/se3.hpp" 7 #include "pinocchio/multibody/visitor.hpp" 8 #include "pinocchio/multibody/model.hpp" 9 #include "pinocchio/multibody/data.hpp" 10 #include "pinocchio/algorithm/aba.hpp" 11 #include "pinocchio/algorithm/rnea.hpp" 12 #include "pinocchio/algorithm/jacobian.hpp" 13 #include "pinocchio/algorithm/joint-configuration.hpp" 14 #include "pinocchio/algorithm/crba.hpp" 15 #include "pinocchio/parsers/sample-models.hpp" 17 #include "pinocchio/algorithm/compute-all-terms.hpp" 18 #include "pinocchio/utils/timer.hpp" 22 #include <boost/test/unit_test.hpp> 23 #include <boost/utility/binary.hpp> 25 BOOST_AUTO_TEST_SUITE ( BOOST_TEST_MODULE )
31 typedef typename JointModel::ConfigVector_t ConfigVector_t;
34 JointData jdata = jmodel.createData();
36 ConfigVector_t ql(ConfigVector_t::Constant(jmodel.nq(),-M_PI));
37 ConfigVector_t qu(ConfigVector_t::Constant(jmodel.nq(),M_PI));
39 ConfigVector_t
q = LieGroupType().randomConfiguration(ql,qu);
41 pinocchio::Inertia::Matrix6 I_check = I;
44 jmodel.calc_aba(jdata,I,
true);
46 Eigen::MatrixXd S = jdata.S.matrix();
47 Eigen::MatrixXd U_check = I_check*S;
48 Eigen::MatrixXd D_check = S.transpose()*U_check;
49 Eigen::MatrixXd Dinv_check = D_check.inverse();
50 Eigen::MatrixXd UDinv_check = U_check*Dinv_check;
51 Eigen::MatrixXd update_check = U_check*Dinv_check*U_check.transpose();
52 I_check -= update_check;
54 BOOST_CHECK(jdata.U.isApprox(U_check));
55 BOOST_CHECK(jdata.Dinv.isApprox(Dinv_check));
56 BOOST_CHECK(jdata.UDinv.isApprox(UDinv_check));
62 if(jmodel.shortname() ==
"JointModelFreeFlyer")
63 BOOST_CHECK((I-I_check).lpNorm<Eigen::Infinity>() < Eigen::NumTraits<double>::dummy_precision());
65 BOOST_CHECK(I.isApprox(I_check));
70 template <
typename Jo
intModel>
128 using namespace Eigen;
142 tau =
rnea(model, data_ref, q, v, a);
143 aba(model, data, q, v, tau);
145 for(
size_t k = 1; k < (size_t)model.
njoints; ++k)
147 BOOST_CHECK(data_ref.liMi[k].isApprox(data.liMi[k]));
148 BOOST_CHECK(data_ref.v[k].isApprox(data.v[k]));
151 BOOST_CHECK(data.
ddq.isApprox(a, 1e-12));
157 using namespace Eigen;
171 crba(model, data, q);
174 data.
M.triangularView<Eigen::StrictlyLower>()
175 = data.
M.transpose().triangularView<Eigen::StrictlyLower>();
182 tau -= J.transpose()*fext[
i].toVector();
185 aba(model, data, q, v, tau, fext);
187 BOOST_CHECK(data.
ddq.isApprox(a, 1e-12));
192 using namespace Eigen;
205 crba(model, data_ref, q);
207 data_ref.
M.triangularView<Eigen::StrictlyLower>()
208 = data_ref.
M.transpose().triangularView<Eigen::StrictlyLower>();
210 tau = data_ref.
M * a + data_ref.
nle;
211 aba(model, data, q, v, tau);
214 BOOST_CHECK(tau_ref.isApprox(tau, 1e-12));
217 BOOST_CHECK(data.
ddq.isApprox(a, 1e-12));
223 using namespace Eigen;
238 crba(model, data_ref, q);
239 data_ref.
M.triangularView<Eigen::StrictlyLower>()
240 = data_ref.
M.transpose().triangularView<Eigen::StrictlyLower>();
241 MatrixXd Minv_ref(data_ref.
M.inverse());
246 BOOST_CHECK(data.
Minv.topRows<6>().isApprox(Minv_ref.topRows<6>()));
248 data.
Minv.triangularView<Eigen::StrictlyLower>()
249 = data.
Minv.transpose().triangularView<Eigen::StrictlyLower>();
251 BOOST_CHECK(data.
Minv.isApprox(Minv_ref));
263 using namespace Eigen;
269 Data data1(model), data2(model);
278 for(
int k = 0; k < 20; ++k)
283 BOOST_CHECK(data1.Minv.isApprox(data2.
Minv));
286 BOOST_AUTO_TEST_SUITE_END ()
const DataTpl< Scalar, Options, JointCollectionTpl >::TangentVectorType & aba(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVectorType1 > &v, const Eigen::MatrixBase< TangentVectorType2 > &tau)
The Articulated-Body algorithm. It computes the forward dynamics, aka the joint accelerations given t...
JointModelPrismaticTpl< double, 0, 0 > JointModelPX
JointModelVector joints
Model of joint i, encapsulated in a JointModelAccessor.
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...
void setIndexes(JointIndex id, int q, int v)
const DataTpl< Scalar, Options, JointCollectionTpl >::RowMatrixXs & computeMinverse(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q)
Computes the inverse of the joint space inertia matrix using Articulated Body formulation.
boost::python::object matrix()
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...
JointModelDerived & addJoint(const JointModelBase< JointModel > &jmodel, const SE3 &placement=SE3::Identity())
Add a joint to the vector of joints.
void test_joint_methods(const pinocchio::JointModelBase< JointModel > &jmodel)
static InertiaTpl Random()
int njoints
Number of joints.
JointModelRevoluteUnboundedTpl< double, 0, 1 > JointModelRUBY
JointModelRevoluteUnalignedTpl< double > JointModelRevoluteUnaligned
JointDataTpl< double > JointData
JointModelPrismaticTpl< double, 0, 1 > JointModelPY
ConfigVectorType lowerPositionLimit
Lower joint configuration limit.
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.
void getJointJacobian(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &data, const typename ModelTpl< Scalar, Options, JointCollectionTpl >::JointIndex jointId, const ReferenceFrame rf, const Eigen::MatrixBase< Matrix6Like > &J)
Computes the Jacobian of a specific joint frame expressed either in the world (rf = WORLD) frame or i...
RowMatrixXs Minv
The inverse of the joint space inertia matrix (a square matrix of dim model.nv).
VectorXs nle
Vector of Non Linear Effects (dim model.nv). It corresponds to concatenation of the Coriolis...
JointModelRevoluteTpl< double, 0, 1 > JointModelRY
JointModelSphericalZYXTpl< double > JointModelSphericalZYX
The LOCAL frame convention corresponds to the frame directly attached to the moving part (Joint...
JointModelRevoluteTpl< double, 0, 2 > JointModelRZ
void operator()(const pinocchio::JointModelBase< pinocchio::JointModelRevoluteUnaligned > &) const
MatrixXs M
The joint space inertia matrix (a square matrix of dim model.nv).
void operator()(const pinocchio::JointModelBase< pinocchio::JointModelPrismaticUnaligned > &) const
#define PINOCCHIO_ALIGNED_STD_VECTOR(Type)
Motion gravity
Spatial gravity of the model.
TangentVectorType ddq
The joint accelerations computed from ABA.
JointModelTranslationTpl< double > JointModelTranslation
void setIndexes(JointIndex id, int nq, int nv)
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...
int nv
Dimension of the velocity vector space.
JointModelPrismaticTpl< double, 0, 2 > JointModelPZ
JointModelTpl< double > JointModel
void operator()(const pinocchio::JointModelBase< pinocchio::JointModelComposite > &) const
BOOST_AUTO_TEST_CASE(test_joint_basic)
JointModelFreeFlyerTpl< double > JointModelFreeFlyer
void normalize(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorType > &qout)
Normalize a configuration vector.
ConfigVectorType upperPositionLimit
Upper joint configuration limit.
const DataTpl< Scalar, Options, JointCollectionTpl >::TangentVectorType & nonLinearEffects(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVectorType > &v)
Computes the non-linear effects (Corriolis, centrifual and gravitationnal effects), also called the bias terms of the Lagrangian dynamics:
JointModelRevoluteUnboundedTpl< double, 0, 0 > JointModelRUBX
JointModelPrismaticUnalignedTpl< double > JointModelPrismaticUnaligned
void operator()(const pinocchio::JointModelBase< JointModel > &) const
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)
JointModelRevoluteTpl< double, 0, 0 > JointModelRX
int nq
Dimension of the configuration vector representation.
JointModelPlanarTpl< double > JointModelPlanar
void fill(Eigen::Ref< MatType > mat, const typename MatType::Scalar &value)