Skip to content

Commit 924da1f

Browse files
committed
Cleanup commits
1 parent 6191da9 commit 924da1f

File tree

3 files changed

+25
-30
lines changed

3 files changed

+25
-30
lines changed

src/adam/model/model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def get_joints_chain(self, root: str, target: str) -> List[Joint]:
124124
List[Joint]: the list of the joints
125125
"""
126126

127-
if target not in list(self.links) and target not in list(self.frames):
127+
if target not in list(self.links) and target not in list(self.tree.graph):
128128
raise ValueError(f"{target} is not not in the robot model.")
129129

130130
if target == root:

src/adam/model/std_factories/std_model.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ def urdf_remove_sensors_tags(xml_string):
1717
for sensors_tag in root.findall("sensor"):
1818
root.remove(sensors_tag)
1919

20-
# Convert the modified XML back to a string
21-
modified_xml_string = ET.tostring(root)
22-
23-
return modified_xml_string
20+
return ET.tostring(root)
2421

2522

2623
class URDFModelFactory(ModelFactory):
@@ -44,9 +41,8 @@ def __init__(self, path: str, math: SpatialMath):
4441
# to have a useless and noisy warning, let's remove before hands all the sensor elements,
4542
# that anyhow are not parser by urdf_parser_py or adam
4643
# See https://github.com/ami-iit/ADAM/issues/59
47-
xml_file = open(path, "r")
48-
xml_string = xml_file.read()
49-
xml_file.close()
44+
with open(path, "r") as xml_file:
45+
xml_string = xml_file.read()
5046
xml_string_without_sensors_tags = urdf_remove_sensors_tags(xml_string)
5147
self.urdf_desc = urdf_parser_py.urdf.URDF.from_xml_string(
5248
xml_string_without_sensors_tags

src/adam/model/tree.py

+21-22
Original file line numberDiff line numberDiff line change
@@ -102,39 +102,38 @@ def reduce(self, considered_joint_names: List[str]) -> "Tree":
102102
for joint in fixed_joints:
103103
joint.type = "fixed"
104104

105-
for f_joint in fixed_joints:
106-
merged_node = self.graph[f_joint.parent]
107-
merged_neighbors = self.graph[f_joint.child]
105+
for fixed_j in fixed_joints:
106+
saved_node = self.graph[fixed_j.parent]
107+
removing_node = self.graph[fixed_j.child]
108108

109-
merged_node.children.remove(merged_neighbors)
110-
merged_node.children.extend(merged_neighbors.children)
109+
saved_node.children.remove(removing_node)
110+
saved_node.children.extend(removing_node.children)
111111
# update the arcs
112-
merged_node.arcs.remove(f_joint)
113-
merged_node.arcs.extend(merged_neighbors.arcs)
112+
saved_node.arcs.remove(fixed_j)
113+
saved_node.arcs.extend(removing_node.arcs)
114114

115-
merged_node.link = merged_node.link.lump(
116-
other=merged_neighbors.link, joint=f_joint
115+
saved_node.link = saved_node.link.lump(
116+
other=removing_node.link, joint=fixed_j
117117
)
118118

119-
merged_joint = merged_node.parent_arc
120-
removed_joint = merged_neighbors.parent_arc
119+
merged_joint = saved_node.parent_arc
120+
removed_joint = removing_node.parent_arc
121121
# update the parent arc of the merged node
122-
merged_node.parent_arc = merged_node.parent_arc.lump(removed_joint)
122+
# saved_node.parent_arc = saved_node.parent_arc.lump(removed_joint)
123123

124124
# we need to updated the parents and child on the joints in fixed_joints
125125
for joint in self.get_joint_list():
126-
if joint.parent == merged_neighbors.name:
127-
joint.parent = merged_node.name
128-
if joint.child == merged_neighbors.name:
129-
joint.child = merged_node.name
126+
if joint.parent == removing_node.name:
127+
joint.parent = saved_node.name
128+
if joint.child == removing_node.name:
129+
joint.child = saved_node.name
130130

131-
for child in merged_node.children:
131+
for child in saved_node.children:
132+
child.parent = saved_node.link
133+
child.parent_arc = saved_node.parent_arc
132134

133-
child.parent = merged_node.link
134-
child.parent_arc = merged_node.parent_arc
135-
136-
self.graph.pop(merged_neighbors.name)
137-
self.graph[merged_node.name] = merged_node
135+
self.graph.pop(removing_node.name)
136+
self.graph[saved_node.name] = saved_node
138137

139138
if {joint.name for joint in self.get_joint_list()} != set(
140139
considered_joint_names

0 commit comments

Comments
 (0)