diff --git a/src/as2fm/resources/bt_control_nodes/if_then_else.ascxml b/src/as2fm/resources/bt_control_nodes/if_then_else.ascxml index b419066d..cb546b66 100644 --- a/src/as2fm/resources/bt_control_nodes/if_then_else.ascxml +++ b/src/as2fm/resources/bt_control_nodes/if_then_else.ascxml @@ -38,24 +38,24 @@ - - + + - - + + - - + + - + - - - + + + @@ -86,11 +86,11 @@ - + - + diff --git a/test/jani_generator/_test_data/bt_test_models/bt_test_ifthenelse_else.xml b/test/jani_generator/_test_data/bt_test_models/bt_test_ifthenelse_else.xml new file mode 100644 index 00000000..ccccf34b --- /dev/null +++ b/test/jani_generator/_test_data/bt_test_models/bt_test_ifthenelse_else.xml @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/test/jani_generator/_test_data/bt_test_models/bt_test_ifthenelse_then.xml b/test/jani_generator/_test_data/bt_test_models/bt_test_ifthenelse_then.xml new file mode 100644 index 00000000..ad772abe --- /dev/null +++ b/test/jani_generator/_test_data/bt_test_models/bt_test_ifthenelse_then.xml @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/test/jani_generator/_test_data/bt_test_models/main_test_ifthenelse_else.xml b/test/jani_generator/_test_data/bt_test_models/main_test_ifthenelse_else.xml new file mode 100644 index 00000000..ece28fe3 --- /dev/null +++ b/test/jani_generator/_test_data/bt_test_models/main_test_ifthenelse_else.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/test/jani_generator/_test_data/bt_test_models/main_test_ifthenelse_then.xml b/test/jani_generator/_test_data/bt_test_models/main_test_ifthenelse_then.xml new file mode 100644 index 00000000..a27aefe6 --- /dev/null +++ b/test/jani_generator/_test_data/bt_test_models/main_test_ifthenelse_then.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/test/jani_generator/_test_data/bt_test_models/property_test_ifthenelse.jani b/test/jani_generator/_test_data/bt_test_models/property_test_ifthenelse.jani new file mode 100644 index 00000000..78fdbfaa --- /dev/null +++ b/test/jani_generator/_test_data/bt_test_models/property_test_ifthenelse.jani @@ -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" + } + ] +} diff --git a/test/jani_generator/test_systemtest_behavior_tree_scxml.py b/test/jani_generator/test_systemtest_behavior_tree_scxml.py index 3701b2fc..bff49caa 100644 --- a/test/jani_generator/test_systemtest_behavior_tree_scxml.py +++ b/test/jani_generator/test_systemtest_behavior_tree_scxml.py @@ -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__])