8 #include "pinocchio/algorithm/contact-cholesky.hxx"
13 #include <boost/test/unit_test.hpp>
14 #include <boost/utility/binary.hpp>
18 template<
typename Scalar,
int Options>
33 return this->parents_fromRow;
37 return this->last_child;
41 return this->nv_subtree_fromRow;
45 return this->joint1_indexes;
49 return this->joint2_indexes;
59 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
63 using namespace Eigen;
68 const std::string RA =
"rleg6_joint";
77 MatrixXd H_inverse(contact_chol.size(), contact_chol.size());
79 VectorXd
v = Eigen::VectorXd::Random(
model.nv);
83 for (
int i = 0;
i < 10;
i++)
87 contact_chol.inverse(H_inverse);
89 Eigen::MatrixXd dampedDelassusInverse;
90 dampedDelassusInverse.resize(contact_chol.constraintDim(), contact_chol.constraintDim());
92 Eigen::MatrixXd dampedDelassusInverse2;
93 dampedDelassusInverse2.resize(contact_chol.constraintDim(), contact_chol.constraintDim());
95 dampedDelassusInverse2 =
96 -H_inverse.topLeftCorner(contact_chol.constraintDim(), contact_chol.constraintDim());
99 dampedDelassusInverse.triangularView<StrictlyLower>() =
100 dampedDelassusInverse.triangularView<StrictlyUpper>().transpose();
101 BOOST_CHECK(dampedDelassusInverse2.isApprox(dampedDelassusInverse, 1e-10));
105 dampedDelassusInverse.triangularView<StrictlyLower>() =
106 dampedDelassusInverse.triangularView<StrictlyUpper>().transpose();
107 BOOST_CHECK(dampedDelassusInverse.isApprox(
108 -H_inverse.topLeftCorner(contact_chol.constraintDim(), contact_chol.constraintDim()), 1e-10));
111 v = Eigen::VectorXd::Random(
model.nv);
117 using namespace Eigen;
122 const std::string RA =
"rleg6_joint";
123 const std::string LA =
"lleg6_joint";
135 MatrixXd H_inverse(contact_chol.size(), contact_chol.size());
137 VectorXd
v = Eigen::VectorXd::Random(
model.nv);
141 contact_chol.inverse(H_inverse);
144 dampedDelassusInverse.resize(contact_chol.constraintDim(), contact_chol.constraintDim());
149 dampedDelassusInverse.triangularView<StrictlyLower>() =
150 dampedDelassusInverse.triangularView<StrictlyUpper>().transpose();
151 BOOST_CHECK(dampedDelassusInverse.isApprox(
152 -H_inverse.topLeftCorner(contact_chol.constraintDim(), contact_chol.constraintDim()), 1e-11));
156 dampedDelassusInverse.triangularView<StrictlyLower>() =
157 dampedDelassusInverse.triangularView<StrictlyUpper>().transpose();
158 BOOST_CHECK(dampedDelassusInverse.isApprox(
159 -H_inverse.topLeftCorner(contact_chol.constraintDim(), contact_chol.constraintDim()), 1e-11));
164 using namespace Eigen;
169 const std::string RF =
"rleg6_joint";
170 const std::string LF =
"lleg6_joint";
171 const std::string RA =
"rarm6_joint";
172 const std::string LA =
"larm6_joint";
190 MatrixXd H_inverse(contact_chol.size(), contact_chol.size());
192 VectorXd
v = Eigen::VectorXd::Random(
model.nv);
196 contact_chol.inverse(H_inverse);
199 dampedDelassusInverse.resize(contact_chol.constraintDim(), contact_chol.constraintDim());
204 dampedDelassusInverse.triangularView<StrictlyLower>() =
205 dampedDelassusInverse.triangularView<StrictlyUpper>().transpose();
206 BOOST_CHECK(dampedDelassusInverse.isApprox(
207 -H_inverse.topLeftCorner(contact_chol.constraintDim(), contact_chol.constraintDim()), 1e-11));
211 dampedDelassusInverse.triangularView<StrictlyLower>() =
212 dampedDelassusInverse.triangularView<StrictlyUpper>().transpose();
213 BOOST_CHECK(dampedDelassusInverse.isApprox(
214 -H_inverse.topLeftCorner(contact_chol.constraintDim(), contact_chol.constraintDim()), 1e-10));
219 using namespace Eigen;
224 const std::string RA =
"rleg6_joint";
235 MatrixXd H_inverse(contact_chol.size(), contact_chol.size());
237 VectorXd
v = Eigen::VectorXd::Random(
model.nv);
241 contact_chol.inverse(H_inverse);
244 dampedDelassusInverse.resize(contact_chol.constraintDim(), contact_chol.constraintDim());
249 dampedDelassusInverse.triangularView<StrictlyLower>() =
250 dampedDelassusInverse.triangularView<StrictlyUpper>().transpose();
251 BOOST_CHECK(dampedDelassusInverse.isApprox(
252 -H_inverse.topLeftCorner(contact_chol.constraintDim(), contact_chol.constraintDim()), 1e-11));
256 dampedDelassusInverse.triangularView<StrictlyLower>() =
257 dampedDelassusInverse.triangularView<StrictlyUpper>().transpose();
258 BOOST_CHECK(dampedDelassusInverse.isApprox(
259 -H_inverse.topLeftCorner(contact_chol.constraintDim(), contact_chol.constraintDim()), 1e-11));
264 using namespace Eigen;
269 const std::string RF =
"rleg6_joint";
270 const std::string LF =
"lleg6_joint";
271 const std::string RA =
"rarm6_joint";
272 const std::string LA =
"larm6_joint";
289 MatrixXd H_inverse(contact_chol.size(), contact_chol.size());
291 VectorXd
v = Eigen::VectorXd::Random(
model.nv);
295 contact_chol.inverse(H_inverse);
298 dampedDelassusInverse.resize(contact_chol.constraintDim(), contact_chol.constraintDim());
303 dampedDelassusInverse.triangularView<StrictlyLower>() =
304 dampedDelassusInverse.triangularView<StrictlyUpper>().transpose();
305 BOOST_CHECK(dampedDelassusInverse.isApprox(
306 -H_inverse.topLeftCorner(contact_chol.constraintDim(), contact_chol.constraintDim()), 1e-11));
310 dampedDelassusInverse.triangularView<StrictlyLower>() =
311 dampedDelassusInverse.triangularView<StrictlyUpper>().transpose();
312 BOOST_CHECK(dampedDelassusInverse.isApprox(
313 -H_inverse.topLeftCorner(contact_chol.constraintDim(), contact_chol.constraintDim()), 1e-11));
318 using namespace Eigen;
323 const std::string RA =
"rleg6_joint";
332 MatrixXd H_inverse(contact_chol.size(), contact_chol.size());
334 VectorXd
v = Eigen::VectorXd::Random(
model.nv);
338 contact_chol.inverse(H_inverse);
341 dampedDelassusInverse.resize(contact_chol.constraintDim(), contact_chol.constraintDim());
346 dampedDelassusInverse.triangularView<StrictlyLower>() =
347 dampedDelassusInverse.triangularView<StrictlyUpper>().transpose();
348 BOOST_CHECK(dampedDelassusInverse.isApprox(
349 -H_inverse.topLeftCorner(contact_chol.constraintDim(), contact_chol.constraintDim()), 1e-11));
353 dampedDelassusInverse.triangularView<StrictlyLower>() =
354 dampedDelassusInverse.triangularView<StrictlyUpper>().transpose();
355 BOOST_CHECK(dampedDelassusInverse.isApprox(
356 -H_inverse.topLeftCorner(contact_chol.constraintDim(), contact_chol.constraintDim()), 1e-7));
361 using namespace Eigen;
366 const std::string RA =
"rleg6_joint";
367 const std::string LA =
"lleg6_joint";
379 MatrixXd H_inverse(contact_chol.size(), contact_chol.size());
381 VectorXd
v = Eigen::VectorXd::Random(
model.nv);
385 contact_chol.inverse(H_inverse);
388 dampedDelassusInverse.resize(contact_chol.constraintDim(), contact_chol.constraintDim());
393 dampedDelassusInverse.triangularView<StrictlyLower>() =
394 dampedDelassusInverse.triangularView<StrictlyUpper>().transpose();
395 BOOST_CHECK(dampedDelassusInverse.isApprox(
396 -H_inverse.topLeftCorner(contact_chol.constraintDim(), contact_chol.constraintDim()), 1e-11));
400 dampedDelassusInverse.triangularView<StrictlyLower>() =
401 dampedDelassusInverse.triangularView<StrictlyUpper>().transpose();
402 BOOST_CHECK(dampedDelassusInverse.isApprox(
403 -H_inverse.topLeftCorner(contact_chol.constraintDim(), contact_chol.constraintDim()), 1e-7));
408 using namespace Eigen;
413 const std::string RF =
"rleg6_joint";
414 const std::string LF =
"lleg6_joint";
415 const std::string RA =
"rarm6_joint";
416 const std::string LA =
"larm6_joint";
434 MatrixXd H_inverse(contact_chol.size(), contact_chol.size());
436 VectorXd
v = Eigen::VectorXd::Random(
model.nv);
440 contact_chol.inverse(H_inverse);
443 dampedDelassusInverse.resize(contact_chol.constraintDim(), contact_chol.constraintDim());
448 dampedDelassusInverse.triangularView<StrictlyLower>() =
449 dampedDelassusInverse.triangularView<StrictlyUpper>().transpose();
450 BOOST_CHECK(dampedDelassusInverse.isApprox(
451 -H_inverse.topLeftCorner(contact_chol.constraintDim(), contact_chol.constraintDim()), 1e-11));
455 dampedDelassusInverse.triangularView<StrictlyLower>() =
456 dampedDelassusInverse.triangularView<StrictlyUpper>().transpose();
457 BOOST_CHECK(dampedDelassusInverse.isApprox(
458 -H_inverse.topLeftCorner(contact_chol.constraintDim(), contact_chol.constraintDim()), 1e-7));
463 using namespace Eigen;
469 const std::string RA =
"rleg6_joint";
480 MatrixXd H_inverse(contact_chol.size(), contact_chol.size());
482 VectorXd
v = Eigen::VectorXd::Random(
model.nv);
486 contact_chol.inverse(H_inverse);
489 dampedDelassusInverse.resize(contact_chol.constraintDim(), contact_chol.constraintDim());
494 dampedDelassusInverse.triangularView<StrictlyLower>() =
495 dampedDelassusInverse.triangularView<StrictlyUpper>().transpose();
496 BOOST_CHECK(dampedDelassusInverse.isApprox(
497 -H_inverse.topLeftCorner(contact_chol.constraintDim(), contact_chol.constraintDim()), 1e-11));
501 dampedDelassusInverse.triangularView<StrictlyLower>() =
502 dampedDelassusInverse.triangularView<StrictlyUpper>().transpose();
503 BOOST_CHECK(dampedDelassusInverse.isApprox(
504 -H_inverse.topLeftCorner(contact_chol.constraintDim(), contact_chol.constraintDim()), 1e-7));
509 using namespace Eigen;
514 const std::string RA =
"rleg6_joint";
529 MatrixXd H_inverse(contact_chol.size(), contact_chol.size());
531 VectorXd
v = Eigen::VectorXd::Random(
model.nv);
535 contact_chol.inverse(H_inverse);
538 dampedDelassusInverse.resize(contact_chol.constraintDim(), contact_chol.constraintDim());
543 dampedDelassusInverse.triangularView<StrictlyLower>() =
544 dampedDelassusInverse.triangularView<StrictlyUpper>().transpose();
545 BOOST_CHECK(dampedDelassusInverse.isApprox(
546 -H_inverse.topLeftCorner(contact_chol.constraintDim(), contact_chol.constraintDim()), 1e-10));
550 dampedDelassusInverse.triangularView<StrictlyLower>() =
551 dampedDelassusInverse.triangularView<StrictlyUpper>().transpose();
552 BOOST_CHECK(dampedDelassusInverse.isApprox(
553 -H_inverse.topLeftCorner(contact_chol.constraintDim(), contact_chol.constraintDim()), 1e-10));
558 using namespace Eigen;
563 const std::string RA =
"rleg6_joint";
576 const std::string RF =
"rleg6_joint";
577 const std::string LF =
"lleg6_joint";
578 const std::string LA =
"larm6_joint";
594 MatrixXd H_inverse(contact_chol.size(), contact_chol.size());
596 VectorXd
v = Eigen::VectorXd::Random(
model.nv);
600 contact_chol.inverse(H_inverse);
603 dampedDelassusInverse.resize(contact_chol.constraintDim(), contact_chol.constraintDim());
608 dampedDelassusInverse.triangularView<StrictlyLower>() =
609 dampedDelassusInverse.triangularView<StrictlyUpper>().transpose();
610 BOOST_CHECK(dampedDelassusInverse.isApprox(
611 -H_inverse.topLeftCorner(contact_chol.constraintDim(), contact_chol.constraintDim()), 1e-11));
615 dampedDelassusInverse.triangularView<StrictlyLower>() =
616 dampedDelassusInverse.triangularView<StrictlyUpper>().transpose();
617 BOOST_CHECK(dampedDelassusInverse.isApprox(
618 -H_inverse.topLeftCorner(contact_chol.constraintDim(), contact_chol.constraintDim()), 1e-7));
623 using namespace Eigen;
629 const std::string RA =
"rleg6_joint";
630 const std::string LA =
"rleg4_joint";
642 MatrixXd H_inverse(contact_chol.size(), contact_chol.size());
644 VectorXd
v = Eigen::VectorXd::Random(
model.nv);
649 contact_chol.inverse(H_inverse);
653 for (
int i = 0;
i < 2;
i++)
655 Eigen::MatrixXd dampedDelassusInverse;
656 dampedDelassusInverse.resize(contact_chol.constraintDim(), contact_chol.constraintDim());
657 dampedDelassusInverse.setZero();
661 contact_chol.inverse(H_inverse);
665 dampedDelassusInverse.triangularView<StrictlyLower>() =
666 dampedDelassusInverse.triangularView<StrictlyUpper>().transpose();
667 BOOST_CHECK(dampedDelassusInverse.isApprox(
668 -H_inverse.topLeftCorner(contact_chol.constraintDim(), contact_chol.constraintDim()), 1e-10));
672 dampedDelassusInverse.triangularView<StrictlyLower>() =
673 dampedDelassusInverse.triangularView<StrictlyUpper>().transpose();
674 BOOST_CHECK(dampedDelassusInverse.isApprox(
675 -H_inverse.topLeftCorner(contact_chol.constraintDim(), contact_chol.constraintDim()), 1e-10));
678 v = Eigen::VectorXd::Random(
model.nv);
684 using namespace Eigen;
689 const std::string RA =
"rleg6_joint";
690 const std::string LA =
"rleg4_joint";
702 MatrixXd H_inverse(contact_chol.size(), contact_chol.size());
704 VectorXd
v = Eigen::VectorXd::Random(
model.nv);
708 contact_chol.inverse(H_inverse);
711 dampedDelassusInverse.resize(contact_chol.constraintDim(), contact_chol.constraintDim());
716 dampedDelassusInverse.triangularView<StrictlyLower>() =
717 dampedDelassusInverse.triangularView<StrictlyUpper>().transpose();
718 BOOST_CHECK(dampedDelassusInverse.isApprox(
719 -H_inverse.topLeftCorner(contact_chol.constraintDim(), contact_chol.constraintDim()), 1e-11));
723 dampedDelassusInverse.triangularView<StrictlyLower>() =
724 dampedDelassusInverse.triangularView<StrictlyUpper>().transpose();
725 BOOST_CHECK(dampedDelassusInverse.isApprox(
726 -H_inverse.topLeftCorner(contact_chol.constraintDim(), contact_chol.constraintDim()), 1e-7));
731 using namespace Eigen;
736 const std::string RA =
"rleg6_joint";
737 const std::string LA =
"rleg4_joint";
747 const std::string RF =
"rleg6_joint";
748 const std::string LF =
"lleg6_joint";
758 MatrixXd H_inverse(contact_chol.size(), contact_chol.size());
760 VectorXd
v = Eigen::VectorXd::Random(
model.nv);
764 contact_chol.inverse(H_inverse);
767 dampedDelassusInverse.resize(contact_chol.constraintDim(), contact_chol.constraintDim());
772 dampedDelassusInverse.triangularView<StrictlyLower>() =
773 dampedDelassusInverse.triangularView<StrictlyUpper>().transpose();
774 BOOST_CHECK(dampedDelassusInverse.isApprox(
775 -H_inverse.topLeftCorner(contact_chol.constraintDim(), contact_chol.constraintDim()), 1e-11));
779 dampedDelassusInverse.triangularView<StrictlyLower>() =
780 dampedDelassusInverse.triangularView<StrictlyUpper>().transpose();
781 BOOST_CHECK(dampedDelassusInverse.isApprox(
782 -H_inverse.topLeftCorner(contact_chol.constraintDim(), contact_chol.constraintDim()), 1e-7));
785 BOOST_AUTO_TEST_SUITE_END()