Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCXML implementation of BT Control Nodes #58

Merged
merged 46 commits into from
Oct 25, 2024
Merged
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
b5ea3be
Initial verasion of BT control nodes scxml
MarcoLm993 Oct 8, 2024
5cb16d3
Second iteration of scxml_control_nodes
MarcoLm993 Oct 8, 2024
1e353c3
Rename BT Ports scxml declarations
MarcoLm993 Oct 9, 2024
7fd7fc6
One more iteration over the BT Control node SCXML
MarcoLm993 Oct 9, 2024
8bd28ed
STart implementing new scxml bt tags
MarcoLm993 Oct 9, 2024
02b7454
First skeleton on new BT tags
MarcoLm993 Oct 9, 2024
019d6c3
Prepare for testing new bt functionality
MarcoLm993 Oct 9, 2024
045f5f7
Prepare example using new format
MarcoLm993 Oct 9, 2024
1f8f6ff
Start implementing new BT SCXML generator
MarcoLm993 Oct 9, 2024
f86b904
Integrate bt_children ids in the scxml root
MarcoLm993 Oct 9, 2024
f7e8f90
Fix package not found in ipython
MarcoLm993 Oct 9, 2024
f11c651
Move controllers scxml to another folder
MarcoLm993 Oct 9, 2024
dab8efe
Check type of BtTickChild id
MarcoLm993 Oct 9, 2024
64e1ed4
Continue new import of bt plugins
MarcoLm993 Oct 14, 2024
44651f8
Install and import plugins in resources
MarcoLm993 Oct 14, 2024
a9bf8de
Continue integration
MarcoLm993 Oct 14, 2024
bc16c96
Implement missing conversions
MarcoLm993 Oct 14, 2024
5d2f706
First scxml without errors
MarcoLm993 Oct 14, 2024
f93c9e3
Substitution of xml escape sequence and re-order ecmascript entities…
MarcoLm993 Oct 14, 2024
54ea01e
First jani result
MarcoLm993 Oct 14, 2024
e00f599
Various fixes
MarcoLm993 Oct 15, 2024
dc64bac
Fix bug and improve variables naming
MarcoLm993 Oct 15, 2024
dd6f908
Yet another bug
MarcoLm993 Oct 15, 2024
84a3e57
First working version
MarcoLm993 Oct 15, 2024
c018af3
Support for old implementation
MarcoLm993 Oct 15, 2024
6e2692a
Rename battery_depleted_bt_tests
MarcoLm993 Oct 15, 2024
3a9704e
Remove btlib-based BT conversion
MarcoLm993 Oct 15, 2024
9797151
Add input ports support
MarcoLm993 Oct 15, 2024
bc24073
Fixing various tests
MarcoLm993 Oct 15, 2024
0a69d0e
Finish tests fixes
MarcoLm993 Oct 15, 2024
02307be
Adjust BT implementations
MarcoLm993 Oct 15, 2024
8c91364
Fix ReactiveFallback control node
MarcoLm993 Oct 15, 2024
8164302
Documentation
MarcoLm993 Oct 15, 2024
29e7a56
Remove deprecated use of importlib's path
MarcoLm993 Oct 15, 2024
5301d90
Remove unused btlib
MarcoLm993 Oct 15, 2024
bb267d7
Remove old dependencies
MarcoLm993 Oct 15, 2024
46478bd
Fix font path in toml file
MarcoLm993 Oct 15, 2024
aeafe3d
Test for reactive sequence
MarcoLm993 Oct 16, 2024
5cb1a43
Add test for reactive fallbacks
MarcoLm993 Oct 16, 2024
ad544f4
Implement BT sequence model and update test plugin for counting ticks
MarcoLm993 Oct 17, 2024
0a61598
Test for sequence controller
MarcoLm993 Oct 17, 2024
6eb2c4c
Implement Fallback control
MarcoLm993 Oct 17, 2024
c5cb74e
Add test for fallback bt controller
MarcoLm993 Oct 17, 2024
18712ea
Small TODO
MarcoLm993 Oct 18, 2024
2a3c64c
Prevent extra self-loops in the BT root jani automaton
MarcoLm993 Oct 18, 2024
e5d3666
Always return a List of transitions when instantiating BT events
MarcoLm993 Oct 25, 2024
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
Prev Previous commit
Next Next commit
Implement BT sequence model and update test plugin for counting ticks
Signed-off-by: Marco Lampacrescia <marco.lampacrescia@de.bosch.com>
MarcoLm993 committed Oct 17, 2024
commit ad544f4b663bce662111fb5958d020d640ecd61b
56 changes: 56 additions & 0 deletions src/as2fm/resources/bt_control_nodes/sequence.scxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<scxml
xmlns="http://www.w3.org/2005/07/scxml"
initial="wait_for_tick"
version="1.0"
name="Sequence"
model_src="https://raw.githubusercontent.com/BehaviorTree/BehaviorTree.CPP/refs/heads/v3.8/src/controls/sequence_node.cpp">

<!-- A default BT port reporting the amount of children -->
<bt_declare_port_in key="CHILDREN_COUNT" type="int8" />

<datamodel>
<data id="current_child_idx" type="int8" expr="0" />
<data id="children_count" type="int8">
<expr>
<bt_get_input key="CHILDREN_COUNT" />
</expr>
</data>
</datamodel>

<state id="wait_for_tick">
<!-- Check if the state is valid. If not, go to error and stop -->
<transition target="error" cond="children_count &lt; 1" />
<!-- React to an incoming BT Tick -->
<bt_tick target="tick_children"/>
</state>

<state id="tick_children">
<onentry>
<if cond="current_child_idx &lt; children_count">
<bt_tick_child id="current_child_idx"/>
</if>
</onentry>
<bt_child_status id="current_child_idx" cond="_bt.status == SUCCESS" target="tick_children">
<assign location="current_child_idx" expr="current_child_idx + 1" />
</bt_child_status>
<bt_child_status id="current_child_idx" cond="_bt.status == FAILURE" target="wait_for_tick">
<assign location="current_child_idx" expr="0" />
<bt_return_status status="FAILURE" />
</bt_child_status>
<bt_child_status id="current_child_idx" cond="_bt.status == RUNNING" target="wait_for_tick">
<bt_return_status status="RUNNING" />
</bt_child_status>
<!-- All children returned success -->
<transition target="wait_for_tick" cond="current_child_idx == children_count">
<assign location="current_child_idx" expr="0" />
<bt_return_status status="SUCCESS" />
</transition>
<!-- The current_child_idx is out of bounds -->
<transition target="error" cond="current_child_idx &lt; 0 || current_child_idx > children_count" />
</state>

<!-- A state to transition to when something did not work -->
<state id="error" />

</scxml>
26 changes: 23 additions & 3 deletions test/jani_generator/_test_data/bt_test_models/bt_count_ticks.scxml
Original file line number Diff line number Diff line change
@@ -5,13 +5,27 @@
version="1.0"
name="BtCountTicks"
model_src="">
<!--
A BT plugin that, upon tick, increases a counter, publishes its value on a topic and
* n_ticks_running times, returns running.
* After n_ticks_running times, returns success and waits for n_ticks_running ticks before returning success again.
-->

<!-- The topic used to publish the tick count -->
<bt_declare_port_in key="topic_name" type="string" />
<!-- How many ticks to get before sending out a success -->
<bt_declare_port_in key="n_ticks_running" type="int8" />

<datamodel>
<data id="counter" type="int16" expr="0" />
<!-- Assign this for accessing the port value in conditions... -->
<data id="ticks_before_success" type="int8">
<expr>
<bt_get_input key="n_ticks_running" />
</expr>
</data>
</datamodel>

<bt_declare_port_in key="topic_name" type="string" />

<ros_topic_publisher type="std_msgs/Int16" name="counter_pub">
<topic>
<bt_get_input key="topic_name" />
@@ -24,7 +38,13 @@
<ros_topic_publish name="counter_pub">
<field name="data" expr="counter" />
</ros_topic_publish>
<bt_return_status status="SUCCESS" />
<if cond="ticks_before_success &lt;= 0">
<bt_return_status status="SUCCESS" />
<elseif cond="counter % ticks_before_success &gt; 0"/>
<bt_return_status status="RUNNING" />
<else/>
<bt_return_status status="SUCCESS" />
</if>
</bt_tick>
</state>

Original file line number Diff line number Diff line change
@@ -3,10 +3,10 @@
<BehaviorTree ID="MainTree">
<ReactiveFallback name="root_sequence">
<Inverter>
<Action ID="BtCountTicks" topic_name="tick_count_0" />
<Action ID="BtCountTicks" topic_name="tick_count_0" n_ticks_running="0" />
</Inverter>
<Action ID="AlwaysSuccess" />
<Action ID="BtCountTicks" topic_name="tick_count_1" />
<Action ID="BtCountTicks" topic_name="tick_count_1" n_ticks_running="0" />
</ReactiveFallback>
</BehaviorTree>
</root>
Original file line number Diff line number Diff line change
@@ -2,9 +2,9 @@
<root BTCPP_format="4" >
<BehaviorTree ID="MainTree">
<ReactiveSequence name="root_sequence">
<Action ID="BtCountTicks" topic_name="tick_count_0" />
<Action ID="BtCountTicks" topic_name="tick_count_0" n_ticks_running="0" />
<Action ID="AlwaysFailure" />
<Action ID="BtCountTicks" topic_name="tick_count_1" />
<Action ID="BtCountTicks" topic_name="tick_count_1" n_ticks_running="0" />
</ReactiveSequence>
</BehaviorTree>
</root>