2013 ICRA Mcko
2013 ICRA Mcko
2013 ICRA Mcko
ym (t)
I. I NTRODUCTION Measurements
Bottom Layer e(t)
0 dt 2dt 3dt 4dt 5dt t
BTs are, however, not the only alternative for Middle Layer Action n Xn (t) ∈ Sn Xn (t) ∈ Fn Xn (t) ∈ Rn
representation, see [21]–[25]. Lastly, we point out that BTs Condition n
Xn (t) ∈ Sn Xn (t) ∈ Fn never
have also been formalized through CSP semantics in [26].
Selector. When a Selector node is enabled, it ticks its B. Action Subsets
children sequentially as long as they continue to return Action nodes rely on three subsets: {Sn , Fn , Rn }, used in
Failure, and until one of them returns Running or Success. If Algorithm 5. Condition nodes rely on two subsets: {Sn , Fn },
the Selector node does not find a running or succeeding child, used in Algorithm 6. We focus on the Action since the
it returns Failure, otherwise it returns Running or Success Condition is simpler. These subsets partition the Action’s
depending on the state of its first non-failing child. state space Xn , where Xn (t) take its values, such that the
Sequence. When a Sequence node is enabled, it ticks following properties hold for Action n and Condition n
its children sequentially as long as they continue to return respectively: Sn ∪Fn ∪Rn ⊇ Xn , and Sn ∪Fn ⊇ Xn . We could
Success, and until one of them returns Running or Failure. If be more restrictive, i.e. Sn ∩ Fn = Sn ∩ Rn = Fn ∩ Rn = ∅.
the Sequence node does not find a running or failing child, However, intersecting subsets allow the use of hysteresis, e.g.
it returns Success, otherwise it returns Running or Failure the threshold for switching from Rn to Sn is not necessarily
depending on the state of its first non-succeeding child. the same as the threshold for switching from Sn to Rn .
Parallel. When a Parallel node is enabled, it ticks all its As an example consider the modular driving BT shown
children sequentially. If the number of succeeding children in Fig. 2, with the corresponding Action subsets portrayed in
is ≥ S, it returns Success. If the number of failing children Fig. 3. A BT being modular means that it can be treated as
is ≥ F , it returns Failure. Otherwise, it returns Running. a stand-alone Action by BTs of higher hierarchy seamlessly.
Decorator. When a Decorator node is enabled, it checks a Modularity is enforced through the logic of the BT (control-
condition on its internal variables, based on which it could flow node placement and subsets definitions). The Root,
tick or not its only child. It applies functions φ1 or φ2 to purposefully omitted in Fig. 2, is always removed before
determine the return state, see Algorithm 11 for the template. composing two BTs to avoid having multiple tick sources.
Action. When an Action node, indexed n, is enabled, it These three Actions, scheduled by the Sequence node,
determines the state value to be returned by checking if try to maintain a proper distance from the next vehicle
its current state space configuration Xn (t) belongs to the using control algorithms γn (Xn (t)) = Un (t). Defining the
Success Sn , Failure Fn or Running Rn subsets. On the third notation return statusaction label
time step , we illustrate the use of
case, it also performs a discrete control step γn : Xn → Un . subsets showing two possible event sequences from the
Condition. When a Condition node is enabled, it behaves perspective of each driver Action (e|n|c): these correspond
like the Action, without the Running subset and control step. to the upper/lower branches, i.e. (se1 →se5 |r1n →sn5 |f1c →sc5 ),
and (se1 → r4e |r1n → f4n |f1c → f4c ) respectively. Qualitatively,
Algorithm 1: Selector Algorithm 2: Sequence both scenarios start with two control steps (r1n , r2n ) executed
1 for i ← 1 to N do 1 for i ← 1 to N do by Normal Driver. On the upper branch, the execution is
2 state ← Tick(child(i)) 2 state ← Tick(child(i)) handed over to Cruise Driver (r3c , r4c ) reaching Success on
3 if state = Running then 3 if state = Running then
4 return Running 4 return Running the fifth control step (sc5 ). On the lower branch, the execution
5 if state = Success then 5 if state = Failure then is handed over to Emergency Driver to take care of an
6 return Success 6 return Failure unexpected situation during two control steps (r3e , r4e ).
7 end 7 end
8 end 8 end
9 return Failure 9 return Success →
2 The function µ : U → X is bijective (one to one correspondence ∀u, x). 3 The barrier will block again if nnow < nreq at any point in time.
VI. C ONTROLLED H YBRID DYNAMICAL S YSTEMS VII. E QUIVALENCE
Following the definitions of [15]–[17]: a CHDS, shown in We show that every CHDS using a specific jump policy
Fig. 5, is an indexed collection of Controlled Dynamical Sys- can be represented with a BT, and every BT composed only
tems (CDS) and a mechanism for switching between them of certain node types can be represented with a CHDS.
whenever the hybrid state satisfies certain conditions and the A. From CHDSs To BTs
control dictates so. More formally, a CHDS H is defined4 as
follows H = (Q, Xq , Uq , Aq , Eq , Iq , Cq , Dq , S0 )q∈Q , with: To prove that any CHDS has an equivalent BT it suffices
to show that the trajectories both systems produce, when
Q discrete state space Q = {qi | i ∈ {1, . . . , |Q|}}
confronted with the same environment (for all possible
Xq continuous state space Xq = {xjq | j ∈ {1, . . . , |Xq |}} environments and initial conditions), are identical. Naturally,
Uq control signal space Uq = {ukq | k ∈ {1, . . . , |Uq |}} a CHDS has continuous dynamics which are impossible to
Aq edge label set Aq = {aqq̄ | q̄ ∈ Nq } mimic using a discrete-time structure like a BT. For this
Nq directed neighborhood of q (q̄ ∈ Nq =⇒ 6 q ∈ Nq̄ ) reason, we define a continuous-time BT as a regular BT
Eq edge set, each edge is Eq,q̄ = (q, q̄, aqq̄ , Gqq̄ , Jqq̄ )q̄∈Nq which has: infinite tick frequency, zero tick propagation time,
q, q̄ initial and final discrete states (q, q̄) ∈ (Q, Nq ) and zero execution time for Actions and Conditions.
aqq̄ edge label connecting (q, q̄) with aqq̄ ∈ Aq Additionally, assuming that the BT initializes Q(t) to the
Gqq̄ edge guard enabled if Xq (t) ∈ Gqq̄ ⊆ Xq initial state of the CHDS, and the CHDS uses a sequential
Jqq̄ state jump sets Xq (t) → Xq̄ (t) ∈ Jqq̄ ⊆ Xq ×Xq̄ prioritized jump policy aj . It is straightforward to check
that for an infinitesimal time window dt, the BT shown
Iq location invariant Xq (t) ∈ Iq ∀t ∈ R, ∀q ∈ Q
in Fig. 6, in continuous-time, produces the same control as
Cq control algorithms Uq (t) = Γq (Xq (t)) the CHDS shown in Fig. 5. Since this holds true for any
Dq system dynamics Ẋq (t) = ∆q (Xq (t), Uq (t)) infinitesimal time window, it follows that the trajectories are
St hybrid state {Q(t), Xq (t), Aq (t), Uq (t)} also identical. More complex jump policies are not covered
S0 initial state {Q(0), Xq (0), Aq (0), Uq (0)} but could possibly be reproduced depending on the case.
Lastly, consider a CHDS where the continuous dynamics
Xq (t) ∈ Iq Xq̄ (t) ∈ Iq̄ are discretized using a finite sampling frequency fCHDS , and
Uq = Γq (Xq ) Uq̄ = Γq̄ (Xq̄ ) a BT which satisfies all the properties of continuous-time BTs
Ẋq = ∆q (Xq , Uq ) Ẋq̄ = ∆q̄ (Xq̄ , Uq̄ ) except for the tick frequency ftick which in this case is finite.
Gqq aqq̄ Jq̄q̄
Gqq̄ Jqq̄ Under the assumption that fCHDS = ftick , and following a
aqq q q̄ aq̄q̄ similar reasoning, it follows that the discretized trajectories
Jq̄q Gq̄q
Jqq aq̄q Gq̄q̄ are equal because they are sampled / executed synchronously.
∅
··· ··· ··· ···
{q ∈ Nq \q̄}{q 0 |q ∈ Nq0 \q̄} {q 0 ∈ Nq̄ \q}{q 0 |q̄ ∈ Nq0 \q}
0
?
Fig. 5. Generic CHDS H, showing two connected states q and q̄.
→ · · · ∀q ∈ Q
Consider a continuous trajectory (q, δq , Xq (t), Uq (t)) as-
δ Forcesuccess
sociated to the discrete state q with a non-negative time
St .Q(t) = q U (t) ← Γq (X(t)) ?
δq (duration of the continuous trajectory), a piecewise con- Ẋ(t) ← ∆q (X(t), U (t))
St .X(t) ∈ Iq
tinuous function Uq (t) : [0, δq ] → Uq , and a continuous · · · ∀q̄ ∈ Nq
→
piecewise differentiable function Xq (t) : [0, δq ] → Xq , such
δ Forcesuccess
that Xq (t) ∈ Iq ∀t ∈ (0, δq ) and ∆(Xq (t), Uq (t)) =
Ẋq (t) ∀t ∈ (0, δq ) except for the points of discontinuity. St .X(t) ∈ Gqq̄ St .Q(t) ← q̄
St .X(t) ← Jqq̄ (X(t))
The trajectory (solution / run) of a CHDS is a (possibly in-
finite) sequence of continuous trajectories chained together: Fig. 6. Equivalent BT to the generic CHDS presented in Fig. 5.
a a
(q 0 , δq0 , Xq0 (t), Uq0 (t)) →0 (q 1 , δq1 , Xq1 (t), Uq1 (t)) →1 · · · ,
such that at the event times where transitions occur t0 , t1 , . . ., This BT mimics the corresponding CHDS as follows: there
defined as: t0 = δq0 , t1 = δq0 + δq1 , t2 = δq0 + δq1 + δq2 , . . ., are |Q| branches departing from the first Selector which
aj
the following inclusions hold for the discrete transitions →: account for the checks that need to be performed in order to
Xqj (tj ) ∈ Gqj qj+1 and (Xqj (tj ), Xqj+1 (tj )) ∈ Jqj qj+1 for determine which discrete state is currently being executed.
all j = 0, 1, . . . , ∞. Where q j is the j-th state q taking The transitions to other discrete states are covered by the
place, to which one associates the symbol aj ≡ aqj qj+1 , that |Nq | branches departing from the second Selector, these
represents the jump policy signal at the j-th state transition. include both the CHDS guards G and the jumps J . The
4I : Q → I ⊆ X , G CHDS-BT equivalence is not unique, to prove it we notice
q q q q q̄ : Q → Gq q̄ ⊆ Xq , Jq q̄ : Q×Xq → Q×Xq̄ ,
∆q : Q × Xq × Uq → Ẋq , Γq : Q × Xq → Uq , Q(t) ∈ Q, Xq (t) ∈ Xq , that any re-ordering of the BT nodes in Fig. 6, that preserves
Aq (t) ∈ Aq , Uq (t) ∈ Uq , St ∈ Q × Xq × Aq × Uq , S0 = S(t0 ). the underlying logic and jump policy, is still a valid BT.
B. From BTs To CHDSs Inside the CHDS discrete states, which correspond to BT
The inclusion of Decorator, Selector∗ , Sequence∗ , and Actions / sub-trees5 (A1 : AN ), we place the corresponding
Parallel nodes precludes the translation because CHDSs do controllers γn presented in Algorithm 5. From this point it is
not support certain features that those nodes bring about. The straightforward to see that under the input / output mindset,
functionality missing from CHDSs to mimic the Selector∗ the CHDS of a BT node primitive can be embedded as an
and Sequence∗ nodes is being able to rewire (on run-time) the Action An in a CHDS of higher hierarchy. Performing this
edges between discrete states; this involves dynamic edges. procedure recursively turns out to be equivalent to translating
The functionality missing from CHDSs to mimic the Parallel the BT to a CHDS starting from the leaves, and following this
node is being able to execute multiple discrete states simulta- embedding procedure recursively until the Root is reached.
neously; this involves multi-valued initial states. Decorators VIII. ROS I MPLEMENTATION
are to be dealt with on a case-by-case basis.
We propose a ROS implementation of the BT framework,
Any BT consisting only of a Root, Selectors, Sequences,
the behavior-trees library, designed abiding by the Google
Actions, and Conditions has an equivalent CHDS representa-
C++ Style Guide with the following compromises:
tion. To show the equivalence we write the CHDS version of
Compatibility with existing ROS libraries, making it fast
a generic Selector / Sequence (with N children), and a Root.
and easy to incorporate into new robotic platforms.
Then, we use the fact that BTs are constructed using these
Simplicity of the code, allowing other programmers to
basic building blocks (node primitives), embedding them one
understand, expand, maintain, and reuse the code.
inside the other, to justify making the following assertion: Efficiency of processing power, providing the complete
finding an equivalent CHDS representation for a set of BT functionality of BTs, using a low amount of resources.
node primitives is a sufficient condition to guarantee that any The implementation consists of three main parts: the
BT built using only this set can be represented with a CHDS. Client, where the BT is held, the Server, where the Action
X1 (t) ∈ F1 X2 (t) ∈ F2 XN−1 (t)∈ FN−1 and Condition algorithms are held, and the Communication,
start A1 A2 ··· AN where the actionlib ROS library provides the connection be-
X1 (t) ∈ S1 X2 (t) ∈ S2
XN (t) ∈ SN tween the first two. In the following paragraphs we describe
S
X1 (t) ∈ R1
X2 (t) ∈ R2
how these parts, represented in Fig. 10, work together.
XN (t) ∈ RN
R
XN (t) ∈ FN Client Communication Server
F
like ours that separate the control algorithms from the Hot Low
∗
Motors Battery ∗
→ →
∗
?
execution logic using clients and servers.
2) For each tick that is sent to traverse the BT, a large Stand Walk
→
∗ Grasp Speak Sit Disable
Up Forward Failed Status Down Motors
number of checks has to be performed over the state
∗ ∗
spaces of the Actions in the tree. Our implementation ? →
overcomes this problem by performing both calcu- Right Hand Left Hand Both Hands Grasp Release Turn Walk
Grasp Grasp Grasp Succeed Ball Around Forward
lations asynchronously, thereby preferring to get a
delayed state update than blocking the tick flow.
Fig. 11. BT representation of the grasping task implemented on the NAO.
6 The callbacks DoneCB, ActiveCB, and FeedbackCB belong to the client. We entirely disregard the automatic plan generation, i.e. Top Layer of Fig. 1.
The callbacks GoalCB, PreemptCB, and ExecuteCB belong to the server.
R EFERENCES
[1] R. Palma, P. A. González-Calero, M. A. Gómez-Martı́n, and
P. P. Gómez-Martı́n, “Extending Case-Based Planning with Behavior
Trees,” in FLAIRS Conference. AAAI Press, 2011.
[2] C.-U. Lim, R. Baumgarten, and S. Colton, “Evolving Behaviour Trees
for the Commercial Game DEFCON,” in Applications of Evolutionary
Computation. Springer, 2010, vol. 6024, pp. 100–110.
(a) Stand (b) Walk (c) Right (d) Left (e) Both (f) Release [3] A. Johansson and P. Dell’Acqua, “Emotional Behavior Trees,” in
Computational Intelligence and Games, 2012 IEEE Conference on.
IEEE, 2012, pp. 355–362.
[4] J. Tremblay, “Understanding and Evaluating Behaviour Trees,” McGill
University, Modelling, Simulation and Design Lab, Tech. Rep., 2012.
[5] S. Delmer, “Behavior Trees for Hierarchical RTS AI,” Diploma Thesis,
Southern Methodist University (SMU), 2012.
[6] G. Flórez-Puga, M. A. Gómez-Martı́n, P. P. Gómez-Martı́n, B. Dı́az-
(g) Stand (h) Walk (i) Right (j) Left (k) Both (l) Failed Agudo, and P. A. González-Calero, “Query-Enabled Behavior Trees,”
Computational Intelligence and AI in Games, IEEE Transactions on,
Fig. 12. Demonstration 1: successful ball grasp depicted in 12(a)–12(f). vol. 1, no. 4, pp. 298–308, 2009.
Demonstration 2: failed bottle grasp depicted in 12(g)–12(l). [7] N. Yatapanage, K. Winter, and S. Zafar, “Slicing Behavior Tree
Models for Verification,” in Theoretical Computer Science, ser. IFIP
Advances in Information and Communication Technology. Springer,
2010, vol. 323, pp. 125–139.
X. C ONCLUSIONS [8] A. Shoulson, F. M. Garcia, M. Jones, R. Mead, and N. I. Badler,
“Parameterizing Behavior Trees,” in Motion in Games, ser. Lecture
We presented an algorithmic BT framework which is Notes in Computer Science. Springer, 2011, vol. 7060, pp. 144–155.
substantially more accurate and compact than previous de- [9] R. Colvin, L. Grunske, and K. Winter, “Probabilistic Timed Behavior
scriptions. We provided equivalence notions between BTs Trees,” in Integrated Formal Methods, ser. Lecture Notes in Computer
Science. Springer, 2007, vol. 4591, pp. 156–175.
and CHDSs which gave us insight about the advantages of [10] M. Cutumisu and D. Szafron, “An Architecture for Game Behavior
each framework: using BTs we lose the ability to be in a AI: Behavior Multi-Queues,” in AIIDE. The AAAI Press, 2009.
certain state, but we achieve modularity. A BT is modular if [11] D. Perez, M. Nicolau, M. O’Neill, and A. Brabazon, “Evolving
Behaviour Trees for the Mario AI Competition Using Grammatical
its control-flow nodes and the subsets are laid out in such a Evolution,” in Applications of Evolutionary Computation, ser. Lecture
way that the goal represented succeeds or fails in finite time, Notes in Computer Science. Springer, 2011, vol. 6624, pp. 123–132.
and its Root receives Running for all intermediate states. [12] D. Becroft, J. Bassett, A. Mejı́a, C. Rich, and C. L. Sidner, “AIPaint:
A Sketch-Based Behavior Tree Authoring Tool,” in AIIDE, 2011.
We introduced the Action and Condition subsets, which [13] P. Ögren, “Increasing Modularity of UAV Control Systems using
allowed us to formalize and motivate two extensions to Computer Game Behavior Trees,” in AIAA Guidance, Navigation, and
the basic BT functionality, thereby avoiding the use of ad- Control Conference. AIAA, 2012.
[14] J. A. Bondy and U. S. R. Murty, Graph Theory with Applications.
hoc solutions. The robotic platform tests and theoretical Macmillan London, 1976, vol. 290.
analysis allowed us to conclude that BTs can replace certain [15] A. J. van der Schaft and J. M. Schumacher, An Introduction to Hybrid
CHDSs without losing accuracy, descriptive power, or human Dynamical Systems. Springer, 2000, vol. 251.
[16] M. S. Branicky, “Introduction to Hybrid Systems,” in Handbook of
readability. Moreover, BTs have a larger set of representable Networked and Embedded Control Systems, ser. Control Engineering.
plans because nodes such as the Parallel, Selector∗ , or Se- Springer, 2005, pp. 91–116.
quence∗ do not have a corresponding CHDS representation. [17] M. Branicky, “Studies in Hybrid Systems: Modeling, Analysis, and
Control,” Ph.D. dissertation, Cambridge, MA, USA, 1995.
While not explicitly demonstrated here, we believe that the [18] Willow Garage. (2012) Robot Operating System (ROS). Groovy.
flexibility and modularity of BTs, make them a good candi- [Online]. Available: http://www.ros.org/wiki/
date for representing Middle Layer plans that are created and [19] M. Colledanchise, A. Marzinotto, and P. Ögren, “Performance Analy-
sis of Stochastic Behavior Trees,” in Robotics and Automation (ICRA),
maintained automatically by high-level AI algorithms. We 2014 IEEE International Conference on, June 2014.
acknowledge that the current demonstration merely shows [20] J. A. D. Bagnell, F. Cavalcanti, L. Cui, T. Galluzzo, M. Hebert,
open-loop action scheduling through BTs, and we plan to M. Kazemi, M. Klingensmith, J. Libby, T. Y. Liu, N. Pollard,
M. Pivtoraiko, J.-S. Valois, and R. Zhu, “An Integrated System
address this by upgrading the system to encompass closed- for Autonomous Robotics Manipulation,” in IEEE/RSJ International
loop controllers. Lastly, we plan to analyze the relation Conference on Intelligent Robots and Systems, 2012, pp. 2955–2962.
between our framework parameters and its functionality. [21] R. A. Brooks, “A Robust Layered Control System for a Mobile Robot,”
IEEE Journal of Robotics and Automation, vol. 2, 1986.
[22] R. C. Arkin, An Behavior-based Robotics. Cambridge, MA, USA:
ACKNOWLEDGMENT MIT Press, 1998.
This work has been supported by the Swedish Research [23] J. Rosenblatt, “DAMN: A Distributed Architecture for Mobile Navi-
gation,” Ph.D. dissertation, Robotics Institute, Carnegie Mellon Uni-
Council (VR) and the European Union Project RECONFIG, versity, Pittsburgh, PA, 1997.
www.reconfig.eu (FP7-ICT-2011-9, Project Number: [24] J. Bohren, R. B. Rusu, E. G. Jones, E. Marder-Eppstein, C. Pantofaru,
600825), the authors gratefully acknowledge the support. M. Wise, L. Mosenlechner, W. Meeussen, and S. Holzer, “Towards
Autonomous Robotic Butlers: Lessons Learned with the PR2,” in
We also thank: Isak Tjernberg for sharing his experience Robotics and Automation (ICRA), 2011 IEEE International Conference
with the NAO platform, Xavi Gratal for providing his pro- on. IEEE, 2011, pp. 5568–5575.
gramming expertise, and Francisco Viña for sharing his ROS [25] H. Nguyen, M. Ciocarlie, K. Hsiao, and C. Kemp, “ROS Commander:
Flexible Behavior Creation for Home Robots,” in ICRA, 2013.
knowledge. Lastly we thank: Danica Kragic, Alessandro [26] R. J. Colvin and I. J. Hayes, “A semantics for Behavior Trees using
Pieropan, Johannes Stork, Jana Tumova, and Yuquan Wang CSP with specification commands,” Science of Computer Program-
for the useful critical reviews provided for this paper. ming, vol. 76, no. 10, pp. 891–914, 2011.