13 #include <boost/test/unit_test.hpp>
14 #include <boost/utility/binary.hpp>
16 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
21 using CppAD::NearEqual;
23 typedef AD<double> AD_double;
33 typedef Eigen::Matrix<AD_double, Eigen::Dynamic, 1> VectorXAD;
34 typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> MatrixX;
37 typedef JointModelRXAD::ConfigVector_t ConfigVectorAD;
42 typedef JointModelRX::ConfigVector_t ConfigVector;
43 typedef JointModelRX::TangentVector_t TangentVector;
47 jmodel.setIndexes(0, 0, 0);
50 JointModelRXAD jmodel_ad = jmodel.cast<AD_double>();
51 JointDataRXAD jdata_ad(jmodel_ad.createData());
54 ConfigVector
q(jmodel.nq());
55 JointOperation().random(
q);
56 ConfigVectorAD q_ad(
q.cast<AD_double>());
59 jmodel_ad.calc(jdata_ad, q_ad);
60 jmodel.calc(jdata,
q);
64 BOOST_CHECK(M1.isApprox(M2.cast<
double>()));
67 TangentVector
v(TangentVector::Random(jmodel.nv()));
68 VectorXAD
X(jmodel_ad.nv());
70 for (Eigen::DenseIndex k = 0; k < jmodel.nv(); ++k)
74 CppAD::Independent(
X);
75 jmodel_ad.calc(jdata_ad, q_ad,
X);
76 jmodel.calc(jdata,
q,
v);
78 MotionAD m_ad(jdata_ad.v);
82 for (Eigen::DenseIndex k = 0; k < 3; ++k)
84 Y[k + Motion::LINEAR] = m_ad.linear()[k];
85 Y[k + Motion::ANGULAR] = m_ad.angular()[k];
88 CppAD::ADFun<double> vjoint(
X,
Y);
90 CPPAD_TESTVECTOR(
double)
x((
size_t)jmodel_ad.nv());
91 for (Eigen::DenseIndex k = 0; k < jmodel.nv(); ++k)
96 CPPAD_TESTVECTOR(
double)
jac = vjoint.Jacobian(
x);
97 MatrixX
S(6,
jac.size() / 6);
98 S = Eigen::Map<MatrixX>(
jac.data(),
S.rows(),
S.cols());
100 BOOST_CHECK(
m.isApprox(m_ad.cast<
double>()));
102 BOOST_CHECK(Sref.matrix().isApprox(
S));
107 template<
typename Jo
intModel>
111 jmodel.setIndexes(0, 0, 0);
116 template<
typename Scalar,
int Options,
int axis>
121 jmodel.setIndexes(0, 0, 0);
126 template<
typename Scalar,
int Options>
131 JointModel jmodel(Vector3::UnitX(), Vector3::UnitY());
132 jmodel.setIndexes(0, 0, 0);
137 template<
typename Scalar,
int Options>
142 JointModel jmodel(Vector3::Random().normalized());
143 jmodel.setIndexes(0, 0, 0);
148 template<
typename Scalar,
int Options>
153 JointModel jmodel(Vector3::Random().normalized());
154 jmodel.setIndexes(0, 0, 0);
159 template<
typename Scalar,
int Options>
164 JointModel jmodel(Vector3::Random().normalized());
165 jmodel.setIndexes(0, 0, 0);
170 template<
typename Scalar,
int Options>
175 JointModel jmodel(Vector3::Random().normalized());
176 jmodel.setIndexes(0, 0, 0);
181 template<
typename Scalar,
int Options,
template<
typename,
int>
class JointCollection>
187 jmodel.setIndexes(0, 0, 0);
193 template<
typename Jo
intModel_>
199 template<
typename Scalar,
int Options,
template<
typename,
int>
class JointCollection>
207 jmodel.setIndexes(0, 0, 0);
212 template<
typename Jo
intModel>
216 using CppAD::NearEqual;
219 typedef typename JointModel::JointDataDerived
JointData;
221 typedef AD<Scalar> AD_scalar;
229 typedef Eigen::Matrix<AD_scalar, Eigen::Dynamic, 1> VectorXAD;
230 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> MatrixX;
233 typedef typename JointModelAD::JointDataDerived JointDataAD;
235 typedef typename JointModelAD::ConfigVector_t ConfigVectorAD;
237 typedef typename JointModel::ConfigVector_t ConfigVector;
238 typedef typename JointModel::TangentVector_t TangentVector;
243 JointModelAD jmodel_ad = jmodel.template cast<AD_scalar>();
244 JointDataAD jdata_ad(jmodel_ad.createData());
247 ConfigVector
q(jmodel.
nq());
248 ConfigVector lb(ConfigVector::Constant(jmodel.
nq(), -1.));
249 ConfigVector ub(ConfigVector::Constant(jmodel.
nq(), 1.));
251 typedef pinocchio::RandomConfigurationStep<
256 ConfigVectorAD q_ad(
q.template cast<AD_scalar>());
259 jmodel_ad.calc(jdata_ad, q_ad);
260 jmodel.
calc(jdata,
q);
262 SE3 M1(jdata_base.
M());
263 SE3AD M2(jdata_ad_base.
M());
264 BOOST_CHECK(M1.isApprox(M2.template cast<Scalar>()));
267 TangentVector
v(TangentVector::Random(jmodel.
nv()));
268 VectorXAD
X(jmodel_ad.nv());
270 for (Eigen::DenseIndex k = 0; k < jmodel.
nv(); ++k)
274 CppAD::Independent(
X);
275 jmodel_ad.calc(jdata_ad, q_ad,
X);
278 MotionAD m_ad(jdata_ad_base.
v());
282 for (Eigen::DenseIndex k = 0; k < 3; ++k)
284 Y[k + Motion::LINEAR] = m_ad.linear()[k];
285 Y[k + Motion::ANGULAR] = m_ad.angular()[k];
288 CppAD::ADFun<Scalar> vjoint(
X,
Y);
290 CPPAD_TESTVECTOR(
Scalar)
x((
size_t)jmodel_ad.nv());
291 for (Eigen::DenseIndex k = 0; k < jmodel.
nv(); ++k)
296 CPPAD_TESTVECTOR(
Scalar)
jac = vjoint.Jacobian(
x);
297 MatrixX
S(6,
jac.size() / 6);
298 S = Eigen::Map<typename PINOCCHIO_EIGEN_PLAIN_ROW_MAJOR_TYPE(MatrixX)>(
299 jac.data(),
S.rows(),
S.cols());
301 BOOST_CHECK(
m.isApprox(m_ad.template cast<Scalar>()));
303 BOOST_CHECK(Sref.matrix().isApprox(
S));
315 BOOST_AUTO_TEST_SUITE_END()