Skip to content

Commit

Permalink
[infra] ascii->unicode updates
Browse files Browse the repository at this point in the history
  • Loading branch information
stonier committed Apr 28, 2019
1 parent 0d7947f commit 32f0a73
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ encoding//py_trees_ros/blackboard.py=utf-8
encoding//py_trees_ros/exceptions.py=utf-8
encoding//py_trees_ros/mock/actions.py=utf-8
encoding//py_trees_ros/mock/dock.py=utf-8
encoding//py_trees_ros/programs/blackboard_watcher.py=utf-8
encoding//py_trees_ros/programs/tree_watcher.py=utf-8
encoding//py_trees_ros/subscribers.py=utf-8
encoding//py_trees_ros/trees.py=utf-8
encoding//tests/test_action_client.py=utf-8
20 changes: 10 additions & 10 deletions py_trees_ros/programs/tree_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
:prog: py-trees-tree-watcher
Command line utility to interact with a running
:class:`~py_trees_ros.trees.BehaviourTree` instance. Print a static ascii
art view of the tree, view snapshots of the tree and tick statistics as
a stream or display the dot graph of the tree.
:class:`~py_trees_ros.trees.BehaviourTree` instance. Print the tree structure
or a live snapshot of the tree state as unicode art on your console,
view tick statistics as a stream or display the tree as a dot graph.
.. image:: images/tree-watcher.gif
Expand All @@ -40,12 +40,12 @@

def description(formatted_for_sphinx):
short = "Open up a window onto the behaviour tree!\n"
long = ("\nPrint static or dynamic (snapshot) ascii art views of the tree on the console\n"
long = ("\nPrint static or dynamic (snapshot) unicode art views of the tree on the console\n"
"or render a dot graph (static view only). Use the namespace argument to select\n"
"from trees when there are multiple available.\n"
)
examples = [
"", "--ascii-tree", "--dot-tree", "--namespace=foo --ascii-tree"
"", "--unicode-tree", "--dot-tree", "--namespace=foo --unicode-tree"
]
script_name = "py-trees-tree-watcher"

Expand Down Expand Up @@ -93,23 +93,23 @@ def command_line_argument_parser(formatted_for_sphinx=True):
parser.add_argument('-n', '--namespace', nargs='?', default=None, help='namespace of pytree communications (if there should be more than one tree active)')
group = parser.add_mutually_exclusive_group()
group.add_argument(
'-s', '--ascii-snapshot',
'-s', '--snapshot',
dest='viewing_mode',
action='store_const',
const=py_trees_ros.trees.WatcherMode.ASCII_SNAPSHOT,
help='print an ascii snapshot of the tree state')
help='print a live snapshot of the tree state as unicode art on your console')
group.add_argument(
'-a', '--ascii-tree',
'-t', '--tree',
dest='viewing_mode',
action='store_const',
const=py_trees_ros.trees.WatcherMode.ASCII_TREE,
help='print an ascii representation of the tree structure')
help='print the tree structure as unicode art on your console')
group.add_argument(
'-d', '--dot-tree',
dest='viewing_mode',
action='store_const',
const=py_trees_ros.trees.WatcherMode.DOT_TREE,
help='print a dot representation of the tree structure')
help='render the tree structure as a dot graph')
return parser


Expand Down
16 changes: 8 additions & 8 deletions py_trees_ros/trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ class BehaviourTree(py_trees.trees.BehaviourTree):
Args:
root (:class:`~py_trees.behaviour.Behaviour`): root node of the tree
ascii_tree_debug (:obj:`bool`, optional): print to console the visited ascii tree after every tick
unicode_tree_debug (:obj:`bool`, optional): print to console the visited ascii tree after every tick
Raises:
AssertionError: if incoming root variable is not the correct type
"""
def __init__(self,
root,
ascii_tree_debug=False):
unicode_tree_debug=False):
super(BehaviourTree, self).__init__(root)
self.snapshot_visitor = py_trees.visitors.SnapshotVisitor()
if ascii_tree_debug:
if unicode_tree_debug:
self.add_post_tick_handler(
lambda tree: self._ascii_tree_post_tick_handler(self.snapshot_visitor, tree)
lambda tree: self._unicode_tree_post_tick_handler(self.snapshot_visitor, tree)
)
self.winds_of_change_visitor = py_trees.visitors.WindsOfChangeVisitor()
self.visitors.append(self.snapshot_visitor)
Expand Down Expand Up @@ -327,10 +327,10 @@ def _publish_serialised_tree(self):
tree_message.behaviours.append(msg)
self.publishers.snapshots.publish(tree_message)

def _ascii_tree_post_tick_handler(self, snapshot_visitor, tree):
def _unicode_tree_post_tick_handler(self, snapshot_visitor, tree):
print(
"\n" +
py_trees.display.ascii_tree(
py_trees.display.unicode_tree(
tree.root,
visited=snapshot_visitor.visited,
previously_visited=tree.snapshot_visitor.previously_visited
Expand Down Expand Up @@ -461,7 +461,7 @@ def deserialise_tree_recursively(msg):
####################
if self.viewing_mode == WatcherMode.ASCII_SNAPSHOT:
console.banner("Tick {}".format(msg.statistics.count))
print(py_trees.display.ascii_tree(
print(py_trees.display.unicode_tree(
root=root,
visited=self.snapshot_visitor.visited,
previously_visited=self.snapshot_visitor.previously_visited
Expand Down Expand Up @@ -494,7 +494,7 @@ def deserialise_tree_recursively(msg):
####################
elif self.viewing_mode == WatcherMode.ASCII_TREE:
print("")
print(py_trees.display.ascii_tree(
print(py_trees.display.unicode_tree(
root=root,
show_status=True,
visited=self.snapshot_visitor.visited,
Expand Down
12 changes: 6 additions & 6 deletions tests/test_action_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ def create_action_client():
return behaviour


def print_ascii_tree(tree):
def print_unicode_tree(tree):
print(
"\n" +
py_trees.display.ascii_tree(
py_trees.display.unicode_tree(
tree.root,
visited=tree.snapshot_visitor.visited,
previously_visited=tree.snapshot_visitor.previously_visited
Expand Down Expand Up @@ -92,7 +92,7 @@ def test_success(self):
root = create_action_client()
tree = py_trees_ros.trees.BehaviourTree(
root=root,
ascii_tree_debug=False
unicode_tree_debug=False
)
tree.setup()

Expand Down Expand Up @@ -141,7 +141,7 @@ def test_priority_interrupt(self):
)
root = py_trees.composites.Selector()
root.add_children([success_eventually, action_client])
tree = py_trees_ros.trees.BehaviourTree(root=root, ascii_tree_debug=False)
tree = py_trees_ros.trees.BehaviourTree(root=root, unicode_tree_debug=False)
tree.setup()

executor = rclpy.executors.MultiThreadedExecutor(num_threads=4)
Expand All @@ -151,7 +151,7 @@ def test_priority_interrupt(self):
assert_banner()

tree.tick()
print_ascii_tree(tree)
print_unicode_tree(tree)

assert_details("action_client.status", "RUNNING", root.status)
self.assertEqual(action_client.status, py_trees.common.Status.RUNNING)
Expand All @@ -163,7 +163,7 @@ def test_priority_interrupt(self):

while tree.count < number_of_iterations and "cancelled" not in action_client.feedback_message:
executor.spin_once(timeout_sec=0.1)
print_ascii_tree(tree)
print_unicode_tree(tree)
assert_details("action_client.status", "INVALID", action_client.status)
self.assertEqual(action_client.status, py_trees.common.Status.INVALID)

Expand Down

0 comments on commit 32f0a73

Please sign in to comment.