bindings/python/multibody/frame.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2016-2022 CNRS INRIA
3 //
4 
5 #ifndef __pinocchio_python_multibody_frame_hpp__
6 #define __pinocchio_python_multibody_frame_hpp__
7 
10 
16 
17 namespace pinocchio
18 {
19  namespace python
20  {
21  namespace bp = boost::python;
22 
23  template<typename Frame>
24  struct FramePythonVisitor : public boost::python::def_visitor<FramePythonVisitor<Frame>>
25  {
26  typedef typename Frame::SE3 SE3;
27  typedef typename Frame::Inertia Inertia;
28 
29  template<class PyClass>
30  void visit(PyClass & cl) const
31  {
32  cl.def(bp::init<>(bp::arg("self"), "Default constructor"))
33  .def(bp::init<const Frame &>(bp::args("self", "other"), "Copy constructor"))
34  .def(bp::init<
35  const std::string &, const JointIndex, const SE3 &, FrameType,
36  bp::optional<const Inertia &>>(
37  (bp::arg("name"), bp::arg("parent_joint"), bp::arg("placement"), bp::arg("type"),
38  bp::arg("inertia")),
39  "Initialize from a given name, type, parent frame index and placement wrt parent joint "
40  "and an spatial inertia object."))
41  .def(bp::init<
42  const std::string &, const JointIndex, const FrameIndex, const SE3 &, FrameType,
43  bp::optional<const Inertia &>>(
44  (bp::arg("name"), bp::arg("parent_joint"), bp::args("parent_frame"),
45  bp::arg("placement"), bp::arg("type"), bp::arg("inertia")),
46  "Initialize from a given name, type, parent joint index, parent frame index and "
47  "placement wrt parent joint and an spatial inertia object."))
48  .def(bp::init<const Frame &>((bp::arg("self"), bp::arg("clone")), "Copy constructor"))
49 
50  .def_readwrite("name", &Frame::name, "name of the frame")
51  .def_readwrite("parentJoint", &Frame::parentJoint, "Index of the parent joint")
52  .def_readwrite("parentFrame", &Frame::parentFrame, "Index of the parent frame")
53  .add_property(
54  "parent",
55  bp::make_function(
56  +[](const Frame & self) { return self.parentJoint; },
57  deprecated_member<>("Deprecated member. Use Frame.parentJoint instead.")),
58  bp::make_function(
59  +[](Frame & self, const JointIndex index) { self.parentJoint = index; },
60  deprecated_member<>("Deprecated member. Use Frame.parentJoint instead.")),
61  "See parentJoint property.")
62  .add_property(
63  "previousFrame",
64  bp::make_function(
65  +[](const Frame & self) { return self.parentFrame; },
66  deprecated_member<>("Deprecated member. Use Frame.parentFrame instead.")),
67  bp::make_function(
68  +[](Frame & self, const FrameIndex index) { self.parentFrame = index; },
69  deprecated_member<>("Deprecated member. Use Frame.parentFrame instead.")),
70  "See parentFrame property.")
71  .def_readwrite(
72  "placement", &Frame::placement, "placement in the parent joint local frame")
73  .def_readwrite("type", &Frame::type, "type of the frame")
74  .def_readwrite("inertia", &Frame::inertia, "Inertia information attached to the frame.")
75 
76 #ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS
77  .def(bp::self == bp::self)
78  .def(bp::self != bp::self)
79 #endif
80  ;
81  }
82 
83  static void expose()
84  {
85  if (!register_symbolic_link_to_registered_type<FrameType>())
86  {
87  bp::enum_<FrameType>("FrameType")
88  .value("OP_FRAME", OP_FRAME)
89  .value("JOINT", JOINT)
90  .value("FIXED_JOINT", FIXED_JOINT)
91  .value("BODY", BODY)
92  .value("SENSOR", SENSOR)
93  .export_values();
94  }
95 
96  bp::class_<Frame>(
97  "Frame",
98  "A Plucker coordinate frame related to a parent joint inside a kinematic tree.\n",
99  bp::no_init)
100  .def(FramePythonVisitor())
101  .def(CastVisitor<Frame>())
103  .def(CopyableVisitor<Frame>())
105  .def_pickle(Pickle());
106  }
107 
108  private:
109  struct Pickle : bp::pickle_suite
110  {
111  static bp::tuple getinitargs(const Frame &)
112  {
113  return bp::make_tuple();
114  }
115 
116  static bp::tuple getstate(const Frame & f)
117  {
118  return bp::make_tuple(
119  f.name, f.parentJoint, f.parentFrame, f.placement, (int)f.type, f.inertia);
120  }
121 
122  static void setstate(Frame & f, bp::tuple tup)
123  {
124  f.name = bp::extract<std::string>(tup[0]);
125  f.parentJoint = bp::extract<JointIndex>(tup[1]);
126  f.parentFrame = bp::extract<JointIndex>(tup[2]);
127  f.placement = bp::extract<SE3 &>(tup[3]);
128  f.type = (FrameType)(int)bp::extract<int>(tup[4]);
129  if (bp::len(tup) > 5)
130  f.inertia = bp::extract<Inertia &>(tup[5]);
131  }
132 
133  static bool getstate_manages_dict()
134  {
135  return true;
136  }
137  };
138  };
139 
140  } // namespace python
141 } // namespace pinocchio
142 
143 #endif // ifndef __pinocchio_python_multibody_frame_hpp__
pinocchio::InertiaTpl< Scalar, Options >
init
void init(bool compute_local_aabb=true)
pinocchio::python::FramePythonVisitor::Pickle::getstate_manages_dict
static bool getstate_manages_dict()
Definition: bindings/python/multibody/frame.hpp:133
pinocchio::FrameIndex
Index FrameIndex
Definition: multibody/fwd.hpp:28
boost::python
pinocchio::ModelItem< FrameTpl< _Scalar, _Options > >::parentJoint
JointIndex parentJoint
Index of the parent joint.
Definition: model-item.hpp:28
registration.hpp
index
index
pinocchio::FrameType
FrameType
Enum on the possible types of frames.
Definition: multibody/frame.hpp:31
pinocchio::SE3Tpl< Scalar, Options >
pinocchio::SENSOR
@ SENSOR
sensor frame: defined in a sensor element
Definition: multibody/frame.hpp:38
pinocchio::python::deprecated_member
Definition: bindings/python/utils/deprecation.hpp:40
pinocchio::python::ExposeConstructorByCastVisitor
Definition: bindings/python/utils/cast.hpp:33
pinocchio::python::FramePythonVisitor::Pickle::setstate
static void setstate(Frame &f, bp::tuple tup)
Definition: bindings/python/multibody/frame.hpp:122
autodiff-rnea.f
f
Definition: autodiff-rnea.py:24
pinocchio::python::FramePythonVisitor::Pickle
Definition: bindings/python/multibody/frame.hpp:109
pinocchio::FrameTpl
A Plucker coordinate frame attached to a parent joint inside a kinematic tree.
Definition: multibody/frame.hpp:55
pinocchio::FrameTpl::inertia
Inertia inertia
Inertia information attached to the frame. This inertia will be appended to the inertia supported by ...
Definition: multibody/frame.hpp:248
pinocchio::ModelItem< FrameTpl< _Scalar, _Options > >::placement
SE3 placement
Position of kinematic element in parent joint frame.
Definition: model-item.hpp:39
deprecation.hpp
cast.hpp
pinocchio::python::PrintableVisitor
Set the Python method str and repr to use the overloading operator<<.
Definition: printable.hpp:21
pinocchio::ModelItem< FrameTpl< _Scalar, _Options > >::parentFrame
FrameIndex parentFrame
Index of the parent frame.
Definition: model-item.hpp:36
python
pinocchio::python::FramePythonVisitor
Definition: bindings/python/multibody/frame.hpp:24
pinocchio::python::CopyableVisitor
Add the Python method copy to allow a copy of this by calling the copy constructor.
Definition: copyable.hpp:21
pinocchio::python::CastVisitor
Add the Python method cast.
Definition: bindings/python/utils/cast.hpp:23
copyable.hpp
pinocchio::JOINT
@ JOINT
joint frame: attached to the child body of a joint (a.k.a. child frame)
Definition: multibody/frame.hpp:34
pinocchio::python::FramePythonVisitor::Pickle::getstate
static bp::tuple getstate(const Frame &f)
Definition: bindings/python/multibody/frame.hpp:116
pinocchio::OP_FRAME
@ OP_FRAME
operational frame: user-defined frames that are defined at runtime
Definition: multibody/frame.hpp:33
pinocchio::FIXED_JOINT
@ FIXED_JOINT
fixed joint frame: joint frame but for a fixed joint
Definition: multibody/frame.hpp:35
cl
cl
frame.hpp
pinocchio::python::FramePythonVisitor::expose
static void expose()
Definition: bindings/python/multibody/frame.hpp:83
pinocchio::JointIndex
Index JointIndex
Definition: multibody/fwd.hpp:26
pinocchio::FrameTpl::type
FrameType type
Type of the frame.
Definition: multibody/frame.hpp:243
printable.hpp
pinocchio::python::FramePythonVisitor::SE3
Frame::SE3 SE3
Definition: bindings/python/multibody/frame.hpp:26
pinocchio::python::FramePythonVisitor::Pickle::getinitargs
static bp::tuple getinitargs(const Frame &)
Definition: bindings/python/multibody/frame.hpp:111
pinocchio::BODY
@ BODY
body frame: attached to the collision, inertial or visual properties of a link
Definition: multibody/frame.hpp:36
pinocchio::python::FramePythonVisitor::visit
void visit(PyClass &cl) const
Definition: bindings/python/multibody/frame.hpp:30
fwd.hpp
pinocchio::ModelItem< FrameTpl< _Scalar, _Options > >::name
std::string name
Name of the kinematic element.
Definition: model-item.hpp:25
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27
pinocchio::python::FramePythonVisitor::Inertia
Frame::Inertia Inertia
Definition: bindings/python/multibody/frame.hpp:27


pinocchio
Author(s):
autogenerated on Thu Dec 19 2024 03:41:29