Skip to content

Commit 4eac29e

Browse files
GiulioRomualdiStéphane Caron
authored andcommitted
General improvements in the iDynTree loader
- The loader will now take as input the package directories - It is now possible to load a reduced model by specifying the list of the joints
1 parent 49f434c commit 4eac29e

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ keywords = ["robot", "description", "urdf", "mjcf"]
3535
[project.optional-dependencies]
3636
opts = [
3737
"pin >=2.6.10",
38-
"idyntree >= 5.0.1",
38+
"idyntree >= 8.0.0",
3939
"robomeshcat >=1.0.4",
4040
"yourdfpy >=0.0.52",
4141
]

robot_descriptions/loaders/idyntree.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,24 @@
2020
"""
2121

2222
from importlib import import_module # type: ignore
23+
from typing import List, Optional
24+
from .pinocchio import get_package_dirs
2325

2426
import idyntree.swig as idyn
2527

2628

27-
def load_robot_description(description_name: str) -> int:
29+
def load_robot_description(description_name: str,
30+
joints_list: Optional[List[str]] = None,
31+
) -> idyn.Model:
2832
"""
2933
Load a robot description in iDynTree.
3034
3135
Args:
3236
description_name: Name of the robot description.
37+
joints_list: Optional parameter containing the list of the joints considered
38+
in the model. If empty the model will contain all the joints
39+
specified in the urdf, otherwise a reduced model containing
40+
only the specified joints is created.
3341
3442
Returns:
3543
Identifier of the robot in iDynTree.
@@ -39,6 +47,18 @@ def load_robot_description(description_name: str) -> int:
3947
raise ValueError(f"{description_name} is not a URDF description")
4048

4149
model_loader = idyn.ModelLoader()
42-
model_loader.loadModelFromFile(module.URDF_PATH)
50+
51+
if (joints_list is None):
52+
if not model_loader.loadModelFromFile(module.URDF_PATH, \
53+
'urdf', \
54+
get_package_dirs(module)):
55+
raise ValueError(f"Unable to load {description_name} with iDynTree")
56+
else:
57+
if not model_loader.loadReducedModelFromFile(module.URDF_PATH, \
58+
joints_list, \
59+
'urdf', \
60+
get_package_dirs(module)):
61+
raise ValueError(f"Unable to load {description_name} with iDynTree")
62+
4363
robot = model_loader.model().copy()
4464
return robot

0 commit comments

Comments
 (0)