5 #include "pinocchio/autodiff/cppad.hpp" 6 #include "pinocchio/multibody/model.hpp" 7 #include "pinocchio/algorithm/joint-configuration.hpp" 11 #include <boost/test/unit_test.hpp> 12 #include <boost/utility/binary.hpp> 16 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
22 using CppAD::NearEqual;
24 typedef AD<Scalar> ADScalar;
35 std::vector<Eigen::VectorXd> results_q(2,Eigen::VectorXd::Zero(model.
nq));
36 std::vector<Eigen::VectorXd> results_v(2,Eigen::VectorXd::Zero(model.
nv));
39 typedef ADModel::ConfigVectorType ADConfigVectorType;
40 ADModel ad_model = model.
cast<ADScalar>();
41 ADConfigVectorType ad_q1(model.
nq);
42 ADConfigVectorType ad_q2(model.
nq);
43 ADConfigVectorType ad_v(model.
nv);
45 typedef Eigen::Matrix<Scalar,Eigen::Dynamic,1> VectorX;
46 typedef Eigen::Matrix<ADScalar,Eigen::Dynamic,1> VectorXAD;
47 typedef Eigen::Matrix<Scalar,Eigen::Dynamic,Eigen::Dynamic> MatrixX;
48 typedef Eigen::Matrix<ADScalar,Eigen::Dynamic,Eigen::Dynamic> MatrixXAD;
52 VectorXAD ad_x(model.
nq+model.
nv);
53 ad_x << q1.cast<ADScalar>(), v.cast<ADScalar>();
54 CppAD::Independent(ad_x);
55 ad_q1 = ad_x.head(model.
nq);
56 ad_v = ad_x.tail(model.
nv);
58 VectorXAD ad_y(model.
nq);
60 CppAD::ADFun<Scalar> ad_fun(ad_x,ad_y);
62 CPPAD_TESTVECTOR(Scalar) x_eval((
size_t)(ad_x.size()));
63 Eigen::Map<VectorX>(x_eval.data(),ad_x.size()) << q1,v;
64 CPPAD_TESTVECTOR(Scalar) y_eval((
size_t)(ad_y.size()));
65 y_eval = ad_fun.Forward(0,x_eval);
66 results_q[0] = Eigen::Map<VectorX>(y_eval.data(),ad_y.size());
69 BOOST_CHECK(results_q[0].
isApprox(results_q[1]));
71 Eigen::Map<VectorX>(x_eval.data(),ad_x.size()) << q1,VectorX::Zero(model.
nv);
72 y_eval = ad_fun.Forward(0,x_eval);
73 results_q[0] = Eigen::Map<VectorX>(y_eval.data(),ad_y.size());
74 BOOST_CHECK(results_q[0].
isApprox(q1));
79 VectorXAD ad_x(model.
nq+model.
nq);
80 ad_x << q1.cast<ADScalar>(), q2.cast<ADScalar>();
81 CppAD::Independent(ad_x);
82 ad_q1 = ad_x.head(model.
nq);
83 ad_q2 = ad_x.tail(model.
nq);
85 VectorXAD ad_y(model.
nv);
87 CppAD::ADFun<Scalar> ad_fun(ad_x,ad_y);
89 CPPAD_TESTVECTOR(Scalar) x_eval((
size_t)(ad_x.size()));
90 Eigen::Map<VectorX>(x_eval.data(),ad_x.size()) << q1,q2;
91 CPPAD_TESTVECTOR(Scalar) y_eval((
size_t)(ad_y.size()));
92 y_eval = ad_fun.Forward(0,x_eval);
93 results_v[0] = Eigen::Map<VectorX>(y_eval.data(),ad_y.size());
96 BOOST_CHECK(results_v[0].
isApprox(results_v[1]));
98 Eigen::Map<VectorX>(x_eval.data(),ad_x.size()) << q1,q1;
99 y_eval = ad_fun.Forward(0,x_eval);
100 results_v[0] = Eigen::Map<VectorX>(y_eval.data(),ad_y.size());
101 BOOST_CHECK(results_v[0].
isZero());
105 std::vector<MatrixX> results_J0(2,MatrixX::Zero(model.
nv,model.
nv));
106 std::vector<MatrixX> results_J1(2,MatrixX::Zero(model.
nv,model.
nv));
108 VectorXAD ad_x(model.
nq+model.
nq);
109 ad_x << q1.cast<ADScalar>(), q2.cast<ADScalar>();
110 CppAD::Independent(ad_x);
111 ad_q1 = ad_x.head(model.
nq);
112 ad_q2 = ad_x.tail(model.
nq);
114 MatrixXAD ad_y(2*model.
nv,model.
nv);
117 VectorXAD ad_y_flatten = Eigen::Map<VectorXAD>(ad_y.data(),ad_y.size());
118 CppAD::ADFun<Scalar> ad_fun(ad_x,ad_y_flatten);
120 CPPAD_TESTVECTOR(Scalar) x_eval((
size_t)(ad_x.size()));
121 Eigen::Map<VectorX>(x_eval.data(),ad_x.size()) << q1, q2;
122 CPPAD_TESTVECTOR(Scalar) y_eval((
size_t)(ad_y.size()));
123 y_eval = ad_fun.Forward(0,x_eval);
124 results_J0[0] = Eigen::Map<MatrixX>(y_eval.data(),ad_y.rows(),ad_y.cols()).topRows(model.
nv);
125 results_J1[0] = Eigen::Map<MatrixX>(y_eval.data(),ad_y.rows(),ad_y.cols()).bottomRows(model.
nv);
129 BOOST_CHECK(results_J0[0].
isApprox(results_J0[1]));
133 BOOST_CHECK(results_J1[0].
isApprox(results_J1[1]));
135 Eigen::Map<VectorX>(x_eval.data(),ad_x.size()) << q1, q1;
136 y_eval = ad_fun.Forward(0,x_eval);
137 results_J0[0] = Eigen::Map<MatrixX>(y_eval.data(),ad_y.rows(),ad_y.cols()).topRows(model.
nv);
138 results_J1[0] = Eigen::Map<MatrixX>(y_eval.data(),ad_y.rows(),ad_y.cols()).bottomRows(model.
nv);
140 BOOST_CHECK((-results_J0[0]).isIdentity());
141 BOOST_CHECK(results_J1[0].isIdentity());
146 BOOST_AUTO_TEST_SUITE_END()
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorType > const Eigen::MatrixBase< TangentVectorType > & v
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...
ModelTpl< NewScalar, Options, JointCollectionTpl > cast() const
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())
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...
bool isApprox(const Shape &s1, const Shape &s2, const FCL_REAL tol)
void buildAllJointsModel(Model &model)
JointCollectionTpl const Eigen::MatrixBase< ConfigVectorIn1 > const Eigen::MatrixBase< ConfigVectorIn2 > & q1
BOOST_AUTO_TEST_CASE(test_joint_configuration)
Main pinocchio namespace.
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.
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > VectorXd
JointCollectionTpl & model
int nq
Dimension of the configuration vector representation.