Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backend] ensure tree modifications are published with an updated timestamps #100

Merged
merged 2 commits into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog

Forthcoming
-----------
* [backend] ensure tree modifications are published with an updated timestamp, `#100 <https://github.com/splintered-reality/py_trees_ros/pull/100>`_

1.1.2 (2019-08-10)
------------------
Expand Down
13 changes: 12 additions & 1 deletion py_trees_ros/trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def _setup_publishers(self):
# set a handler to publish future modifications whenever the tree is modified
# (e.g. pruned). The tree_update_handler method is in the base class, set this
# to the callback function here.
self.tree_update_handler = self._publish_serialised_tree
self.tree_update_handler = self._on_tree_update_handler

def tick_tock(
self,
Expand Down Expand Up @@ -239,6 +239,17 @@ def _tick_tock_timer_callback(
else:
self.timer.cancel()

def _on_tree_update_handler(self):
"""
Whenever there has been a modification to the tree (insertion/pruning), publish
the snapshot.
"""
# only worth notifying once we've actually commenced
if self.statistics is not None:
rclpy_start_time = rclpy.clock.Clock().now()
self.statistics.stamp = rclpy_start_time.to_msg()
self._publish_serialised_tree()

def _statistics_pre_tick_handler(self, tree: py_trees.trees.BehaviourTree):
"""
Pre-tick handler that resets the statistics and starts the clock.
Expand Down