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;
32 model.lowerPositionLimit.head<3>().
fill(-1.);
33 model.upperPositionLimit.head<3>().
fill(1.);
35 VectorXd
v(VectorXd::Random(
model.nv));
36 VectorXd
tau(VectorXd::Random(
model.nv));
40 BOOST_CHECK(tau_from_a.isApprox(
tau));
43 aba_partial_dq.setZero();
45 aba_partial_dv.setZero();
47 aba_partial_dtau.setZero();
49 const double prec = Eigen::NumTraits<double>::dummy_precision();
53 BOOST_CHECK(
data.J.isApprox(data_ref.
J));
56 BOOST_CHECK(
data.oMi[k].isApprox(data_ref.oMi[k]));
57 BOOST_CHECK(
data.ov[k].isApprox(data_ref.ov[k]));
58 BOOST_CHECK(
data.oh[k].isApprox(data_ref.oh[k]));
59 BOOST_CHECK(
data.oa_gf[k].isApprox(data_ref.oa[k] -
model.gravity));
60 BOOST_CHECK(
data.oa_gf[k].isApprox(data_ref.oa_gf[k]));
61 BOOST_CHECK(
data.of[k].isApprox(data_ref.of[k], 1e1 * prec));
62 BOOST_CHECK(
data.oYcrb[k].isApprox(data_ref.oYcrb[k]));
63 BOOST_CHECK(
data.doYcrb[k].isApprox(data_ref.doYcrb[k]));
69 BOOST_CHECK(
data.oYaba[k].isApprox(
70 data_ref.oMi[k].toDualActionMatrix() * data_ref.Yaba[k]
71 * data_ref.oMi[k].inverse().toActionMatrix()));
74 BOOST_CHECK(
data.ddq.isApprox(data_ref.
ddq));
77 BOOST_CHECK(
data.J.isApprox(data_ref.
J));
78 BOOST_CHECK(
data.u.isApprox(data_ref.
u));
81 BOOST_CHECK(
data.oMi[k].isApprox(data_ref.oMi[k]));
82 BOOST_CHECK(
data.ov[k].isApprox(data_ref.ov[k]));
83 BOOST_CHECK(
data.oYaba[k].isApprox(data_ref.oYaba[k]));
85 BOOST_CHECK(
data.oa_gf[k].isApprox(data_ref.oa_gf[k]));
86 BOOST_CHECK(
data.joints[k].U().isApprox(data_ref.
joints[k].U()));
87 BOOST_CHECK(
data.joints[k].StU().isApprox(data_ref.
joints[k].StU()));
88 BOOST_CHECK(
data.joints[k].Dinv().isApprox(data_ref.
joints[k].Dinv()));
89 BOOST_CHECK(
data.joints[k].UDinv().isApprox(data_ref.
joints[k].UDinv()));
91 BOOST_CHECK(
data.ddq.isApprox(data_ref.
ddq));
94 BOOST_CHECK(
data.J.isApprox(data_ref.
J));
97 data_ref.
Minv.triangularView<Eigen::StrictlyLower>() =
98 data_ref.
Minv.transpose().triangularView<Eigen::StrictlyLower>();
100 BOOST_CHECK(aba_partial_dtau.isApprox(data_ref.
Minv));
102 BOOST_CHECK(
data.J.isApprox(data_ref.
J));
103 BOOST_CHECK(
data.dJ.isApprox(data_ref.
dJ));
104 BOOST_CHECK(
data.dVdq.isApprox(data_ref.
dVdq));
105 BOOST_CHECK(
data.dAdq.isApprox(data_ref.
dAdq));
106 BOOST_CHECK(
data.dAdv.isApprox(data_ref.
dAdv));
107 BOOST_CHECK(
data.dtau_dq.isApprox(data_ref.
dtau_dq));
108 BOOST_CHECK(
data.dtau_dv.isApprox(data_ref.
dtau_dv));
110 MatrixXd aba_partial_dq_fd(
model.nv,
model.nv);
111 aba_partial_dq_fd.setZero();
112 MatrixXd aba_partial_dv_fd(
model.nv,
model.nv);
113 aba_partial_dv_fd.setZero();
114 MatrixXd aba_partial_dtau_fd(
model.nv,
model.nv);
115 aba_partial_dtau_fd.setZero();
119 VectorXd v_eps(VectorXd::Zero(
model.nv));
120 VectorXd q_plus(
model.nq);
121 VectorXd a_plus(
model.nv);
122 const double alpha = 1e-8;
123 for (
int k = 0; k <
model.nv; ++k)
129 aba_partial_dq_fd.col(k) = (a_plus -
a0) /
alpha;
132 BOOST_CHECK(aba_partial_dq.isApprox(aba_partial_dq_fd, sqrt(
alpha)));
135 for (
int k = 0; k <
model.nv; ++k)
140 aba_partial_dv_fd.col(k) = (a_plus -
a0) /
alpha;
143 BOOST_CHECK(aba_partial_dv.isApprox(aba_partial_dv_fd, sqrt(
alpha)));
145 VectorXd tau_plus(
tau);
146 for (
int k = 0; k <
model.nv; ++k)
148 tau_plus[k] +=
alpha;
151 aba_partial_dtau_fd.col(k) = (a_plus -
a0) /
alpha;
152 tau_plus[k] -=
alpha;
154 BOOST_CHECK(aba_partial_dtau.isApprox(aba_partial_dtau_fd, sqrt(
alpha)));
159 using namespace Eigen;
167 model.lowerPositionLimit.head<3>().
fill(-1.);
168 model.upperPositionLimit.head<3>().
fill(1.);
170 VectorXd
v(VectorXd::Random(
model.nv));
171 VectorXd
tau(VectorXd::Random(
model.nv));
175 aba_partial_dq.setZero();
177 aba_partial_dv.setZero();
179 aba_partial_dtau.setZero();
182 model, data_ref,
q,
v,
tau, aba_partial_dq, aba_partial_dv, aba_partial_dtau);
186 BOOST_CHECK(
data.J.isApprox(data_ref.
J));
187 BOOST_CHECK(
data.dJ.isApprox(data_ref.
dJ));
188 BOOST_CHECK(
data.dVdq.isApprox(data_ref.
dVdq));
189 BOOST_CHECK(
data.dAdq.isApprox(data_ref.
dAdq));
190 BOOST_CHECK(
data.dAdv.isApprox(data_ref.
dAdv));
191 BOOST_CHECK(
data.dtau_dq.isApprox(data_ref.
dtau_dq));
192 BOOST_CHECK(
data.dtau_dv.isApprox(data_ref.
dtau_dv));
193 BOOST_CHECK(
data.Minv.isApprox(aba_partial_dtau));
194 BOOST_CHECK(
data.ddq_dq.isApprox(aba_partial_dq));
195 BOOST_CHECK(
data.ddq_dv.isApprox(aba_partial_dv));
200 using namespace Eigen;
208 model.lowerPositionLimit.head<3>().
fill(-1.);
209 model.upperPositionLimit.head<3>().
fill(1.);
211 VectorXd
v(VectorXd::Random(
model.nv));
212 VectorXd
tau(VectorXd::Random(
model.nv));
216 ForceVector fext((
size_t)
model.njoints);
217 for (ForceVector::iterator
it = fext.begin();
it != fext.end(); ++
it)
221 aba_partial_dq.setZero();
223 aba_partial_dv.setZero();
225 aba_partial_dtau.setZero();
228 model,
data,
q,
v,
tau, fext, aba_partial_dq, aba_partial_dv, aba_partial_dtau);
238 BOOST_CHECK(
data.ddq.isApprox(data_ref.
ddq));
241 BOOST_CHECK(aba_partial_dv.isApprox(data_ref.
ddq_dv));
242 BOOST_CHECK(aba_partial_dtau.isApprox(data_ref.
Minv));
244 MatrixXd aba_partial_dq_fd(
model.nv,
model.nv);
245 aba_partial_dq_fd.setZero();
246 MatrixXd aba_partial_dv_fd(
model.nv,
model.nv);
247 aba_partial_dv_fd.setZero();
248 MatrixXd aba_partial_dtau_fd(
model.nv,
model.nv);
249 aba_partial_dtau_fd.setZero();
253 VectorXd v_eps(VectorXd::Zero(
model.nv));
254 VectorXd q_plus(
model.nq);
255 VectorXd a_plus(
model.nv);
256 const double alpha = 1e-8;
257 for (
int k = 0; k <
model.nv; ++k)
263 aba_partial_dq_fd.col(k) = (a_plus -
a0) /
alpha;
266 BOOST_CHECK(aba_partial_dq.isApprox(aba_partial_dq_fd, sqrt(
alpha)));
269 for (
int k = 0; k <
model.nv; ++k)
274 aba_partial_dv_fd.col(k) = (a_plus -
a0) /
alpha;
277 BOOST_CHECK(aba_partial_dv.isApprox(aba_partial_dv_fd, sqrt(
alpha)));
279 VectorXd tau_plus(
tau);
280 for (
int k = 0; k <
model.nv; ++k)
282 tau_plus[k] +=
alpha;
285 aba_partial_dtau_fd.col(k) = (a_plus -
a0) /
alpha;
286 tau_plus[k] -=
alpha;
288 BOOST_CHECK(aba_partial_dtau.isApprox(aba_partial_dtau_fd, sqrt(
alpha)));
293 BOOST_CHECK(data_shortcut.
ddq_dq.isApprox(aba_partial_dq));
294 BOOST_CHECK(data_shortcut.
ddq_dv.isApprox(aba_partial_dv));
295 BOOST_CHECK(data_shortcut.
Minv.isApprox(aba_partial_dtau));
300 using namespace Eigen;
308 model.lowerPositionLimit.head<3>().
fill(-1.);
309 model.upperPositionLimit.head<3>().
fill(1.);
311 VectorXd
v(VectorXd::Random(
model.nv));
312 VectorXd
tau(VectorXd::Random(
model.nv));
317 for (
int k = 0; k < 20; ++k)
322 BOOST_CHECK(data1.J.isApprox(data2.
J));
323 BOOST_CHECK(data1.dJ.isApprox(data2.
dJ));
324 BOOST_CHECK(data1.dVdq.isApprox(data2.
dVdq));
325 BOOST_CHECK(data1.dAdq.isApprox(data2.
dAdq));
326 BOOST_CHECK(data1.dAdv.isApprox(data2.
dAdv));
328 BOOST_CHECK(data1.dFdq.isApprox(data2.
dFdq));
329 BOOST_CHECK(data1.dFdv.isApprox(data2.
dFdv));
331 BOOST_CHECK(data1.dtau_dq.isApprox(data2.
dtau_dq));
332 BOOST_CHECK(data1.dtau_dv.isApprox(data2.
dtau_dv));
334 BOOST_CHECK(data1.ddq_dq.isApprox(data2.
ddq_dq));
335 BOOST_CHECK(data1.ddq_dv.isApprox(data2.
ddq_dv));
336 BOOST_CHECK(data1.Minv.isApprox(data2.
Minv));
341 using namespace Eigen;
349 model.lowerPositionLimit.head<3>().
fill(-1.);
350 model.upperPositionLimit.head<3>().
fill(1.);
352 VectorXd
v(VectorXd::Random(
model.nv));
353 VectorXd
a(VectorXd::Random(
model.nv));
358 aba_partial_dq.setZero();
360 aba_partial_dv.setZero();
361 MatrixXd aba_partial_dtau(
model.nv,
model.nv);
362 aba_partial_dtau.setZero();
367 BOOST_CHECK(
data.J.isApprox(data_ref.
J));
368 BOOST_CHECK(
data.dJ.isApprox(data_ref.
dJ));
370 for (
size_t k = 1; k < (size_t)
model.njoints; ++k)
372 BOOST_CHECK(
data.oMi[k].isApprox(data_ref.oMi[k]));
373 BOOST_CHECK(
data.ov[k].isApprox(data_ref.ov[k]));
374 BOOST_CHECK(
data.oa[k].isApprox(data_ref.oa[k]));
380 using namespace Eigen;
388 model.lowerPositionLimit.head<3>().
fill(-1.);
389 model.upperPositionLimit.head<3>().
fill(1.);
391 VectorXd
v(VectorXd::Random(
model.nv));
392 VectorXd
tau(VectorXd::Random(
model.nv));
395 aba_partial_dq.setZero();
397 aba_partial_dv.setZero();
398 MatrixXd aba_partial_dtau(
model.nv,
model.nv);
399 aba_partial_dtau.setZero();
404 MatrixXd aba_partial_dq_ref(
model.nv,
model.nv);
405 aba_partial_dq_ref.setZero();
406 MatrixXd aba_partial_dv_ref(
model.nv,
model.nv);
407 aba_partial_dv_ref.setZero();
408 MatrixXd aba_partial_dtau_ref(
model.nv,
model.nv);
409 aba_partial_dtau_ref.setZero();
412 model, data_ref,
q,
v,
tau, aba_partial_dq_ref, aba_partial_dv_ref, aba_partial_dtau_ref);
414 BOOST_CHECK(
data.ddq.isApprox(data_ref.
ddq));
415 BOOST_CHECK(
data.Minv.isApprox(data_ref.
Minv));
417 BOOST_CHECK(aba_partial_dq.isApprox(aba_partial_dq_ref));
418 BOOST_CHECK(aba_partial_dv.isApprox(aba_partial_dv_ref));
419 BOOST_CHECK(aba_partial_dtau.isApprox(aba_partial_dtau_ref));
422 const int num_calls = 20;
424 for (
int it = 0;
it < num_calls; ++
it)
428 BOOST_CHECK(
data.ddq.isApprox(data_ref.
ddq));
429 BOOST_CHECK(
data.Minv.isApprox(data_ref.
Minv));
443 BOOST_CHECK(
data.J.isApprox(data_ref.
J));
444 BOOST_CHECK(
data.dJ.isApprox(data_ref.
dJ));
445 BOOST_CHECK(
data.dVdq.isApprox(data_ref.
dVdq));
446 BOOST_CHECK(
data.dAdq.isApprox(data_ref.
dAdq));
447 BOOST_CHECK(
data.dAdv.isApprox(data_ref.
dAdv));
448 BOOST_CHECK(
data.dFdq.isApprox(data_ref.
dFdq));
449 BOOST_CHECK(
data.dFdv.isApprox(data_ref.
dFdv));
450 BOOST_CHECK(
data.dFda.isApprox(data_ref.
dFda));
452 BOOST_CHECK(aba_partial_dq.isApprox(aba_partial_dq_ref));
453 BOOST_CHECK(aba_partial_dv.isApprox(aba_partial_dv_ref));
454 BOOST_CHECK(aba_partial_dtau.isApprox(aba_partial_dtau_ref));
460 using namespace Eigen;
468 model.lowerPositionLimit.head<3>().
fill(-1.);
469 model.upperPositionLimit.head<3>().
fill(1.);
471 VectorXd
v(VectorXd::Random(
model.nv));
472 VectorXd
tau(VectorXd::Random(
model.nv));
475 ForceVector fext((
size_t)
model.njoints);
476 for (ForceVector::iterator
it = fext.begin();
it != fext.end(); ++
it)
480 aba_partial_dq.setZero();
482 aba_partial_dv.setZero();
483 MatrixXd aba_partial_dtau(
model.nv,
model.nv);
484 aba_partial_dtau.setZero();
489 MatrixXd aba_partial_dq_ref(
model.nv,
model.nv);
490 aba_partial_dq_ref.setZero();
491 MatrixXd aba_partial_dv_ref(
model.nv,
model.nv);
492 aba_partial_dv_ref.setZero();
493 MatrixXd aba_partial_dtau_ref(
model.nv,
model.nv);
494 aba_partial_dtau_ref.setZero();
497 model, data_ref,
q,
v,
tau, fext, aba_partial_dq_ref, aba_partial_dv_ref, aba_partial_dtau_ref);
499 BOOST_CHECK(
data.ddq.isApprox(data_ref.
ddq));
500 BOOST_CHECK(
data.Minv.isApprox(data_ref.
Minv));
502 BOOST_CHECK(aba_partial_dq.isApprox(aba_partial_dq_ref));
503 BOOST_CHECK(aba_partial_dv.isApprox(aba_partial_dv_ref));
504 BOOST_CHECK(aba_partial_dtau.isApprox(aba_partial_dtau_ref));
507 const int num_calls = 20;
509 for (
int it = 0;
it < num_calls; ++
it)
513 BOOST_CHECK(
data.ddq.isApprox(data_ref.
ddq));
514 BOOST_CHECK(
data.Minv.isApprox(data_ref.
Minv));
528 BOOST_CHECK(
data.J.isApprox(data_ref.
J));
529 BOOST_CHECK(
data.dJ.isApprox(data_ref.
dJ));
530 BOOST_CHECK(
data.dVdq.isApprox(data_ref.
dVdq));
531 BOOST_CHECK(
data.dAdq.isApprox(data_ref.
dAdq));
532 BOOST_CHECK(
data.dAdv.isApprox(data_ref.
dAdv));
533 BOOST_CHECK(
data.dFdq.isApprox(data_ref.
dFdq));
534 BOOST_CHECK(
data.dFdv.isApprox(data_ref.
dFdv));
535 BOOST_CHECK(
data.dFda.isApprox(data_ref.
dFda));
537 BOOST_CHECK(aba_partial_dq.isApprox(aba_partial_dq_ref));
538 BOOST_CHECK(aba_partial_dv.isApprox(aba_partial_dv_ref));
539 BOOST_CHECK(aba_partial_dtau.isApprox(aba_partial_dtau_ref));
543 BOOST_AUTO_TEST_SUITE_END()