2020"""
2121
2222from importlib import import_module # type: ignore
23+ from typing import List , Optional
24+ from .pinocchio import get_package_dirs
2325
2426import 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