refine_plan.models.behaviour_tree

A very lightweight set of classes for BTs.

This is effectively a BT data structure which allows us to write out to a BT.cpp XML file recursively. I don’t want the heavyweight baggage of pytree etc.

Author: Charlie Street Owner: Charlie Street

Module Contents

Classes

BTNode

Base class for individual BT nodes.

ActionNode

Node class for BT action nodes.

ConditionNode

Node class for BT condition nodes.

CompositeNode

A class for BT composite nodes (sequence/fallback).

SequenceNode

Subclass of CompositeNode for sequence nodes.

FallbackNode

Subclass of CompositeNode for fallback nodes.

BehaviourTree

Class for a complete behaviour tree.

class refine_plan.models.behaviour_tree.BTNode

Bases: object

Base class for individual BT nodes.

abstract to_BT_XML()

Outputs a string containing the BT.cpp XML for this node.

Returns:

The BT XML for this node as a string

class refine_plan.models.behaviour_tree.ActionNode(name)

Bases: BTNode

Node class for BT action nodes.

_name

The name of the action being executed.

get_name()

Getter for self._name.

Returns:

The action name

to_BT_XML()

Generates the BT.cpp XML string for the action node.

Returns:

The BT.cpp XML for the action node

tick_at_state(state)

Computes node return value if ticked in a given state.

This function ignores any node memory, and should only be used to check correspondence with a Markov policy.

Parameters:

state – The state to check

Returns:

The return value of this node being ticked (action name)

class refine_plan.models.behaviour_tree.ConditionNode(name, cond)

Bases: BTNode

Node class for BT condition nodes.

_name

The name of the condition node

_cond

The condition which the node checks

get_name()

Getter for self._name.

Returns:

The condition node name

get_cond()

Getter for self._cond.

Returns:

The condition being checked

to_BT_XML()

Generates the BT.cpp XML string for the condition node.

Returns:

The BT.cpp XML for the condition node

tick_at_state(state)

Computes node return value if ticked in a given state.

This function ignores any node memory, and should only be used to check correspondence with a Markov policy.

Parameters:

state – The state to check

Returns:

The return value of this node being ticked (True or False)

class refine_plan.models.behaviour_tree.CompositeNode(*children)

Bases: BTNode

A class for BT composite nodes (sequence/fallback).

This class currently represents synchronous composite nodes, i.e. composite with memory nodes.

_children

The child nodes

add_child(child)

Add a new child to the composite node.

Parameters:

child – The new child

Raises:

invalid_child_exception – Raised if a child is not a BT node

abstract to_BT_XML()

Generates the BT.cpp XML string for the composite node.

Returns:

The BT.cpp XML string for the composite node

class refine_plan.models.behaviour_tree.SequenceNode(*children)

Bases: CompositeNode

Subclass of CompositeNode for sequence nodes.

Same as superclass.
to_BT_XML()

Generates the BT.cpp XML string for the sequence node.

Returns:

The BT.cpp XML for the sequence node

tick_at_state(state)

Computes node return value if ticked in a given state.

This function ignores any node memory, and should only be used to check correspondence with a Markov policy.

Parameters:

state – The state to check

Returns:

The return value of this node being ticked

class refine_plan.models.behaviour_tree.FallbackNode(*children)

Bases: CompositeNode

Subclass of CompositeNode for fallback nodes.

Same as superclass.
to_BT_XML()

Generates the BT.cpp XML string for the fallback node.

Returns:

The BT.cpp XML for the fallback node

tick_at_state(state)

Computes node return value if ticked in a given state.

This function ignores any node memory, and should only be used to check correspondence with a Markov policy.

This is because it won’t work if we have two actions in sequence… The convert_policy functionality ensures this will never happen.

Parameters:

state – The state to check

Returns:

The return value of this node being ticked

class refine_plan.models.behaviour_tree.BehaviourTree(root_node)

Bases: object

Class for a complete behaviour tree.

This class just enforces a root node and adds the outer layers on the BT.cpp XML file.

_root_node

A root BTNode

get_root_node()

Getter for self._root_node.

Returns:

The root node of the BT

to_BT_XML(out_file=None)

Produces the BT.cpp XML file for the BT.

Parameters:

out_file – Optional. If specified, will write the BT XML string to file

Returns:

The BT.cpp XML

tick_at_state(state)

Computes node return value if ticked in a given state.

This function ignores any node memory, and should only be used to check correspondence with a Markov policy.

This is because it won’t work if we have two actions in sequence in the fallback. The convert_policy functionality ensures this will never happen.

Parameters:

state – The state to check

Returns:

The return value of this node being ticked