18 #include <boost/test/unit_test.hpp>
19 #include <boost/utility/binary.hpp>
21 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
25 using namespace Eigen;
33 model.lowerPositionLimit.head<3>().
fill(-1.);
34 model.upperPositionLimit.head<3>().
fill(1.);
36 VectorXd
v(VectorXd::Zero(
model.nv));
37 VectorXd
a(VectorXd::Zero(
model.nv));
41 g_partial_dq.setZero();
45 BOOST_CHECK(
data.g.isApprox(g0));
48 g_partial_dq_fd.setZero();
50 VectorXd v_eps(Eigen::VectorXd::Zero(
model.nv));
51 VectorXd q_plus(
model.nq);
52 VectorXd g_plus(
model.nv);
53 const double alpha = 1e-8;
54 for (
int k = 0; k <
model.nv; ++k)
60 g_partial_dq_fd.col(k) = (g_plus - g0) /
alpha;
64 BOOST_CHECK(g_partial_dq.isApprox(g_partial_dq_fd, sqrt(
alpha)));
69 using namespace Eigen;
77 model.lowerPositionLimit.head<3>().
fill(-1.);
78 model.upperPositionLimit.head<3>().
fill(1.);
82 ForceVector fext((
size_t)
model.njoints);
83 for (ForceVector::iterator
it = fext.begin();
it != fext.end(); ++
it)
87 MatrixXd static_vec_partial_dq(
model.nv,
model.nv);
88 static_vec_partial_dq.setZero();
92 BOOST_CHECK(
data.tau.isApprox(tau0));
94 MatrixXd static_vec_partial_dq_fd(
model.nv,
model.nv);
96 VectorXd v_eps(Eigen::VectorXd::Zero(
model.nv));
97 VectorXd q_plus(
model.nq);
98 VectorXd tau_plus(
model.nv);
99 const double alpha = 1e-8;
100 for (
int k = 0; k <
model.nv; ++k)
106 static_vec_partial_dq_fd.col(k) = (tau_plus - tau0) /
alpha;
110 BOOST_CHECK(static_vec_partial_dq.isApprox(static_vec_partial_dq_fd, sqrt(
alpha)));
115 using namespace Eigen;
120 model.armature = VectorXd::Random(
model.nv) + VectorXd::Ones(
model.nv);
124 model.lowerPositionLimit.head<3>().
fill(-1.);
125 model.upperPositionLimit.head<3>().
fill(1.);
127 VectorXd
v(VectorXd::Random(
model.nv));
128 VectorXd
a(VectorXd::Random(
model.nv));
132 rnea_partial_dq.setZero();
134 rnea_partial_dv.setZero();
136 rnea_partial_da.setZero();
139 rnea_partial_dv, rnea_partial_da);
143 BOOST_CHECK(
data.of[k].isApprox(
data.oMi[k].act(data_ref.f[k])));
147 g_partial_dq.setZero();
150 BOOST_CHECK(
data.dFdq.isApprox(data_ref.
dFdq));
151 BOOST_CHECK(rnea_partial_dq.isApprox(g_partial_dq));
152 BOOST_CHECK(
data.tau.isApprox(data_ref.
g));
155 MatrixXd rnea_partial_dq_fd(
model.nv,
model.nv);
156 rnea_partial_dq_fd.setZero();
158 VectorXd v_eps(VectorXd::Zero(
model.nv));
159 VectorXd q_plus(
model.nq);
160 VectorXd tau_plus(
model.nv);
161 const double alpha = 1e-8;
162 for (
int k = 0; k <
model.nv; ++k)
166 tau_plus =
rnea(
model, data_fd, q_plus, VectorXd::Zero(
model.nv), VectorXd::Zero(
model.nv));
168 rnea_partial_dq_fd.col(k) = (tau_plus - tau0) /
alpha;
171 BOOST_CHECK(rnea_partial_dq.isApprox(rnea_partial_dq_fd, sqrt(
alpha)));
175 rnea_partial_dq_fd.setZero();
177 for (
int k = 0; k <
model.nv; ++k)
183 rnea_partial_dq_fd.col(k) = (tau_plus - tau0) /
alpha;
187 rnea_partial_dq.setZero();
189 model,
data,
q, VectorXd::Zero(
model.nv),
a, rnea_partial_dq, rnea_partial_dv, rnea_partial_da);
194 BOOST_CHECK(
data.a[k].isApprox(data_ref.a[k]));
195 BOOST_CHECK(
data.v[k].isApprox(data_ref.v[k]));
196 BOOST_CHECK(
data.oMi[k].isApprox(data_ref.oMi[k]));
197 BOOST_CHECK(
data.oh[k].isApprox(Force::Zero()));
200 BOOST_CHECK(
data.tau.isApprox(tau0));
201 BOOST_CHECK(rnea_partial_dq.isApprox(rnea_partial_dq_fd, sqrt(
alpha)));
205 model.gravity.setZero();
207 rnea_partial_dq_fd.setZero();
209 for (
int k = 0; k <
model.nv; ++k)
215 rnea_partial_dq_fd.col(k) = (tau_plus - tau0) /
alpha;
220 MatrixXd rnea_partial_dv_fd(
model.nv,
model.nv);
221 rnea_partial_dv_fd.setZero();
223 for (
int k = 0; k <
model.nv; ++k)
228 rnea_partial_dv_fd.col(k) = (tau_plus - tau0) /
alpha;
232 rnea_partial_dq.setZero();
233 rnea_partial_dv.setZero();
235 model,
data,
q,
v, VectorXd::Zero(
model.nv), rnea_partial_dq, rnea_partial_dv, rnea_partial_da);
240 BOOST_CHECK(
data.a[k].isApprox(data_ref.a[k]));
241 BOOST_CHECK(
data.v[k].isApprox(data_ref.v[k]));
242 BOOST_CHECK(
data.oMi[k].isApprox(data_ref.oMi[k]));
245 BOOST_CHECK(
data.tau.isApprox(tau0));
246 BOOST_CHECK(rnea_partial_dq.isApprox(rnea_partial_dq_fd, sqrt(
alpha)));
247 BOOST_CHECK(rnea_partial_dv.isApprox(rnea_partial_dv_fd, sqrt(
alpha)));
257 rnea_partial_dq_fd.setZero();
259 for (
int k = 0; k <
model.nv; ++k)
265 rnea_partial_dq_fd.col(k) = (tau_plus - tau0) /
alpha;
269 rnea_partial_dv_fd.setZero();
270 for (
int k = 0; k <
model.nv; ++k)
275 rnea_partial_dv_fd.col(k) = (tau_plus - tau0) /
alpha;
279 rnea_partial_dq.setZero();
280 rnea_partial_dv.setZero();
286 BOOST_CHECK(
data.a[k].isApprox(data_ref.a[k]));
287 BOOST_CHECK(
data.v[k].isApprox(data_ref.v[k]));
288 BOOST_CHECK(
data.oMi[k].isApprox(data_ref.oMi[k]));
292 BOOST_CHECK(
data.dJ.isApprox(data_ref.
dJ));
294 data_ref.
M.triangularView<Eigen::StrictlyLower>() =
295 data_ref.
M.transpose().triangularView<Eigen::StrictlyLower>();
297 rnea_partial_da.triangularView<Eigen::StrictlyLower>() =
298 rnea_partial_da.transpose().triangularView<Eigen::StrictlyLower>();
299 BOOST_CHECK(rnea_partial_da.isApprox(data_ref.
M));
301 BOOST_CHECK(
data.tau.isApprox(tau0));
302 BOOST_CHECK(rnea_partial_dq.isApprox(rnea_partial_dq_fd, sqrt(
alpha)));
303 BOOST_CHECK(rnea_partial_dv.isApprox(rnea_partial_dv_fd, sqrt(
alpha)));
307 data2.
M.triangularView<Eigen::StrictlyLower>() =
308 data2.
M.transpose().triangularView<Eigen::StrictlyLower>();
310 BOOST_CHECK(rnea_partial_dq.isApprox(data2.
dtau_dq));
311 BOOST_CHECK(rnea_partial_dv.isApprox(data2.
dtau_dv));
312 BOOST_CHECK(rnea_partial_da.isApprox(data2.
M));
317 using namespace Eigen;
326 model.lowerPositionLimit.head<3>().
fill(-1.);
327 model.upperPositionLimit.head<3>().
fill(1.);
329 VectorXd
v(VectorXd::Random(
model.nv));
330 VectorXd
a(VectorXd::Random(
model.nv));
333 ForceVector fext((
size_t)
model.njoints);
334 for (ForceVector::iterator
it = fext.begin();
it != fext.end(); ++
it)
339 rnea_partial_dq.setZero();
341 rnea_partial_dv.setZero();
343 rnea_partial_da.setZero();
346 model,
data,
q,
v,
a, fext, rnea_partial_dq, rnea_partial_dv, rnea_partial_da);
349 BOOST_CHECK(
data.tau.isApprox(data_ref.
tau));
352 BOOST_CHECK(rnea_partial_dv.isApprox(data_ref.
dtau_dv));
353 BOOST_CHECK(rnea_partial_da.isApprox(data_ref.
M));
355 MatrixXd rnea_partial_dq_fd(
model.nv,
model.nv);
356 rnea_partial_dq_fd.setZero();
357 MatrixXd rnea_partial_dv_fd(
model.nv,
model.nv);
358 rnea_partial_dv_fd.setZero();
359 MatrixXd rnea_partial_da_fd(
model.nv,
model.nv);
360 rnea_partial_da_fd.setZero();
362 VectorXd v_eps(VectorXd::Zero(
model.nv));
363 VectorXd q_plus(
model.nq);
364 VectorXd tau_plus(
model.nv);
365 const double eps = 1e-8;
367 const VectorXd tau_ref =
rnea(
model, data_ref,
q,
v,
a, fext);
368 for (
int k = 0; k <
model.nv; ++k)
372 tau_plus =
rnea(
model, data_fd, q_plus,
v,
a, fext);
374 rnea_partial_dq_fd.col(k) = (tau_plus - tau_ref) /
eps;
378 BOOST_CHECK(rnea_partial_dq.isApprox(rnea_partial_dq_fd, sqrt(
eps)));
381 for (
int k = 0; k <
model.nv; ++k)
385 tau_plus =
rnea(
model, data_fd,
q, v_plus,
a, fext);
387 rnea_partial_dv_fd.col(k) = (tau_plus - tau_ref) /
eps;
391 BOOST_CHECK(rnea_partial_dv.isApprox(rnea_partial_dv_fd, sqrt(
eps)));
394 for (
int k = 0; k <
model.nv; ++k)
398 tau_plus =
rnea(
model, data_fd,
q,
v, a_plus, fext);
400 rnea_partial_da_fd.col(k) = (tau_plus - tau_ref) /
eps;
405 rnea_partial_da.triangularView<Eigen::Lower>() =
406 rnea_partial_da.transpose().triangularView<Eigen::Lower>();
407 BOOST_CHECK(rnea_partial_da.isApprox(rnea_partial_da_fd, sqrt(
eps)));
412 BOOST_CHECK(data_shortcut.
dtau_dq.isApprox(rnea_partial_dq));
413 BOOST_CHECK(data_shortcut.
dtau_dv.isApprox(rnea_partial_dv));
414 data_shortcut.
M.triangularView<Eigen::Lower>() =
415 data_shortcut.
M.transpose().triangularView<Eigen::Lower>();
416 BOOST_CHECK(data_shortcut.
M.isApprox(rnea_partial_da));
421 using namespace Eigen;
429 model.lowerPositionLimit.head<3>().
fill(-1.);
430 model.upperPositionLimit.head<3>().
fill(1.);
432 VectorXd
v(VectorXd::Random(
model.nv));
433 VectorXd
a(VectorXd::Random(
model.nv));
437 rnea_partial_dq.setZero();
439 rnea_partial_dv.setZero();
441 rnea_partial_da.setZero();
446 BOOST_CHECK(
data.J.isApprox(data_ref.
J));
447 BOOST_CHECK(
data.dJ.isApprox(data_ref.
dJ));
449 for (
size_t k = 1; k < (size_t)
model.njoints; ++k)
451 BOOST_CHECK(
data.oMi[k].isApprox(data_ref.oMi[k]));
452 BOOST_CHECK(
data.ov[k].isApprox(data_ref.ov[k]));
453 BOOST_CHECK(
data.oa[k].isApprox(data_ref.oa[k]));
459 using namespace Eigen;
467 model.lowerPositionLimit.head<3>().
fill(-1.);
468 model.upperPositionLimit.head<3>().
fill(1.);
470 VectorXd
v(VectorXd::Random(
model.nv));
471 VectorXd
a(VectorXd::Random(
model.nv));
476 for (
int k = 0; k < 20; ++k)
481 BOOST_CHECK(data1.J.isApprox(data2.
J));
482 BOOST_CHECK(data1.dJ.isApprox(data2.
dJ));
483 BOOST_CHECK(data1.dVdq.isApprox(data2.
dVdq));
484 BOOST_CHECK(data1.dAdq.isApprox(data2.
dAdq));
485 BOOST_CHECK(data1.dAdv.isApprox(data2.
dAdv));
487 BOOST_CHECK(data1.dFdq.isApprox(data2.
dFdq));
488 BOOST_CHECK(data1.dFdv.isApprox(data2.
dFdv));
489 BOOST_CHECK(data1.dFda.isApprox(data2.
dFda));
491 BOOST_CHECK(data1.dtau_dq.isApprox(data2.
dtau_dq));
492 BOOST_CHECK(data1.dtau_dv.isApprox(data2.
dtau_dv));
493 BOOST_CHECK(data1.M.isApprox(data2.
M));
498 using namespace Eigen;
504 model.lowerPositionLimit.head<3>().
fill(-1.);
505 model.upperPositionLimit.head<3>().
fill(1.);
511 VectorXd
v = VectorXd::Random(
model.nv);
512 VectorXd
tau = VectorXd::Random(
model.nv);
519 BOOST_CHECK(
data.J.isApprox(data_ref.
J));
520 BOOST_CHECK(
data.dJ.isApprox(data_ref.
dJ));
521 BOOST_CHECK(
data.Ag.isApprox(data_ref.
Ag));
524 BOOST_CHECK(
data.B[k].isApprox(data_ref.B[k]));
525 BOOST_CHECK(
data.oYcrb[k].isApprox(data_ref.oYcrb[k]));
528 BOOST_CHECK(
data.C.isApprox(data_ref.
C));
531 BOOST_AUTO_TEST_SUITE_END()