Newer
Older
// Copyright (c) 2015-2016 CNRS
//
// This file is part of Pinocchio
// Pinocchio is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// Pinocchio is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// Pinocchio If not, see
// <http://www.gnu.org/licenses/>.
#include "pinocchio/multibody/model.hpp"
#include "pinocchio/algorithm/jacobian.hpp"
#include "pinocchio/algorithm/crba.hpp"
#include "pinocchio/algorithm/rnea.hpp"
#include "pinocchio/algorithm/center-of-mass.hpp"
#include "pinocchio/tools/timer.hpp"
#include "pinocchio/parsers/sample-models.hpp"
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE ComTest
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE ( ComTest)
BOOST_AUTO_TEST_CASE ( test_com )
using namespace Eigen;
se3::Model model;
se3::buildModels::humanoidSimple(model);
se3::Data data(model);
jcarpent
committed
VectorXd q = VectorXd::Ones(model.nq);
q.middleRows<4> (3).normalize();
VectorXd v = VectorXd::Ones(model.nv);
VectorXd a = VectorXd::Ones(model.nv);
jcarpent
committed
crba(model,data,q);
/* Test COM against CRBA*/
Vector3d com = centerOfMass(model,data,q);
Valenza Florian
committed
BOOST_CHECK(data.com[0].isApprox(getComFromCrba(model,data), 1e-12));
/* Test COM against Jcom (both use different way of compute the COM. */
com = centerOfMass(model,data,q);
jacobianCenterOfMass(model,data,q);
Valenza Florian
committed
BOOST_CHECK(com.isApprox(data.com[0], 1e-12));
/* Test COM against Jcom (both use different way of compute the COM. */
centerOfMass(model,data,q,v,a);
Valenza Florian
committed
BOOST_CHECK(com.isApprox(data.com[0], 1e-12));
jcarpent
committed
/* Test vCoM againt nle algorithm without gravity field */
a.setZero();
model.gravity.setZero();
centerOfMass(model,data,q,v,a);
jcarpent
committed
se3::SE3::Vector3 acom_from_nle (data.nle.head <3> ()/data.mass[0]);
Valenza Florian
committed
BOOST_CHECK((data.liMi[1].rotation() * acom_from_nle).isApprox(data.acom[0], 1e-12));
/* Test Jcom against CRBA */
Eigen::MatrixXd Jcom = jacobianCenterOfMass(model,data,q);
Valenza Florian
committed
BOOST_CHECK(data.Jcom.isApprox(getJacobianComFromCrba(model,data), 1e-12));
jcarpent
committed
/* Test CoM vecolity againt jacobianCenterOfMass */
Valenza Florian
committed
BOOST_CHECK((Jcom * v).isApprox(data.vcom[0], 1e-12));
centerOfMass(model,data,q,v);
/* Test CoM vecolity againt jacobianCenterOfMass */
BOOST_CHECK((Jcom * v).isApprox(data.vcom[0], 1e-12));
// std::cout << "com = [ " << data.com[0].transpose() << " ];" << std::endl;
// std::cout << "mass = [ " << data.mass[0] << " ];" << std::endl;
// std::cout << "Jcom = [ " << data.Jcom << " ];" << std::endl;
// std::cout << "M3 = [ " << data.M.topRows<3>() << " ];" << std::endl;
}
//BOOST_AUTO_TEST_CASE ( test_timings )
//{
// using namespace Eigen;
// using namespace se3;
//
// se3::Model model;
// se3::buildModels::humanoidSimple(model);
// se3::Data data(model);
//
// long flag = BOOST_BINARY(1111);
// StackTicToc timer(StackTicToc::US);
// #ifdef NDEBUG
// #ifdef _INTENSE_TESTING_
// const size_t NBT = 1000*1000;
// #else
// const size_t NBT = 10;
// #endif
// #else
// const size_t NBT = 1;
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// std::cout << "(the time score in debug mode is not relevant) " ;
// #endif
//
// bool verbose = flag & (flag-1) ; // True is two or more binaries of the flag are 1.
// if(verbose) std::cout <<"--" << std::endl;
// Eigen::VectorXd q = Eigen::VectorXd::Zero(model.nq);
//
// if( flag >> 0 & 1 )
// {
// timer.tic();
// SMOOTH(NBT)
// {
// centerOfMass(model,data,q);
// }
// if(verbose) std::cout << "COM =\t";
// timer.toc(std::cout,NBT);
// }
//
// if( flag >> 1 & 1 )
// {
// timer.tic();
// SMOOTH(NBT)
// {
// centerOfMass(model,data,q,false);
// }
// if(verbose) std::cout << "Without sub-tree =\t";
// timer.toc(std::cout,NBT);
// }
//
// if( flag >> 2 & 1 )
// {
// timer.tic();
// SMOOTH(NBT)
// {
// jacobianCenterOfMass(model,data,q);
// }
// if(verbose) std::cout << "Jcom =\t";
// timer.toc(std::cout,NBT);
// }
//}
BOOST_AUTO_TEST_SUITE_END ()