| Total Complexity | 6 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | """Tutorial 1 code.""" |
||
| 2 | import curio |
||
| 3 | import async_btree as bt |
||
| 4 | |||
| 5 | |||
| 6 | def approach_object(name: str): |
||
| 7 | print(f"approach_object: {name}") |
||
| 8 | |||
| 9 | |||
| 10 | def check_battery(): |
||
| 11 | print("battery ok") |
||
| 12 | |||
| 13 | |||
| 14 | async def say_hello(name: str): |
||
| 15 | print(f"Hello: {name}") |
||
| 16 | |||
| 17 | |||
| 18 | class GripperInterface: |
||
| 19 | def __init__(self): |
||
| 20 | self._open = False |
||
| 21 | |||
| 22 | def open(self): |
||
| 23 | print("GripperInterface Open") |
||
| 24 | self._open = True |
||
| 25 | |||
| 26 | def close(self): |
||
| 27 | print("GripperInterface Close") |
||
| 28 | self._open = False |
||
| 29 | |||
| 30 | |||
| 31 | gripper = GripperInterface() |
||
| 32 | |||
| 33 | b_tree = bt.sequence( |
||
| 34 | children=[ |
||
| 35 | bt.always_success(child=bt.action(target=say_hello, name="John")), |
||
| 36 | bt.always_success(child=bt.action(target=gripper.open)), |
||
| 37 | bt.always_success(child=bt.action(target=approach_object, name="house")), |
||
| 38 | bt.always_success(child=bt.action(target=gripper.close)), |
||
| 39 | ] |
||
| 40 | ) |
||
| 41 | |||
| 42 | |||
| 43 | if __name__ == '__main__': |
||
| 44 | curio.run(b_tree) |
||
| 45 |