12 #include "pinocchio/spatial/se3.hpp" 13 #include "pinocchio/multibody/model.hpp" 14 #include "pinocchio/multibody/data.hpp" 15 #include "pinocchio/algorithm/crba.hpp" 16 #include "pinocchio/algorithm/cholesky.hpp" 17 #include "pinocchio/parsers/sample-models.hpp" 18 #include "pinocchio/utils/timer.hpp" 19 #include "pinocchio/algorithm/joint-configuration.hpp" 23 # include <Eigen/Cholesky> 26 #include <boost/test/unit_test.hpp> 27 #include <boost/utility/binary.hpp> 30 BOOST_AUTO_TEST_SUITE ( BOOST_TEST_MODULE )
34 using namespace Eigen;
48 data.
M.triangularView<Eigen::StrictlyLower>() =
49 data.
M.triangularView<Eigen::StrictlyUpper>().transpose();
51 const Eigen::MatrixXd &
U = data.
U;
53 const Eigen::MatrixXd &
M = data.
M;
56 std::cout <<
"M = [\n" << M <<
"];" << std::endl;
57 std::cout <<
"U = [\n" << U <<
"];" << std::endl;
58 std::cout <<
"D = [\n" << D.transpose() <<
"];" << std::endl;
61 BOOST_CHECK(M.isApprox(U*D.asDiagonal()*U.transpose() , 1e-12));
67 BOOST_CHECK(Uv.isApprox(U*v, 1e-12));
70 BOOST_CHECK(Utv.isApprox(U.transpose()*v, 1e-12));
73 BOOST_CHECK(Uiv.isApprox(U.inverse()*v, 1e-12));
77 BOOST_CHECK(Utiv.isApprox(U.transpose().inverse()*v, 1e-12));
80 BOOST_CHECK(Miv.isApprox(M.inverse()*v, 1e-12));
83 BOOST_CHECK(Mv.isApprox(M*v, 1e-12));
85 BOOST_CHECK(Mv.isApprox(M*v, 1e-12));
99 using namespace Eigen;
113 long flag = BOOST_BINARY(1111111);
116 #ifdef _INTENSE_TESTING_ 117 const size_t NBT = 1000*1000;
119 const size_t NBT = 10;
122 const size_t NBT = 1;
123 std::cout <<
"(the time score in debug mode is not relevant) " ;
126 bool verbose = flag & (flag-1) ;
127 if(verbose) std::cout <<
"--" << std::endl;
136 if(verbose) std::cout <<
"Decompose =\t";
137 timer.
toc(std::cout,NBT);
147 Eigen::LDLT <Eigen::MatrixXd> Mchol(data.
M);
148 res = Mchol.solve(v);
150 if(verbose) std::cout <<
"Eigen::LDLt =\t";
151 timer.
toc(std::cout,NBT);
156 std::vector<Eigen::VectorXd> randvec(NBT);
157 for(
size_t i=0;
i<NBT;++
i ) randvec[
i] = Eigen::VectorXd::Random(model.
nv);
169 if(verbose) std::cout <<
"solve =\t\t";
170 timer.
toc(std::cout,NBT);
180 if(verbose) std::cout <<
"Uv =\t\t";
181 timer.
toc(std::cout,NBT);
191 if(verbose) std::cout <<
"Uiv =\t\t";
192 timer.
toc(std::cout,NBT);
202 if(verbose) std::cout <<
"Mv =\t\t";
203 timer.
toc(std::cout,NBT);
212 if(verbose) std::cout <<
"UDUtv =\t\t";
213 timer.
toc(std::cout,NBT);
220 using namespace Eigen;
231 data.
M.triangularView<Eigen::StrictlyLower>() =
232 data.
M.triangularView<Eigen::StrictlyUpper>().transpose();
233 MatrixXd Minv_ref(data.
M.inverse());
241 for(
int k = 0; k < model.
nv; ++k)
243 v_unit = VectorXd::Unit(model.
nv,k);
245 cholesky::internal::Miunit(model,data,k,Ui_v_unit);
246 Ui_v_unit_ref = v_unit;
248 Ui_v_unit_ref.array() *= data.
Dinv.array();
251 BOOST_CHECK(Ui_v_unit.isApprox(Ui_v_unit_ref));
253 Ui_v_unit_ref = v_unit;
255 BOOST_CHECK(Ui_v_unit.isApprox(Ui_v_unit_ref));
261 MatrixXd Minv(model.
nv,model.
nv);
265 BOOST_CHECK(Minv.isApprox(Minv_ref));
269 BOOST_CHECK(Minv.isApprox(Minv_ref));
272 Data data_bis(model);
273 crba(model,data_bis,q);
276 BOOST_CHECK(data_bis.Minv.isApprox(Minv_ref));
279 BOOST_AUTO_TEST_SUITE_END ()
const DataTpl< Scalar, Options, JointCollectionTpl >::MatrixXs & crba(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q)
Computes the upper triangular part of the joint space inertia matrix M by using the Composite Rigid B...
Mat & computeMinv(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< Mat > &Minv)
Computes the inverse of the joint space inertia matrix M from its Cholesky factorization.
const DataTpl< Scalar, Options, JointCollectionTpl >::MatrixXs & decompose(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data)
Compute the Cholesky decomposition of the joint space inertia matrix M contained in data...
ConfigVectorType lowerPositionLimit
Lower joint configuration limit.
void randomConfiguration(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorIn1 > &lowerLimits, const Eigen::MatrixBase< ConfigVectorIn2 > &upperLimits, const Eigen::MatrixBase< ReturnType > &qout)
Generate a configuration vector uniformly sampled among provided limits.
VectorXs D
Diagonal of the joint space intertia matrix obtained by a Cholesky Decomposition. ...
Mat & Utiv(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< Mat > &v)
Perform the pivot inversion using the Cholesky decomposition stored in data and acting in place...
BOOST_AUTO_TEST_CASE(test_cholesky)
MatrixXs M
The joint space inertia matrix (a square matrix of dim model.nv).
Mat & Uv(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< Mat > &v)
Perform the sparse multiplication using the Cholesky decomposition stored in data and acting in plac...
Main pinocchio namespace.
VectorXs Dinv
Diagonal inverse of the joint space intertia matrix obtained by a Cholesky Decomposition.
Mat & UDUtv(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< Mat > &m)
Performs the multiplication by using the Cholesky decomposition of M stored in data.
int nv
Dimension of the velocity vector space.
Mat & Uiv(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< Mat > &v)
Perform the pivot inversion using the Cholesky decomposition stored in data and acting in place...
Mat & solve(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< Mat > &y)
Return the solution of using the Cholesky decomposition stored in data given the entry ...
MatRes & Mv(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< Mat > &min, const Eigen::MatrixBase< MatRes > &mout)
Performs the multiplication by using the sparsity pattern of the M matrix.
ConfigVectorType upperPositionLimit
Upper joint configuration limit.
void humanoidRandom(ModelTpl< Scalar, Options, JointCollectionTpl > &model, bool usingFF=true)
Create a humanoid kinematic tree with 6-DOF limbs and random joint placements.
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > VectorXd
MatrixXs U
Joint space intertia matrix square root (upper trianglular part) computed with a Cholesky Decompositi...
Mat & Utv(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< Mat > &v)
Perform the sparse multiplication using the Cholesky decomposition stored in data and acting in plac...
void fill(Eigen::Ref< MatType > mat, const typename MatType::Scalar &value)