pinocchio  3.9.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
Loading...
Searching...
No Matches
model-graph.hpp
1//
2// Copyright (c) 2025 INRIA
3//
4
5#ifndef __pinocchio_parsers_graph_model_graph_hpp__
6#define __pinocchio_parsers_graph_model_graph_hpp__
7
8#include "pinocchio/parsers/graph/fwd.hpp"
9
10#include "pinocchio/parsers/config.hpp"
11
12#include "pinocchio/parsers/graph/joints.hpp"
13#include "pinocchio/parsers/graph/frames.hpp"
14#include "pinocchio/parsers/graph/geometries.hpp"
15
16#include <Eigen/Core>
17
18#include <boost/optional.hpp>
19#include <boost/graph/adjacency_list.hpp>
20
21#include <vector>
22#include <string>
23#include <unordered_map>
24#include <stdexcept>
25
26namespace pinocchio
27{
28 namespace graph
29 {
30 struct EdgeBuilder;
31 struct EdgeParameters;
32 struct GeometryBuilder;
33
36 {
38 std::string name;
39
40 FrameVariant frame;
41
42 std::vector<Geometry> geometries;
43
44 void addGeometry(const Geometry & geo)
45 {
46 geometries.push_back(geo);
47 }
48 };
49
52 {
54 std::string name;
55
57 JointVariant joint;
58
61
66
71
73 bool forward = true;
74 };
75
80 {
82 std::unordered_map<std::string, bool> _joint_forward;
85 };
86
91 struct PINOCCHIO_PARSERS_DLLAPI ModelGraph
92 {
93 typedef boost::
94 adjacency_list<boost::vecS, boost::vecS, boost::directedS, ModelGraphVertex, ModelGraphEdge>
95 Graph;
96 typedef typename boost::graph_traits<Graph>::vertex_descriptor VertexDesc;
97 typedef typename boost::graph_traits<Graph>::edge_descriptor EdgeDesc;
98
99 ModelGraph() = default;
104 void addFrame(const std::string & vertex_name, const FrameVariant & frame);
105
110 void addBody(const std::string & vertex_name, const Inertia & inert);
111
112 GeometryBuilder geometryBuilder();
113 void addGeometry(const std::string & vertex_name, const Geometry & geom);
114 void addGeometries(const std::string & vertex_name, const std::vector<Geometry> & geoms);
115
129 const std::string & joint_name,
130 const JointVariant & joint,
131 const std::string & source_body,
132 const SE3 & source_to_joint,
133 const std::string & target_body,
134 const SE3 & joint_to_target);
135
143 void addJoint(const EdgeParameters & params);
144
148
155 void appendGraph(const ModelGraph & g);
156
158 Graph graph;
160 std::unordered_map<std::string, VertexDesc> name_to_vertex;
161 };
162
164 struct PINOCCHIO_PARSERS_DLLAPI EdgeParameters
165 {
167 std::string name;
168
170 std::string source_vertex;
172 SE3 source_to_joint = SE3::Identity();
174 std::string target_vertex;
176 SE3 joint_to_target = SE3::Identity();
177
179 JointVariant joint = JointFixed();
180
182 boost::optional<Eigen::VectorXd> q_ref = boost::none;
183
184 JointLimits jlimit;
185
187 EdgeParameters() = default;
188
191 const std::string & jname,
192 const std::string & source_name,
193 const SE3 & source_to_joint,
194 const std::string & target_name,
195 const SE3 & joint_to_target,
196 const JointVariant & joint,
197 const boost::optional<Eigen::VectorXd> q_ref = boost::none);
198 };
199
202 struct PINOCCHIO_PARSERS_DLLAPI EdgeBuilder
203 {
206
209
210 boost::optional<Eigen::VectorXd> minConfig;
211 boost::optional<Eigen::VectorXd> maxConfig;
212 boost::optional<Eigen::VectorXd> maxVel;
213 boost::optional<Eigen::VectorXd> maxEffort;
214 boost::optional<Eigen::VectorXd> armature;
215 boost::optional<Eigen::VectorXd> friction;
216 boost::optional<Eigen::VectorXd> damping;
217
218 double frictionLoss = 0;
219
221 explicit EdgeBuilder(ModelGraph & graph)
222 : g(graph)
223 {
224 }
225
227 EdgeBuilder & withJointType(const JointVariant & jtype)
228 {
229 param.joint = jtype;
230 return *this;
231 }
232
234 EdgeBuilder & withName(const std::string & name)
235 {
236 param.name = name;
237 return *this;
238 }
239
240 EdgeBuilder & withTargetVertex(const std::string & target_name)
241 {
242 param.target_vertex = target_name;
243 return *this;
244 }
245
246 EdgeBuilder & withSourceVertex(const std::string & source_name)
247 {
248 param.source_vertex = source_name;
249 return *this;
250 }
251
252 EdgeBuilder & withTargetPose(const SE3 & target_pose)
253 {
254 param.joint_to_target = target_pose;
255 return *this;
256 }
257
258 EdgeBuilder & withSourcePose(const SE3 & source_pose)
259 {
260 param.source_to_joint = source_pose;
261 return *this;
262 }
263
265 EdgeBuilder & withQref(const Eigen::VectorXd & qref)
266 {
267 param.q_ref = qref;
268 return *this;
269 }
270
272 EdgeBuilder & withMinConfig(const Eigen::VectorXd & minConfig_)
273 {
274 minConfig = minConfig_;
275 return *this;
276 }
277
279 EdgeBuilder & withMaxConfig(const Eigen::VectorXd & maxConfig_)
280 {
281 maxConfig = maxConfig_;
282 return *this;
283 }
284
286 EdgeBuilder & withMaxVel(const Eigen::VectorXd & maxVel_)
287 {
288 maxVel = maxVel_;
289 return *this;
290 }
291
293 EdgeBuilder & withMaxEffort(const Eigen::VectorXd & maxEffort_)
294 {
295 maxEffort = maxEffort_;
296 return *this;
297 }
298
300 EdgeBuilder & withFriction(const Eigen::VectorXd & friction_)
301 {
302 friction = friction_;
303 return *this;
304 }
305
307 EdgeBuilder & withDamping(const Eigen::VectorXd & damping_)
308 {
309 damping = damping_;
310 return *this;
311 }
312
314 EdgeBuilder & withArmature(const Eigen::VectorXd & armature_)
315 {
316 armature = armature_;
317 return *this;
318 }
319
321 EdgeBuilder & withFrictionLoss(const double frictionLoss_)
322 {
323 frictionLoss = frictionLoss_;
324 return *this;
325 }
326
328 void build();
329 };
330
331 struct GeometryBuilder
332 {
333 Geometry geometry;
334 std::string name_body;
335
336 ModelGraph & g;
337
338 GeometryBuilder(ModelGraph & g)
339 : g(g)
340 {
341 }
342
343 GeometryBuilder & withName(const std::string & n)
344 {
345 geometry.name = n;
346 return *this;
347 }
348
349 GeometryBuilder & withBody(const std::string & n)
350 {
351 name_body = n;
352 return *this;
353 }
354
355 GeometryBuilder & withPlacement(const SE3 & p)
356 {
357 geometry.placement = p;
358 return *this;
359 }
360
361 GeometryBuilder & withScale(const Eigen::Vector3d & s)
362 {
363 geometry.scale = s;
364 return *this;
365 }
366
367 GeometryBuilder & withColor(const Eigen::Vector4d & c)
368 {
369 geometry.color = c;
370 return *this;
371 }
372
373 GeometryBuilder & withGeomType(const GeomType type)
374 {
375 geometry.type = type;
376 return *this;
377 }
378
379 GeometryBuilder & withGeom(const GeomVariant & g)
380 {
381 geometry.geometry = g;
382 return *this;
383 }
384
385 void build()
386 {
387 if (geometry.name.empty())
388 PINOCCHIO_THROW_PRETTY(std::invalid_argument, "Graph - geometry should have a name.");
389
390 return g.addGeometry(name_body, geometry);
391 }
392 };
393 } // namespace graph
394} // namespace pinocchio
395
396#endif // ifndef __pinocchio_parsers_graph_model_graph_hpp__
Main pinocchio namespace.
Definition treeview.dox:11
std::string name(const LieGroupGenericTpl< LieGroupCollection > &lg)
Visit a LieGroupVariant to get the name of it.
Builder interface to add an edge to the graph. Allows for an easy customization of the edge.
EdgeBuilder & withSourcePose(const SE3 &source_pose)
Specify the pose of the joint wrt the source vertex. Default : Identity.
EdgeBuilder & withTargetVertex(const std::string &target_name)
Specify the name of the target vertex.
EdgeBuilder & withMaxEffort(const Eigen::VectorXd &maxEffort_)
Specify limit maxEffort.
EdgeParameters param
Parameters of the edge.
EdgeBuilder & withJointType(const JointVariant &jtype)
Specify the type of joint for the edge. Default : Fixed.
EdgeBuilder & withFriction(const Eigen::VectorXd &friction_)
Specify friction.
EdgeBuilder & withMinConfig(const Eigen::VectorXd &minConfig_)
Specify limit minConfig.
EdgeBuilder & withFrictionLoss(const double frictionLoss_)
Specify friction loss.
ModelGraph & g
ModelGraph to which the edge will be added.
void build()
Add the edge to the ModelGraph.
EdgeBuilder & withArmature(const Eigen::VectorXd &armature_)
Specify armature.
EdgeBuilder & withQref(const Eigen::VectorXd &qref)
Specify a bias for the joint configuration.
EdgeBuilder & withTargetPose(const SE3 &target_pose)
Specify the pose of target vertex wrt edge. Default : Identity.
EdgeBuilder & withDamping(const Eigen::VectorXd &damping_)
Specify damping.
EdgeBuilder & withMaxVel(const Eigen::VectorXd &maxVel_)
Specify limit maxVel.
EdgeBuilder(ModelGraph &graph)
Constructor.
EdgeBuilder & withName(const std::string &name)
Specify the name of the edge.
EdgeBuilder & withMaxConfig(const Eigen::VectorXd &maxConfig_)
Specify limit maxConfig.
EdgeBuilder & withSourceVertex(const std::string &source_name)
Specify the name of the source vertex.
Structure that holds all the parameters useful to create an edge.
std::string source_vertex
Source name.
SE3 joint_to_target
Placement of target wrt edge.
boost::optional< Eigen::VectorXd > q_ref
Bias for the joint.
EdgeParameters(const std::string &jname, const std::string &source_name, const SE3 &source_to_joint, const std::string &target_name, const SE3 &joint_to_target, const JointVariant &joint, const boost::optional< Eigen::VectorXd > q_ref=boost::none)
Constructor with all parameters.
std::string target_vertex
Target name.
JointVariant joint
Type of joint for edge.
EdgeParameters()=default
Default Constructor.
SE3 source_to_joint
Placement of Edge wrt source vertex.
Contains information about how buildModel walked the ModelGraph to construct a Model....
bool _is_fixed
True if the root joint is fixed.
std::unordered_map< std::string, bool > _joint_forward
Map joint name to joint direction.
Represents an edge (joint) in the model graph.
SE3 joint_to_target
Transformation from edge to next vertex.
std::string name
Unique name of the joint.
bool forward
boolean to know if we are in a forward or backward edge
JointVariant joint
What is the type of the joint.
SE3 source_to_joint
Transformation from the previous vertex to edge.
JointLimits jlimit
All the limits of the joint.
Represents a vertex (body, sensor, operational frame) in the model graph.
std::string name
Unique name of the body.
Represents multibody model as a bidirectional graph.
void appendGraph(const ModelGraph &g)
add all the vertex and edges from a graph to this one. Attention : it does not add an edge between th...
void addFrame(const std::string &vertex_name, const FrameVariant &frame)
Add a new vertex to the graph.
EdgeBuilder edgeBuilder()
Create an EdgeBuilde. This will allow to use EdgeBuilder interface to have a more flexible edge confi...
std::unordered_map< std::string, VertexDesc > name_to_vertex
Name of the vertexes in the graph. Useful for graph parcours.
void addJoint(const EdgeParameters &params)
Add edges (joint) to the graph. Since it's a bidirectional graph, edge and its reverse are added to t...
Graph graph
Boost graph structure that holds the graph structure.
void addJoint(const std::string &joint_name, const JointVariant &joint, const std::string &source_body, const SE3 &source_to_joint, const std::string &target_body, const SE3 &joint_to_target)
Add edges (joint) to the graph. Since it's a bidirectional graph, edge and its reverse are added to t...
void addBody(const std::string &vertex_name, const Inertia &inert)
Add a new body to the graph.