diff --git a/src/adam/model/std_factories/std_model.py b/src/adam/model/std_factories/std_model.py index ffeff713..7bb7f83d 100644 --- a/src/adam/model/std_factories/std_model.py +++ b/src/adam/model/std_factories/std_model.py @@ -37,16 +37,8 @@ def __init__(self, path: str, math: SpatialMath): if not path.exists(): raise FileExistsError(path) - # Read URDF, but before passing it to urdf_parser_py get rid of all sensor tags - # sensor tags are valid elements of URDF (see ), - # but they are ignored by urdf_parser_py, that complains every time it sees one. - # As there is nothing to be fixed in the used models, and it is not useful - # to have a useless and noisy warning, let's remove before hands all the sensor elements, - # that anyhow are not parser by urdf_parser_py or adam - # See https://github.com/ami-iit/ADAM/issues/59 - xml_file = open(path, "r") - xml_string = xml_file.read() - xml_file.close() + with open(path, "r") as xml_file: + xml_string = xml_file.read() xml_string_without_sensors_tags = urdf_remove_sensors_tags(xml_string) self.urdf_desc = urdf_parser_py.urdf.URDF.from_xml_string( xml_string_without_sensors_tags @@ -66,7 +58,9 @@ def get_links(self) -> List[StdLink]: List[StdLink]: build the list of the links """ return [ - self.build_link(l) for l in self.urdf_desc.links if l.inertial is not None + self.build_link(l) + for l in self.urdf_desc.links + if (l.inertial is not None or l.name in self.urdf_desc.child_map.keys()) ] def get_frames(self) -> List[StdLink]: @@ -74,7 +68,11 @@ def get_frames(self) -> List[StdLink]: Returns: List[StdLink]: build the list of the links """ - return [self.build_link(l) for l in self.urdf_desc.links if l.inertial is None] + return [ + self.build_link(l) + for l in self.urdf_desc.links + if l.inertial is None and l.name not in self.urdf_desc.child_map.keys() + ] def build_joint(self, joint: urdf_parser_py.urdf.Joint) -> StdJoint: """