@@ -92,15 +92,17 @@ class SequenceNode(ControlNode):
92
92
Executes child nodes in sequence until one fails or all succeed.
93
93
94
94
Returns:
95
- - Returns FAILURE if any child returns FAILURE
96
- - Returns SUCCESS when all children have succeeded
97
- - Returns RUNNING when a child is still running or when moving to the next child
95
+ - Returns FAILURE if any child returns FAILURE
96
+ - Returns SUCCESS when all children have succeeded
97
+ - Returns RUNNING when a child is still running or when moving to the next child
98
98
99
99
Example:
100
- <Sequence>
101
- <Action1 />
102
- <Action2 />
103
- </Sequence>
100
+ .. code-block:: xml
101
+
102
+ <Sequence>
103
+ <Action1 />
104
+ <Action2 />
105
+ </Sequence>
104
106
"""
105
107
106
108
def __init__ (self , name ):
@@ -131,15 +133,17 @@ class SelectorNode(ControlNode):
131
133
Executes child nodes in sequence until one succeeds or all fail.
132
134
133
135
Returns:
134
- - Returns SUCCESS if any child returns SUCCESS
135
- - Returns FAILURE when all children have failed
136
- - Returns RUNNING when a child is still running or when moving to the next child
136
+ - Returns SUCCESS if any child returns SUCCESS
137
+ - Returns FAILURE when all children have failed
138
+ - Returns RUNNING when a child is still running or when moving to the next child
137
139
138
- Example:
139
- <Selector>
140
- <Action1 />
141
- <Action2 />
142
- </Selector>
140
+ Examples:
141
+ .. code-block:: xml
142
+
143
+ <Selector>
144
+ <Action1 />
145
+ <Action2 />
146
+ </Selector>
143
147
"""
144
148
145
149
def __init__ (self , name ):
@@ -170,17 +174,19 @@ class WhileDoElseNode(ControlNode):
170
174
Conditional execution node with three parts: condition, do, and optional else.
171
175
172
176
Returns:
173
- - First executes the condition node (child[0])
174
- - If condition succeeds, executes do node (child[1]) and returns RUNNING
175
- - If condition fails, executes else node (child[2]) if present and returns result of else node
176
- - If condition fails and there is no else node, returns SUCCESS
177
+ First executes the condition node (child[0])
178
+ If condition succeeds, executes do node (child[1]) and returns RUNNING
179
+ If condition fails, executes else node (child[2]) if present and returns result of else node
180
+ If condition fails and there is no else node, returns SUCCESS
177
181
178
182
Example:
179
- <WhileDoElse>
180
- <Condition />
181
- <Do />
182
- <Else />
183
- </WhileDoElse>
183
+ .. code-block:: xml
184
+
185
+ <WhileDoElse>
186
+ <Condition />
187
+ <Do />
188
+ <Else />
189
+ </WhileDoElse>
184
190
"""
185
191
186
192
def __init__ (self , name ):
@@ -236,11 +242,13 @@ class SleepNode(ActionNode):
236
242
Sleep node that sleeps for a specified duration.
237
243
238
244
Returns:
239
- - Returns SUCCESS after the specified duration has passed
240
- - Returns RUNNING if the duration has not yet passed
245
+ Returns SUCCESS after the specified duration has passed
246
+ Returns RUNNING if the duration has not yet passed
241
247
242
248
Example:
243
- <Sleep sec="1.5" />
249
+ .. code-block:: xml
250
+
251
+ <Sleep sec="1.5" />
244
252
"""
245
253
246
254
def __init__ (self , name , duration ):
@@ -261,10 +269,12 @@ class EchoNode(ActionNode):
261
269
Echo node that prints a message to the console.
262
270
263
271
Returns:
264
- - Returns SUCCESS after the message has been printed
272
+ Returns SUCCESS after the message has been printed
265
273
266
274
Example:
267
- <Echo message="Hello, World!" />
275
+ .. code-block:: xml
276
+
277
+ <Echo message="Hello, World!" />
268
278
"""
269
279
270
280
def __init__ (self , name , message ):
@@ -302,13 +312,16 @@ class InverterNode(DecoratorNode):
302
312
Inverter node that inverts the status of its child node.
303
313
304
314
Returns:
305
- - Returns SUCCESS if the child returns FAILURE
306
- - Returns FAILURE if the child returns SUCCESS
307
- - Returns RUNNING if the child returns RUNNING
308
- Example:
309
- <Inverter>
310
- <Action />
311
- </Inverter>
315
+ - Returns SUCCESS if the child returns FAILURE
316
+ - Returns FAILURE if the child returns SUCCESS
317
+ - Returns RUNNING if the child returns RUNNING
318
+
319
+ Examples:
320
+ .. code-block:: xml
321
+
322
+ <Inverter>
323
+ <Action />
324
+ </Inverter>
312
325
"""
313
326
314
327
def __init__ (self , name ):
@@ -325,13 +338,15 @@ class TimeoutNode(DecoratorNode):
325
338
Timeout node that fails if the child node takes too long to execute
326
339
327
340
Returns:
328
- - FAILURE: If the timeout duration has been exceeded
329
- - Child's status: Otherwise, passes through the status of the child node
341
+ - FAILURE: If the timeout duration has been exceeded
342
+ - Child's status: Otherwise, passes through the status of the child node
330
343
331
344
Example:
332
- <Timeout sec="1.5">
333
- <Action />
334
- </Timeout>
345
+ .. code-block:: xml
346
+
347
+ <Timeout sec="1.5">
348
+ <Action />
349
+ </Timeout>
335
350
"""
336
351
337
352
def __init__ (self , name , timeout ):
@@ -354,13 +369,15 @@ class DelayNode(DecoratorNode):
354
369
Delay node that delays the execution of its child node for a specified duration.
355
370
356
371
Returns:
357
- - Returns RUNNING if the duration has not yet passed
358
- - Returns child's status after the duration has passed
372
+ - Returns RUNNING if the duration has not yet passed
373
+ - Returns child's status after the duration has passed
359
374
360
375
Example:
361
- <Delay sec="1.5">
362
- <Action />
363
- </Delay>
376
+ .. code-block:: xml
377
+
378
+ <Delay sec="1.5">
379
+ <Action />
380
+ </Delay>
364
381
"""
365
382
366
383
def __init__ (self , name , delay ):
@@ -382,8 +399,8 @@ class ForceSuccessNode(DecoratorNode):
382
399
ForceSuccess node that always returns SUCCESS.
383
400
384
401
Returns:
385
- - Returns RUNNING if the child returns RUNNING
386
- - Returns SUCCESS if the child returns SUCCESS or FAILURE
402
+ - Returns RUNNING if the child returns RUNNING
403
+ - Returns SUCCESS if the child returns SUCCESS or FAILURE
387
404
"""
388
405
389
406
def __init__ (self , name ):
@@ -402,8 +419,8 @@ class ForceFailureNode(DecoratorNode):
402
419
ForceFailure node that always returns FAILURE.
403
420
404
421
Returns:
405
- - Returns RUNNING if the child returns RUNNING
406
- - Returns FAILURE if the child returns SUCCESS or FAILURE
422
+ - Returns RUNNING if the child returns RUNNING
423
+ - Returns FAILURE if the child returns SUCCESS or FAILURE
407
424
"""
408
425
409
426
def __init__ (self , name ):
@@ -484,12 +501,12 @@ def print_tree(self):
484
501
"""
485
502
Print the behavior tree.
486
503
487
- Node types :
504
+ Node print format :
488
505
Action: <Action>
489
506
Decorator: (Decorator)
490
507
Control: [Control]
491
508
492
- Colors :
509
+ Node status colors :
493
510
Yellow: RUNNING
494
511
Green: SUCCESS
495
512
Red: FAILURE
@@ -577,6 +594,18 @@ def register_node_builder(self, node_name, builder):
577
594
Args:
578
595
node_name (str): The name of the node.
579
596
builder (function): The builder function.
597
+
598
+ Example:
599
+ .. code-block:: python
600
+
601
+ factory = BehaviorTreeFactory()
602
+ factory.register_node_builder(
603
+ "MyNode",
604
+ lambda node: MyNode(
605
+ node.attrib.get("name", MyNode.__name__),
606
+ node.attrib["my_param"],
607
+ ),
608
+ )
580
609
"""
581
610
self .node_builders [node_name ] = builder
582
611
0 commit comments