5 #include "pinocchio/multibody/model.hpp" 6 #include "pinocchio/multibody/data.hpp" 7 #include "pinocchio/algorithm/jacobian.hpp" 8 #include "pinocchio/algorithm/joint-configuration.hpp" 9 #include "pinocchio/algorithm/crba.hpp" 10 #include "pinocchio/algorithm/compute-all-terms.hpp" 11 #include "pinocchio/algorithm/rnea.hpp" 12 #include "pinocchio/algorithm/center-of-mass.hpp" 13 #include "pinocchio/utils/timer.hpp" 14 #include "pinocchio/parsers/sample-models.hpp" 18 #include <boost/test/unit_test.hpp> 19 #include <boost/utility/binary.hpp> 21 BOOST_AUTO_TEST_SUITE ( BOOST_TEST_MODULE )
25 using namespace Eigen;
42 BOOST_CHECK(data.com[0].isApprox(
getComFromCrba(model,data), 1e-12));
47 BOOST_CHECK(com.isApprox(data.com[0], 1e-12));
51 BOOST_CHECK(com.isApprox(data.com[0], 1e-12));
60 BOOST_CHECK((data.liMi[1].rotation() * acom_from_nle).isApprox(data.acom[0], 1e-12));
67 BOOST_CHECK((Jcom * v).isApprox(data.vcom[0], 1e-12));
72 BOOST_CHECK((Jcom * v).isApprox(data.vcom[0], 1e-12));
83 using namespace Eigen;
91 BOOST_CHECK(mass == mass);
93 double mass_check = 0.0;
95 mass_check += model.inertias[
i].mass();
97 BOOST_CHECK_CLOSE(mass, mass_check, 1e-12);
103 BOOST_CHECK(mass_data == mass_data);
104 BOOST_CHECK_CLOSE(mass, mass_data, 1e-12);
105 BOOST_CHECK_CLOSE(data1.
mass[0], mass_data, 1e-12);
112 BOOST_CHECK_CLOSE(data2.
mass[0], mass, 1e-12);
117 using namespace Eigen;
132 for(
size_t i=0;
i<(size_t)(model.
njoints);++
i)
134 BOOST_CHECK_CLOSE(data1.
mass[
i], data2.
mass[
i], 1e-12);
200 using namespace Eigen;
212 Data data_ref(model);
219 BOOST_CHECK(Jcom.isApprox(data_ref.
Jcom));
224 Data data_extracted(model), data_fd(model);
225 const double eps = 1e-8;
239 Jcom_extracted.setZero();
247 for(Eigen::DenseIndex k = 0; k < model.
nv; ++k)
253 Jcom_fd.col(k) = (com_plus -
com)/eps;
263 BOOST_CHECK(Jcom.isApprox(Jcom_fd,sqrt(eps)));
264 BOOST_CHECK(Jcom_extracted.isApprox(Jcom_fd,sqrt(eps)));
265 BOOST_CHECK(Jcom_extracted.isApprox(Jcom));
269 BOOST_CHECK(subtreeComVelocityInWorld.isApprox(subtreeComVelocityInWorld_ref));
273 BOOST_AUTO_TEST_SUITE_END ()
const DataTpl< Scalar, Options, JointCollectionTpl >::Matrix3x & getJacobianComFromCrba(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data)
Extracts both the jacobian of the center of mass (CoM), the total mass of the system and the CoM posi...
const DataTpl< Scalar, Options, JointCollectionTpl >::Matrix3x & jacobianCenterOfMass(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const bool computeSubtreeComs=true)
Computes both the jacobian and the the center of mass position of a given model according to a partic...
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...
Matrix6x J
Jacobian of joint placements.
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...
int njoints
Number of joints.
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.
Scalar computeTotalMass(const ModelTpl< Scalar, Options, JointCollectionTpl > &model)
Compute the total mass of the model and return it.
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...
BOOST_AUTO_TEST_CASE(test_com)
VectorXs nle
Vector of Non Linear Effects (dim model.nv). It corresponds to concatenation of the Coriolis...
void computeSubtreeMasses(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data)
Compute the mass of each kinematic subtree and store it in data.mass. The element mass[0] corresponds...
Matrix3x Jcom
Jacobian of center of mass.
Motion gravity
Spatial gravity of the model.
traits< SE3Tpl >::Vector3 Vector3
void getJacobianSubtreeCenterOfMass(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &data, const JointIndex &rootSubtreeId, const Eigen::MatrixBase< Matrix3xLike > &res)
Retrieves the Jacobian of the center of mass of the given subtree according to the current value stor...
Main pinocchio namespace.
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.
Eigen::Matrix< Scalar, 3, Eigen::Dynamic, Options > Matrix3x
The 3d jacobian type (temporary)
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...
void normalize(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorType > &qout)
Normalize a configuration vector.
ConfigVectorType upperPositionLimit
Upper joint configuration limit.
std::vector< int > nvSubtree
Dimension of the subtree motion space (for CRBA)
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:
void jacobianSubtreeCenterOfMass(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const JointIndex &rootSubtreeId, const Eigen::MatrixBase< Matrix3xLike > &res)
Computes the Jacobian of the center of mass of the given subtree according to a particular joint conf...
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
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 ...
void fill(Eigen::Ref< MatType > mat, const typename MatType::Scalar &value)