Skip to content

Commit 61264d7

Browse files
GiulioRomualdiStéphane Caron
authored andcommitted
Add iDynTree loader
1 parent ebab7f6 commit 61264d7

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright 2022 Giulio Romualdi
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
"""
19+
Load a robot description in iDynTree.
20+
"""
21+
22+
from importlib import import_module # type: ignore
23+
24+
import idyntree.swig as idyn
25+
26+
27+
def load_robot_description(description_name: str) -> int:
28+
"""
29+
Load a robot description in iDynTree.
30+
31+
Args:
32+
description_name: Name of the robot description.
33+
34+
Returns:
35+
Identifier of the robot in iDynTree.
36+
"""
37+
module = import_module(f"robot_descriptions.{description_name}")
38+
if not hasattr(module, "URDF_PATH"):
39+
raise ValueError(f"{description_name} is not a URDF description")
40+
41+
model_loader = idyn.ModelLoader()
42+
model_loader.loadModelFromFile(module.URDF_PATH)
43+
robot = model_loader.model().copy()
44+
return robot

0 commit comments

Comments
 (0)