pinocchio  3.9.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
Loading...
Searching...
No Matches
joints.hpp
1//
2// Copyright (c) 2025 INRIA
3//
4
5#ifndef __pinocchio_parsers_graph_joints_hpp__
6#define __pinocchio_parsers_graph_joints_hpp__
7
8#include "pinocchio/parsers/graph/fwd.hpp"
9
10#include "pinocchio/parsers/config.hpp"
11
12#include <boost/variant/apply_visitor.hpp>
13#include <boost/variant/variant.hpp>
14
15#include <Eigen/Core>
16
17#include <string>
18
19namespace pinocchio
20{
21 namespace graph
22 {
23 struct PINOCCHIO_PARSERS_DLLAPI JointLimits
24 {
25 // Max effort
26 Eigen::VectorXd maxEffort;
27 // Max velocity
28 Eigen::VectorXd maxVel;
29 // Max position
30 Eigen::VectorXd maxConfig;
31 // Min position
32 Eigen::VectorXd minConfig;
33
34 // friction applied in this joint
35 Eigen::VectorXd friction;
36 // Damping applied by this joint.
37 Eigen::VectorXd damping;
38
39 // Armature inertia created by this joint
40 Eigen::VectorXd armature;
41 // Dry friction.
42 double frictionLoss = 0.;
43
44 JointLimits() = default;
45
46 template<int Nq, int Nv>
47 void setDimensions();
48
49 void append(const JointLimits & jlimit, const int nq, const int nv);
50 };
51
52 struct JointFixed
53 {
54 SE3 joint_offset = SE3::Identity();
55 static constexpr int nq = 0;
56 static constexpr int nv = 0;
57
58 JointFixed() = default;
59 explicit JointFixed(const SE3 & pose)
60 : joint_offset(pose)
61 {
62 }
63
64 bool operator==(const JointFixed & other) const
65 {
66 return joint_offset == other.joint_offset;
67 }
68 };
69
70 struct JointRevolute
71 {
72 // rotation axis
73 Eigen::Vector3d axis = Eigen::Vector3d::UnitX();
74 static constexpr int nq = 1;
75 static constexpr int nv = 1;
76
77 JointRevolute() = default;
78 explicit JointRevolute(const Eigen::Vector3d & ax)
79 : axis(ax)
80 {
81 }
82
83 bool operator==(const JointRevolute & other) const
84 {
85 return axis == other.axis;
86 }
87 };
88
89 struct JointRevoluteUnbounded
90 {
91 Eigen::Vector3d axis = Eigen::Vector3d::UnitX();
92 static constexpr int nq = 2;
93 static constexpr int nv = 1;
94
95 JointRevoluteUnbounded() = default;
96 explicit JointRevoluteUnbounded(const Eigen::Vector3d & ax)
97 : axis(ax)
98 {
99 }
100
101 bool operator==(const JointRevoluteUnbounded & other) const
102 {
103 return axis == other.axis;
104 }
105 };
106
107 struct JointPrismatic
108 {
109 Eigen::Vector3d axis = Eigen::Vector3d::UnitX();
110 static constexpr int nq = 1;
111 static constexpr int nv = 1;
112
113 JointPrismatic() = default;
114 explicit JointPrismatic(const Eigen::Vector3d & ax)
115 : axis(ax)
116 {
117 }
118
119 bool operator==(const JointPrismatic & other) const
120 {
121 return axis == other.axis;
122 }
123 };
124
125 struct JointFreeFlyer
126 {
127 static constexpr int nq = 7;
128 static constexpr int nv = 6;
129
130 JointFreeFlyer() = default;
131
132 bool operator==(const JointFreeFlyer &) const
133 {
134 return true;
135 }
136 };
137
138 struct JointSpherical
139 {
140 static constexpr int nq = 4;
141 static constexpr int nv = 3;
142
143 JointSpherical() = default;
144
145 bool operator==(const JointSpherical &) const
146 {
147 return true;
148 }
149 };
150
151 struct JointSphericalZYX
152 {
153 static constexpr int nq = 3;
154 static constexpr int nv = 3;
155
156 JointSphericalZYX() = default;
157
158 bool operator==(const JointSphericalZYX &) const
159 {
160 return true;
161 }
162 };
163
164 struct JointEllipsoid
165 {
166 double radius_x = 0;
167 double radius_y = 0;
168 double radius_z = 0;
169
170 static constexpr int nq = 3;
171 static constexpr int nv = 3;
172
173 JointEllipsoid() = default;
174 JointEllipsoid(const double r_a, const double r_b, const double r_c)
175 : radius_x(r_a)
176 , radius_y(r_b)
177 , radius_z(r_c)
178 {
179 }
180
181 bool operator==(const JointEllipsoid & other) const
182 {
183 return radius_x == other.radius_x && radius_y == other.radius_y
184 && radius_z == other.radius_z;
185 }
186 };
187
188 struct JointTranslation
189 {
190 static constexpr int nq = 3;
191 static constexpr int nv = 3;
192
193 JointTranslation() = default;
194
195 bool operator==(const JointTranslation &) const
196 {
197 return true;
198 }
199 };
200
201 struct JointPlanar
202 {
203 static constexpr int nq = 4;
204 static constexpr int nv = 3;
205
206 JointPlanar() = default;
207
208 bool operator==(const JointPlanar &) const
209 {
210 return true;
211 }
212 };
213
214 struct JointHelical
215 {
216 Eigen::Vector3d axis = Eigen::Vector3d::UnitX();
217 double pitch = 0.;
218
219 static constexpr int nq = 1;
220 static constexpr int nv = 1;
221
222 JointHelical() = default;
223 JointHelical(const Eigen::Vector3d & ax, const double p)
224 : axis(ax)
225 , pitch(p)
226 {
227 }
228
229 bool operator==(const JointHelical & other) const
230 {
231 return axis == other.axis && pitch == other.pitch;
232 }
233 };
234
235 struct JointUniversal
236 {
237 Eigen::Vector3d axis1 = Eigen::Vector3d::UnitX();
238 Eigen::Vector3d axis2 = Eigen::Vector3d::UnitY();
239
240 static constexpr int nq = 2;
241 static constexpr int nv = 2;
242
243 JointUniversal() = default;
244 JointUniversal(const Eigen::Vector3d & ax1, const Eigen::Vector3d & ax2)
245 : axis1(ax1)
246 , axis2(ax2)
247 {
248 }
249
250 bool operator==(const JointUniversal & other) const
251 {
252 return axis1 == other.axis1 && axis2 == other.axis2;
253 }
254 };
255
256 // Forward declare
257 struct JointComposite;
258 struct JointMimic;
259
260 typedef boost::variant<
273 boost::recursive_wrapper<JointComposite>,
274 boost::recursive_wrapper<JointMimic>>
275 JointVariant;
276
277 struct JointMimic
278 {
279 std::string primary_name;
280
281 JointVariant secondary_joint;
282 double scaling = 1.;
283 double offset = 0.;
284
285 static constexpr int nq = 0;
286 static constexpr int nv = 0;
287
288 JointMimic() = default;
289
290 JointMimic(
291 const JointVariant & jmodel_secondary,
292 const std::string & name_primary,
293 const double scaling_,
294 const double offset_)
295 : primary_name(name_primary)
296 , secondary_joint(jmodel_secondary)
297 , scaling(scaling_)
298 , offset(offset_)
299 {
300 }
301
302 bool operator==(const JointMimic & other) const
303 {
304 return primary_name == other.primary_name && scaling == other.scaling
305 && offset == other.offset && secondary_joint == other.secondary_joint;
306 }
307 };
308
309 struct JointComposite
310 {
311 std::vector<JointVariant> joints;
312 std::vector<SE3> jointsPlacements;
313
314 int nq = 0;
315 int nv = 0;
316
317 JointComposite() = default;
318
319 JointComposite(const JointVariant & j, const SE3 & jPose)
320 {
321 joints.push_back(j);
322 jointsPlacements.push_back(jPose);
323 nq += boost::apply_visitor([](const auto & j_) { return j_.nq; }, j);
324 nv += boost::apply_visitor([](const auto & j_) { return j_.nv; }, j);
325 }
326
327 JointComposite(const std::vector<JointVariant> & js, const std::vector<SE3> & jPoses)
328 : joints(js)
329 , jointsPlacements(jPoses)
330 {
331 for (const auto & j : js)
332 {
333 nq += boost::apply_visitor([](const auto & j_) { return j_.nq; }, j);
334 nv += boost::apply_visitor([](const auto & j_) { return j_.nv; }, j);
335 }
336 }
337
338 void addJoint(const JointVariant & jm, const SE3 & pose = SE3::Identity())
339 {
340 joints.push_back(jm);
341 jointsPlacements.push_back(pose);
342 nq += boost::apply_visitor([](const auto & j) { return j.nq; }, jm);
343 nv += boost::apply_visitor([](const auto & j) { return j.nv; }, jm);
344 }
345
346 bool operator==(const JointComposite & other) const
347 {
348 return joints == other.joints && jointsPlacements == other.jointsPlacements
349 && nq == other.nq && nv == other.nv;
350 }
351 };
352 } // namespace graph
353} // namespace pinocchio
354
355#endif // ifndef __pinocchio_parsers_graph_joints_hpp__
Main pinocchio namespace.
Definition treeview.dox:11
int nv(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointNvVisitor to get the dimension of the joint tangent space.
int nq(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointNqVisitor to get the dimension of the joint configuration space.