6 #include "pinocchio/parsers/sample-models.hpp" 7 #include "pinocchio/algorithm/joint-configuration.hpp" 8 #include "pinocchio/math/quaternion.hpp" 10 #include <boost/test/unit_test.hpp> 11 #include <boost/utility/binary.hpp> 15 BOOST_AUTO_TEST_SUITE ( BOOST_TEST_MODULE )
21 std::vector<Eigen::VectorXd> qs(2);
22 std::vector<Eigen::VectorXd> qdots(2);
23 std::vector<Eigen::VectorXd> results(2);
28 qs[0] = Eigen::VectorXd::Ones(model.
nq);
31 qdots[0] = Eigen::VectorXd::Zero(model.
nv);
32 results[0] =
integrate(model,qs[0],qdots[0]);
34 BOOST_CHECK_MESSAGE(results[0].isApprox(qs[0], 1e-12),
"integration of full body with zero velocity - wrong results");
55 std::vector<Eigen::VectorXd> qs(2);
56 std::vector<Eigen::VectorXd> vs(2);
57 std::vector<Eigen::MatrixXd> results(2,Eigen::MatrixXd::Zero(model.
nv,model.
nv));
58 std::vector<Eigen::MatrixXd> results_fd(2,Eigen::MatrixXd::Zero(model.
nv,model.
nv));
60 qs[0] = Eigen::VectorXd::Ones(model.
nq);
63 vs[0] = Eigen::VectorXd::Zero(model.
nv);
64 vs[1] = Eigen::VectorXd::Ones(model.
nv);
68 const double eps = 1e-8;
69 for(Eigen::DenseIndex k = 0; k < model.
nv; ++k)
76 BOOST_CHECK(results[0].isIdentity(sqrt(eps)));
77 BOOST_CHECK(results[0].isApprox(results_fd[0],sqrt(eps)));
80 BOOST_CHECK(results[1].isApprox(results[0]));
85 for(Eigen::DenseIndex k = 0; k < model.
nv; ++k)
88 q_fd_intermediate =
integrate(model,qs[0],v_fd);
89 q_fd =
integrate(model,q_fd_intermediate,vs[1]);
94 BOOST_CHECK(results[0].isApprox(results_fd[0],sqrt(eps)));
98 for(Eigen::DenseIndex k = 0; k < model.
nv; ++k)
106 BOOST_CHECK(results[1].isApprox(results_fd[1],sqrt(eps)));
113 std::vector<Eigen::VectorXd> qs(2);
114 std::vector<Eigen::VectorXd> vs(2);
115 std::vector<Eigen::MatrixXd> results(2,Eigen::MatrixXd::Zero(model.
nv,model.
nv));
116 std::vector<Eigen::MatrixXd> results_fd(2,Eigen::MatrixXd::Zero(model.
nv,model.
nv));
118 qs[0] = Eigen::VectorXd::Random(model.
nq);
121 qs[1] = Eigen::VectorXd::Random(model.
nq);
125 vs[0] = Eigen::VectorXd::Zero(model.
nv);
126 vs[1] = Eigen::VectorXd::Ones(model.
nv);
130 const double eps = 1e-8;
132 for(Eigen::DenseIndex k = 0; k < model.
nv; ++k)
136 results_fd[0].col(k) = (
difference(model,q_fd,q1) - v_ref)/eps;
139 BOOST_CHECK(results[0].isApprox(results_fd[0],sqrt(eps)));
142 BOOST_CHECK((-results[0]).isIdentity());
145 BOOST_CHECK(results[1].isIdentity());
148 for(Eigen::DenseIndex k = 0; k < model.
nv; ++k)
152 results_fd[1].col(k) = (
difference(model,q0,q_fd) - v_ref)/eps;
155 BOOST_CHECK(results[1].isApprox(results_fd[1],sqrt(eps)));
162 std::vector<Eigen::VectorXd> qs(2);
163 std::vector<Eigen::VectorXd> vs(2);
164 std::vector<Eigen::MatrixXd> results(2,Eigen::MatrixXd::Zero(model.
nv,model.
nv));
165 std::vector<Eigen::MatrixXd> results_fd(2,Eigen::MatrixXd::Zero(model.
nv,model.
nv));
174 BOOST_CHECK(v_diff.isApprox(v));
176 Eigen::MatrixXd J_int_dq = Eigen::MatrixXd::Zero(model.
nv,model.
nv);
177 Eigen::MatrixXd J_int_dv = Eigen::MatrixXd::Zero(model.
nv,model.
nv);
181 Eigen::MatrixXd J_diff_dq0 = Eigen::MatrixXd::Zero(model.
nv,model.
nv);
182 Eigen::MatrixXd J_diff_dq1 = Eigen::MatrixXd::Zero(model.
nv,model.
nv);
186 BOOST_CHECK(J_int_dq.isApprox(Eigen::MatrixXd(-(J_int_dv * J_diff_dq0))));
187 BOOST_CHECK(Eigen::MatrixXd(J_int_dv * J_diff_dq1).isIdentity());
195 std::vector<Eigen::MatrixXd> results(3,Eigen::MatrixXd::Zero(model.
nv,model.
nv));
205 BOOST_CHECK(results[0].isApprox(results[1]));
208 results[1] = Eigen::MatrixXd::Random(model.
nv, model.
nv);
209 results[2] = results[1];
210 results[0].setZero();
213 BOOST_CHECK(results[1].isApprox(results[2] + results[0]));
216 results[1] = Eigen::MatrixXd::Random(model.
nv, model.
nv);
217 results[2] = results[1];
218 results[0].setZero();
221 BOOST_CHECK(results[1].isApprox(results[2] - results[0]));
224 results[0].setZero();
225 results[1].setZero();
228 BOOST_CHECK(results[0].isApprox(results[1]));
231 results[1] = Eigen::MatrixXd::Random(model.
nv, model.
nv);
232 results[2] = results[1];
233 results[0].setZero();
236 BOOST_CHECK(results[1].isApprox(results[2] + results[0]));
239 results[1] = Eigen::MatrixXd::Random(model.
nv, model.
nv);
240 results[2] = results[1];
241 results[0].setZero();
244 BOOST_CHECK(results[1].isApprox(results[2] - results[0]));
247 std::vector<Eigen::MatrixXd>
J(2,Eigen::MatrixXd::Zero(model.
nv,2*model.
nv));
248 J[0] = Eigen::MatrixXd::Random(model.
nv, 2*model.
nv);
249 results[0].setZero();
252 BOOST_CHECK(J[1].isApprox(results[0] * J[0]));
254 J[0] = Eigen::MatrixXd::Random(model.
nv, 2*model.
nv);
255 results[0].setZero();
258 BOOST_CHECK(J[1].isApprox(results[0] * J[0]));
261 J[1] = Eigen::MatrixXd::Random(model.
nv, 2*model.
nv);
263 results[0].setZero();
266 BOOST_CHECK(J[1].isApprox(results[0] * J[0]));
268 J[1] = Eigen::MatrixXd::Random(model.
nv, 2*model.
nv);
270 results[0].setZero();
273 BOOST_CHECK(J[1].isApprox(results[0] * J[0]));
287 BOOST_CHECK_MESSAGE(
difference(model, q0,
integrate(model,q0, qdot)).isApprox(qdot),
"difference (integrate) - wrong results");
296 expected << 0,0,0,0,0,0,1,
308 BOOST_CHECK_MESSAGE(neutral_config.isApprox(expected, 1e-12),
"neutral configuration - wrong results");
318 double dist =
distance(model,q0,q1);
320 BOOST_CHECK_MESSAGE(dist > 0.,
"distance - wrong results");
321 BOOST_CHECK_SMALL(dist-
difference(model,q0,q1).norm(), 1e-12);
331 double dist =
distance(model,q0,q1);
334 BOOST_CHECK_SMALL(dist-math::sqrt(squaredDistance_.sum()), 1e-12);
345 for (
int i = 0;
i < model.
nq; ++
i)
358 BOOST_CHECK(q.head<3>().isApprox(Eigen::VectorXd::Ones(3)));
359 BOOST_CHECK(fabs(q.segment<4>(3).norm() - 1) < Eigen::NumTraits<double>::epsilon());
360 BOOST_CHECK(fabs(q.segment<4>(7).norm() - 1) < Eigen::NumTraits<double>::epsilon());
361 const int n = model.
nq - 7 - 4 - 4;
362 BOOST_CHECK(q.tail(n).isApprox(Eigen::VectorXd::Ones(n)));
370 q = Eigen::VectorXd::Ones(model.
nq);
397 Eigen::MatrixXd jac(model.
nq,model.
nv); jac.setZero();
402 Eigen::MatrixXd jac_fd(model.
nq,model.
nv);
404 const double eps = 1e-8;
407 for(
int k = 0; k < model.
nv; ++k)
411 jac_fd.col(k) = (q_plus -
q)/eps;
415 BOOST_CHECK(jac.isApprox(jac_fd,sqrt(eps)));
418 BOOST_AUTO_TEST_SUITE_END ()
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorType > const Eigen::MatrixBase< TangentVectorType > & v
Scalar distance(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorIn1 > &q0, const Eigen::MatrixBase< ConfigVectorIn2 > &q1)
Distance between two configuration vectors, namely .
void integrateCoeffWiseJacobian(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVector > &q, const Eigen::MatrixBase< JacobianMatrix > &jacobian)
Return the Jacobian of the integrate function for the components of the config vector.
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...
void dDifference(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVector1 > &q0, const Eigen::MatrixBase< ConfigVector2 > &q1, const Eigen::MatrixBase< JacobianMatrix > &J, const ArgumentPosition arg)
Computes the Jacobian of a small variation of the configuration vector into the tangent space at iden...
void difference(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorIn1 > &q0, const Eigen::MatrixBase< ConfigVectorIn2 > &q1, const Eigen::MatrixBase< ReturnType > &dvout)
Compute the tangent vector that must be integrated during one unit time to go from q0 to q1...
ConfigVectorType lowerPositionLimit
Lower joint configuration limit.
BOOST_AUTO_TEST_CASE(integration_test)
bool isNormalized(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorType > &q, const Scalar &prec=Eigen::NumTraits< Scalar >::dummy_precision())
Check whether a configuration vector is normalized within the given precision provided by prec...
bool isSameConfiguration(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorIn1 > &q1, const Eigen::MatrixBase< ConfigVectorIn2 > &q2, const Scalar &prec=Eigen::NumTraits< Scalar >::dummy_precision())
Return true if the given configurations are equivalents, within the given precision.
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.
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorType > & q
void dIntegrateTransport(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVectorType > &v, const Eigen::MatrixBase< JacobianMatrixType1 > &Jin, const Eigen::MatrixBase< JacobianMatrixType2 > &Jout, const ArgumentPosition arg)
Transport a matrix from the terminal to the originate tangent space of the integrate operation...
void dIntegrate(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVectorType > &v, const Eigen::MatrixBase< JacobianMatrixType > &J, const ArgumentPosition arg, const AssignmentOperatorType op=SETTO)
Computes the Jacobian of a small variation of the configuration vector or the tangent vector into the...
void buildAllJointsModel(Model &model)
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorIn1 > const Eigen::MatrixBase< ConfigVectorIn2 > & q1
Main pinocchio namespace.
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorIn1 > & q0
void neutral(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ReturnType > &qout)
Return the neutral configuration element related to the model configuration space.
int nv
Dimension of the velocity vector space.
void interpolate(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorIn1 > &q0, const Eigen::MatrixBase< ConfigVectorIn2 > &q1, const Scalar &u, const Eigen::MatrixBase< ReturnType > &qout)
Interpolate two configurations for a given model.
VectorXs ConfigVectorType
Dense vectorized version of a joint configuration vector.
void normalize(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorType > &qout)
Normalize a configuration vector.
ConfigVectorType upperPositionLimit
Upper joint configuration limit.
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
JointCollectionTpl & model
int nq
Dimension of the configuration vector representation.
void squaredDistance(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorIn1 > &q0, const Eigen::MatrixBase< ConfigVectorIn2 > &q1, const Eigen::MatrixBase< ReturnType > &out)
Squared distance between two configuration vectors.