Skip to content

Commit

Permalink
[trees] make use of the new DisplaySnapshotVisitor (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
stonier committed Sep 18, 2019
1 parent 4e01454 commit ec2be7b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ py_trees*.tar.gz
py_trees_ros/resources/*.py
html

scripts
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Forthcoming
-----------
* [backend] ensure tree modifications are published with an updated timestamp, `#100 <https://github.com/splintered-reality/py_trees_ros/pull/100>`_
* [trees] ros parameterisation of the setup timeout, `#101 <https://github.com/splintered-reality/py_trees_ros/pull/101>`_
* [trees] make use of the new `DisplaySnapshotVisitor`, `#102 <https://github.com/splintered-reality/py_trees_ros/pull/102>`_

1.1.2 (2019-08-10)
------------------
Expand Down
28 changes: 6 additions & 22 deletions py_trees_ros/trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import tempfile
import time
import unique_identifier_msgs.msg as unique_identifier_msgs
import uuid

from . import blackboard
from . import conversions
Expand Down Expand Up @@ -77,14 +76,11 @@ def __init__(self,
root,
unicode_tree_debug=False):
super(BehaviourTree, self).__init__(root)
self.snapshot_visitor = py_trees.visitors.SnapshotVisitor()
if unicode_tree_debug:
self.add_post_tick_handler(
lambda tree: self._unicode_tree_post_tick_handler(self.snapshot_visitor, tree)
)
self.winds_of_change_visitor = py_trees.visitors.WindsOfChangeVisitor()
self.snapshot_visitor = py_trees.visitors.DisplaySnapshotVisitor()
else:
self.snapshot_visitor = py_trees.visitors.SnapshotVisitor()
self.visitors.append(self.snapshot_visitor)
self.visitors.append(self.winds_of_change_visitor)

self.statistics = None
self.tick_start_time = None
Expand Down Expand Up @@ -204,8 +200,7 @@ def tick_tock(
period_ms,
number_of_iterations=py_trees.trees.CONTINUOUS_TICK_TOCK,
pre_tick_handler=None,
post_tick_handler=None
):
post_tick_handler=None):
"""
Tick continuously at the period specified.
Expand Down Expand Up @@ -256,8 +251,7 @@ def _tick_tock_timer_callback(
period_ms,
number_of_iterations,
pre_tick_handler,
post_tick_handler
):
post_tick_handler):
"""
Tick tock callback passed to the timer to be periodically triggered.
Expand Down Expand Up @@ -356,7 +350,7 @@ def _on_change_post_tick_handler(self, tree: py_trees.trees.BehaviourTree):
return

# if there's been a change, serialise, publish and log
if self.winds_of_change_visitor.changed:
if self.snapshot_visitor.changed:
self._publish_serialised_tree()
# with self.lock:
# if not self._bag_closed:
Expand All @@ -378,16 +372,6 @@ def _publish_serialised_tree(self):
tree_message.behaviours.append(msg)
self.publishers.snapshots.publish(tree_message)

def _unicode_tree_post_tick_handler(self, snapshot_visitor, tree):
print(
"\n" +
py_trees.display.unicode_tree(
tree.root,
visited=snapshot_visitor.visited,
previously_visited=tree.snapshot_visitor.previously_visited
)
)

def _cleanup(self):
with self.lock:
# self.bag.close()
Expand Down

0 comments on commit ec2be7b

Please sign in to comment.