-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.py
59 lines (50 loc) · 1.59 KB
/
demo.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
from __future__ import annotations
from py_trees import common
import pybts
from pybts.display import render_node
class Person(pybts.Action):
def __init__(self, age: int | str, **kwargs):
super().__init__(**kwargs)
self.age = int(age)
self.cache = self.attach_blackboard_client()
self.cache.register_key('age', pybts.Access.WRITE)
def update(self) -> common.Status:
self.age += 1
return common.Status.SUCCESS
def to_data(self):
return {
'age' : self.age,
'test': {
'hello': {
'world': 1
}
}
}
def main():
builder = pybts.builder.Builder()
builder.register_node(Person)
root = builder.build_from_file('demos/demo_bt.xml')
tree = pybts.Tree(root=root, name='Person')
# board = pybts.board.Board(tree=tree, log_dir='logs')
render_node(tree.root, filepath='demo-tree.jpg', fontsize=24)
if __name__ == '__main__':
main()
# for node in tree.root.iterate():
# print(node.__str__())
# pybts.logging.level = pybts.logging.Level.DEBUG
# for data in board.iterate():
# print(data)
# break
# board.clear()
# for i in range(10000):
# tree.tick()
# board.track(info={
# 'test_info': i,
# })
# time.sleep(0.5)
# if i % 5 == 0:
# tree.reset()
# print(i)
# WebUI
# python -m pybts.board_server --dir=logs --debug --host=localhost --port=10000
# or pybts - -dir = logs - -debug - -host = localhost - -port = 10000