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
24 changes: 12 additions & 12 deletions src/as2fm/resources/bt_control_nodes/if_then_else.ascxml
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,24 @@

<state id="reset_children">
<onentry>
<if cond="current_child_idx &lt; children_count">
<bt_halt_child id="current_child_idx" />
<if cond="child_idx &lt; children_count">
<bt_halt_child id="child_idx" />
</if>
</onentry>
<bt_child_halted id="current_child_idx" target="reset_children">
<assign location="current_child_idx" expr="current_child_idx + 1" />
<bt_child_halted id="child_idx" target="reset_children">
<assign location="child_idx" expr="child_idx + 1" />
</bt_child_halted>
<transition cond="current_child_idx &gt;= children_count" target="wait_for_tick">
<if cond="seq_failure">
<transition cond="child_idx &gt;= children_count" target="wait_for_tick">
<if cond="ret_failure">
<bt_return_status status="FAILURE" />
<elseif cond="seq_success" />
<elseif cond="ret_success" />
<bt_return_status status="SUCCESS" />
<else/>
<bt_return_halted/>
</if>
<assign location="current_child_idx" expr="0" />
<assign location="seq_failure" expr="false" />
<assign location="seq_success" expr="false" />
<assign location="child_idx" expr="0" />
<assign location="ret_failure" expr="false" />
<assign location="ret_success" expr="false" />
</transition>
</state>

Expand Down Expand Up @@ -86,11 +86,11 @@
<transition target="error" cond="child_idx >= children_count" />
<bt_child_status id="child_idx" cond="_bt.status == SUCCESS" target="reset_children">
<assign location="child_idx" expr="0" />
<assign location="seq_success" expr="true" />
<assign location="ret_success" expr="true" />
</bt_child_status>
<bt_child_status id="child_idx" cond="_bt.status == FAILURE" target="reset_children">
<assign location="child_idx" expr="0" />
<assign location="seq_failure" expr="true" />
<assign location="ret_failure" expr="true" />
</bt_child_status>
<bt_child_status id="child_idx" cond="_bt.status == RUNNING" target="wait_for_tick">
<bt_return_status status="RUNNING" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- Test that as soon as the Sequence returns success (tick_count_3 = 1):
- tick_count_0 is ticked one time
- tick_count_1 is ticked three times
- tick_count_2 is ticked one time
-->
<root BTCPP_format="4" >
<BehaviorTree ID="MainTree">
<IfThenElse>
<Action ID="AlwaysFailure" />
<Action ID="BtCountTicks" topic_name="tick_count_then" reset_name="reset_count_then" n_ticks_running="0" />
<Action ID="BtCountTicks" topic_name="tick_count_else" reset_name="reset_count_else" n_ticks_running="0" />
</IfThenElse>
</BehaviorTree>
</root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- Test that as soon as the Sequence returns success (tick_count_3 = 1):
- tick_count_0 is ticked one time
- tick_count_1 is ticked three times
- tick_count_2 is ticked one time
-->
<root BTCPP_format="4" >
<BehaviorTree ID="MainTree">
<IfThenElse>
<Action ID="AlwaysSuccess" />
<Action ID="BtCountTicks" topic_name="tick_count_then" reset_name="reset_count_then" n_ticks_running="0" />
<Action ID="BtCountTicks" topic_name="tick_count_else" reset_name="reset_count_else" n_ticks_running="0" />
</IfThenElse>
</BehaviorTree>
</root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<roaml>
<parameters>
<max_time value="10" unit="s" />
<bt_tick_rate value="1.0" />
<bt_tick_if_not_running value="true" />
</parameters>

<behavior_tree>
<input type="bt.cpp-xml" src="./bt_test_ifthenelse_else.xml" />
<input type="bt-plugin-ascxml" src="./bt_count_ticks.ascxml" />
</behavior_tree>

<properties>
<input type="jani" src="./property_test_ifthenelse.jani" />
</properties>
</roaml>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<roaml>
<parameters>
<max_time value="10" unit="s" />
<bt_tick_rate value="1.0" />
<bt_tick_if_not_running value="true" />
</parameters>

<behavior_tree>
<input type="bt.cpp-xml" src="./bt_test_ifthenelse_then.xml" />
<input type="bt-plugin-ascxml" src="./bt_count_ticks.ascxml" />
</behavior_tree>

<properties>
<input type="jani" src="./property_test_ifthenelse.jani" />
</properties>
</roaml>
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"properties": [
{
"expression": {
"fun": "values",
"op": "filter",
"states": {
"op": "initial"
},
"values": {
"exp": {
"exp": {
"comment": "Bt 1000 is always the root, Values = {1: SUCCESS, 2: FAILURE, 3: RUNNING}",
"left": "bt_1000_response__status",
"op": "=",
"right": 1
},
"op": "F"
},
"op": "Pmin"
}
},
"name": "tree_success"
},
{
"expression": {
"fun": "values",
"op": "filter",
"states": {
"op": "initial"
},
"values": {
"exp": {
"exp": {
"comment": "10 ticks to the then branch and the else branch should have never had a message.",
"left": {
"left": "topic_tick_count_then_msg__ros_fields__data",
"op": "=",
"right": 10
},
"op": "∧",
"right": {
"exp": "topic_tick_count_else_msg.valid",
"op": "¬"
}
},
"op": "F"
},
"op": "Pmin"
}
},
"name": "counter_then_10"
},
{
"expression": {
"fun": "values",
"op": "filter",
"states": {
"op": "initial"
},
"values": {
"exp": {
"exp": {
"comment": "10 ticks to the else branch and the then branch should have never had a message.",
"left": {
"left": "topic_tick_count_else_msg__ros_fields__data",
"op": "=",
"right": 10
},
"op": "∧",
"right": {
"exp": "topic_tick_count_then_msg.valid",
"op": "¬"
}
},
"op": "F"
},
"op": "Pmin"
}
},
"name": "counter_else_10"
}
]
}
32 changes: 32 additions & 0 deletions test/jani_generator/test_systemtest_behavior_tree_scxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,38 @@ def test_repeat(self):
expected_result_probability=1.0,
)

def test_ifthenelse_then_tree_success(self):
"""Test the ifthenelse BT plugins then branch for tree success."""
self._test_with_main(
os.path.join("bt_test_models", "main_test_ifthenelse_then.xml"),
"tree_success",
expected_result_probability=1.0,
)

def test_ifthenelse_then_counter(self):
"""Test the ifthenelse BT plugins then branch for correct number of ticks."""
self._test_with_main(
os.path.join("bt_test_models", "main_test_ifthenelse_then.xml"),
"counter_then_10",
expected_result_probability=1.0,
)

def test_ifthenelse_else_tree_success(self):
"""Test the ifthenelse BT plugins else branch for tree success."""
self._test_with_main(
os.path.join("bt_test_models", "main_test_ifthenelse_else.xml"),
"tree_success",
expected_result_probability=1.0,
)

def test_ifthenelse_else_counter(self):
"""Test the ifthenelse BT plugins else branch for correct number of ticks."""
self._test_with_main(
os.path.join("bt_test_models", "main_test_ifthenelse_else.xml"),
"counter_else_10",
expected_result_probability=1.0,
)


if __name__ == "__main__":
pytest.main(["-s", "-v", __file__])
Loading