shortcuts.py
Go to the documentation of this file.
1 # ruff: noqa: E501
2 #
3 # Copyright (c) 2018-2020 CNRS INRIA
4 #
5 
6 
7 
8 from typing import Tuple
9 
10 from . import WITH_HPP_FCL, WITH_HPP_FCL_BINDINGS
11 from . import pinocchio_pywrap_default as pin
12 
13 nle = pin.nonLinearEffects
14 
15 
17  filename, *args, **kwargs
18 ) -> Tuple[pin.Model, pin.GeometryModel, pin.GeometryModel]:
19  """Parse the URDF file given in input and return a Pinocchio Model followed by corresponding GeometryModels of types specified by geometry_types, in the same order as listed.
20  Arguments:
21  - filename - name of the urdf file to load
22  - package_dirs - where the meshes of the urdf are located. (default - None)
23  - root_joint - Joint at the base of the model (default - None)
24  - root_joint_name - Name for the root_joint (default - "root_joint")
25  - verbose - print information of parsing (default - False)
26  - meshLoader - object used to load meshes (default - hpp::fcl::MeshLoader)
27  - geometry_types - Which geometry model to load. Can be pin.GeometryType.COLLISION, pin.GeometryType.VISUAL or both. (default - [pin.GeometryType.COLLISION, pin.GeometryType.VISUAL])
28  Return:
29  Tuple of the models, in this order : model, collision model, and visual model.
30 
31  Example:
32  model, collision_model, visual_model = buildModelsFromUrdf(filename, root_joint, verbose, meshLoader, geometry_types, root_joint_name="root_joint_name")
33 
34  Remark: In the URDF format, a joint of type fixed can be defined. For efficiency reasons, it is treated as operational frame and not as a joint of the model.
35  """
36  # Handle the switch from old to new api
37  arg_keys = ["package_dirs", "root_joint", "verbose", "meshLoader", "geometry_types"]
38  if len(args) >= 3:
39  if isinstance(args[2], str):
40  arg_keys = [
41  "package_dirs",
42  "root_joint",
43  "root_joint_name",
44  "verbose",
45  "meshLoader",
46  "geometry_types",
47  ]
48 
49  for key, arg in zip(arg_keys, args):
50  if key in kwargs.keys():
51  raise TypeError("Function got multiple values for argument ", key)
52  else:
53  kwargs[key] = arg
54 
55  return _buildModelsFromUrdf(filename, **kwargs)
56 
57 
59  filename,
60  package_dirs=None,
61  root_joint=None,
62  root_joint_name=None,
63  verbose=False,
64  meshLoader=None,
65  geometry_types=None,
66 ) -> Tuple[pin.Model, pin.GeometryModel, pin.GeometryModel]:
67  if geometry_types is None:
68  geometry_types = [pin.GeometryType.COLLISION, pin.GeometryType.VISUAL]
69 
70  if root_joint is None:
71  model = pin.buildModelFromUrdf(filename)
72  elif root_joint is not None and root_joint_name is None:
73  model = pin.buildModelFromUrdf(filename, root_joint)
74  else:
75  model = pin.buildModelFromUrdf(filename, root_joint, root_joint_name)
76 
77  if verbose and not WITH_HPP_FCL and meshLoader is not None:
78  print(
79  "Info: MeshLoader is ignored. Pinocchio has not been compiled with HPP-FCL."
80  )
81  if verbose and not WITH_HPP_FCL_BINDINGS and meshLoader is not None:
82  print(
83  "Info: MeshLoader is ignored. The HPP-FCL Python bindings have not been installed."
84  )
85  if package_dirs is None:
86  package_dirs = []
87 
88  lst = [model]
89 
90  if not hasattr(geometry_types, "__iter__"):
91  geometry_types = [geometry_types]
92 
93  for geometry_type in geometry_types:
94  if meshLoader is None or (not WITH_HPP_FCL and not WITH_HPP_FCL_BINDINGS):
95  geom_model = pin.buildGeomFromUrdf(
96  model, filename, geometry_type, package_dirs=package_dirs
97  )
98  else:
99  geom_model = pin.buildGeomFromUrdf(
100  model,
101  filename,
102  geometry_type,
103  package_dirs=package_dirs,
104  mesh_loader=meshLoader,
105  )
106  lst.append(geom_model)
107 
108  return tuple(lst)
109 
110 
111 def createDatas(*models):
112  """
113  Call createData() on each Model or GeometryModel in input and return the results in
114  a tuple. If one of the models is None, the corresponding data object in the result
115  is also None.
116  """
117  return tuple([None if model is None else model.createData() for model in models])
118 
119 
121  filename, *args, **kwargs
122 ) -> Tuple[pin.Model, pin.GeometryModel, pin.GeometryModel]:
123  """Parse the Sdf file given in input and return a Pinocchio Model and a list of Constraint Models, followed by corresponding GeometryModels of types specified by geometry_types, in the same order as listed.
124  Arguments:
125  - filename - name of the urdf file to load
126  - package_dirs - where the meshes of the urdf are located. (default - None)
127  - root_joint - Joint at the base of the model (default - None)
128  - root_link_name - Name of the body to use as root of the model (default - "")
129  - root_joint_name - Name for the root_joint (default - "root_joint")
130  - parent_guidance - Joint names which should be preferred for cases where two joints can qualify as parent. The other joint appears in the constraint_model. If empty, joint appearance order in .sdf is taken as default.
131  - verbose - print information of parsing (default - False)
132  - meshLoader - object used to load meshes (default - hpp::fcl::MeshLoader)
133  - geometry_types - Which geometry model to load. Can be pin.GeometryType.COLLISION, pin.GeometryType.VISUAL, both or None. (default - None])
134  Return:
135  Tuple of the models, in this order : model, collision model, and visual model.
136 
137  Example:
138  model, collision_model, visual_model = buildModelsFromSdf(filename, root_joint, root_link_name, parent_guidance, verbose, meshLoader, geometry_types, root_joint_name="root_joint_name")
139  """
140 
141  arg_keys = [
142  "package_dirs",
143  "root_joint",
144  "root_link_name",
145  "parent_guidance",
146  "verbose",
147  "meshLoader",
148  "geometry_types",
149  ]
150  # Handle the switch from old to new api
151  if len(args) >= 4:
152  if isinstance(args[3], str):
153  arg_keys = [
154  "package_dirs",
155  "root_joint",
156  "root_link_name",
157  "root_joint_name",
158  "parent_guidance",
159  "verbose",
160  "meshLoader",
161  "geometry_types",
162  ]
163 
164  for key, arg in zip(arg_keys, args):
165  if key in kwargs.keys():
166  raise TypeError("Function got multiple values for argument ", key)
167  else:
168  kwargs[key] = arg
169 
170  return _buildModelsFromSdf(filename, **kwargs)
171 
172 
174  filename,
175  package_dirs=None,
176  root_joint=None,
177  root_link_name="",
178  root_joint_name=None,
179  parent_guidance=None,
180  verbose=False,
181  meshLoader=None,
182  geometry_types=None,
183 ):
184  if parent_guidance is None:
185  parent_guidance = []
186 
187  if geometry_types is None:
188  geometry_types = [pin.GeometryType.COLLISION, pin.GeometryType.VISUAL]
189 
190  if root_joint is None:
191  model, constraint_models = pin.buildModelFromSdf(
192  filename, root_link_name, parent_guidance
193  )
194  elif root_joint is not None and root_joint_name is None:
195  model, constraint_models = pin.buildModelFromSdf(
196  filename, root_joint, root_link_name, parent_guidance
197  )
198  else:
199  model, constraint_models = pin.buildModelFromSdf(
200  filename, root_joint, root_link_name, root_joint_name, parent_guidance
201  )
202  if verbose and not WITH_HPP_FCL and meshLoader is not None:
203  print(
204  "Info: MeshLoader is ignored. Pinocchio has not been compiled with HPP-FCL."
205  )
206  if verbose and not WITH_HPP_FCL_BINDINGS and meshLoader is not None:
207  print(
208  "Info: MeshLoader is ignored. The HPP-FCL Python bindings have not been installed."
209  )
210  if package_dirs is None:
211  package_dirs = []
212 
213  lst = [model, constraint_models]
214 
215  if not hasattr(geometry_types, "__iter__"):
216  geometry_types = [geometry_types]
217 
218  for geometry_type in geometry_types:
219  if meshLoader is None or (not WITH_HPP_FCL and not WITH_HPP_FCL_BINDINGS):
220  geom_model = pin.buildGeomFromSdf(
221  model, filename, geometry_type, root_link_name, package_dirs
222  )
223  else:
224  geom_model = pin.buildGeomFromSdf(
225  model, filename, geometry_type, root_link_name, package_dirs, meshLoader
226  )
227  lst.append(geom_model)
228 
229  return tuple(lst)
230 
231 
232 def buildModelsFromMJCF(filename, *args, **kwargs):
233  """Parse the Mjcf file given in input and return a Pinocchio Model followed by corresponding GeometryModels of types specified by geometry_types, in the same order as listed.
234  Arguments:
235  - filename - name of the urdf file to load
236  - package_dirs - where the meshes of the urdf are located. (default - None)
237  - root_joint - Joint at the base of the model (default - None)
238  - root_joint_name - Name for the root_joint (default - "root_joint")
239  - verbose - print information of parsing (default - False)
240  - meshLoader - object used to load meshes (default - hpp::fcl::MeshLoader)
241  - geometry_types - Which geometry model to load. Can be pin.GeometryType.COLLISION, pin.GeometryType.VISUAL or both. (default - [pin.GeometryType.COLLISION, pin.GeometryType.VISUAL])
242  - contacts - Boolean to know if contraint models are wanted (default - False)
243  Return:
244  Tuple of the models, in this order : model, collision model, and visual model, or model, constraint_list, collision model, and visual model, if contacts is True.
245 
246  Example:
247  model, collision_model, visual_model = buildModelsFromMJCF(filename, root_joint, verbose, meshLoader, geometry_types, root_joint_name="root_joint_name")
248  """
249  # Handle the switch from old to new api
250  arg_keys = ["root_joint", "verbose", "meshLoader", "geometry_types", "contacts"]
251  if len(args) >= 2:
252  if isinstance(args[1], str):
253  arg_keys = [
254  "root_joint",
255  "root_joint_name",
256  "verbose",
257  "meshLoader",
258  "geometry_types",
259  "contacts",
260  ]
261 
262  for key, arg in zip(arg_keys, args):
263  if key in kwargs.keys():
264  raise TypeError("Function got multiple values for argument ", key)
265  else:
266  kwargs[key] = arg
267 
268  return _buildModelsFromMJCF(filename, **kwargs)
269 
270 
272  filename,
273  root_joint=None,
274  root_joint_name=None,
275  verbose=False,
276  meshLoader=None,
277  geometry_types=None,
278  contacts=False,
279 ):
280  if geometry_types is None:
281  geometry_types = [pin.GeometryType.COLLISION, pin.GeometryType.VISUAL]
282 
283  contact_models = []
284  if root_joint is None:
285  model = pin.buildModelFromMJCF(filename)
286  elif root_joint is not None and root_joint_name is None:
287  model = pin.buildModelFromMJCF(filename, root_joint)
288  else:
289  model, contact_models = pin.buildModelFromMJCF(
290  filename, root_joint, root_joint_name
291  )
292 
293  if verbose and not WITH_HPP_FCL and meshLoader is not None:
294  print(
295  "Info: MeshLoader is ignored. Pinocchio has not been compiled with HPP-FCL."
296  )
297  if verbose and not WITH_HPP_FCL_BINDINGS and meshLoader is not None:
298  print(
299  "Info: MeshLoader is ignored. "
300  "The HPP-FCL Python bindings have not been installed."
301  )
302 
303  lst = [model]
304  if contacts:
305  lst.append(contact_models)
306 
307  if not hasattr(geometry_types, "__iter__"):
308  geometry_types = [geometry_types]
309 
310  for geometry_type in geometry_types:
311  if meshLoader is None or (not WITH_HPP_FCL and not WITH_HPP_FCL_BINDINGS):
312  geom_model = pin.buildGeomFromMJCF(model, filename, geometry_type)
313  else:
314  geom_model = pin.buildGeomFromMJCF(
315  model, filename, geometry_type, mesh_loader=meshLoader
316  )
317  lst.append(geom_model)
318 
319  return tuple(lst)
pinocchio.shortcuts._buildModelsFromUrdf
Tuple[pin.Model, pin.GeometryModel, pin.GeometryModel] _buildModelsFromUrdf(filename, package_dirs=None, root_joint=None, root_joint_name=None, verbose=False, meshLoader=None, geometry_types=None)
Definition: shortcuts.py:58
pinocchio.shortcuts.buildModelsFromUrdf
Tuple[pin.Model, pin.GeometryModel, pin.GeometryModel] buildModelsFromUrdf(filename, *args, **kwargs)
Definition: shortcuts.py:16
pinocchio.shortcuts._buildModelsFromMJCF
def _buildModelsFromMJCF(filename, root_joint=None, root_joint_name=None, verbose=False, meshLoader=None, geometry_types=None, contacts=False)
Definition: shortcuts.py:271
pinocchio.shortcuts.createDatas
def createDatas(*models)
Definition: shortcuts.py:111
pinocchio.shortcuts.buildModelsFromSdf
Tuple[pin.Model, pin.GeometryModel, pin.GeometryModel] buildModelsFromSdf(filename, *args, **kwargs)
Definition: shortcuts.py:120
pinocchio.shortcuts._buildModelsFromSdf
def _buildModelsFromSdf(filename, package_dirs=None, root_joint=None, root_link_name="", root_joint_name=None, parent_guidance=None, verbose=False, meshLoader=None, geometry_types=None)
Definition: shortcuts.py:173
pinocchio.shortcuts.buildModelsFromMJCF
def buildModelsFromMJCF(filename, *args, **kwargs)
Definition: shortcuts.py:232


pinocchio
Author(s):
autogenerated on Fri Nov 1 2024 02:41:48