20 #include <boost/test/unit_test.hpp>
21 #include <boost/utility/binary.hpp>
24 using namespace Eigen;
27 bool within(
const T & elt,
const std::vector<T> & vec)
29 typename std::vector<T>::const_iterator
it;
31 it = std::find(
vec.begin(),
vec.end(), elt);
38 template<
typename Matrix>
41 for (DenseIndex
i = 0;
i <
mat.rows(); ++
i)
42 for (DenseIndex j = 0; j <
mat.rows(); ++j)
51 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
62 BOOST_CHECK(cmodel2.joint1_id == 0);
63 BOOST_CHECK(cmodel2.joint1_placement.isApprox(
M));
64 BOOST_CHECK(cmodel2.size() == 3);
69 BOOST_CHECK(cmodel2prime.joint1_id == 0);
70 BOOST_CHECK(cmodel2prime.joint1_placement.isIdentity());
71 BOOST_CHECK(cmodel2prime.size() == 3);
75 BOOST_CHECK(cmodel3 == cmodel2);
80 BOOST_CHECK(cmodel4.joint1_id == 0);
81 BOOST_CHECK(cmodel4.joint1_placement.isIdentity());
82 BOOST_CHECK(cmodel4.size() == 6);
91 const RigidConstraintModel::Matrix36 A1 =
cmodel.getA1(cdata);
92 const RigidConstraintModel::Matrix36 A1_ref = cdata.oMc1.toActionMatrixInverse().topRows<3>();
94 BOOST_CHECK(A1.isApprox(A1_ref));
96 const RigidConstraintModel::Matrix36 A2 =
cmodel.getA2(cdata);
97 const RigidConstraintModel::Matrix36 A2_ref =
98 -cdata.c1Mc2.rotation() * cdata.oMc2.toActionMatrixInverse().topRows<3>();
100 BOOST_CHECK(A2.isApprox(A2_ref));
110 BOOST_CHECK(
J.isApprox(J_ref));
113 const Eigen::DenseIndex
m = 40;
122 BOOST_CHECK(
res.isApprox(res_ref));
132 model.lowerPositionLimit.head<3>().
fill(-1.);
133 model.upperPositionLimit.head<3>().
fill(1.);
137 const std::string RF =
"rleg6_joint";
138 const std::string LF =
"lleg6_joint";
147 CONTACT_6D,
model, cm_RF_LOCAL.joint1_id, cm_RF_LOCAL.joint1_placement, cm_LF_LOCAL.joint1_id,
148 cm_LF_LOCAL.joint1_placement,
LOCAL);
152 J_RF_LOCAL.setZero();
154 model,
data, cm_RF_LOCAL.joint1_id, cm_RF_LOCAL.joint1_placement, cm_RF_LOCAL.reference_frame,
157 J_LF_LOCAL.setZero();
159 model,
data, cm_LF_LOCAL.joint1_id, cm_LF_LOCAL.joint1_placement, cm_LF_LOCAL.reference_frame,
162 for (DenseIndex k = 0; k <
model.nv; ++k)
164 BOOST_CHECK(J_RF_LOCAL.col(k).isZero() != cm_RF_LOCAL.colwise_joint1_sparsity[k]);
165 BOOST_CHECK(J_LF_LOCAL.col(k).isZero() != cm_LF_LOCAL.colwise_joint1_sparsity[k]);
167 BOOST_CHECK(cm_RF_LOCAL.colwise_joint2_sparsity.isZero());
168 BOOST_CHECK(cm_LF_LOCAL.colwise_joint2_sparsity.isZero());
170 const SE3 oMc1 =
data.oMi[clm_RF_LF_LOCAL.joint1_id] * clm_RF_LF_LOCAL.joint1_placement;
171 const SE3 oMc2 =
data.oMi[clm_RF_LF_LOCAL.joint2_id] * clm_RF_LF_LOCAL.joint2_placement;
172 const SE3 c1Mc2 = oMc1.actInv(oMc2);
173 const Data::Matrix6x J_clm_LOCAL = J_RF_LOCAL - c1Mc2.toActionMatrix() * J_LF_LOCAL;
175 for (DenseIndex k = 0; k <
model.nv; ++k)
177 BOOST_CHECK(J_clm_LOCAL.col(k).isZero() !=
within(k, clm_RF_LF_LOCAL.colwise_span_indexes));
182 J_RF_LOCAL_sparse.setZero();
185 BOOST_CHECK(J_RF_LOCAL.isApprox(J_RF_LOCAL_sparse));
188 J_LF_LOCAL_sparse.setZero();
191 BOOST_CHECK(J_LF_LOCAL.isApprox(J_LF_LOCAL_sparse));
194 J_clm_LOCAL_sparse.setZero();
197 BOOST_CHECK(J_clm_LOCAL.isApprox(J_clm_LOCAL_sparse));
209 CONTACT_6D,
model, cm_RF_LWA.joint1_id, cm_RF_LWA.joint1_placement, cm_LF_LWA.joint1_id,
214 J_RF_LOCAL.setZero();
216 model,
data, cm_RF_LWA.joint1_id, cm_RF_LWA.joint1_placement,
LOCAL, J_RF_LOCAL);
218 J_LF_LOCAL.setZero();
220 model,
data, cm_LF_LWA.joint1_id, cm_LF_LWA.joint1_placement,
LOCAL, J_LF_LOCAL);
231 for (DenseIndex k = 0; k <
model.nv; ++k)
233 BOOST_CHECK(J_RF_LWA.col(k).isZero() != cm_RF_LWA.colwise_joint1_sparsity[k]);
234 BOOST_CHECK(J_LF_LWA.col(k).isZero() != cm_LF_LWA.colwise_joint1_sparsity[k]);
236 BOOST_CHECK(cm_RF_LWA.colwise_joint2_sparsity.isZero());
237 BOOST_CHECK(cm_LF_LWA.colwise_joint2_sparsity.isZero());
239 const SE3 oMc1 =
data.oMi[clm_RF_LF_LWA.joint1_id] * clm_RF_LF_LWA.joint1_placement;
240 const SE3 oMc2 =
data.oMi[clm_RF_LF_LWA.joint2_id] * clm_RF_LF_LWA.joint2_placement;
241 const SE3 c1Mc2 = oMc1.actInv(oMc2);
243 const SE3 oMc2_lwa = oMc1_lwa * c1Mc2;
245 oMc1_lwa.toActionMatrix() * J_RF_LOCAL - oMc2_lwa.toActionMatrix() * J_LF_LOCAL;
247 for (DenseIndex k = 0; k <
model.nv; ++k)
249 BOOST_CHECK(J_clm_LWA.col(k).isZero() !=
within(k, clm_RF_LF_LWA.colwise_span_indexes));
254 J_RF_LWA_sparse.setZero();
257 BOOST_CHECK(J_RF_LWA.isApprox(J_RF_LWA_sparse));
260 J_LF_LWA_sparse.setZero();
263 BOOST_CHECK(J_LF_LWA.isApprox(J_LF_LWA_sparse));
266 J_clm_LWA_sparse.setZero();
269 BOOST_CHECK(J_clm_LWA.isApprox(J_clm_LWA_sparse));
279 CONTACT_3D,
model, cm_RF_LOCAL.joint1_id, cm_RF_LOCAL.joint1_placement, cm_LF_LOCAL.joint1_id,
280 cm_LF_LOCAL.joint1_placement,
LOCAL);
284 J_RF_LOCAL.setZero();
286 model,
data, cm_RF_LOCAL.joint1_id, cm_RF_LOCAL.joint1_placement, cm_RF_LOCAL.reference_frame,
289 J_LF_LOCAL.setZero();
291 model,
data, cm_LF_LOCAL.joint1_id, cm_LF_LOCAL.joint1_placement, cm_LF_LOCAL.reference_frame,
294 for (DenseIndex k = 0; k <
model.nv; ++k)
297 J_RF_LOCAL.middleRows<3>(SE3::LINEAR).col(k).isZero()
298 != cm_RF_LOCAL.colwise_joint1_sparsity[k]);
300 J_LF_LOCAL.middleRows<3>(SE3::LINEAR).col(k).isZero()
301 != cm_LF_LOCAL.colwise_joint1_sparsity[k]);
303 BOOST_CHECK(cm_RF_LOCAL.colwise_joint2_sparsity.isZero());
304 BOOST_CHECK(cm_LF_LOCAL.colwise_joint2_sparsity.isZero());
306 const SE3 oMc1 =
data.oMi[clm_RF_LF_LOCAL.joint1_id] * clm_RF_LF_LOCAL.joint1_placement;
307 const SE3 oMc2 =
data.oMi[clm_RF_LF_LOCAL.joint2_id] * clm_RF_LF_LOCAL.joint2_placement;
308 const SE3 c1Mc2 = oMc1.actInv(oMc2);
309 const Data::Matrix3x J_clm_LOCAL = J_RF_LOCAL.middleRows<3>(SE3::LINEAR)
310 - c1Mc2.
rotation() * J_LF_LOCAL.middleRows<3>(SE3::LINEAR);
312 for (DenseIndex k = 0; k <
model.nv; ++k)
314 BOOST_CHECK(J_clm_LOCAL.col(k).isZero(0) !=
within(k, clm_RF_LF_LOCAL.colwise_span_indexes));
319 J_RF_LOCAL_sparse.setZero();
322 BOOST_CHECK(J_RF_LOCAL.middleRows<3>(SE3::LINEAR).isApprox(J_RF_LOCAL_sparse));
325 J_LF_LOCAL_sparse.setZero();
328 BOOST_CHECK(J_LF_LOCAL.middleRows<3>(SE3::LINEAR).isApprox(J_LF_LOCAL_sparse));
331 J_clm_LOCAL_sparse.setZero();
334 BOOST_CHECK(J_clm_LOCAL.isApprox(J_clm_LOCAL_sparse));
350 CONTACT_3D,
model, cm_RF_LWA.joint1_id, cm_RF_LWA.joint1_placement, cm_LF_LWA.joint1_id,
355 J_RF_LOCAL.setZero();
357 model,
data, cm_RF_LWA.joint1_id, cm_RF_LWA.joint1_placement,
LOCAL, J_RF_LOCAL);
359 J_LF_LOCAL.setZero();
361 model,
data, cm_LF_LWA.joint1_id, cm_LF_LWA.joint1_placement,
LOCAL, J_LF_LOCAL);
372 for (DenseIndex k = 0; k <
model.nv; ++k)
375 J_RF_LWA.middleRows<3>(SE3::LINEAR).col(k).isZero()
376 != cm_RF_LWA.colwise_joint1_sparsity[k]);
378 J_LF_LWA.middleRows<3>(SE3::LINEAR).col(k).isZero()
379 != cm_LF_LWA.colwise_joint1_sparsity[k]);
381 BOOST_CHECK(cm_RF_LWA.colwise_joint2_sparsity.isZero());
382 BOOST_CHECK(cm_LF_LWA.colwise_joint2_sparsity.isZero());
384 const SE3 oMc1 =
data.oMi[clm_RF_LF_LWA.joint1_id] * clm_RF_LF_LWA.joint1_placement;
385 const SE3 oMc2 =
data.oMi[clm_RF_LF_LWA.joint2_id] * clm_RF_LF_LWA.joint2_placement;
389 (oMc1_lwa.toActionMatrix() * J_RF_LOCAL - oMc2_lwa.toActionMatrix() * J_LF_LOCAL)
390 .middleRows<3>(Motion::LINEAR);
392 for (DenseIndex k = 0; k <
model.nv; ++k)
394 BOOST_CHECK(J_clm_LWA.col(k).isZero(0) !=
within(k, clm_RF_LF_LWA.colwise_span_indexes));
399 J_RF_LWA_sparse.setZero();
402 BOOST_CHECK(J_RF_LWA.middleRows<3>(SE3::LINEAR).isApprox(J_RF_LWA_sparse));
405 J_LF_LWA_sparse.setZero();
408 BOOST_CHECK(J_LF_LWA.middleRows<3>(SE3::LINEAR).isApprox(J_LF_LWA_sparse));
411 J_clm_LWA_sparse.setZero();
414 BOOST_CHECK(J_clm_LWA.isApprox(J_clm_LWA_sparse));
418 BOOST_AUTO_TEST_SUITE_END()