contact-model.hpp
Go to the documentation of this file.
1 // Copyright (c) 2015-2018, CNRS
2 // Authors: Justin Carpentier <jcarpent@laas.fr>
3 
4 #ifndef __multicontact_api_python_scenario_contact_model_planar_hpp__
5 #define __multicontact_api_python_scenario_contact_model_planar_hpp__
6 
7 #include <eigenpy/eigenpy.hpp>
8 #include <string>
9 
14 
15 namespace multicontact_api {
16 namespace python {
17 
18 namespace bp = boost::python;
19 
20 template <typename ContactModel>
22  : public boost::python::def_visitor<
23  ContactModelPythonVisitor<ContactModel> > {
24  typedef typename ContactModel::Scalar Scalar;
26  typedef typename ContactModel::Matrix3X Matrix3X;
27  typedef typename ContactModel::Matrix6X Matrix6X;
28 
29  template <class PyClass>
30  void visit(PyClass& cl) const {
31  cl.def(bp::init<>())
32  .def(bp::init<Scalar>(bp::args("mu")))
33  .def(bp::init<Scalar, ContactType>(bp::args("mu", "contact_type")))
34  .def(bp::init<ContactModel>(bp::args("other"), "Copy contructor."))
35  .def_readwrite("mu", &ContactModel::m_mu, "Friction coefficient.")
36  .def_readwrite("contact_type", &ContactModel::m_contact_type,
37  "Enum that define the type of contact.")
38  .add_property(
39  "num_contact_points", &getNumContact, &setNumContact,
40  "The number of contact points used to model this contact. \n"
41  "Changing this value will clear the contact_points_positions "
42  "matrix")
43  .add_property("contact_points_positions", &getContactPositions,
44  &setContactPositions,
45  "3xnum_contact_points matrix defining the contact points "
46  "positions in the frame of the contact "
47  "placement. \n"
48  "num_contact_points is automatically updated to the "
49  "number of columns of this matrix.")
50  .def("generatorMatrix", &ContactModel::generatorMatrix,
51  "generatorMatrix Return a 6x(num_contact_points*3) matrix"
52  "containing the generator used to compute contact forces.")
53  .def(bp::self == bp::self)
54  .def(bp::self != bp::self)
55  .def("copy", &copy, "Returns a copy of *this.");
56  }
57 
58  static void expose(const std::string& class_name) {
59  std::string doc = "Contact Model";
60  bp::class_<ContactModel>(class_name.c_str(), doc.c_str(), bp::no_init)
64 
65  ENABLE_SPECIFIC_MATRIX_TYPE(Matrix3X);
66  ENABLE_SPECIFIC_MATRIX_TYPE(Matrix6X);
67  }
68 
69  private:
70  static ContactModel copy(const ContactModel& self) {
71  return ContactModel(self);
72  }
73  // define setter and getter
74  static size_t getNumContact(ContactModel& self) {
75  return self.num_contact_points();
76  }
77  static void setNumContact(ContactModel& self, const size_t num) {
78  self.num_contact_points(num);
79  }
80  static Matrix3X getContactPositions(ContactModel& self) {
81  return self.contact_points_positions();
82  }
83  static void setContactPositions(ContactModel& self, const Matrix3X& pos) {
84  self.contact_points_positions(pos);
85  }
86 };
87 } // namespace python
88 } // namespace multicontact_api
89 
90 #endif // ifndef __multicontact_api_python_scenario_contact_model_planar_hpp__
ContactType
Definition: fwd.hpp:33
ContactModelTpl< double > ContactModel
Definition: fwd.hpp:30
Definition: ellipsoid.hpp:12
void visit(PyClass &cl) const
Definition: contact-model.hpp:30
ContactModel::Scalar Scalar
Definition: contact-model.hpp:24
scenario::ContactType ContactType
Definition: contact-model.hpp:25
ContactModel::Matrix6X Matrix6X
Definition: contact-model.hpp:27
static void expose(const std::string &class_name)
Definition: contact-model.hpp:58
ContactModel::Matrix3X Matrix3X
Definition: contact-model.hpp:26
Set the Python method str and repr to use the overloading operator<<.
Definition: printable.hpp:19