Behavior Trees (Thu Oct 31, lect 18) | previous | next | slides |

Behavior trees are a better way to create interesting Robot behavior

Logistics

  • Discuss lab situation
  • Fiducial Follow was the last PA!
  • Quiz on Wednesday
    1. 11 short answer questions.
    2. 9 Points each.
    3. It will count for 5% of the grade
  • Standups
    1. 3 minutes each
    2. Achievements this week
    3. Plans next week
    4. Blockers
  1. dynamaze
  2. cargo
  3. dashboard
  4. sort
  5. typist
  6. race
  7. convoy
  8. autopilot
  9. bowling
  10. guard

Introduction to Behavior Trees

  • Some similarity to FSM, however…
  • BTs are specifically trees, with one root and leaves
  • BTs have different kinds of nodes with very different semantics
  • The leaves represent the actual control actions
  • All the other nodes are part of the control logic

py_trees

  • This example uses this library: py_trees
  • As we are using ROS1, you need to use py_trees 0.7 of this library
  • Latest version is not compatible with the current version of ROS
  • CampusRover has developed our own version of behavior trees
  • It is conceptually the same, but the details are totally different
  • Adam Ring will present it in a few minutes

Behavior Tree Execution

  • “Tick” oriented control flow
  • A tree is “ticked”, which “ticks” the top node
  • Each node type has specific semantics about what happens on a tick
  • Nodes can return one of: SUCCESS, FAILURE, RUNNING

Behavior Tree Returns

  • SUCCESS: The action is complete and was successfull
  • FAILURE: The action is done but failed
  • RUNNING: The action is incomplete and needs to be ticked again

  • You will discover that the semantics of these are a little subtler than they seem initially

Behavior Nodes - Example

  • Behavior nodes are the leaf nodes.
  • They execute code which actually “do something” to outside of the tree
  • They could cause an action or read a sensor or anything else.
  • Simple example: blink light once would:
    1. On Update: Tell the hardware to turn the light on and off; Return SUCCESS (because it always works.)
  • Simple example: turn light on with a parameter: n seconds, would:
    1. On Init: set initial time <- current time; turn the light on
    2. On Update: if current time > initial time + n: turn off the light; return SUCCESS; else return RUNNING

Behavior Nodes

  • Life Cycle of a behavior node
  • Setup (optional): one time initiatlization of state when first instantiated
  • Initialize (optional): called each time that the node is entered anew (i.e. when its not RUNNING)
  • Update (required): called each time the node is ticked
  • Terminate (optional): called whenever the node goes to not RUNNING

Composites

  • The non-leaf nodes are all known as composites
  • Generally the leftmost leaf is ticked first
  • Depending on Composite type and returned status of that node, different next nodes may be ticked
  • Core (traditional) set of Composites are: Sequence, Selector, Parallel
  • But depending on the library, there may be other variations (which are all extensions of this set.

Sequence

  • Most common
  • Tick from left to right
  • Each SUCCESS result leads to the next node
  • Any non-SUCCESS ends the sequence and returns that same status up the chain

Selector

  • Also very useful, kind of the reverse
  • Tick from left to right as long as the child returns FAILURE
  • The first non-failure makes the whole Composit3e return

Parallel

  • Returns FAILURE if any child returns FAILURE
  • Otherwise keeps ticking all the children
  • Depending on policy it will return when one or all the children have returned SUCCESS

Adam Ring’s Package

  • Lets look at some code!

Papers and articles relevant to today

Thank you. Questions?  (random Image from picsum.photos)