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

Introduce blackboard support #71

Merged
merged 58 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
b1c63c2
Initial implementation of Blackboard example
MarcoLm993 Nov 26, 2024
f9d05bb
a brand new world
ct2034 Nov 26, 2024
1b09d13
valid xml
ct2034 Nov 26, 2024
d28b03d
Implement some plugins
MarcoLm993 Nov 26, 2024
e949f5b
Continue implementation
MarcoLm993 Nov 27, 2024
1fb5849
Check the BT Tree return status instead of publishing empty msgs
MarcoLm993 Nov 27, 2024
4c24685
Some braindump about how to proceed with the blackboard implementation
MarcoLm993 Nov 27, 2024
87b8f09
Enable the test (will fail)
MarcoLm993 Nov 28, 2024
6d690eb
Implemented unctionality to extract BT variables information from fsm…
MarcoLm993 Nov 28, 2024
2b0df5f
Remove assertions for Blackboard variables in BtPortsHandler
MarcoLm993 Nov 28, 2024
e1c29ba
Add flag to check if there are blackboard variables or not
MarcoLm993 Nov 28, 2024
d8cb76d
Prepare state bt processing for generating additional states
MarcoLm993 Nov 28, 2024
2ec87a7
Code cleanup
MarcoLm993 Nov 29, 2024
9717cdc
Implement the additional states generation
MarcoLm993 Nov 29, 2024
19fe5ad
Generate class to set value through a port
MarcoLm993 Nov 29, 2024
89d02c7
Implement reading from blackboard
MarcoLm993 Nov 29, 2024
a969129
Split BT ports files to break cyclic dependencies
MarcoLm993 Nov 29, 2024
1adf823
First complete bt_out_port scxml class
MarcoLm993 Nov 29, 2024
395f2bc
Add Scxml Blackboard FSM
MarcoLm993 Nov 29, 2024
bf596da
Enable test
MarcoLm993 Nov 29, 2024
f668748
Fixed model
MarcoLm993 Nov 29, 2024
4be98dc
Fixed models
MarcoLm993 Nov 29, 2024
ac88e3a
Quick pass over documentation
MarcoLm993 Dec 9, 2024
7e37d91
Additional property to check actual functionality
MarcoLm993 Dec 9, 2024
9ad0363
Comments for readability
MarcoLm993 Dec 9, 2024
ac9038e
Prepare method for checking the need of reading from the blackboard
MarcoLm993 Dec 9, 2024
09f5a56
Add support for reading blackboard from all other transitions
MarcoLm993 Dec 10, 2024
8736824
Update property name in test of grid_world
MarcoLm993 Dec 10, 2024
1f8819e
Add test and bug circumventing
MarcoLm993 Dec 10, 2024
b87bef2
Proper check for plain scxml of scxml_root object
MarcoLm993 Dec 11, 2024
c8aaaaa
a simple grid example that doesnt work right now
ct2034 Dec 13, 2024
fbfbb69
a bug
ct2034 Dec 14, 2024
59a28f4
bug .. Unknown identifier _event.data.move
ct2034 Dec 14, 2024
508ee9e
but why though?
ct2034 Dec 14, 2024
68b7c7a
also here
ct2034 Dec 14, 2024
4ce9387
Revert "but why though?"
ct2034 Dec 15, 2024
f8cd877
Revert "also here"
ct2034 Dec 15, 2024
7465db1
it does something
ct2034 Dec 15, 2024
6cc80e8
Introduce support for randomness in the model
MarcoLm993 Dec 16, 2024
c0c4e62
this makes a bit more sense
ct2034 Dec 15, 2024
ecfefc1
Differentiating between trigger and data events in executable content
ct2034 Dec 16, 2024
4d22d75
Allow reading output BT variables
MarcoLm993 Dec 16, 2024
2953e42
cleaning up example
ct2034 Dec 16, 2024
d9f6084
works when smaller
ct2034 Dec 16, 2024
c4d6236
updating ground truth after ecfefc135aa66b8c802951f3fb95c9678206425f
ct2034 Dec 16, 2024
ff26900
Remove flag for input blackboards in the full model
MarcoLm993 Dec 16, 2024
b932b4c
running bigger tests
ct2034 Dec 16, 2024
efadf65
handling has_bt_blackboard_input for RosActionHandleGoalResponse
ct2034 Dec 16, 2024
f80e1fc
using randomness
ct2034 Dec 16, 2024
b26c36b
Running 3 goal example
MarcoLm993 Dec 16, 2024
6e005f9
Making n options configurable and fix bt
MarcoLm993 Dec 16, 2024
60f1fb4
3 goals
ct2034 Dec 16, 2024
afc8035
Developed a simple and fast approach, with 3 consecutive goals
MarcoLm993 Dec 16, 2024
36ad842
Naming error fix
MarcoLm993 Dec 16, 2024
c2d74c1
Fix default value of options
MarcoLm993 Dec 16, 2024
f759782
Some more comments
MarcoLm993 Dec 16, 2024
a554237
Update src/as2fm/scxml_converter/bt_converter.py
ct2034 Dec 16, 2024
f34e42e
Update src/as2fm/jani_generator/jani_entries/jani_assignment.py
ct2034 Dec 16, 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
107 changes: 107 additions & 0 deletions docs/source/graphics/blackboard_to_scxml.drawio.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 59 additions & 36 deletions docs/source/scxml-jani-conversion.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,68 @@ Low-Level SCXML Conversion

Low-Level SCXML is the standard SCXML format defined `here <https://www.w3.org/TR/scxml/>`_.

Our converter is able to transform high-level SCXML to low-level SCXML by translating the ROS specific features to standard SCXML features.
In case of timers, we need additional information that cannot be encoded in SCXML, such that information is generated at runtime.
Our converter is able to transform High-Level (HL) SCXML to Low-Level (LL) SCXML by translating ROS and BT specific features to standard SCXML features.
This applies also for timers: we generate an additional SCXML FSM encoding a global clock, sending out events to trigger the timers defined in the model at the correct rate.

The conversion between the two SCXML formats is implemented in ScxmlRoot.as_plain_scxml(). TODO: Link to API.
The next subsections describe our conversion strategy from HL-SCXML to LL-SCXML.
The entry-point for the conversion is implemented in ScxmlRoot.as_plain_scxml(). TODO: Link to API.

TODO: Describe how we translate the high-level SCXML to the low-level SCXML.
Handling of (ROS) Timers
__________________________

TODO

Handling of (ROS) Services
_____________________________

ROS services, as well as ROS topics, can be handled directly in the ROS to plain SCXML conversion, without the need of adding JANI-specific features, as for the ROS timers.
MarcoLm993 marked this conversation as resolved.
Show resolved Hide resolved

The main structure of the SCXML related state machines can be inspected in the diagram below:

.. image:: graphics/ros_service_to_scxml.drawio.svg
:alt: Handling of ROS Services
:align: center

The automata of clients and services are converted directly from the existing ROS-SCXML files, while the "Extra Service Handler" is autogenerated starting from the provided clients and services.


Handling of (ROS) Actions
_____________________________

ROS actions are handled similarly to ROS Services: a ROS-SCXML description of the system is converted to plain SCXML, and an additional automaton is generated to handle the synchronization between the clients and the server.

The structure of a client-server communication through actions and additional threads looks as follows:

.. image:: graphics/ros_action_to_scxml.drawio.svg
:alt: Handling of ROS Actions
:align: center


Handling the BT Blackboard
_____________________________

The Blackboard is a container that shares variables across different BT plugins. The value if those variables normally changes over time, and is expected to be updated at each tick.
MarcoLm993 marked this conversation as resolved.
Show resolved Hide resolved

In LL-SCXML, this is handled by an autogenerated SCXML FSM, that receives the updates from the various plugins and, upon request, provides the data.
This diagram summarizes the FSM structure.

.. image:: graphics/blackboard_to_scxml.drawio.svg
:alt: Blackboard FSM
:align: center

TODO: Timers are useful for SCAN as well: instead of keeping them in a runtime object, we can consider to list them in an intermediary XML file.

Setting Blackboard Variables
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This can be done using the tag `bt_set_output` in HL-SCXML. In LL-SCXML this translates to a send event, that is received by the Blackboard FSM to update the internal data.

Reading Blackboard Variables
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

At the current state, to read the internal variables there needs to be some message exchange between the plugin FSM and the Blackboard FSM.
This needs to happen for each and every Blackboard variable that is read.

Optimization is nevertheless possible (sending the whole set of blackboard variables each time), but this would diverge from the Blackboard.CPP implementation, so it should rather be an automatic conversion.

JANI Conversion
----------------
Expand Down Expand Up @@ -114,34 +168,3 @@ The JANI model resulting from applying the conversion strategies we just describ
:align: center

It can be seen how new self loop edges are added in the `A_B_receiver` automaton (the dashed ones) and how the `ev_a_on_send` is now duplicated in the composition table, one advancing the `A sender` automaton and the other one advancing the `A_B sender` automaton.


Handling of (ROS) Timers
__________________________

TODO

Handling of (ROS) Services
_____________________________

ROS services, as well as ROS topics, can be handled directly in the ROS to plain SCXML conversion, without the need of adding JANI-specific features, as for the ROS timers.

The main structure of the SCXML related state machines can be inspected in the diagram below:

.. image:: graphics/ros_service_to_scxml.drawio.svg
:alt: Handling of ROS Services
:align: center

The automata of clients and services are converted directly from the existing ROS-SCXML files, while the "Extra Service Handler" is autogenerated starting from the provided clients and services.


Handling of (ROS) Actions
_____________________________

ROS actions are handled similarly to ROS Services: a ROS-SCXML description of the system is converted to plain SCXML, and an additional automaton is generated to handle the synchronization between the clients and the server.

The structure of a client-server communication through actions and additional threads looks as follows:

.. image:: graphics/ros_action_to_scxml.drawio.svg
:alt: Handling of ROS Actions
:align: center
42 changes: 42 additions & 0 deletions ros_support_interfaces/grid_robot_interfaces/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
cmake_minimum_required(VERSION 3.5)
project(grid_robot_interfaces)

# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
find_package(std_msgs REQUIRED)

find_package(rosidl_default_generators REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
"msg/Int2D.msg"
DEPENDENCIES std_msgs
)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# uncomment the line when a copyright and license is not present in all source files
#set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# uncomment the line when this package is not in a git repo
#set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()

ament_package()
1 change: 1 addition & 0 deletions ros_support_interfaces/grid_robot_interfaces/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Used in `test/jani_generator/_test_data/grid_robot_blackboard`
2 changes: 2 additions & 0 deletions ros_support_interfaces/grid_robot_interfaces/msg/Int2D.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
int32 x
int32 y
22 changes: 22 additions & 0 deletions ros_support_interfaces/grid_robot_interfaces/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>grid_robot_interfaces</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="[email protected]">root</maintainer>
<license>TODO: License declaration</license>

<buildtool_depend>ament_cmake</buildtool_depend>
<depend>std_msgs</depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

<build_depend>rosidl_default_generators</build_depend>
<exec_depend>rosidl_default_runtime</exec_depend>
<member_of_group>rosidl_interface_packages</member_of_group>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
10 changes: 9 additions & 1 deletion src/as2fm/jani_generator/scxml_helpers/top_level_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@
from as2fm.jani_generator.ros_helpers.ros_service_handler import RosServiceHandler
from as2fm.jani_generator.ros_helpers.ros_timer import RosTimer, make_global_timer_scxml
from as2fm.jani_generator.scxml_helpers.scxml_to_jani import convert_multiple_scxmls_to_jani
from as2fm.scxml_converter.bt_converter import bt_converter
from as2fm.scxml_converter.bt_converter import (
bt_converter,
generate_blackboard_scxml,
get_blackboard_variables_from_models,
)
from as2fm.scxml_converter.scxml_entries import EventsToAutomata, ScxmlRoot


Expand Down Expand Up @@ -174,6 +178,7 @@ def generate_plain_scxml_models_and_timers(
all_timers: List[RosTimer] = []
all_services: Dict[str, RosCommunicationHandler] = {}
all_actions: Dict[str, RosCommunicationHandler] = {}
bt_blackboard_vars: Dict[str, str] = get_blackboard_variables_from_models(ros_scxmls)
for scxml_entry in ros_scxmls:
plain_scxmls, ros_declarations = scxml_entry.to_plain_scxml_and_declarations()
# Handle ROS timers
Expand All @@ -197,6 +202,9 @@ def generate_plain_scxml_models_and_timers(
ros_declarations._action_clients,
)
plain_scxml_models.extend(plain_scxmls)
# Generate sync SCXML model for BT Blackboard (if needed)
if len(bt_blackboard_vars) > 0:
plain_scxml_models.append(generate_blackboard_scxml(bt_blackboard_vars))
# Generate sync SCXML models for services and actions
for plain_scxml in generate_plain_scxml_from_handlers(all_services | all_actions):
plain_scxml_models.append(plain_scxml)
Expand Down
Loading