From 13d974e9c3f85f49b43fdf868eb8793b75f7f9d9 Mon Sep 17 00:00:00 2001 From: Florian Vahl Date: Mon, 29 Jan 2024 22:18:04 +0100 Subject: [PATCH 1/6] Update dynamic_stack_decider_visualization/dynamic_stack_decider_visualization/dsd_follower.py Co-authored-by: Jan Gutsche <34797331+jaagut@users.noreply.github.com> --- .../dynamic_stack_decider_visualization/dsd_follower.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dynamic_stack_decider_visualization/dynamic_stack_decider_visualization/dsd_follower.py b/dynamic_stack_decider_visualization/dynamic_stack_decider_visualization/dsd_follower.py index 4a22e8c..8bc7fff 100644 --- a/dynamic_stack_decider_visualization/dynamic_stack_decider_visualization/dsd_follower.py +++ b/dynamic_stack_decider_visualization/dynamic_stack_decider_visualization/dsd_follower.py @@ -350,8 +350,9 @@ def to_q_item_model(self): def destroy(self): """ - Cleanup the subscriptions, to we don't receive any more data that we don't need (performance) - Also this allows the garbage collector to delete this object and prevent memory leaks + Cleanup the subscriptions, so we don't receive any more data that we don't need. + This improves the performance. + Also this allows the garbage collector to delete this object and prevent memory leaks. """ self._node.destroy_subscription(self.tree_sub) self._node.destroy_subscription(self.stack_sub) From 90e26b7597b6be2103c5cf8a0e3912afca75528f Mon Sep 17 00:00:00 2001 From: Florian Vahl Date: Mon, 29 Jan 2024 22:18:12 +0100 Subject: [PATCH 2/6] Update dynamic_stack_decider_visualization/dynamic_stack_decider_visualization/dsd_visualization_plugin.py Co-authored-by: Jan Gutsche <34797331+jaagut@users.noreply.github.com> --- .../dsd_visualization_plugin.py | 1 - 1 file changed, 1 deletion(-) diff --git a/dynamic_stack_decider_visualization/dynamic_stack_decider_visualization/dsd_visualization_plugin.py b/dynamic_stack_decider_visualization/dynamic_stack_decider_visualization/dsd_visualization_plugin.py index 82c7bf4..40848fb 100644 --- a/dynamic_stack_decider_visualization/dynamic_stack_decider_visualization/dsd_visualization_plugin.py +++ b/dynamic_stack_decider_visualization/dynamic_stack_decider_visualization/dsd_visualization_plugin.py @@ -131,7 +131,6 @@ def wheel_event(event): self._widget.graphics_view.wheelEvent = wheel_event # Add widget to the user interface - context.add_widget(self._widget) # Start a timer that calls back every 100 ms From 78154f162113310b206a63b0c75c354208e2ce60 Mon Sep 17 00:00:00 2001 From: Florian Vahl Date: Mon, 29 Jan 2024 22:18:26 +0100 Subject: [PATCH 3/6] Update dynamic_stack_decider_visualization/dynamic_stack_decider_visualization/dsd_visualization_plugin.py Co-authored-by: Jan Gutsche <34797331+jaagut@users.noreply.github.com> --- .../dsd_visualization_plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dynamic_stack_decider_visualization/dynamic_stack_decider_visualization/dsd_visualization_plugin.py b/dynamic_stack_decider_visualization/dynamic_stack_decider_visualization/dsd_visualization_plugin.py index 40848fb..c954890 100644 --- a/dynamic_stack_decider_visualization/dynamic_stack_decider_visualization/dsd_visualization_plugin.py +++ b/dynamic_stack_decider_visualization/dynamic_stack_decider_visualization/dsd_visualization_plugin.py @@ -127,7 +127,7 @@ def wheel_event(event): self._widget.auto_fit_graph_check_box.setChecked(False) self._widget.graphics_view.__class__.wheelEvent(self._widget.graphics_view, event) - # Call it as well as the original wheelEvent + # Overwrite the original wheelEvent handler self._widget.graphics_view.wheelEvent = wheel_event # Add widget to the user interface From 1112d7dc90518a6c94bacba4c46ea884cb1eb0e3 Mon Sep 17 00:00:00 2001 From: Florian Vahl Date: Mon, 29 Jan 2024 22:18:49 +0100 Subject: [PATCH 4/6] Update dynamic_stack_decider_visualization/dynamic_stack_decider_visualization/dsd_follower.py Co-authored-by: Jan Gutsche <34797331+jaagut@users.noreply.github.com> --- .../dynamic_stack_decider_visualization/dsd_follower.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dynamic_stack_decider_visualization/dynamic_stack_decider_visualization/dsd_follower.py b/dynamic_stack_decider_visualization/dynamic_stack_decider_visualization/dsd_follower.py index 8bc7fff..9df9749 100644 --- a/dynamic_stack_decider_visualization/dynamic_stack_decider_visualization/dsd_follower.py +++ b/dynamic_stack_decider_visualization/dynamic_stack_decider_visualization/dsd_follower.py @@ -211,9 +211,9 @@ def _stack_to_dotgraph( """ # Sanity check if stack_root is not None: - assert stack_root["type"] == subtree_root["type"], "The stack and the tree do not match" + assert stack_root["type"] == subtree_root["type"], "The stack root type and the tree root type do not match" if stack_root["type"] != "sequence": - assert stack_root["name"] == subtree_root["name"], "The stack and the tree do not match" + assert stack_root["name"] == subtree_root["name"], "The stack root name and the tree root name do not match" # Generate dot node for the root and mark it as active if it is on the stack dot_node = DsdFollower._dot_node_from_tree_element(subtree_root, stack_root) From a3f3c308bb1799ac03f2297ccc16e9db2a07a4f1 Mon Sep 17 00:00:00 2001 From: Florian Vahl Date: Mon, 29 Jan 2024 22:48:16 +0100 Subject: [PATCH 5/6] Fix review comments --- .../dsd_follower.py | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/dynamic_stack_decider_visualization/dynamic_stack_decider_visualization/dsd_follower.py b/dynamic_stack_decider_visualization/dynamic_stack_decider_visualization/dsd_follower.py index 4a22e8c..3ad3ebd 100644 --- a/dynamic_stack_decider_visualization/dynamic_stack_decider_visualization/dsd_follower.py +++ b/dynamic_stack_decider_visualization/dynamic_stack_decider_visualization/dsd_follower.py @@ -33,18 +33,19 @@ def __init__(self, node: Node, debug_topic: str): self._cached_dotgraph: Optional[pydot.Dot] = None # Subscribe to the DSDs tree (latched) + dsd_tree_topic = f"{debug_topic}/dsd_tree" self.tree_sub = self._node.create_subscription( String, - f"{debug_topic}/dsd_tree", + dsd_tree_topic, self._tree_callback, qos_profile=QoSProfile(depth=10, durability=DurabilityPolicy.TRANSIENT_LOCAL), ) - - self._node.get_logger().info(f"Subscribed to {debug_topic}/dsd_tree") + self._node.get_logger().info(f"Subscribed to {dsd_tree_topic}") # Subscribe to the DSDs stack - self.stack_sub = self._node.create_subscription(String, f"{debug_topic}/dsd_stack", self._stack_callback, 10) - self._node.get_logger().info(f"Subscribed to {debug_topic}/dsd_stack") + dsd_stack_topic = f"{debug_topic}/dsd_stack" + self.stack_sub = self._node.create_subscription(String, dsd_stack_topic, self._stack_callback, 10) + self._node.get_logger().info(f"Subscribed to {dsd_stack_topic}") def _tree_callback(self, msg): self._node.get_logger().info("Received tree") @@ -158,9 +159,13 @@ def param_string(params: dict) -> str: # Sanity check if stack_element is not None: - assert stack_element["type"] == tree_element["type"], "The stack and the tree do not match" + assert ( + stack_element["type"] == tree_element["type"] + ), f"The stack and the tree do not match (element type mismatch: {stack_element['type']} vs. {tree_element['type']})" if stack_element["type"] != "sequence": - assert stack_element["name"] == tree_element["name"], "The stack and the tree do not match" + assert ( + stack_element["name"] == tree_element["name"] + ), f"The stack and the tree do not match (element name mismatch: {stack_element['name']} vs. {tree_element['name']})" # Initialize parameters of the dot node we are going to create dot_node_params = { @@ -224,7 +229,7 @@ def _stack_to_dotgraph( if "children" in subtree_root and (stack_root is not None or full_tree): # Go through all children for activating_result, child in subtree_root["children"].items(): - # Get the root of the sub stack if this branch the one which is currently on the stack + # Get the root of the sub stack if this branch of the tree is the one which is currently on the stack sub_stack_root = None if ( stack_root is not None @@ -244,7 +249,7 @@ def _append_debug_data_to_item( self, parent_item: QStandardItem, debug_data: Union[dict, list, int, float, str, bool] ): """ - Append an elements debug_data to a QStandardItem. + Appends debug_data of a given element and its children to a QStandardItem. :type parent_item: python_qt_binding.QtGui.QStandardItem :type debug_data: dict or list or int or float or str or bool @@ -278,7 +283,7 @@ def to_dotgraph(self, full_tree: bool) -> pydot.Dot: if self._cached_dotgraph is not None: return self._cached_dotgraph - self._node.get_logger().info("Generating dotgraph") + self._node.get_logger().debug("Generating dotgraph") # Check if we received any data yet if self.stack is None or self.tree is None: From 05c730b60e95720c5b9c2b2d86d897a607d5e955 Mon Sep 17 00:00:00 2001 From: Florian Vahl Date: Mon, 29 Jan 2024 22:51:13 +0100 Subject: [PATCH 6/6] Fix formatting --- .../dynamic_stack_decider_visualization/dsd_follower.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dynamic_stack_decider_visualization/dynamic_stack_decider_visualization/dsd_follower.py b/dynamic_stack_decider_visualization/dynamic_stack_decider_visualization/dsd_follower.py index b3ec6c9..e77b6f2 100644 --- a/dynamic_stack_decider_visualization/dynamic_stack_decider_visualization/dsd_follower.py +++ b/dynamic_stack_decider_visualization/dynamic_stack_decider_visualization/dsd_follower.py @@ -216,9 +216,13 @@ def _stack_to_dotgraph( """ # Sanity check if stack_root is not None: - assert stack_root["type"] == subtree_root["type"], "The stack root type and the tree root type do not match" + assert ( + stack_root["type"] == subtree_root["type"] + ), f"The stack element type and the tree element type do not match ({stack_root['type']} vs. {subtree_root['type']})" if stack_root["type"] != "sequence": - assert stack_root["name"] == subtree_root["name"], "The stack root name and the tree root name do not match" + assert ( + stack_root["name"] == subtree_root["name"] + ), f"The stack element name and the tree element name do not match ({stack_root['name']} vs. {subtree_root['name']})" # Generate dot node for the root and mark it as active if it is on the stack dot_node = DsdFollower._dot_node_from_tree_element(subtree_root, stack_root)