Commit d5e383f7 authored by Pierre Fernbach's avatar Pierre Fernbach
Browse files

[Python] update python API and tests to changes in ContactModel

parent ee000a8a
......@@ -19,6 +19,14 @@ void exposeEnumConicType() {
.value("CONIC_UNDEFINED", CONIC_UNDEFINED);
}
void exposeScenarioEnums() { exposeEnumConicType(); }
void exposeEnumContactType() {
bp::enum_<ContactType>("ContactType")
.value("CONTACT_UNDEFINED", CONTACT_UNDEFINED)
.value("CONTACT_PLANAR", CONTACT_PLANAR)
.value("CONTACT_POINT", CONTACT_POINT);
}
void exposeScenarioEnums() { exposeEnumConicType(); exposeEnumContactType();}
} // namespace python
} // namespace multicontact_api
......@@ -5,7 +5,7 @@
#define __multicontact_api_python_scenario_contact_model_planar_hpp__
#include <string>
#include "multicontact-api/scenario/fwd.hpp"
#include "multicontact-api/scenario/contact-model.hpp"
#include "multicontact-api/bindings/python/serialization/archive.hpp"
#include "multicontact-api/bindings/python/utils/printable.hpp"
......@@ -19,14 +19,16 @@ template <typename ContactModel>
struct ContactModelPythonVisitor
: public boost::python::def_visitor<ContactModelPythonVisitor<ContactModel> > {
typedef typename ContactModel::Scalar Scalar;
typedef scenario::ContactType ContactType;
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<Scalar>(bp::args("mu")))
.def(bp::init<Scalar, ContactType>(bp::args("mu", "contact_type")))
.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_readwrite("contact_type", &ContactModel::m_contact_type, "Enum that define the type of contact.")
.def(bp::self == bp::self)
.def(bp::self != bp::self)
......@@ -34,7 +36,7 @@ struct ContactModelPythonVisitor
}
static void expose(const std::string& class_name) {
std::string doc = "Contact Model Planar";
std::string doc = "Contact Model";
bp::class_<ContactModel>(class_name.c_str(), doc.c_str(), bp::no_init)
.def(ContactModelPythonVisitor<ContactModel>())
.def(SerializableVisitor<ContactModel>())
......
......@@ -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 ContactModel, ContactPatch, ContactPhase, ContactSequence
from multicontact_api import ContactModel, ContactPatch, ContactPhase, ContactSequence, ContactType
from pinocchio import SE3, Quaternion
import pickle
pin.switchToNumpyArray()
......@@ -149,19 +149,28 @@ def buildRandomContactPhase(min=-1, max=-1):
class ContactModelTest(unittest.TestCase):
def test_contact_model_planar(self):
def test_contact_model(self):
mu = 0.3
zmp_radius = 0.01
# default constructor
mp = ContactModel()
self.assertEqual(mp.mu, -1.)
self.assertEqual(mp.contact_type, ContactType.CONTACT_UNDEFINED)
# constructor with friction
mp_mu = ContactModel(mu)
self.assertEqual(mp_mu.mu, mu)
self.assertEqual(mp_mu.contact_type, ContactType.CONTACT_UNDEFINED)
# constructor with both values
mp1 = ContactModel(mu, zmp_radius)
mp1 = ContactModel(mu, ContactType.CONTACT_PLANAR)
# test getter bindings
self.assertEqual(mp1.mu, mu)
self.assertEqual(mp1.ZMP_radius, zmp_radius)
self.assertEqual(mp1.contact_type, ContactType.CONTACT_PLANAR)
# copy constructor :
mp2 = ContactModel(mp1)
self.assertEqual(mp2.mu, mu)
self.assertEqual(mp2.ZMP_radius, zmp_radius)
self.assertEqual(mp2.contact_type, ContactType.CONTACT_PLANAR)
# test operator ==
self.assertTrue(mp1 == mp2)
......@@ -188,9 +197,8 @@ class ContactModelTest(unittest.TestCase):
def test_contact_model_serialization_full(self):
mu = 0.3
zmp_radius = 0.01
# constructor with both values
mp1 = ContactModel(mu, zmp_radius)
mp1 = ContactModel(mu, ContactType.CONTACT_PLANAR)
mp1.saveAsText("mp_test.txt")
mp_txt = ContactModel()
mp_txt.loadFromText("mp_test.txt")
......
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