robokudo.display

Visualization utilities for behavior trees in RoboKudo.

This module provides functionality to visualize behavior trees using dot graphs. It is adapted from py_trees and enhanced with RoboKudo-specific features like timing information for annotators.

The module supports:

  • Generating dot graphs from behavior trees

  • Rendering trees to various output formats (dot, png)

  • Adding timing information for annotators

  • Customizing node appearance based on node type and status

Functions

generate_pydot_graph(root, visibility_level[, ...])

Generate a pydot graph representation of a behavior tree.

stringify_dot_tree(root)

Generate dot tree graphs and return a string representation

render_dot_tree(root[, visibility_level, ...])

Render the dot tree to .dot, .svg, .png files in the current

write_timing_info_to_csv(filename_wo_extension, ...)

Write timing information for annotators to a CSV file.

Module Contents

robokudo.display.generate_pydot_graph(root, visibility_level, collapse_decorators=False)

Generate a pydot graph representation of a behavior tree.

Creates a visual representation of a behavior tree using pydot. The graph includes:

  • Nodes for each behavior tree component

  • Edges showing parent-child relationships

  • Visual attributes (shape, color) based on node type and status

  • Timing information for annotator nodes

The graph can be customized by:

  • Collapsing subtrees based on visibility level

  • Collapsing decorator nodes

  • Using different visual attributes for different node types

  • Including timing information for annotators

Parameters:
  • root (Behaviour) – The root node of the tree or subtree to visualize

  • visibility_level (VisibilityLevel) – Level at which to collapse subtrees

  • collapse_decorators (bool) – Whether to collapse decorator nodes, defaults to False

Returns:

Tuple of (pydot graph object, timing information dictionary)

Return type:

tuple(pydot.Dot, dict)

robokudo.display.stringify_dot_tree(root)

Generate dot tree graphs and return a string representation of the dot graph.

Parameters:

root (Behaviour) – The root of a tree, or subtree

Returns:

Dot graph as a string

Return type:

str

robokudo.display.render_dot_tree(root, visibility_level=common.VisibilityLevel.DETAIL, collapse_decorators=False, name=None, threadpool_executor: concurrent.futures.ThreadPoolExecutor = None, path_prefix=None)

Render the dot tree to .dot, .svg, .png files in the current working directory. These will be named with the root behaviour name.

Parameters:
  • root (Behaviour) – The root of a tree, or subtree

  • visibility_level (VisibilityLevel) – Collapse subtrees at or under this level

  • collapse_decorators (bool) – Only show the decorator (not the child)

  • name (str, optional) – Name to use for the created files (defaults to the root behaviour name)

  • threadpool_executor (concurrent.futures.ThreadPoolExecutor, optional) – ThreadPoolExecutor for file writing

  • path_prefix (str, optional) – String to be put before the filename

Example:

Render a simple tree to dot/svg/png file:

root = py_trees.composites.Sequence("Sequence")
for job in ["Action 1", "Action 2", "Action 3"]:
    success_after_two = py_trees.behaviours.Count(name=job,
                                                  fail_until=0,
                                                  running_until=1,
                                                  success_until=10)
    root.add_child(success_after_two)
py_trees.display.render_dot_tree(root)

Tip

A good practice is to provide a command line argument for optional rendering of a program so users can quickly visualise what tree the program will execute.

robokudo.display.write_timing_info_to_csv(filename_wo_extension, timing_info_dict)

Write timing information for annotators to a CSV file.

Creates a CSV file containing the runtime information for each annotator in the behavior tree. The CSV has two columns: AnnotatorName and Runtime.

Parameters:
  • filename_wo_extension (str) – Base filename without extension to write the CSV to

  • timing_info_dict (dict) – Dictionary mapping annotator names to their runtime in seconds