Skip to content

Commit

Permalink
Remove unnecessary file reading code in URDFModelFactory
Browse files Browse the repository at this point in the history
Fix variable name in get_chain() method
  • Loading branch information
Giulero committed Mar 8, 2024
1 parent 8d61492 commit 2187a4c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
14 changes: 7 additions & 7 deletions src/adam/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 3 additions & 7 deletions src/adam/model/std_factories/std_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down

0 comments on commit 2187a4c

Please sign in to comment.