Commit 308fad23 authored by Pierre Fernbach's avatar Pierre Fernbach
Browse files

Refactor ContactModelPlanar -> ContactModel

parent ec4f55f9
......@@ -2,12 +2,12 @@
// Authors: Justin Carpentier <jcarpent@laas.fr>
#include "multicontact-api/bindings/python/scenario/expose-scenario.hpp"
#include "multicontact-api/bindings/python/scenario/contact-model-planar.hpp"
#include "multicontact-api/bindings/python/scenario/contact-model.hpp"
namespace multicontact_api {
namespace python {
void exposeContactModels() {
ContactModelPlanarPythonVisitor<multicontact_api::scenario::ContactModelPlanar>::expose("ContactModelPlanar");
ContactModelPythonVisitor<multicontact_api::scenario::ContactModel>::expose("ContactModel");
}
} // namespace python
} // namespace multicontact_api
......@@ -15,7 +15,7 @@ SET(${PROJECT_NAME}_SERIALIZATION_HEADERS
)
SET(${PROJECT_NAME}_SCENARIO_HEADERS
scenario/contact-model-planar.hpp
scenario/contact-model.hpp
scenario/contact-patch.hpp
scenario/contact-phase.hpp
scenario/contact-sequence.hpp
......@@ -29,7 +29,7 @@ SET(${PROJECT_NAME}_PYTHON_HEADERS
bindings/python/geometry/linear-cone.hpp
bindings/python/geometry/second-order-cone.hpp
bindings/python/serialization/archive.hpp
bindings/python/scenario/contact-model-planar.hpp
bindings/python/scenario/contact-model.hpp
bindings/python/scenario/contact-patch.hpp
bindings/python/scenario/contact-phase.hpp
bindings/python/scenario/contact-sequence.hpp
......
......@@ -6,7 +6,7 @@
#include <string>
#include "multicontact-api/scenario/contact-model-planar.hpp"
#include "multicontact-api/scenario/contact-model.hpp"
#include "multicontact-api/bindings/python/serialization/archive.hpp"
#include "multicontact-api/bindings/python/utils/printable.hpp"
......@@ -15,18 +15,18 @@ namespace python {
namespace bp = boost::python;
template <typename ContactModelPlanar>
struct ContactModelPlanarPythonVisitor
: public boost::python::def_visitor<ContactModelPlanarPythonVisitor<ContactModelPlanar> > {
typedef typename ContactModelPlanar::Scalar Scalar;
template <typename ContactModel>
struct ContactModelPythonVisitor
: public boost::python::def_visitor<ContactModelPythonVisitor<ContactModel> > {
typedef typename ContactModel::Scalar Scalar;
template <class PyClass>
void visit(PyClass& cl) const {
cl.def(bp::init<>())
.def(bp::init<Scalar, Scalar>(bp::args("mu", "ZMP_radius")))
.def(bp::init<ContactModelPlanar>(bp::args("other"), "Copy contructor."))
.def_readwrite("mu", &ContactModelPlanar::m_mu, "Friction coefficient.")
.def_readwrite("ZMP_radius", &ContactModelPlanar::m_ZMP_radius, "Radius of the ZMP region.")
.def(bp::init<ContactModel>(bp::args("other"), "Copy contructor."))
.def_readwrite("mu", &ContactModel::m_mu, "Friction coefficient.")
.def_readwrite("ZMP_radius", &ContactModel::m_ZMP_radius, "Radius of the ZMP region.")
.def(bp::self == bp::self)
.def(bp::self != bp::self)
......@@ -35,14 +35,14 @@ struct ContactModelPlanarPythonVisitor
static void expose(const std::string& class_name) {
std::string doc = "Contact Model Planar";
bp::class_<ContactModelPlanar>(class_name.c_str(), doc.c_str(), bp::no_init)
.def(ContactModelPlanarPythonVisitor<ContactModelPlanar>())
.def(SerializableVisitor<ContactModelPlanar>())
.def(PrintableVisitor<ContactModelPlanar>());
bp::class_<ContactModel>(class_name.c_str(), doc.c_str(), bp::no_init)
.def(ContactModelPythonVisitor<ContactModel>())
.def(SerializableVisitor<ContactModel>())
.def(PrintableVisitor<ContactModel>());
}
private:
static ContactModelPlanar copy(const ContactModelPlanar& self) { return ContactModelPlanar(self); }
static ContactModel copy(const ContactModel& self) { return ContactModel(self); }
};
} // namespace python
} // namespace multicontact_api
......
// Copyright (c) 2015-2018, CNRS
// Authors: Justin Carpentier <jcarpent@laas.fr>
#ifndef __multicontact_api_scenario_contact_model_planar_hpp__
#define __multicontact_api_scenario_contact_model_planar_hpp__
#include "multicontact-api/scenario/fwd.hpp"
#include "multicontact-api/serialization/archive.hpp"
#include <iostream>
#include <Eigen/Dense>
namespace multicontact_api {
namespace scenario {
template <typename _Scalar>
struct ContactModelTpl : public serialization::Serializable<ContactModelTpl<_Scalar> > {
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
typedef _Scalar Scalar;
/// \brief Default constructor.
ContactModelTpl() : m_mu(-1.), m_ZMP_radius(-1.) {}
/// \brief Default constructor.
ContactModelTpl(const Scalar mu, const Scalar ZMP_radius) : m_mu(mu), m_ZMP_radius(ZMP_radius) {}
/// \brief Copy constructor
template <typename S2>
explicit ContactModelTpl(const ContactModelTpl<S2>& other)
: m_mu(other.mu), m_ZMP_radius(other.ZMP_radius) {}
template <typename S2>
bool operator==(const ContactModelTpl<S2>& other) const {
return m_mu == other.m_mu && m_ZMP_radius == other.m_ZMP_radius;
}
template <typename S2>
bool operator!=(const ContactModelTpl<S2>& other) const {
return !(*this == other);
}
void disp(std::ostream& os) const {
os << "mu: " << m_mu << std::endl << "ZMP radius: " << m_ZMP_radius << std::endl;
}
template <typename S2>
friend std::ostream& operator<<(std::ostream& os, const ContactModelTpl<S2>& cp) {
cp.disp(os);
return os;
}
/// \brief Friction coefficient.
Scalar m_mu;
/// \brief ZMP radius.
Scalar m_ZMP_radius;
private:
// Serialization of the class
friend class boost::serialization::access;
template <class Archive>
void save(Archive& ar, const unsigned int /*version*/) const {
ar& boost::serialization::make_nvp("mu", m_mu);
ar& boost::serialization::make_nvp("ZMP_radius", m_ZMP_radius);
}
template <class Archive>
void load(Archive& ar, const unsigned int /*version*/) {
ar >> boost::serialization::make_nvp("mu", m_mu);
ar >> boost::serialization::make_nvp("ZMP_radius", m_ZMP_radius);
}
BOOST_SERIALIZATION_SPLIT_MEMBER()
};
} // namespace scenario
} // namespace multicontact_api
#endif // ifndef __multicontact_api_scenario_contact_model_planar_hpp__
......@@ -26,8 +26,8 @@ struct ContactSequenceTpl;
typedef ContactSequenceTpl<ContactPhase> ContactSequence;
template <typename Scalar>
struct ContactModelPlanarTpl;
typedef ContactModelPlanarTpl<double> ContactModelPlanar;
struct ContactModelTpl;
typedef ContactModelTpl<double> ContactModel;
enum ConicType { CONIC_SOWC, CONIC_DOUBLE_DESCRIPTION, CONIC_UNDEFINED };
......
......@@ -9,7 +9,7 @@ from curves import SE3Curve, bezier, piecewise, piecewise_SE3, polynomial
from numpy import array, array_equal, isclose, random
import pinocchio as pin
from multicontact_api import ContactModelPlanar, ContactPatch, ContactPhase, ContactSequence
from multicontact_api import ContactModel, ContactPatch, ContactPhase, ContactSequence
from pinocchio import SE3, Quaternion
import pickle
pin.switchToNumpyArray()
......@@ -153,13 +153,13 @@ class ContactModelTest(unittest.TestCase):
mu = 0.3
zmp_radius = 0.01
# constructor with both values
mp1 = ContactModelPlanar(mu, zmp_radius)
mp1 = ContactModel(mu, zmp_radius)
# test getter bindings
self.assertEqual(mp1.mu, mu)
self.assertEqual(mp1.ZMP_radius, zmp_radius)
# copy constructor :
mp2 = ContactModelPlanar(mp1)
mp2 = ContactModel(mp1)
self.assertEqual(mp2.mu, mu)
self.assertEqual(mp2.ZMP_radius, zmp_radius)
......@@ -169,17 +169,17 @@ class ContactModelTest(unittest.TestCase):
self.assertTrue(mp1 != mp2)
def test_contact_model_serialization_default(self):
mp1 = ContactModelPlanar()
mp1 = ContactModel()
mp1.saveAsText("mp_test.txt")
mp_txt = ContactModelPlanar()
mp_txt = ContactModel()
mp_txt.loadFromText("mp_test.txt")
self.assertEqual(mp1, mp_txt)
mp1.saveAsBinary("mp_test")
mp_bin = ContactModelPlanar()
mp_bin = ContactModel()
mp_bin.loadFromBinary("mp_test")
self.assertEqual(mp1, mp_bin)
mp1.saveAsXML("mp_test.xml", 'ContactModel')
mp_xml = ContactModelPlanar()
mp_xml = ContactModel()
mp_xml.loadFromXML("mp_test.xml", 'ContactPatch')
self.assertEqual(mp1, mp_xml)
mp_pickled = pickle.dumps(mp1)
......@@ -190,17 +190,17 @@ class ContactModelTest(unittest.TestCase):
mu = 0.3
zmp_radius = 0.01
# constructor with both values
mp1 = ContactModelPlanar(mu, zmp_radius)
mp1 = ContactModel(mu, zmp_radius)
mp1.saveAsText("mp_test.txt")
mp_txt = ContactModelPlanar()
mp_txt = ContactModel()
mp_txt.loadFromText("mp_test.txt")
self.assertEqual(mp1, mp_txt)
mp1.saveAsBinary("mp_test")
mp_bin = ContactModelPlanar()
mp_bin = ContactModel()
mp_bin.loadFromBinary("mp_test")
self.assertEqual(mp1, mp_bin)
mp1.saveAsXML("mp_test.xml", 'ContactModel')
mp_xml = ContactModelPlanar()
mp_xml = ContactModel()
mp_xml.loadFromXML("mp_test.xml", 'ContactPatch')
self.assertEqual(mp1, mp_xml)
mp_pickled = pickle.dumps(mp1)
......
......@@ -6,7 +6,7 @@ import multicontact_api
class TrivialTest(unittest.TestCase):
""" A test written by someone who has no idea what this software is about"""
def test_trivial(self):
comopla = multicontact_api.ContactModelPlanar()
comopla = multicontact_api.ContactModel()
epsilon = 0.00001
value_wanted = -1.0
self.assertTrue((comopla.mu - value_wanted) < epsilon)
......
......@@ -7,7 +7,7 @@
#include <boost/test/unit_test.hpp>
#include <boost/utility/binary.hpp>
#include "multicontact-api/scenario/contact-model-planar.hpp"
#include "multicontact-api/scenario/contact-model.hpp"
#include "multicontact-api/scenario/contact-patch.hpp"
#include "multicontact-api/scenario/contact-phase.hpp"
#include "multicontact-api/scenario/contact-sequence.hpp"
......@@ -343,35 +343,35 @@ BOOST_AUTO_TEST_CASE(contact_model) {
const double mu = 0.3;
const double ZMP_radius = 0.01;
ContactModelPlanar mp1(mu, ZMP_radius);
ContactModelPlanar mp2(mp1);
ContactModel mp1(mu, ZMP_radius);
ContactModel mp2(mp1);
BOOST_CHECK(mp1.m_mu == mu);
BOOST_CHECK(mp1.m_ZMP_radius == ZMP_radius);
BOOST_CHECK(mp1 == mp2);
mp1.m_mu = 0.5;
BOOST_CHECK(mp1 != mp2);
ContactModelPlanar mp3(mp1);
ContactModel mp3(mp1);
BOOST_CHECK(mp1 == mp3);
mp3.m_ZMP_radius = 0.5;
BOOST_CHECK(mp1 != mp3);
std::cout<<"ContactModel Planar before serialization : \n "<<mp1<<std::endl;
std::cout<<"ContactModel before serialization : \n "<<mp1<<std::endl;
std::string fileName("fileTest_contactModel");
mp1.saveAsText(fileName + ".txt");
ContactModelPlanar mp_from_text;
ContactModel mp_from_text;
mp_from_text.loadFromText(fileName + ".txt");
std::cout<<"ContactModel Planar after serialization : \n "<<mp_from_text<<std::endl;
std::cout<<"ContactModel after serialization : \n "<<mp_from_text<<std::endl;
BOOST_CHECK(mp1 == mp_from_text);
mp1.saveAsXML(fileName + ".xml", "ContactModel");
ContactModelPlanar mp_from_xml;
ContactModel mp_from_xml;
mp_from_xml.loadFromXML(fileName + ".xml", "ContactModel");
BOOST_CHECK(mp1 == mp_from_xml);
mp1.saveAsBinary(fileName);
ContactModelPlanar mp_from_bin;
ContactModel mp_from_bin;
mp_from_bin.loadFromBinary(fileName);
BOOST_CHECK(mp1 == mp_from_bin);
}
......
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