robokudo.utils.tree

Functions

behavior_iterate_except_type(tree, child_type[, ...])

Generator similar to Behavior.iterate(). But this one doesn't traverse

find_parent_of_type(→ Optional[py_trees.Behaviour])

Traverse the given behaviour up until we either hit the top of the tree or find a node of type parent_type.

find_children_with_name(→ Optional[py_trees.Behaviour])

Iterate() the given composite over its children and return the first child

get_scoped_list_of_names(→ list)

This method can generate behaviour names which represent the structure of the tree.

get_scoped_name(→ str)

setup_with_descendants_rk(tree[, setup_timeout])

Call setup(0) on all children of tree.root

setup_with_descendants_on_behavior(tree[, setup_timeout])

Call setup(0) on all children of tree

fix_parent_relationship_of_childs(behavior)

Iterate top-down over this tree and reset the parent relationship for all childs.

find_root(→ Optional[py_trees.Behaviour])

Find the root of this behavior tree

Module Contents

robokudo.utils.tree.behavior_iterate_except_type(tree: py_trees.Behaviour, child_type, direct_descendants=False, include_tree=False)

Generator similar to Behavior.iterate(). But this one doesn’t traverse nodes of a specific type. It also traverses in a post-order manner like Behavior.iterate(). @param include_tree will control if you want to include ‘tree’ itself in the enumeration, like it is done in Behavior.iterate()

robokudo.utils.tree.find_parent_of_type(behaviour: py_trees.Behaviour, parent_type) py_trees.Behaviour | None

Traverse the given behaviour up until we either hit the top of the tree or find a node of type parent_type. :return: return the first parent with type == parent_type. None otherwise

robokudo.utils.tree.find_children_with_name(composite: py_trees.Composite, name: str, direct_descendants=False) py_trees.Behaviour | None

Iterate() the given composite over its children and return the first child with child.name == name. :return: Found child or None

robokudo.utils.tree.get_scoped_list_of_names(behaviour: py_trees.Behaviour, scoping_behaviour_type) list

This method can generate behaviour names which represent the structure of the tree. For that, we can prefix (or scope) the name of the input behaviour with a scoping behaviour parent. Imagine a tree like this:

Sequence (“Z”)

Sequence (“Y”)

Behaviour (“B”)

Then get_scoped_list(b,Sequence) would return a list of the instances [B,Y,Z]

Returns:

The scoped name like described above

robokudo.utils.tree.get_scoped_name(behaviour: py_trees.Behaviour, scoping_behaviour_type, delimiter='/') str
robokudo.utils.tree.setup_with_descendants_rk(tree: py_trees_ros.trees.BehaviourTree, setup_timeout=0)

Call setup(0) on all children of tree.root :param tree: A py_trees_ros.trees.BehaviourTree which already constains all trees that should be setup’ed during startup. :param setup_timeout: Timeout value that is passed to the setup of each child.

robokudo.utils.tree.setup_with_descendants_on_behavior(tree: py_trees.Behaviour, setup_timeout=0)

Call setup(0) on all children of tree :param tree: A Behaviour, which might also be a composition :param setup_timeout: Timeout value that is passed to the setup of each child.

robokudo.utils.tree.fix_parent_relationship_of_childs(behavior: py_trees.behaviour.Behaviour)

Iterate top-down over this tree and reset the parent relationship for all childs. This may be required if you dynamically assign the same instance of a Behavior Tree node into different parts of the BT or also have the same instance in multiple individual Behavior Trees.

Parameters:

behavior – The behavior to start with. This is typically the root node of the tree you need to “repair”

robokudo.utils.tree.find_root(behavior: py_trees.Behaviour) py_trees.Behaviour | None

Find the root of this behavior tree

Parameters:

behavior

Returns:

A py_trees.Behaviour or None