1 minute read

Summary

In the previous weeks, I achieved a working parser, that given Python actions and an XML, generates a self-contained XML.

Later, I implemented a translator to generate an executable tree, but it had still limited element support. This week, I expanded the support to include the majority of the Sequences and Fallbacks available in BT.cpp.

Development

My translator works by:

  • Reading the different actions of the XML and adding them to an action dictionary.
  • Reading the first element of the BehaviorTree section of the XML (which is usually a sequence), instantiating its appropriate class, and then populating it with its children recursively according to the tree.
  • Using this root action, an executable tree can be created. This works because the function that traverses the tree takes care of adding to all the blocks all the children. As per BT definition, a node can only have one parent, the process is always complete.

As some of the composites (Sequences and Fallbacks) and decorators don’t work the same in both libraries, a node-by-node adaptation is needed. This week I successfully adapted all the composites. The goal for next week is the complete support of all the nodes and start a ROS 2 package.

factory = {
    "Sequence": py_trees.composites.Sequence,
    "ReactiveSequence": ReactiveSequence,
    "SequenceWithMemory": SequenceWithMemory,
    "Fallback": py_trees.composites.Selector,
    "ReactiveFallback": ReactiveFallback,
    "Inverter": py_trees.decorators.Inverter,
    "ForceSuccess": py_trees.decorators.FailureIsSuccess,
    "ForceFailure": py_trees.decorators.SuccessIsFailure,
    "Repeat": py_trees.decorators.Repeat,
    "RetryUntilSuccessful": py_trees.decorators.Retry,
    "KeepRunningUntilFailure": py_trees.decorators.SuccessIsRunning,
    "RunOnce": py_trees.decorators.OneShot,
    "Delay": Delay
}

This is the class dictionary used to instantiate the appropriate classes when needed.

References

BehaviorTrees