bindings/python/spatial/motion.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2015-2020 CNRS INRIA
3 // Copyright (c) 2016 Wandercraft, 86 rue de Paris 91400 Orsay, France.
4 //
5 
6 #ifndef __pinocchio_python_spatial_motion_hpp__
7 #define __pinocchio_python_spatial_motion_hpp__
8 
9 #include <eigenpy/memory.hpp>
11 #include <boost/python/tuple.hpp>
12 
13 #include "pinocchio/spatial/se3.hpp"
14 #include "pinocchio/spatial/motion.hpp"
15 #include "pinocchio/spatial/force.hpp"
18 
20 
21 namespace pinocchio
22 {
23  namespace python
24  {
25  namespace bp = boost::python;
26 
27  template<typename T> struct call;
28 
29  template<typename Scalar, int Options>
31  {
33 
34  static bool isApprox(const Motion & self, const Motion & other,
35  const Scalar & prec = Eigen::NumTraits<Scalar>::dummy_precision())
36  {
37  return self.isApprox(other,prec);
38  }
39 
40  static bool isZero(const Motion & self,
41  const Scalar & prec = Eigen::NumTraits<Scalar>::dummy_precision())
42  {
43  return self.isZero(prec);
44  }
45  };
46 
47  BOOST_PYTHON_FUNCTION_OVERLOADS(isApproxMotion_overload,call<Motion>::isApprox,2,3)
49 
50  template<typename Motion>
52  : public boost::python::def_visitor< MotionPythonVisitor<Motion> >
53  {
55 
56  typedef typename Motion::Scalar Scalar;
58  typedef typename Motion::Vector6 Vector6;
59  typedef typename Motion::Vector3 Vector3;
60 
61  typedef typename Eigen::Map<Vector3> MapVector3;
62  typedef typename Eigen::Ref<Vector3> RefVector3;
63 
64  public:
65 
66  template<class PyClass>
67  void visit(PyClass& cl) const
68  {
69  cl
70  .def(bp::init<>(bp::arg("self"),"Default constructor"))
71  .def(bp::init<Vector3,Vector3>
72  ((bp::arg("self"),bp::arg("linear"),bp::arg("angular")),
73  "Initialize from linear and angular components of a Motion vector (don't mix the order)."))
74  .def(bp::init<Vector6>((bp::arg("self"),bp::arg("array")),"Init from a vector 6 [linear velocity, angular velocity]"))
75  .def(bp::init<Motion>((bp::arg("self"),bp::arg("other")),"Copy constructor."))
76 
77  .add_property("linear",
78  bp::make_function(&MotionPythonVisitor::getLinear,
79  bp::with_custodian_and_ward_postcall<0,1>()),
80  &MotionPythonVisitor::setLinear,
81  "Linear part of a *this, corresponding to the linear velocity in case of a Spatial velocity.")
82  .add_property("angular",
83  bp::make_function(&MotionPythonVisitor::getAngular,
84  bp::with_custodian_and_ward_postcall<0,1>()),
85  &MotionPythonVisitor::setAngular,
86  "Angular part of a *this, corresponding to the angular velocity in case of a Spatial velocity.")
87  .add_property("vector",
88  bp::make_function((typename Motion::ToVectorReturnType (Motion::*)())&Motion::toVector,
89  bp::return_internal_reference<>()),
90  &MotionPythonVisitor::setVector,
91  "Returns the components of *this as a 6d vector.")
92  .add_property("np",
93  bp::make_function((typename Motion::ToVectorReturnType (Motion::*)())&Motion::toVector,
94  bp::return_internal_reference<>()))
95 
96  .def("se3Action",&Motion::template se3Action<Scalar,Options>,
97  bp::args("self","M"),"Returns the result of the action of M on *this.")
98  .def("se3ActionInverse",&Motion::template se3ActionInverse<Scalar,Options>,
99  bp::args("self","M"),"Returns the result of the action of the inverse of M on *this.")
100 
101  .add_property("action",&Motion::toActionMatrix,"Returns the action matrix of *this (acting on Motion).")
102  .add_property("dualAction",&Motion::toDualActionMatrix,"Returns the dual action matrix of *this (acting on Force).")
103 
104  .def("setZero",&MotionPythonVisitor::setZero,bp::arg("self"),
105  "Set the linear and angular components of *this to zero.")
106  .def("setRandom",&MotionPythonVisitor::setRandom,bp::arg("self"),
107  "Set the linear and angular components of *this to random values.")
108 
109  .def("cross",(Motion (Motion::*)(const Motion &) const) &Motion::cross,
110  bp::args("self","m"),"Action of *this onto another Motion m. Returns ยจ*this x m.")
111  .def("cross",(Force (Motion::*)(const Force &) const) &Motion::cross,
112  bp::args("self","f"),"Dual action of *this onto a Force f. Returns *this x* f.")
113 
114  .def(bp::self + bp::self)
115  .def(bp::self += bp::self)
116  .def(bp::self - bp::self)
117  .def(bp::self -= bp::self)
118  .def(-bp::self)
119  .def(bp::self ^ bp::self)
120  .def(bp::self ^ Force())
121 
122  .def(bp::self == bp::self)
123  .def(bp::self != bp::self)
124 
125  .def(bp::self * Scalar())
126  .def(Scalar() * bp::self)
127  .def(bp::self / Scalar())
128 
129  .def("isApprox",
131  isApproxMotion_overload(bp::args("self","other","prec"),
132  "Returns true if *this is approximately equal to other, within the precision given by prec."))
133 
134  .def("isZero",
136  isZero_overload(bp::args("self","prec"),
137  "Returns true if *this is approximately equal to the zero Motion, within the precision given by prec."))
138 
139  .def("Random",&Motion::Random,"Returns a random Motion.")
140  .staticmethod("Random")
141  .def("Zero",&Motion::Zero,"Returns a zero Motion.")
142  .staticmethod("Zero")
143 
144  .def("__array__",bp::make_function((typename Motion::ToVectorReturnType (Motion::*)())&Motion::toVector,
145  bp::return_internal_reference<>()))
146 
147  .def_pickle(Pickle())
148  ;
149  }
150 
151  static void expose()
152  {
153  bp::class_<Motion>("Motion",
154  "Motion vectors, in se3 == M^6.\n\n"
155  "Supported operations ...",
156  bp::no_init)
160  ;
161  }
162 
163  private:
164 
165  struct Pickle : bp::pickle_suite
166  {
167  static
168  boost::python::tuple
169  getinitargs(const Motion & m)
170  { return bp::make_tuple((Vector3)m.linear(),(Vector3)m.angular()); }
171  };
172 
173  static RefVector3 getLinear(Motion & self) { return self.linear(); }
174  static void setLinear (Motion & self, const Vector3 & v) { self.linear(v); }
175  static RefVector3 getAngular(Motion & self) { return self.angular(); }
176  static void setAngular(Motion & self, const Vector3 & w) { self.angular(w); }
177 
178  static void setVector(Motion & self, const Vector6 & v) { self = v; }
179 
180  static void setZero(Motion & self) { self.setZero(); }
181  static void setRandom(Motion & self) { self.setRandom(); }
182 
183  };
184 
185  }} // namespace pinocchio::python
186 
187 #endif // ifndef __pinocchio_python_spatial_motion_hpp__
ForceTpl< double, 0 > Force
static bool isZero(const Motion &self, const Scalar &prec=Eigen::NumTraits< Scalar >::dummy_precision())
Set the Python method str and repr to use the overloading operator<<.
Definition: printable.hpp:21
BOOST_PYTHON_FUNCTION_OVERLOADS(computeKKTContactDynamicMatrixInverse_overload, computeKKTContactDynamicMatrixInverse_proxy, 4, 5) static const Eigen
static void setLinear(Motion &self, const Vector3 &v)
static void setAngular(Motion &self, const Vector3 &w)
SE3::Scalar Scalar
Definition: conversions.cpp:13
ConstLinearType linear() const
Definition: motion-base.hpp:22
static boost::python::tuple getinitargs(const Motion &m)
Add the Python method copy to allow a copy of this by calling the copy constructor.
Definition: copyable.hpp:21
Main pinocchio namespace.
Definition: timings.cpp:30
static void setVector(Motion &self, const Vector6 &v)
Common traits structure to fully define base classes for CRTP.
Definition: src/fwd.hpp:44
static bool isApprox(const Motion &self, const Motion &other, const Scalar &prec=Eigen::NumTraits< Scalar >::dummy_precision())
ConstAngularType angular() const
Definition: motion-base.hpp:21
#define EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(...)
w
Definition: ur5x4.py:45
ForceTpl< Scalar, traits< Motion >::Options > Force


pinocchio
Author(s):
autogenerated on Tue Jun 1 2021 02:45:04