Commit c2d7abbb authored by Justin Carpentier's avatar Justin Carpentier Committed by GitHub

Merge pull request #860 from jcarpent/devel

Improve coverage
parents 4da60a47 f9986693
......@@ -166,6 +166,8 @@ namespace pinocchio
const int nvj = nv (model.joints[joint]);
const int idx_vj = idx_v(model.joints[joint]);
assert(idx_vj >= 0 && idx_vj < model.nv);
if(parent>0) parents_fromRow[(Index)idx_vj] = idx_v(model.joints[parent])+nv(model.joints[parent])-1;
else parents_fromRow[(Index)idx_vj] = -1;
nvSubtree_fromRow[(Index)idx_vj] = nvSubtree[joint];
......
......@@ -83,6 +83,9 @@ namespace pinocchio
JointModelDerived & jmodel = boost::get<JointModelDerived>(joints.back());
jmodel.setIndexes(idx,nq,nv);
assert(jmodel.idx_q() >= 0);
assert(jmodel.idx_v() >= 0);
inertias .push_back(Inertia::Zero());
parents .push_back(parent);
jointPlacements.push_back(joint_placement);
......
......@@ -96,7 +96,6 @@ ENDIF(BUILD_PYTHON_INTERFACE)
ADD_PINOCCHIO_UNIT_TEST(model)
ADD_PINOCCHIO_UNIT_TEST(constraint)
#ADD_PINOCCHIO_UNIT_TEST(variant)
ADD_PINOCCHIO_UNIT_TEST(joints)
ADD_PINOCCHIO_UNIT_TEST(compute-all-terms)
ADD_PINOCCHIO_UNIT_TEST(energy)
......
......@@ -229,4 +229,45 @@ BOOST_AUTO_TEST_CASE(test_model_serialization)
generic_test(model,TEST_SERIALIZATION_FOLDER"/Model","Model");
}
BOOST_AUTO_TEST_CASE(test_throw_extension)
{
using namespace pinocchio;
Model model;
buildModels::humanoidRandom(model);
const std::string & fake_filename = "this_is_a_fake_filename";
{
const std::string complete_filename = fake_filename + ".txt";
BOOST_REQUIRE_THROW(loadFromText(model,complete_filename),
std::invalid_argument);
}
saveToText(model,TEST_SERIALIZATION_FOLDER"/model.txt");
saveToXML(model,TEST_SERIALIZATION_FOLDER"/model.xml","model");
saveToBinary(model,TEST_SERIALIZATION_FOLDER"/model.bin");
{
const std::string complete_filename = fake_filename + ".txte";
BOOST_REQUIRE_THROW(loadFromText(model,complete_filename),
std::invalid_argument);
}
{
const std::string complete_filename = fake_filename + ".xmle";
BOOST_REQUIRE_THROW(loadFromXML(model,complete_filename,"model"),
std::invalid_argument);
}
{
const std::string complete_filename = fake_filename + ".bine";
BOOST_REQUIRE_THROW(loadFromBinary(model,complete_filename),
std::invalid_argument);
}
}
BOOST_AUTO_TEST_SUITE_END()
//
// Copyright (c) 2015 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/multibody/joint/joint-generic.hpp"
#include <iostream>
#include "pinocchio/tools/timer.hpp"
#include <boost/test/unit_test.hpp>
#include <boost/utility/binary.hpp>
BOOST_AUTO_TEST_SUITE ( BOOST_TEST_MODULE )
BOOST_AUTO_TEST_CASE ( test_variant )
{
using namespace Eigen;
using namespace se3;
JointModelVariant jmodel = JointModelRX();
const JointDataVariant & jdata = CreateJointData::run(jmodel);
JointDataGeneric jdatagen(jdata);
JointModelGeneric jmodelgen(jmodel);
se3::Model model;
}
BOOST_AUTO_TEST_SUITE_END ()
//
// Copyright (c) 2015-2018 CNRS
// Copyright (c) 2015-2019 CNRS INRIA
//
#include <iostream>
#include <pinocchio/multibody/joint/joint-composite.hpp>
#include <pinocchio/multibody/model.hpp>
#include "pinocchio/multibody/model.hpp"
#include "pinocchio/multibody/data.hpp"
#include "pinocchio/multibody/visitor.hpp"
#include <iostream>
#include <boost/test/unit_test.hpp>
#include <boost/utility/binary.hpp>
namespace pinocchio
namespace bf = boost::fusion;
struct SimpleVisitor
: public pinocchio::fusion::JointVisitorBase<SimpleVisitor>
{
struct SimpleVisitor : public pinocchio::fusion::JointVisitorBase<SimpleVisitor>
typedef bf::vector<const pinocchio::Model &,
pinocchio::Data &,
pinocchio::JointIndex> ArgsType;
template<typename JointModel>
static void algo(const pinocchio::JointModelBase<JointModel> & jmodel,
pinocchio::JointDataBase<typename JointModel::JointDataDerived> & jdata,
const pinocchio::Model & model,
pinocchio::Data & data,
pinocchio::JointIndex jindex)
{
typedef boost::fusion::vector<const pinocchio::Model &,
pinocchio::Data &,
JointIndex
> ArgsType;
template<typename JointModel>
static void algo(const pinocchio::JointModelBase<JointModel> & jmodel,
pinocchio::JointDataBase<typename JointModel::JointDataDerived> & jdata,
const pinocchio::Model & model,
pinocchio::Data & data,
JointIndex jointId);
};
PINOCCHIO_UNUSED_VARIABLE(jdata);
PINOCCHIO_UNUSED_VARIABLE(model);
PINOCCHIO_UNUSED_VARIABLE(data);
PINOCCHIO_UNUSED_VARIABLE(jindex);
std::cout << "joint name: " << jmodel.shortname() << std::endl;
}
};
template<typename JointModel>
void SimpleVisitor::algo(const pinocchio::JointModelBase<JointModel> & /*jmodel*/,
pinocchio::JointDataBase<typename JointModel::JointDataDerived> & /*jdata*/,
const pinocchio::Model & /*model*/,
pinocchio::Data & /*data*/,
JointIndex /*dummy*/)
{ /* --- do nothing --- */ }
template<>
void SimpleVisitor::algo(const pinocchio::JointModelBase<JointModelRevoluteUnaligned> & jmodel,
pinocchio::JointDataBase<JointDataRevoluteUnaligned> & /*jdata*/,
const pinocchio::Model & /*model*/,
pinocchio::Data & /*data*/,
JointIndex /*dummy*/)
BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
template<typename JointModel_> struct init;
template<typename JointModel_>
struct init
{
static JointModel_ run(const pinocchio::Model &/* model*/)
{
BOOST_CHECK( jmodel.shortname() == JointModelRevoluteUnaligned::classname() );
Eigen::Vector3d axis = jmodel.derived().axis;
Eigen::Vector3d axis_z; axis_z << 0,0,1;
JointModel_ jmodel;
return jmodel;
}
};
BOOST_CHECK ( axis == axis_z );
template<typename Scalar, int Options>
struct init<pinocchio::JointModelRevoluteUnalignedTpl<Scalar,Options> >
{
typedef pinocchio::JointModelRevoluteUnalignedTpl<Scalar,Options> JointModel;
static JointModel run(const pinocchio::Model &/* model*/)
{
typedef typename JointModel::Vector3 Vector3;
JointModel jmodel(Vector3::Random().normalized());
return jmodel;
}
};
} // namespace pinocchio
template<typename Scalar, int Options>
struct init<pinocchio::JointModelRevoluteUnboundedUnalignedTpl<Scalar,Options> >
{
typedef pinocchio::JointModelRevoluteUnboundedUnalignedTpl<Scalar,Options> JointModel;
static JointModel run(const pinocchio::Model &/* model*/)
{
typedef typename JointModel::Vector3 Vector3;
JointModel jmodel(Vector3::Random().normalized());
return jmodel;
}
};
/* Validates the access to memory stored in joint models, by using the class
* joint model revolute unaligned.
*/
template<typename Scalar, int Options>
struct init<pinocchio::JointModelPrismaticUnalignedTpl<Scalar,Options> >
{
typedef pinocchio::JointModelPrismaticUnalignedTpl<Scalar,Options> JointModel;
static JointModel run(const pinocchio::Model &/* model*/)
{
typedef typename JointModel::Vector3 Vector3;
JointModel jmodel(Vector3::Random().normalized());
return jmodel;
}
};
BOOST_AUTO_TEST_SUITE ( BOOST_TEST_MODULE )
template<typename Scalar, int Options, template<typename,int> class JointCollection>
struct init<pinocchio::JointModelTpl<Scalar,Options,JointCollection> >
{
typedef pinocchio::JointModelTpl<Scalar,Options,JointCollection> JointModel;
static JointModel run(const pinocchio::Model &/* model*/)
{
typedef pinocchio::JointModelRevoluteTpl<Scalar,Options,0> JointModelRX;
JointModel jmodel((JointModelRX()));
return jmodel;
}
};
template<typename Scalar, int Options, template<typename,int> class JointCollection>
struct init<pinocchio::JointModelCompositeTpl<Scalar,Options,JointCollection> >
{
typedef pinocchio::JointModelCompositeTpl<Scalar,Options,JointCollection> JointModel;
static JointModel run(const pinocchio::Model &/* model*/)
{
typedef pinocchio::JointModelRevoluteTpl<Scalar,Options,0> JointModelRX;
typedef pinocchio::JointModelRevoluteTpl<Scalar,Options,1> JointModelRY;
typedef pinocchio::JointModelRevoluteTpl<Scalar,Options,2> JointModelRZ;
JointModel jmodel(JointModelRX(),pinocchio::SE3::Random());
jmodel.addJoint(JointModelRY(),pinocchio::SE3::Random());
jmodel.addJoint(JointModelRZ(),pinocchio::SE3::Random());
return jmodel;
}
};
BOOST_AUTO_TEST_CASE ( test_runal )
template<typename JointModel_>
struct init<pinocchio::JointModelMimic<JointModel_> >
{
typedef pinocchio::JointModelMimic<JointModel_> JointModel;
static JointModel run(const pinocchio::Model & model)
{
const pinocchio::JointIndex joint_id = model.getJointId(JointModel_::classname());
std::cout << "joint_id: " << joint_id << std::endl;
JointModel jmodel(boost::get<JointModel_>(model.joints[joint_id]),1.,0.);
return jmodel;
}
};
struct AppendJointToModel
{
AppendJointToModel(pinocchio::Model & model) : model(model) {}
template<typename JointModel>
void operator()(const pinocchio::JointModelBase<JointModel> &) const
{
JointModel jmodel = init<JointModel>::run(model);
model.addJoint(model.joints.size()-1,jmodel,
pinocchio::SE3::Random(),jmodel.classname());
}
pinocchio::Model & model;
};
BOOST_AUTO_TEST_CASE(test_run_over_all_joints)
{
using namespace pinocchio;
pinocchio::Model model;
model.addJoint(0,pinocchio::JointModelRevoluteUnaligned(0,0,1),pinocchio::SE3::Random(),"");
typedef JointCollectionDefault::JointModelVariant Variant;
Model model;
boost::mpl::for_each<Variant::types>(AppendJointToModel(model));
Data data(model);
for( Model::JointIndex i=1;i<(Model::JointIndex)model.njoints;++i )
{
SimpleVisitor::run(model.joints[i],data.joints[i],
SimpleVisitor::ArgsType(model,data,i));
}
{
SimpleVisitor::run(model.joints[i],data.joints[i],
SimpleVisitor::ArgsType(model,data,i));
}
}
BOOST_AUTO_TEST_SUITE_END ()
BOOST_AUTO_TEST_SUITE_END()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment