cppadcg-joint-configurations.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 CNRS INRIA
3 //
4 
5 #include "pinocchio/codegen/cppadcg.hpp"
6 #include "pinocchio/codegen/code-generator-algo.hpp"
7 #include "pinocchio/multibody/model.hpp"
8 #include "pinocchio/algorithm/joint-configuration.hpp"
9 
11 
12 #include <boost/test/unit_test.hpp>
13 #include <boost/utility/binary.hpp>
14 
15 using namespace pinocchio;
16 
17 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
18 
19 BOOST_AUTO_TEST_CASE(test_joint_configuration_code_generation)
20 {
21  typedef double Scalar;
22 
24 
25  Model model; buildAllJointsModel(model);
26  Eigen::VectorXd q1 = Eigen::VectorXd::Random(model.nq);
27  Eigen::VectorXd q2 = Eigen::VectorXd::Random(model.nq);
28  normalize(model,q1);
29  normalize(model,q2);
30 
31  Eigen::VectorXd v = Eigen::VectorXd::Random(model.nv);
32  std::vector<Eigen::VectorXd> results_q(2,Eigen::VectorXd::Zero(model.nq));
33  std::vector<Eigen::VectorXd> results_v(2,Eigen::VectorXd::Zero(model.nv));
34 
35  //Integrate
36  CodeGenIntegrate<double> cg_integrate(model);
37  cg_integrate.initLib();
38  cg_integrate.loadLib();
39 
40  cg_integrate.evalFunction(q1,v, results_q[0]);
41  pinocchio::integrate(model, q1,v,results_q[1]);
42  BOOST_CHECK(results_q[1].isApprox(results_q[0]));
43 
44  cg_integrate.evalFunction(q1,0*v,results_q[0]);
45  BOOST_CHECK(results_q[0].isApprox(q1));
46 
47  //Difference
48  CodeGenDifference<double> cg_difference(model);
49  cg_difference.initLib();
50  cg_difference.loadLib();
51 
52  cg_difference.evalFunction(q1,q2, results_v[0]);
53  pinocchio::difference(model,q1,q2,results_v[1]);
54  BOOST_CHECK(results_v[1].isApprox(results_v[0]));
55 
56  cg_difference.evalFunction(q1,q1,results_v[0]);
57  BOOST_CHECK(results_v[0].isZero());
58 
59  //dDifference
60  CodeGenDDifference<double> cg_dDifference(model);
61  cg_dDifference.initLib();
62  cg_dDifference.loadLib();
63 
64  //ARG0
65  std::vector<Eigen::MatrixXd> results_J(2,Eigen::MatrixXd::Zero(model.nv,model.nv));
66  cg_dDifference.evalFunction(q1,q2, results_J[0], pinocchio::ARG0);
67  pinocchio::dDifference(model,q1,q2,results_J[1], pinocchio::ARG0);
68  BOOST_CHECK(results_J[1].isApprox(results_J[0]));
69 
70  //ARG1
71  cg_dDifference.evalFunction(q1,q2, results_J[0], pinocchio::ARG1);
72  pinocchio::dDifference(model,q1,q2,results_J[1], pinocchio::ARG1);
73  BOOST_CHECK(results_J[1].isApprox(results_J[0]));
74 
75  //ARG0
76  cg_dDifference.evalFunction(q1,q1,results_J[0],pinocchio::ARG0);
77  BOOST_CHECK((-results_J[0]).isIdentity());
78 
79  //ARG1
80  cg_dDifference.evalFunction(q1,q1,results_J[0],pinocchio::ARG1);
81  BOOST_CHECK(results_J[0].isIdentity());
82 
83 }
84 
85 BOOST_AUTO_TEST_SUITE_END()
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorType > const Eigen::MatrixBase< TangentVectorType > & v
void evalFunction(const Eigen::MatrixBase< ConfigVectorType1 > &q0, const Eigen::MatrixBase< ConfigVectorType2 > &q1, const Eigen::MatrixBase< TangentVector > &v)
ModelTpl< double > Model
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...
bool isZero(const Eigen::MatrixBase< MatrixLike > &m, const typename MatrixLike::RealScalar &prec=Eigen::NumTraits< typename MatrixLike::Scalar >::dummy_precision())
Definition: math/matrix.hpp:56
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...
void evalFunction(const Eigen::MatrixBase< ConfigVectorType1 > &q0, const Eigen::MatrixBase< ConfigVectorType2 > &q1, const Eigen::MatrixBase< JacobianMatrix > &J, const ArgumentPosition arg)
SE3::Scalar Scalar
Definition: conversions.cpp:13
BOOST_AUTO_TEST_CASE(test_joint_configuration_code_generation)
void loadLib(const bool generate_if_not_exist=true)
void buildAllJointsModel(Model &model)
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorIn1 > const Eigen::MatrixBase< ConfigVectorIn2 > & q1
Main pinocchio namespace.
Definition: timings.cpp:30
q2
int nv
Dimension of the velocity vector space.
void normalize(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorType > &qout)
Normalize a configuration vector.
void evalFunction(const Eigen::MatrixBase< ConfigVectorType1 > &q, const Eigen::MatrixBase< TangentVector > &v, const Eigen::MatrixBase< ConfigVectorType2 > &qout)
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > VectorXd
Definition: conversions.cpp:14
JointCollectionTpl & model
int nq
Dimension of the configuration vector representation.


pinocchio
Author(s):
autogenerated on Tue Jun 1 2021 02:45:02