diff --git a/src/adam/model/model.py b/src/adam/model/model.py index 4c1f9299..5d34a62f 100644 --- a/src/adam/model/model.py +++ b/src/adam/model/model.py @@ -124,24 +124,24 @@ def get_joints_chain(self, root: str, target: str) -> List[Joint]: List[Joint]: the list of the joints """ - if target not in list(self.links) and target not in list(self.frames): + if target not in list(self.links) and target not in list(self.tree.graph): raise ValueError(f"{target} is not not in the robot model.") if target == root: return [] chain = [] - current_node = [ + current_joint = [ joint for joint in self.joints.values() if joint.child == target ][0] - chain.insert(0, current_node) - while current_node.parent != root: - current_node = [ + chain.insert(0, current_joint) + while current_joint.parent != root: + current_joint = [ joint for joint in self.joints.values() - if joint.child == current_node.parent + if joint.child == current_joint.parent ][0] - chain.insert(0, current_node) + chain.insert(0, current_joint) return chain def get_total_mass(self) -> float: diff --git a/src/adam/model/std_factories/std_model.py b/src/adam/model/std_factories/std_model.py index ffeff713..bf3c3e75 100644 --- a/src/adam/model/std_factories/std_model.py +++ b/src/adam/model/std_factories/std_model.py @@ -17,10 +17,7 @@ def urdf_remove_sensors_tags(xml_string): for sensors_tag in root.findall("sensor"): root.remove(sensors_tag) - # Convert the modified XML back to a string - modified_xml_string = ET.tostring(root) - - return modified_xml_string + return ET.tostring(root) class URDFModelFactory(ModelFactory): @@ -44,9 +41,8 @@ def __init__(self, path: str, math: SpatialMath): # 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