12 #include "pinocchio/spatial/fwd.hpp" 13 #include "pinocchio/multibody/model.hpp" 14 #include "pinocchio/multibody/data.hpp" 15 #include "pinocchio/algorithm/rnea.hpp" 16 #include "pinocchio/algorithm/jacobian.hpp" 17 #include "pinocchio/algorithm/center-of-mass.hpp" 18 #include "pinocchio/algorithm/joint-configuration.hpp" 19 #include "pinocchio/algorithm/crba.hpp" 20 #include "pinocchio/algorithm/centroidal.hpp" 21 #include "pinocchio/parsers/sample-models.hpp" 22 #include "pinocchio/utils/timer.hpp" 30 #include <pmmintrin.h> 33 #include <boost/test/unit_test.hpp> 34 #include <boost/utility/binary.hpp> 36 BOOST_AUTO_TEST_SUITE ( BOOST_TEST_MODULE )
41 _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
43 using namespace Eigen;
52 data.v[0] = Motion::Zero();
60 const size_t NBT = 10000;
63 std::cout <<
"(the time score in debug mode is not relevant) " ;
69 rnea(model,data,q,v,a);
71 timer.
toc(std::cout,NBT);
77 using namespace Eigen;
95 q.tail(model.
nq-7).setZero();
99 tau_rnea =
rnea(model,data_rnea,q,v,VectorXd::Zero (model.
nv));
101 BOOST_CHECK(tau_nle.isApprox(tau_rnea, 1e-12));
104 q.tail(model.
nq-7).setZero();
108 tau_rnea =
rnea(model,data_rnea,q,v,VectorXd::Zero (model.
nv));
110 BOOST_CHECK(tau_nle.isApprox(tau_rnea, 1e-12));
113 q.tail(model.
nq-7).setOnes();
117 tau_rnea =
rnea(model,data_rnea,q,v,VectorXd::Zero (model.
nv));
119 BOOST_CHECK(tau_nle.isApprox(tau_rnea, 1e-12));
126 tau_rnea =
rnea(model,data_rnea,q,v,VectorXd::Zero (model.
nv));
128 BOOST_CHECK(tau_nle.isApprox(tau_rnea, 1e-12));
133 using namespace Eigen;
142 Data data_rnea_fext(model);
143 Data data_rnea(model);
157 rnea(model,data_rnea,q,v,a);
161 tau_ref -= Jrf.transpose() * Frf.
toVector();
165 tau_ref -= Jlf.transpose() * Flf.
toVector();
167 rnea(model,data_rnea_fext,q,v,a,fext);
169 BOOST_CHECK(tau_ref.isApprox(data_rnea_fext.
tau));
174 using namespace Eigen;
183 Data data_rnea(model);
188 rnea(model,data_rnea,q,VectorXd::Zero(model.
nv),VectorXd::Zero(model.
nv));
191 BOOST_CHECK(data_rnea.
tau.isApprox(data.
g));
194 crba(model,data_rnea,q);
197 VectorXd g_ref(-data_rnea.
mass[0]*Jcom.transpose()*Model::gravity981);
199 BOOST_CHECK(g_ref.isApprox(data.
g));
204 using namespace Eigen;
213 Data data_rnea(model);
219 ForceVector fext((
size_t)model.
njoints);
220 for(ForceVector::iterator it = fext.begin(); it != fext.end(); ++it)
223 rnea(model,data_rnea,q,VectorXd::Zero(model.
nv),VectorXd::Zero(model.
nv),fext);
226 BOOST_CHECK(data_rnea.
tau.isApprox(data.
tau));
229 crba(model,data_rnea,q);
232 VectorXd static_torque_ref = -data_rnea.
mass[0]*Jcom.transpose()*Model::gravity981;
240 static_torque_ref -= J_local.transpose() * fext[
joint_id].toVector();
243 BOOST_CHECK(static_torque_ref.isApprox(data.
tau));
248 using namespace Eigen;
251 const double prec = Eigen::NumTraits<double>::dummy_precision();
259 Data data_ref(model);
266 BOOST_CHECK(data.
C.isZero(prec));
270 rnea(model,data_ref,q,v,VectorXd::Zero(model.
nv));
274 BOOST_CHECK(data.
dJ.isApprox(data_ref.
dJ));
275 BOOST_CHECK(data.
J.isApprox(data_ref.
J));
278 BOOST_CHECK(tau.isApprox(data_ref.
tau,prec));
280 dccrba(model,data_ref,q,v);
281 crba(model,data_ref,q);
284 Motion vcom(data_ref.vcom[0],Data::Vector3::Zero());
291 BOOST_CHECK(dh.
isApprox(dh_ref,prec));
294 Data data_ref(model), data_ref_plus(model);
295 Eigen::MatrixXd
dM(data.
C + data.
C.transpose());
297 const double alpha = 1e-8;
301 crba(model,data_ref,q);
302 data_ref.
M.triangularView<Eigen::StrictlyLower>() = data_ref.
M.transpose().triangularView<Eigen::StrictlyLower>();
303 crba(model,data_ref_plus,q_plus);
304 data_ref_plus.
M.triangularView<Eigen::StrictlyLower>() = data_ref_plus.
M.transpose().triangularView<Eigen::StrictlyLower>();
306 Eigen::MatrixXd dM_ref = (data_ref_plus.
M - data_ref.
M)/alpha;
307 BOOST_CHECK(
dM.isApprox(dM_ref,sqrt(alpha)));
312 BOOST_AUTO_TEST_SUITE_END()
Matrix6x dJ
Derivative of the Jacobian with respect to the time.
BOOST_AUTO_TEST_CASE(test_rnea)
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...
TangentVectorType tau
Vector of joint torques (dim model.nv).
bool isApprox(const ForceDense< M2 > &f, const Scalar &prec=Eigen::NumTraits< Scalar >::dummy_precision()) const
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...
VectorXs g
Vector of generalized gravity (dim model.nv).
ForceTpl< double, 0 > Force
const DataTpl< Scalar, Options, JointCollectionTpl >::TangentVectorType & computeStaticTorque(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const container::aligned_vector< ForceTpl< Scalar, Options > > &fext)
Computes the generalized static torque contribution of the Lagrangian dynamics: ...
Matrix6x J
Jacobian of joint placements.
ToVectorConstReturnType toVector() const
Return the force as an Eigen vector.
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...
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.
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...
ActionMatrixType toDualActionMatrix() const
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...
The LOCAL frame convention corresponds to the frame directly attached to the moving part (Joint...
MatrixXs M
The joint space inertia matrix (a square matrix of dim model.nv).
MatrixXs C
The Coriolis matrix (a square matrix of dim model.nv).
#define PINOCCHIO_ALIGNED_STD_VECTOR(Type)
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.
const DataTpl< Scalar, Options, JointCollectionTpl >::TangentVectorType & computeGeneralizedGravity(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q)
Computes the generalized gravity contribution of the Lagrangian dynamics:
Main pinocchio namespace.
JointIndex getJointId(const std::string &name) const
Return the index of a joint given by its name.
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.
Eigen::Matrix< Scalar, 3, Eigen::Dynamic, Options > Matrix3x
The 3d jacobian type (temporary)
const DataTpl< Scalar, Options, JointCollectionTpl >::MatrixXs & computeCoriolisMatrix(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVectorType > &v)
Computes the Coriolis Matrix of the Lagrangian dynamics:
SE3GroupAction< D >::ReturnType act(const D &d) const
ay = aXb.act(by)
ConfigVectorType upperPositionLimit
Upper joint configuration limit.
void computeJointJacobian(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const JointIndex jointId, const Eigen::MatrixBase< Matrix6Like > &J)
Computes the Jacobian of a specific joint frame expressed in the local frame of the joint and store t...
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 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)
int nq
Dimension of the configuration vector representation.
Eigen::Matrix< Scalar, 3, 1, Options > Vector3
std::vector< Scalar > mass
Vector of subtree mass. In other words, mass[j] is the mass of the subtree supported by joint ...
ConstLinearRef translation() const