15 #include <boost/test/unit_test.hpp>
16 #include <boost/utility/binary.hpp>
18 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
22 using namespace Eigen;
29 ?
model.getJointId(
"rarm2_joint")
34 BOOST_CHECK(
model.getFrameId(
"rand") == frameId);
35 BOOST_CHECK(
model.frames[frameId].parentJoint == jointId);
39 model.lowerPositionLimit.head<3>().
fill(-1.);
40 model.upperPositionLimit.head<3>().
fill(1.);
42 VectorXd
v(VectorXd::Random(
model.nv));
43 VectorXd
a(VectorXd::Random(
model.nv));
50 partial_dq_local_world_aligned.setZero();
52 partial_dq_local.setZero();
56 partial_dv_local_world_aligned.setZero();
58 partial_dv_local.setZero();
64 partial_dv_local_world_aligned);
71 J_ref_local_world_aligned.setZero();
73 J_ref_local.setZero();
79 BOOST_CHECK(data_ref.oMf[frameId].isApprox(
data.oMf[frameId]));
80 BOOST_CHECK(partial_dv.isApprox(J_ref));
81 BOOST_CHECK(partial_dv_local_world_aligned.isApprox(J_ref_local_world_aligned));
82 BOOST_CHECK(partial_dv_local.isApprox(J_ref_local));
86 partial_dq_fd.setZero();
88 partial_dq_fd_local_world_aligned.setZero();
90 partial_dq_fd_local.setZero();
92 partial_dv_fd.setZero();
94 partial_dv_fd_local_world_aligned.setZero();
96 partial_dv_fd_local.setZero();
97 const double alpha = 1e-8;
100 Eigen::VectorXd v_plus(
v);
106 for (
int k = 0; k <
model.nv; ++k)
111 partial_dv_fd.col(k) =
113 partial_dv_fd_local_world_aligned.col(k) =
117 partial_dv_fd_local.col(k) =
122 BOOST_CHECK(partial_dv.isApprox(partial_dv_fd, sqrt(
alpha)));
124 partial_dv_local_world_aligned.isApprox(partial_dv_fd_local_world_aligned, sqrt(
alpha)));
125 BOOST_CHECK(partial_dv_local.isApprox(partial_dv_fd_local, sqrt(
alpha)));
128 Eigen::VectorXd q_plus(
q), v_eps(Eigen::VectorXd::Zero(
model.nv));
132 for (
int k = 0; k <
model.nv; ++k)
139 Motion v_plus_local_world_aligned =
141 SE3::Vector3 trans = data_plus.oMf[frameId].translation() - data_ref.oMf[frameId].translation();
142 v_plus_local_world_aligned.linear() -= v_plus_local_world_aligned.angular().cross(trans);
143 partial_dq_fd.col(k) =
145 partial_dq_fd_local_world_aligned.col(k) =
146 (v_plus_local_world_aligned - v0_local_world_aligned).toVector() /
alpha;
147 partial_dq_fd_local.col(k) =
152 BOOST_CHECK(partial_dq.isApprox(partial_dq_fd, sqrt(
alpha)));
154 partial_dq_local_world_aligned.isApprox(partial_dq_fd_local_world_aligned, sqrt(
alpha)));
155 BOOST_CHECK(partial_dq_local.isApprox(partial_dq_fd_local, sqrt(
alpha)));
160 using namespace Eigen;
167 ?
model.getJointId(
"rarm2_joint")
172 BOOST_CHECK(
model.getFrameId(
"rand") == frameId);
173 BOOST_CHECK(
model.frames[frameId].parentJoint == jointId);
177 model.lowerPositionLimit.head<3>().
fill(-1.);
178 model.upperPositionLimit.head<3>().
fill(1.);
180 VectorXd
v(VectorXd::Random(
model.nv));
181 VectorXd
a(VectorXd::Random(
model.nv));
186 v_partial_dq.setZero();
188 v_partial_dq_local.setZero();
190 v_partial_dq_local_world_aligned.setZero();
192 a_partial_dq.setZero();
194 a_partial_dq_local_world_aligned.setZero();
196 a_partial_dq_local.setZero();
198 a_partial_dv.setZero();
200 a_partial_dv_local_world_aligned.setZero();
202 a_partial_dv_local.setZero();
204 a_partial_da.setZero();
206 a_partial_da_local_world_aligned.setZero();
208 a_partial_da_local.setZero();
211 model,
data, frameId,
WORLD, v_partial_dq, a_partial_dq, a_partial_dv, a_partial_da);
215 a_partial_dq_local_world_aligned, a_partial_dv_local_world_aligned,
216 a_partial_da_local_world_aligned);
219 model,
data, frameId,
LOCAL, v_partial_dq_local, a_partial_dq_local, a_partial_dv_local,
228 v_partial_dq_ref.setZero();
230 v_partial_dq_ref_local_world_aligned.setZero();
232 v_partial_dq_ref_local.setZero();
234 v_partial_dv_ref.setZero();
236 v_partial_dv_ref_local_world_aligned.setZero();
238 v_partial_dv_ref_local.setZero();
242 BOOST_CHECK(v_partial_dq.isApprox(v_partial_dq_ref));
243 BOOST_CHECK(a_partial_da.isApprox(v_partial_dv_ref));
247 v_partial_dv_ref_local_world_aligned);
249 BOOST_CHECK(v_partial_dq_local_world_aligned.isApprox(v_partial_dq_ref_local_world_aligned));
250 BOOST_CHECK(a_partial_da_local_world_aligned.isApprox(v_partial_dv_ref_local_world_aligned));
253 model, data_v, frameId,
LOCAL, v_partial_dq_ref_local, v_partial_dv_ref_local);
255 BOOST_CHECK(v_partial_dq_local.isApprox(v_partial_dq_ref_local));
256 BOOST_CHECK(a_partial_da_local.isApprox(v_partial_dv_ref_local));
262 J_ref_local.setZero();
264 J_ref_local_world_aligned.setZero();
270 BOOST_CHECK(a_partial_da.isApprox(J_ref));
271 BOOST_CHECK(a_partial_da_local_world_aligned.isApprox(J_ref_local_world_aligned));
272 BOOST_CHECK(a_partial_da_local.isApprox(J_ref_local));
276 a_partial_da_fd.setZero();
278 a_partial_da_fd_local_world_aligned.setZero();
280 a_partial_da_fd_local.setZero();
281 const double alpha = 1e-8;
283 Eigen::VectorXd v_plus(
v), a_plus(
a);
291 for (
int k = 0; k <
model.nv; ++k)
296 a_partial_da_fd.col(k) =
298 a_partial_da_fd_local_world_aligned.col(k) =
300 - a0_local_world_aligned)
303 a_partial_da_fd_local.col(k) =
307 BOOST_CHECK(a_partial_da.isApprox(a_partial_da_fd, sqrt(
alpha)));
309 a_partial_da_local_world_aligned.isApprox(a_partial_da_fd_local_world_aligned, sqrt(
alpha)));
310 BOOST_CHECK(a_partial_da_local.isApprox(a_partial_da_fd_local, sqrt(
alpha)));
314 a_partial_dv_fd.setZero();
316 a_partial_dv_fd_local_world_aligned.setZero();
318 a_partial_dv_fd_local.setZero();
319 for (
int k = 0; k <
model.nv; ++k)
324 a_partial_dv_fd.col(k) =
326 a_partial_dv_fd_local_world_aligned.col(k) =
328 - a0_local_world_aligned)
331 a_partial_dv_fd_local.col(k) =
336 BOOST_CHECK(a_partial_dv.isApprox(a_partial_dv_fd, sqrt(
alpha)));
338 a_partial_dv_local_world_aligned.isApprox(a_partial_dv_fd_local_world_aligned, sqrt(
alpha)));
339 BOOST_CHECK(a_partial_dv_local.isApprox(a_partial_dv_fd_local, sqrt(
alpha)));
342 a_partial_dq.setZero();
343 a_partial_dv.setZero();
344 a_partial_da.setZero();
346 a_partial_dq_local_world_aligned.setZero();
347 a_partial_dv_local_world_aligned.setZero();
348 a_partial_da_local_world_aligned.setZero();
350 a_partial_dq_local.setZero();
351 a_partial_dv_local.setZero();
352 a_partial_da_local.setZero();
355 a_partial_dq_fd.setZero();
357 a_partial_dq_fd_local_world_aligned.setZero();
359 a_partial_dq_fd_local.setZero();
363 model,
data, frameId,
WORLD, v_partial_dq, a_partial_dq, a_partial_dv, a_partial_da);
367 a_partial_dq_local_world_aligned, a_partial_dv_local_world_aligned,
368 a_partial_da_local_world_aligned);
371 model,
data, frameId,
LOCAL, v_partial_dq_local, a_partial_dq_local, a_partial_dv_local,
374 Eigen::VectorXd q_plus(
q), v_eps(Eigen::VectorXd::Zero(
model.nv));
381 for (
int k = 0; k <
model.nv; ++k)
388 a_partial_dq_fd.col(k) =
390 Motion a_plus_local_world_aligned =
393 data_plus.oMf[frameId].translation() - data_ref.oMf[frameId].translation();
394 a_plus_local_world_aligned.linear() -= a_plus_local_world_aligned.angular().cross(trans);
395 a_partial_dq_fd_local_world_aligned.col(k) =
396 (a_plus_local_world_aligned - a0_local_world_aligned).toVector() /
alpha;
397 a_partial_dq_fd_local.col(k) =
402 BOOST_CHECK(a_partial_dq.isApprox(a_partial_dq_fd, sqrt(
alpha)));
404 a_partial_dq_local_world_aligned.isApprox(a_partial_dq_fd_local_world_aligned, sqrt(
alpha)));
405 BOOST_CHECK(a_partial_dq_local.isApprox(a_partial_dq_fd_local, sqrt(
alpha)));
409 v_partial_dq_other.setZero();
411 v_partial_dq_local_other.setZero();
413 v_partial_dq_local_world_aligned_other.setZero();
415 v_partial_dv_other.setZero();
417 v_partial_dv_local_other.setZero();
419 v_partial_dv_local_world_aligned_other.setZero();
421 a_partial_dq_other.setZero();
423 a_partial_dq_local_world_aligned_other.setZero();
425 a_partial_dq_local_other.setZero();
427 a_partial_dv_other.setZero();
429 a_partial_dv_local_world_aligned_other.setZero();
431 a_partial_dv_local_other.setZero();
433 a_partial_da_other.setZero();
435 a_partial_da_local_world_aligned_other.setZero();
437 a_partial_da_local_other.setZero();
440 model,
data, frameId,
WORLD, v_partial_dq_other, v_partial_dv_other, a_partial_dq_other,
441 a_partial_dv_other, a_partial_da_other);
443 BOOST_CHECK(v_partial_dq_other.isApprox(v_partial_dq));
444 BOOST_CHECK(v_partial_dv_other.isApprox(a_partial_da));
445 BOOST_CHECK(a_partial_dq_other.isApprox(a_partial_dq));
446 BOOST_CHECK(a_partial_dv_other.isApprox(a_partial_dv));
447 BOOST_CHECK(a_partial_da_other.isApprox(a_partial_da));
451 v_partial_dv_local_world_aligned_other, a_partial_dq_local_world_aligned_other,
452 a_partial_dv_local_world_aligned_other, a_partial_da_local_world_aligned_other);
454 BOOST_CHECK(v_partial_dq_local_world_aligned_other.isApprox(v_partial_dq_local_world_aligned));
455 BOOST_CHECK(v_partial_dv_local_world_aligned_other.isApprox(a_partial_da_local_world_aligned));
456 BOOST_CHECK(a_partial_dq_local_world_aligned_other.isApprox(a_partial_dq_local_world_aligned));
457 BOOST_CHECK(a_partial_dv_local_world_aligned_other.isApprox(a_partial_dv_local_world_aligned));
458 BOOST_CHECK(a_partial_da_local_world_aligned_other.isApprox(a_partial_da_local_world_aligned));
461 model,
data, frameId,
LOCAL, v_partial_dq_local_other, v_partial_dv_local_other,
462 a_partial_dq_local_other, a_partial_dv_local_other, a_partial_da_local_other);
464 BOOST_CHECK(v_partial_dq_local_other.isApprox(v_partial_dq_local));
465 BOOST_CHECK(v_partial_dv_local_other.isApprox(a_partial_da_local));
466 BOOST_CHECK(a_partial_dq_local_other.isApprox(a_partial_dq_local));
467 BOOST_CHECK(a_partial_dv_local_other.isApprox(a_partial_dv_local));
468 BOOST_CHECK(a_partial_da_local_other.isApprox(a_partial_da_local));
471 BOOST_AUTO_TEST_SUITE_END()