pinocchio  3.7.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
 
Loading...
Searching...
No Matches
joint-derived.hpp
1//
2// Copyright (c) 2015-2021 CNRS INRIA
3//
4
5#ifndef __pinocchio_python_multibody_joint_joint_base_hpp__
6#define __pinocchio_python_multibody_joint_joint_base_hpp__
7
8#include <boost/python.hpp>
9#include <eigenpy/exception.hpp>
10
11#include "pinocchio/bindings/python/fwd.hpp"
12#include "pinocchio/multibody/joint/joint-collection.hpp"
13
14namespace pinocchio
15{
16 namespace python
17 {
18 namespace bp = boost::python;
19
20 template<class JointModelDerived>
21 struct JointModelBasePythonVisitor
22 : public boost::python::def_visitor<JointModelBasePythonVisitor<JointModelDerived>>
23 {
24 public:
25 typedef typename JointModelDerived::JointDataDerived JointDataDerived;
26
27 template<class PyClass>
28 void visit(PyClass & cl) const
29 {
30 cl.def(bp::init<>(bp::arg("self")))
31 // All are add_properties cause ReadOnly
32 .add_property("id", &get_id)
33 .add_property("idx_q", &get_idx_q)
34 .add_property("idx_v", &get_idx_v)
35 .add_property("idx_vExtended", &get_idx_vExtended)
36 .add_property("nq", &get_nq)
37 .add_property("nv", &get_nv)
38 .add_property("nvExtended", &get_nvExtended)
39 .add_property(
40 "hasConfigurationLimit", &JointModelDerived::hasConfigurationLimit,
41 "Return vector of boolean if joint has configuration limits.")
42 .add_property(
43 "hasConfigurationLimitInTangent", &JointModelDerived::hasConfigurationLimitInTangent,
44 "Return vector of boolean if joint has configuration limits in tangent space.")
45 .def("setIndexes", &setIndexes0, bp::args("self", "joint_id", "idx_q", "idx_v"))
46 .def(
47 "setIndexes", &setIndexes1,
48 bp::args("self", "joint_id", "idx_q", "idx_v", "idx_vExtended"))
49 .def("classname", &JointModelDerived::classname)
50 .staticmethod("classname")
51 .def("calc", &calc0, bp::args("self", "jdata", "q"))
52 .def("calc", &calc1, bp::args("self", "jdata", "q", "v"))
53 .def(
54 "createData", &JointModelDerived::createData, bp::arg("self"),
55 "Create data associated to the joint model.")
56 .def(
57 "hasSameIndexes", &JointModelDerived::template hasSameIndexes<JointModelDerived>,
58 bp::args("self", "other"), "Check if this has same indexes than other.")
59 .def(
60 "shortname", &JointModelDerived::shortname, bp::arg("self"),
61 "Returns string indicating the joint type (class name):"
62 "\n\t- JointModelR[*]: Revolute Joint, with rotation axis [*] ∈ [X,Y,Z]"
63 "\n\t- JointModelRevoluteUnaligned: Revolute Joint, with rotation axis not aligned "
64 "with X, Y, nor Z"
65 "\n\t- JointModelRUB[*]: Unbounded revolute Joint (without position limits), with "
66 "rotation axis [*] ∈ [X,Y,Z]"
67 "\n\t- JointModelRevoluteUnboundedUnaligned: Unbounded revolute Joint, with "
68 "rotation axis not aligned with X, Y, nor Z"
69 "\n\t- JointModelP[*]: Prismatic Joint, with rotation axis [*] ∈ [X,Y,Z]"
70 "\n\t- JointModelPlanar: Planar joint"
71 "\n\t- JointModelPrismaticUnaligned: Prismatic joint, with translation axis not "
72 "aligned with X, Y, nor Z"
73 "\n\t- JointModelSphericalZYX: Spherical joint (3D rotation)"
74 "\n\t- JointModelTranslation: Translation joint (3D translation)"
75 "\n\t- JointModelFreeFlyer: Joint enabling 3D rotation and translations.")
76
77#ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS
78 .def(bp::self == bp::self)
79 .def(bp::self != bp::self)
80#endif
81 ;
82 }
83
84 static JointIndex get_id(const JointModelDerived & self)
85 {
86 return self.id();
87 }
88 static int get_idx_q(const JointModelDerived & self)
89 {
90 return self.idx_q();
91 }
92 static int get_idx_v(const JointModelDerived & self)
93 {
94 return self.idx_v();
95 }
96 static int get_idx_vExtended(const JointModelDerived & self)
97 {
98 return self.idx_vExtended();
99 }
100 static int get_nq(const JointModelDerived & self)
101 {
102 return self.nq();
103 }
104 static int get_nv(const JointModelDerived & self)
105 {
106 return self.nv();
107 }
108 static int get_nvExtended(const JointModelDerived & self)
109 {
110 return self.nvExtended();
111 }
112
113 static void
114 calc0(const JointModelDerived & self, JointDataDerived & jdata, const context::VectorXs & q)
115 {
116 self.calc(jdata, q);
117 }
118 static void calc1(
119 const JointModelDerived & self,
120 JointDataDerived & jdata,
121 const context::VectorXs & q,
122 const context::VectorXs & v)
123 {
124 self.calc(jdata, q, v);
125 }
126
127 static void
128 setIndexes0(JointModelDerived & self, const int & id, const int & idx_q, const int & idx_v)
129 {
130 self.setIndexes(id, idx_q, idx_v);
131 }
132
133 static void setIndexes1(
134 JointModelDerived & self,
135 const int & id,
136 const int & idx_q,
137 const int & idx_v,
138 const int & idx_vExtended)
139 {
140 self.setIndexes(id, idx_q, idx_v, idx_vExtended);
141 }
142 };
143
144 template<class JointDataDerived>
145 struct JointDataBasePythonVisitor
146 : public boost::python::def_visitor<JointDataBasePythonVisitor<JointDataDerived>>
147 {
148 public:
149 template<class PyClass>
150 void visit(PyClass & cl) const
151 {
152 cl
153 // All are add_properties cause ReadOnly
154 .add_property("joint_q", &get_joint_q)
155 .add_property("joint_v", &get_joint_v)
156 .add_property("S", &get_S)
157 .add_property("M", &get_M)
158 .add_property("v", &get_v)
159 .add_property("c", &get_c)
160 .add_property("U", &get_U)
161 .add_property("Dinv", &get_Dinv)
162 .add_property("UDinv", &get_UDinv)
163 .def("shortname", &JointDataDerived::shortname, bp::arg("self"))
164
165#ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS
166 .def(bp::self == bp::self)
167 .def(bp::self != bp::self)
168#endif
169 ;
170 }
171
172 static typename JointDataDerived::ConfigVector_t get_joint_q(const JointDataDerived & self)
173 {
174 return self.joint_q_accessor();
175 }
176 static typename JointDataDerived::TangentVector_t get_joint_v(const JointDataDerived & self)
177 {
178 return self.joint_v_accessor();
179 }
180 // static typename JointDataDerived::Constraint_t get_S(const JointDataDerived & self)
181 // { return self.S_accessor(); }
182 static typename JointDataDerived::Constraint_t::DenseBase get_S(const JointDataDerived & self)
183 {
184 return self.S_accessor().matrix();
185 }
186 static typename JointDataDerived::Transformation_t get_M(const JointDataDerived & self)
187 {
188 return self.M_accessor();
189 }
190 static typename JointDataDerived::Motion_t get_v(const JointDataDerived & self)
191 {
192 return self.v_accessor();
193 }
194 static typename JointDataDerived::Bias_t get_c(const JointDataDerived & self)
195 {
196 return self.c_accessor();
197 }
198 static typename JointDataDerived::U_t get_U(const JointDataDerived & self)
199 {
200 return self.U_accessor();
201 }
202 static typename JointDataDerived::D_t get_Dinv(const JointDataDerived & self)
203 {
204 return self.Dinv_accessor();
205 }
206 static typename JointDataDerived::UD_t get_UDinv(const JointDataDerived & self)
207 {
208 return self.UDinv_accessor();
209 }
210
211 static void expose()
212 {
213 }
214 };
215
216 } // namespace python
217} // namespace pinocchio
218
219#endif // ifndef __pinocchio_python_multibody_joint_joint_base_hpp__
Main pinocchio namespace.
Definition treeview.dox:11
int idx_v(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointIdxVVisitor to get the index in the model tangent space correspond...
int idx_q(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointIdxQVisitor to get the index in the full model configuration space...
int idx_vExtended(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointIdvExtendedVisitor to get the index in the model extended tangent ...