Commit 7d28299e authored by Pierre Fernbach's avatar Pierre Fernbach
Browse files

[Python] add API for new ContactModel methods

parent 441223de
......@@ -9,6 +9,7 @@
#include "multicontact-api/scenario/contact-model.hpp"
#include "multicontact-api/bindings/python/serialization/archive.hpp"
#include "multicontact-api/bindings/python/utils/printable.hpp"
#include <eigenpy/eigenpy.hpp>
namespace multicontact_api {
namespace python {
......@@ -16,10 +17,10 @@ namespace python {
namespace bp = boost::python;
template <typename ContactModel>
struct ContactModelPythonVisitor
: public boost::python::def_visitor<ContactModelPythonVisitor<ContactModel> > {
struct ContactModelPythonVisitor : public boost::python::def_visitor<ContactModelPythonVisitor<ContactModel> > {
typedef typename ContactModel::Scalar Scalar;
typedef scenario::ContactType ContactType;
typedef typename ContactModel::Matrix3X Matrix3X;
template <class PyClass>
void visit(PyClass& cl) const {
......@@ -29,6 +30,13 @@ struct ContactModelPythonVisitor
.def(bp::init<ContactModel>(bp::args("other"), "Copy contructor."))
.def_readwrite("mu", &ContactModel::m_mu, "Friction coefficient.")
.def_readwrite("contact_type", &ContactModel::m_contact_type, "Enum that define the type of contact.")
.add_property("num_contact_points", &getNumContact, &setNumContact,
"The number of contact points used to model this contact. \n"
"Changing this value will clear the contact_points_positions matrix")
.add_property("contact_points_positions", &getContactPositions, &setContactPositions,
"3xnum_contact_points matrix defining the contact points positions in the frame of the contact "
"placement. \n"
"num_contact_points is automatically updated to the number of columns of this matrix.")
.def(bp::self == bp::self)
.def(bp::self != bp::self)
.def("copy", &copy, "Returns a copy of *this.");
......@@ -40,10 +48,17 @@ struct ContactModelPythonVisitor
static ContactModel copy(const ContactModel& self) { return ContactModel(self); }
// define setter and getter
static size_t getNumContact(ContactModel& self) { return self.num_contact_points(); }
static void setNumContact(ContactModel& self, const size_t num) { self.num_contact_points(num); }
static Matrix3X getContactPositions(ContactModel& self) { return self.contact_points_positions(); }
static void setContactPositions(ContactModel& self, const Matrix3X& pos) { self.contact_points_positions(pos); }
} // namespace python
} // namespace multicontact_api
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