10 #include <boost/test/unit_test.hpp>
11 #include <boost/utility/binary.hpp>
14 using namespace Eigen;
16 template<
typename Jo
intModel>
20 template<
typename Jo
intModel>
27 template<
typename Jo
intModel>
36 jmodel_composite.setIndexes(jmodel.
id(), jmodel.
idx_q(), jmodel.
idx_v());
38 typedef typename JointModel::ConfigVector_t ConfigVector_t;
39 typedef typename JointModel::TangentVector_t TangentVector_t;
42 typedef Eigen::Matrix<typename ConfigVector_t::Scalar, Eigen::Dynamic, 1, ConfigVector_t::Options>
44 typedef DynConfigVectorType DynTangentVectorType;
46 ConfigVector_t ql(ConfigVector_t::Constant(jmodel.
nq(), -M_PI));
47 ConfigVector_t qu(ConfigVector_t::Constant(jmodel.
nq(), M_PI));
48 DynConfigVectorType
q = LieGroupType().randomConfiguration(ql, qu);
50 BOOST_CHECK(jmodel.
nv() == jmodel_composite.nv());
51 BOOST_CHECK(jmodel.
nq() == jmodel_composite.nq());
53 jmodel.
calc(jdata,
q);
54 jmodel_composite.
calc(jdata_composite,
q);
56 BOOST_CHECK(jdata_composite.
M.isApprox((
SE3)jdata.
M));
57 BOOST_CHECK(jdata_composite.
S.matrix().isApprox(jdata.
S.matrix()));
59 q = LieGroupType().randomConfiguration(ql, qu);
60 DynTangentVectorType
v = TangentVector_t::Random(jmodel.
nv());
62 jmodel_composite.
calc(jdata_composite,
q,
v);
64 BOOST_CHECK(jdata_composite.
M.isApprox((
SE3)jdata.
M));
65 BOOST_CHECK(jdata_composite.
S.matrix().isApprox(jdata.
S.matrix()));
66 BOOST_CHECK(jdata_composite.
v.isApprox((
Motion)jdata.
v));
67 BOOST_CHECK(jdata_composite.
c.isApprox((
Motion)jdata.
c));
92 Inertia::Matrix6 I1 = I0;
93 Inertia::Matrix6 I2 = I0;
95 const Eigen::VectorXd armature =
96 Eigen::VectorXd::Random(jmodel.
nv()) + Eigen::VectorXd::Ones(jmodel.
nv());
97 jmodel.
calc_aba(jdata, armature, I1,
true);
98 jmodel_composite.
calc_aba(jdata_composite, armature, I2,
true);
102 BOOST_CHECK(jdata.
U.isApprox(jdata_composite.
U, prec));
103 BOOST_CHECK(jdata.
Dinv.isApprox(jdata_composite.
Dinv, prec));
104 BOOST_CHECK(jdata.
UDinv.isApprox(jdata_composite.
UDinv, prec));
110 if (jmodel.
shortname() ==
"JointModelFreeFlyer")
111 BOOST_CHECK((I1 - I2).lpNorm<Eigen::Infinity>() < prec);
113 BOOST_CHECK(I1.isApprox(I2, prec));
119 jmodel_composite2.
calc(jdata_composite2,
q,
v);
121 Inertia::Matrix6 I3 = I0;
122 jmodel_composite2.
calc_aba(jdata_composite2, armature, I3,
true);
124 if (jmodel.
shortname() ==
"JointModelFreeFlyer")
125 BOOST_CHECK((I3 - I2).lpNorm<Eigen::Infinity>() < prec);
127 BOOST_CHECK(I3.isApprox(I2, prec));
129 BOOST_CHECK(jmodel_composite2 == jmodel_composite);
131 BOOST_CHECK(jdata_composite2.
U.isApprox(jdata_composite.
U, prec));
132 BOOST_CHECK(jdata_composite2.
Dinv.isApprox(jdata_composite.
Dinv, prec));
133 BOOST_CHECK(jdata_composite2.
UDinv.isApprox(jdata_composite.
UDinv, prec));
136 std::cout <<
"JointModelComposite operator<<:\n" << jmodel_composite << std::endl;
160 template<
typename Jo
intModel>
195 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
199 typedef boost::variant<
215 BOOST_CHECK_MESSAGE(jmodel_composite.nq() == 3,
"Chain did not work");
216 BOOST_CHECK_MESSAGE(jmodel_composite.nv() == 3,
"Chain did not work");
217 BOOST_CHECK_MESSAGE(jmodel_composite.
njoints == 3,
"Chain did not work");
254 jmodel_composite_recursive.
addJoint(jmodel_composite_two_rx);
262 jmodel_composite_planar.setIndexes(0, 0, 0);
266 VectorXd
q1(VectorXd::Random(3));
267 VectorXd q1_dot(VectorXd::Random(3));
273 model_copy.nq() == jmodel_composite_planar.nq(),
"Test Copy Composite, nq are differents");
275 model_copy.nv() == jmodel_composite_planar.nv(),
"Test Copy Composite, nv are differents");
277 jmodel_composite_planar.
calc(jdata_composite_planar,
q1, q1_dot);
278 model_copy.
calc(data_copy,
q1, q1_dot);
289 for (
int i = 0;
i < 10;
i++)
302 Data data_c(model_c);
304 BOOST_CHECK(
model.nv == model_c.
nv);
305 BOOST_CHECK(
model.nq == model_c.
nq);
307 VectorXd
q(VectorXd::Random(
model.nv));
311 BOOST_CHECK(
data.oMi.back().isApprox(data_c.oMi.back()));
314 VectorXd
v(VectorXd::Random(
model.nv));
318 BOOST_CHECK(
data.oMi.back().isApprox(data_c.oMi.back()));
319 BOOST_CHECK(
data.v.back().isApprox(data_c.v.back()));
323 VectorXd
a(VectorXd::Random(
model.nv));
327 BOOST_CHECK(
data.oMi.back().isApprox(data_c.oMi.back()));
328 BOOST_CHECK(
data.v.back().isApprox(data_c.v.back()));
329 BOOST_CHECK(
data.a.back().isApprox(data_c.a.back()));
332 BOOST_AUTO_TEST_SUITE_END()