Skip to content

Commit

Permalink
Auto stash before revert of "Change to clear naming"
Browse files Browse the repository at this point in the history
  • Loading branch information
Giulero committed Mar 8, 2024
1 parent dbaac64 commit 24cfda2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 31 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.tree.graph):
if target not in list(self.links) and target not in list(self.frames):
raise ValueError(f"{target} is not not in the robot model.")

if target == root:
return []
chain = []
current_joint = [
current_node = [
joint for joint in self.joints.values() if joint.child == target
][0]

chain.insert(0, current_joint)
while current_joint.parent != root:
current_joint = [
chain.insert(0, current_node)
while current_node.parent != root:
current_node = [
joint
for joint in self.joints.values()
if joint.child == current_joint.parent
if joint.child == current_node.parent
][0]
chain.insert(0, current_joint)
chain.insert(0, current_node)
return chain

def get_total_mass(self) -> float:
Expand Down
10 changes: 7 additions & 3 deletions src/adam/model/std_factories/std_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ def urdf_remove_sensors_tags(xml_string):
for sensors_tag in root.findall("sensor"):
root.remove(sensors_tag)

return ET.tostring(root)
# Convert the modified XML back to a string
modified_xml_string = ET.tostring(root)

return modified_xml_string


class URDFModelFactory(ModelFactory):
Expand All @@ -41,8 +44,9 @@ 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
with open(path, "r") as xml_file:
xml_string = xml_file.read()
xml_file = open(path, "r")
xml_string = xml_file.read()
xml_file.close()
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
43 changes: 22 additions & 21 deletions src/adam/model/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,38 +102,39 @@ def reduce(self, considered_joint_names: List[str]) -> "Tree":
for joint in fixed_joints:
joint.type = "fixed"

for fixed_j in fixed_joints:
saved_node = self.graph[fixed_j.parent]
removing_node = self.graph[fixed_j.child]
for f_joint in fixed_joints:
merged_node = self.graph[f_joint.parent]
merged_neighbors = self.graph[f_joint.child]

saved_node.children.remove(removing_node)
saved_node.children.extend(removing_node.children)
merged_node.children.remove(merged_neighbors)
merged_node.children.extend(merged_neighbors.children)
# update the arcs
saved_node.arcs.remove(fixed_j)
saved_node.arcs.extend(removing_node.arcs)
merged_node.arcs.remove(f_joint)
merged_node.arcs.extend(merged_neighbors.arcs)

saved_node.link = saved_node.link.lump(
other=removing_node.link, joint=fixed_j
merged_node.link = merged_node.link.lump(
other=merged_neighbors.link, joint=f_joint
)

merged_joint = saved_node.parent_arc
removed_joint = removing_node.parent_arc
merged_joint = merged_node.parent_arc
removed_joint = merged_neighbors.parent_arc
# update the parent arc of the merged node
# saved_node.parent_arc = saved_node.parent_arc.lump(removed_joint)
merged_node.parent_arc = merged_node.parent_arc.lump(removed_joint)

# we need to updated the parents and child on the joints in fixed_joints
for joint in self.get_joint_list():
if joint.parent == removing_node.name:
joint.parent = saved_node.name
if joint.child == removing_node.name:
joint.child = saved_node.name
if joint.parent == merged_neighbors.name:
joint.parent = merged_node.name
if joint.child == merged_neighbors.name:
joint.child = merged_node.name

for child in saved_node.children:
child.parent = saved_node.link
child.parent_arc = saved_node.parent_arc
for child in merged_node.children:

self.graph.pop(removing_node.name)
self.graph[saved_node.name] = saved_node
child.parent = merged_node.link
child.parent_arc = merged_node.parent_arc

self.graph.pop(merged_neighbors.name)
self.graph[merged_node.name] = merged_node

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

0 comments on commit 24cfda2

Please sign in to comment.