contact-patch.hpp 2.85 KB
Newer Older
Justin Carpentier's avatar
Justin Carpentier committed
1
2
3
// Copyright (c) 2015-2018, CNRS
// Authors: Justin Carpentier <jcarpent@laas.fr>

Guilhem Saurel's avatar
Guilhem Saurel committed
4
5
#ifndef __multicontact_api_python_scenario_contact_patch_hpp__
#define __multicontact_api_python_scenario_contact_patch_hpp__
Justin Carpentier's avatar
Justin Carpentier committed
6
7
8

#include <string>

Guilhem Saurel's avatar
Guilhem Saurel committed
9
10
11
#include "multicontact-api/scenario/contact-patch.hpp"
#include "multicontact-api/bindings/python/serialization/archive.hpp"
#include "multicontact-api/bindings/python/utils/printable.hpp"
Justin Carpentier's avatar
Justin Carpentier committed
12

Guilhem Saurel's avatar
Guilhem Saurel committed
13
14
namespace multicontact_api {
namespace python {
Justin Carpentier's avatar
Justin Carpentier committed
15

Guilhem Saurel's avatar
Guilhem Saurel committed
16
namespace bp = boost::python;
Guilhem Saurel's avatar
Guilhem Saurel committed
17

Guilhem Saurel's avatar
Guilhem Saurel committed
18
19
20
21
template <typename ContactPatch>
struct ContactPatchPythonVisitor : public boost::python::def_visitor<ContactPatchPythonVisitor<ContactPatch> > {
  typedef typename ContactPatch::Scalar Scalar;
  typedef typename ContactPatch::SE3 SE3;
Guilhem Saurel's avatar
Guilhem Saurel committed
22

Guilhem Saurel's avatar
Guilhem Saurel committed
23
24
  template <class PyClass>
  void visit(PyClass& cl) const {
Pierre Fernbach's avatar
Pierre Fernbach committed
25
    cl.def(bp::init<>(bp::arg(""), "Default constructor."))
26
        .def(bp::init<SE3>(bp::arg("placement"), "Init with a given placement."))
Pierre Fernbach's avatar
Pierre Fernbach committed
27
28
        .def(bp::init<SE3, Scalar>(bp::args("placement", "friction"),
                                   "Init with a given placement and friction coefficient."))
29
        .def(bp::init<ContactPatch>(bp::arg("other"), "Copy contructor."))
Justin Carpentier's avatar
Justin Carpentier committed
30
        .add_property("placement",
Pierre Fernbach's avatar
Pierre Fernbach committed
31
32
33
                      // getter require to use "make_function" to pass the return_internal_reference policy (return ref
                      // to custom object)
                      bp::make_function(&getPlacement, bp::return_internal_reference<>()), &setPlacement,
34
                      "Placement of the patch represented as a pinocchio SE3 object.")
35
        .add_property("friction", &getFriction, &setFriction,
36
                      "Friction coefficient between the robot and the environment for this contact.")
37
        .def_readwrite("contact_model", &ContactPatch::m_contact_model, "The contact model defining this contact.")
Justin Carpentier's avatar
Justin Carpentier committed
38
39
        .def(bp::self == bp::self)
        .def(bp::self != bp::self)
Guilhem Saurel's avatar
Guilhem Saurel committed
40
41
        .def("copy", &copy, "Returns a copy of *this.");
  }
Guilhem Saurel's avatar
Guilhem Saurel committed
42

Guilhem Saurel's avatar
Guilhem Saurel committed
43
44
45
  static void expose(const std::string& class_name) {
    std::string doc = "Contact Patch";
    bp::class_<ContactPatch>(class_name.c_str(), doc.c_str(), bp::no_init)
Justin Carpentier's avatar
Justin Carpentier committed
46
47
        .def(ContactPatchPythonVisitor<ContactPatch>())
        .def(SerializableVisitor<ContactPatch>())
Guilhem Saurel's avatar
Guilhem Saurel committed
48
        .def(PrintableVisitor<ContactPatch>());
Justin Carpentier's avatar
Justin Carpentier committed
49
50
  }

Guilhem Saurel's avatar
Guilhem Saurel committed
51
 protected:
52
  // define setter and getter
Pierre Fernbach's avatar
Pierre Fernbach committed
53
  static SE3& getPlacement(ContactPatch& self) { return self.placement(); }
Guilhem Saurel's avatar
Guilhem Saurel committed
54
  static void setPlacement(ContactPatch& self, const SE3& placement) { self.placement() = placement; }
Pierre Fernbach's avatar
Pierre Fernbach committed
55
  static Scalar getFriction(ContactPatch& self) { return self.friction(); }
56
  static void setFriction(ContactPatch& self, const Scalar& friction) { self.friction() = friction; }
Guilhem Saurel's avatar
Guilhem Saurel committed
57
58
59
60
  static ContactPatch copy(const ContactPatch& self) { return ContactPatch(self); }
};
}  // namespace python
}  // namespace multicontact_api
Justin Carpentier's avatar
Justin Carpentier committed
61

Guilhem Saurel's avatar
Guilhem Saurel committed
62
#endif  // ifndef __multicontact_api_python_scenario_contact_patch_hpp__