-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
73 lines (60 loc) · 1.84 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import py_trees
class Root(py_trees.composites.Sequence):
def __init__(self):
"""
Defines the children nodes of this root.
"""
super(Root, self).__init__(name="root", memory=False)
self.logger.debug("%s.__init__()" % (self.__class__.__name__))
def setup(self):
"""
Starts seperate threads/proccesses, connect to hardware, etc.
"""
print("Called .setup()")
def initialise(self):
"""
What to run right before the node can start ticking.
"""
print("Called .initialised() for root")
def update(self):
"""
What to run when behaviour is ticked
"""
self.logger.debug("Root updated!")
class check_at_goal(py_trees.behaviour.Behaviour):
def __init__(self):
"""
Condition node
"""
super(check_at_goal, self).__init__("check_at_goal")
self.logger.debug("%s.__init__()" % (self.__class__.__name__))
self.counter = 0
def setup(self):
pass
def initialise(self):
print("Called .initialised() for check_at_goal")
def update(self):
"""
What to run when behaviour is ticked
"""
if self.counter < 7:
self.counter += 1
return py_trees.common.Status.RUNNING
else:
return py_trees.common.Status.SUCCESS
def create_root():
"""
Demo single thread BT w/ 2 nodes, just for me to get something to run :)
"""
# Create a root node
root = Root()
root.add_child(check_at_goal())
return root
if __name__ == '__main__':
# Create the root of the tree
root = create_root()
tree = py_trees.trees.BehaviourTree(root)
# some ticks
for i in range(10):
tree.tick()
print(f"Tree status: {tree.root.status}")