pinocchio 4.1.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
Loading...
Searching...
No Matches
frame.hpp
1//
2// Copyright (c) 2016-2018 CNRS
3// Copyright (c) 2018-2025 INRIA
4//
5
6#pragma once
7
8#include <eigenpy/copyable.hpp>
9
10#include "pinocchio/multibody.hpp"
11
12#include <eigenpy/deprecation-policy.hpp>
13#include "pinocchio/bindings/python/utils/cast.hpp"
14#include "pinocchio/bindings/python/utils/printable.hpp"
15
16namespace pinocchio
17{
18 namespace python
19 {
20 namespace bp = boost::python;
21
22 template<typename Frame>
23 struct FramePythonVisitor : public boost::python::def_visitor<FramePythonVisitor<Frame>>
24 {
25 typedef typename Frame::SE3 SE3;
26 typedef typename Frame::Inertia Inertia;
27
28 template<class PyClass>
29 void visit(PyClass & cl) const
30 {
31 cl.def(bp::init<>(bp::arg("self"), "Default constructor"))
32 .def(bp::init<const Frame &>(bp::args("self", "other"), "Copy constructor"))
33 .def(
34 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 "
40 "joint "
41 "and an spatial inertia object."))
42 .def(
43 bp::init<
44 const std::string &, const JointIndex, const FrameIndex, const SE3 &, FrameType,
45 bp::optional<const Inertia &>>(
46 (bp::arg("name"), bp::arg("parent_joint"), bp::args("parent_frame"),
47 bp::arg("placement"), bp::arg("type"), bp::arg("inertia")),
48 "Initialize from a given name, type, parent joint index, parent frame index and "
49 "placement wrt parent joint and an spatial inertia object."))
50 .def(bp::init<const Frame &>((bp::arg("self"), bp::arg("clone")), "Copy constructor"))
51
52 .def_readwrite("name", &Frame::name, "name of the frame")
53 .def_readwrite("parentJoint", &Frame::parentJoint, "Index of the parent joint")
54 .def_readwrite("parentFrame", &Frame::parentFrame, "Index of the parent frame")
55 .add_property(
56 "parent",
57 bp::make_function(
58 +[](const Frame & self) { return self.parentJoint; },
59 ::eigenpy::deprecated_member<>("Deprecated member. Use Frame.parentJoint instead.")),
60 bp::make_function(
61 +[](Frame & self, const JointIndex index) { self.parentJoint = index; },
62 ::eigenpy::deprecated_member<>("Deprecated member. Use Frame.parentJoint instead.")),
63 "See parentJoint property.")
64 .add_property(
65 "previousFrame",
66 bp::make_function(
67 +[](const Frame & self) { return self.parentFrame; },
68 ::eigenpy::deprecated_member<>("Deprecated member. Use Frame.parentFrame instead.")),
69 bp::make_function(
70 +[](Frame & self, const FrameIndex index) { self.parentFrame = index; },
71 ::eigenpy::deprecated_member<>("Deprecated member. Use Frame.parentFrame instead.")),
72 "See parentFrame property.")
73 .def_readwrite(
74 "placement", &Frame::placement, "placement in the parent joint local frame")
75 .def_readwrite("type", &Frame::type, "type of the frame")
76 .def_readwrite("inertia", &Frame::inertia, "Inertia information attached to the frame.")
77
78#ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS
79 .def(bp::self == bp::self)
80 .def(bp::self != bp::self)
81#endif
82 ;
83 }
84
85 static void expose()
86 {
87 if (!register_symbolic_link_to_registered_type<FrameType>())
88 {
89 bp::enum_<FrameType>("FrameType")
90 .value("OP_FRAME", OP_FRAME)
91 .value("JOINT", JOINT)
92 .value("FIXED_JOINT", FIXED_JOINT)
93 .value("BODY", BODY)
94 .value("SENSOR", SENSOR)
95 .export_values();
96 }
97
98 bp::class_<Frame>(
99 "Frame",
100 "A Plucker coordinate frame related to a parent joint inside a kinematic tree.\n",
101 bp::no_init)
102 .def(FramePythonVisitor())
103 .def(CastVisitor<Frame>())
105 .def(::eigenpy::CopyableVisitor<Frame>())
107 .def_pickle(Pickle());
108 }
109
110 private:
111 struct Pickle : bp::pickle_suite
112 {
113 static bp::tuple getinitargs(const Frame &)
114 {
115 return bp::make_tuple();
116 }
117
118 static bp::tuple getstate(const Frame & f)
119 {
120 return bp::make_tuple(
121 f.name, f.parentJoint, f.parentFrame, f.placement, (int)f.type, f.inertia);
122 }
123
124 static void setstate(Frame & f, bp::tuple tup)
125 {
126 f.name = bp::extract<std::string>(tup[0]);
127 f.parentJoint = bp::extract<JointIndex>(tup[1]);
128 f.parentFrame = bp::extract<JointIndex>(tup[2]);
129 f.placement = bp::extract<SE3 &>(tup[3]);
130 f.type = (FrameType)(int)bp::extract<int>(tup[4]);
131 if (bp::len(tup) > 5)
132 f.inertia = bp::extract<Inertia &>(tup[5]);
133 }
134
135 static bool getstate_manages_dict()
136 {
137 return true;
138 }
139 };
140 };
141
142 } // namespace python
143} // namespace pinocchio
Main pinocchio namespace.
Definition treeview.dox:11
Add the Python method cast.
Definition cast.hpp:23
Set the Python method str and repr to use the overloading operator<<.
Definition printable.hpp:21