Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions MissionPlanning/BehaviorTree/behavior_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ def __init__(self, name):
def tick(self) -> Status:
self.not_set_child_raise_error()
status = self.child.tick_and_set_status()
if status == Status.RUNNING:
return Status.RUNNING
return Status.SUCCESS if status == Status.FAILURE else Status.FAILURE


Expand Down
35 changes: 35 additions & 0 deletions tests/test_behavior_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,44 @@
BehaviorTreeFactory,
Status,
ActionNode,
InverterNode,
)


@pytest.mark.parametrize("child_status, expected_status", [
(Status.SUCCESS, Status.FAILURE),
(Status.FAILURE, Status.SUCCESS),
(Status.RUNNING, Status.RUNNING),
])
def test_inverter_node_status(child_status, expected_status):
class FixedStatusNode(ActionNode):
def tick(self):
return child_status

inverter = InverterNode("inverter")
inverter.child = FixedStatusNode("child")
assert inverter.tick_and_set_status() == expected_status
assert inverter.status == expected_status
assert inverter.child.status == child_status


def test_inverter_waits_for_sleep(monkeypatch):
now = 0.0
monkeypatch.setattr(
"MissionPlanning.BehaviorTree.behavior_tree.time.time", lambda: now
)
tree = BehaviorTreeFactory().build_tree(
'<Inverter><Sleep sec="1.5" /></Inverter>'
)
tree.tick()
assert tree.root.status == Status.RUNNING
assert tree.root.child.status == Status.RUNNING
now = 2.0
tree.tick()
assert tree.root.status == Status.FAILURE
assert tree.root.child.status == Status.SUCCESS


def test_sequence_node1():
xml_string = """
<Sequence>
Expand Down