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

Hackathon #4

Merged
merged 101 commits into from
Jul 4, 2024
Merged
Changes from 1 commit
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
b51c4e3
Marcos Question
ct2034 Jun 12, 2024
6a6e637
Note on architecture
ct2034 Jun 14, 2024
36ab9ab
spelling, cleanup
ct2034 Jun 14, 2024
29d7858
empty files for future implementations
ct2034 Jun 14, 2024
3edcf05
adding return event to bt plugin implementation
ct2034 Jun 14, 2024
16caf95
Introduce initial scxml entries
MarcoLm993 Jun 14, 2024
b3c1ef8
Move files to correct folder and add missing entries
MarcoLm993 Jun 14, 2024
a56559c
Implement scxml param
MarcoLm993 Jun 14, 2024
9628def
Implement data and xml conversion for base scxml entries
MarcoLm993 Jun 14, 2024
911afdd
First untested version of scxml model
MarcoLm993 Jun 14, 2024
47fd779
Write system test
MarcoLm993 Jun 17, 2024
7f58f3a
Resolve cyclic dependencies using FW declaration
MarcoLm993 Jun 17, 2024
407c707
Running scxml_entries system test
MarcoLm993 Jun 17, 2024
7921177
Adapt system test for ros to plain scxml. Needs alignment
MarcoLm993 Jun 17, 2024
efad742
eof new line
ct2034 Jun 17, 2024
6cda6d7
instantiation of bt leaves
ct2034 Jun 17, 2024
b46b630
Small todo to get clarification
MarcoLm993 Jun 17, 2024
bbf997c
making plugin events unique
ct2034 Jun 17, 2024
99e25f6
first steps bt runtime
ct2034 Jun 18, 2024
151c892
Remove send targets
MarcoLm993 Jun 18, 2024
a1e5771
bt translation with events
ct2034 Jun 18, 2024
4093b4c
renaming ros-specific tags
ct2034 Jun 18, 2024
3bee6cb
Define Ros specific entries in separated file
MarcoLm993 Jun 18, 2024
ba31ff7
using ros tag in exmpl
ct2034 Jun 18, 2024
ce15acb
this is generated by the test
ct2034 Jun 18, 2024
f4a1858
asserting existence of file
ct2034 Jun 18, 2024
7c5210d
importing the ros rate timer from somewhere else
ct2034 Jun 18, 2024
eb86a3f
fixing line length
ct2034 Jun 18, 2024
50f5efc
formatting
ct2034 Jun 18, 2024
bd49f83
WIP: Implement ros entries
MarcoLm993 Jun 18, 2024
05f2f54
Rename method
MarcoLm993 Jun 18, 2024
47ce46f
adding RosTimeRate on module level
ct2034 Jun 18, 2024
15e65f3
Ros scxml continues
MarcoLm993 Jun 18, 2024
b80c789
Re-order init imports
MarcoLm993 Jun 18, 2024
a815450
reorganized all the tests
ct2034 Jun 18, 2024
6c59f4e
Handle ros declarations in scxml root
MarcoLm993 Jun 18, 2024
c36941e
moved test folder
ct2034 Jun 18, 2024
20b0112
Add missing ROS declaration
MarcoLm993 Jun 18, 2024
4dc6b69
implementing bt handling in main.xml
ct2034 Jun 18, 2024
1c575d6
Continue Ros entries
MarcoLm993 Jun 18, 2024
23ebee4
Complete implementation of ROS scxml entries
MarcoLm993 Jun 18, 2024
dfbbf2c
Add test for ROS scxml components
MarcoLm993 Jun 18, 2024
bc15a36
Linting scxml transition
MarcoLm993 Jun 19, 2024
91e7ed6
Document initial scxml to jani translation + linting some files
MarcoLm993 Jun 19, 2024
e8d9ab7
Push WIP
MarcoLm993 Jun 19, 2024
abb163b
implementation of receiving and sending event in the same transition
ct2034 Jun 19, 2024
5de8c31
fixing if / else in scxml syntax
ct2034 Jun 19, 2024
f60a34b
making sure to not use an old test product by accident
ct2034 Jun 19, 2024
32f764e
add a drawing on if handling
ct2034 Jun 26, 2024
a86daab
concept for if done
ct2034 Jun 26, 2024
f96a393
maybe solved a bug for edges without executable content
ct2034 Jun 26, 2024
1a713c2
Add symlink to graphics
MarcoLm993 Jun 26, 2024
99e5c36
WIP xml reader
MarcoLm993 Jun 26, 2024
939dad8
a workflow to test our python packages
ct2034 Jun 24, 2024
1511390
installing dev dependencies
ct2034 Jun 24, 2024
d83c927
manually setting up python
ct2034 Jun 24, 2024
bca0f7a
versions as strings
ct2034 Jun 24, 2024
3ee0f15
setting up ros
ct2034 Jun 24, 2024
c218110
we probably need the pytest-3 executable now
ct2034 Jun 24, 2024
fc603c9
installing storm
ct2034 Jun 24, 2024
77ef441
installing storm dependencies
ct2034 Jun 24, 2024
7d70e51
a test to make sure smc_storm can be called
ct2034 Jun 24, 2024
6d0f91a
installing bt_tools from source
ct2034 Jun 26, 2024
a68943f
Mörge branch 'main' into add/hackathon_240612
ct2034 Jun 26, 2024
38dc710
checking out workspace so pip doesnt complain that btlib is missing
ct2034 Jun 26, 2024
4f5a87a
always global path
ct2034 Jun 26, 2024
52bb39d
Implement parsers for datamodel and ros declarations
MarcoLm993 Jun 27, 2024
1be3385
Some polishing
MarcoLm993 Jun 27, 2024
f5e0e9d
WIP
MarcoLm993 Jun 27, 2024
b5a8450
Figure out how to access only direct children of xml element
MarcoLm993 Jun 27, 2024
48377f0
Implementing the If conversion
MarcoLm993 Jun 27, 2024
d9aaf48
Finish executable content conversion
MarcoLm993 Jun 28, 2024
f67040f
First complete implementation
MarcoLm993 Jun 28, 2024
8c6aa26
Initial debugging
MarcoLm993 Jun 28, 2024
656ac60
Fix order of ros declarations
MarcoLm993 Jun 28, 2024
8e5a8b5
Add missing parsing of ROS callbacks
MarcoLm993 Jun 28, 2024
6a89052
Try fixing test job
MarcoLm993 Jun 28, 2024
2c916f6
Fix If tag conversion
MarcoLm993 Jun 28, 2024
cfba14e
Add dependency installation for ROS pkgs
MarcoLm993 Jun 28, 2024
effde20
Do not test dependency repos
MarcoLm993 Jun 28, 2024
b4103ca
Add plain scxml check
MarcoLm993 Jul 1, 2024
1925a4e
Check ros macros validity and fix bug with empty datamodel
MarcoLm993 Jul 1, 2024
551afba
Fix msg import and add missing checks
MarcoLm993 Jul 1, 2024
8cf1f9f
Move RosDeclaration generation to separated method for reusability an…
MarcoLm993 Jul 1, 2024
07aef7d
Introduce ScxmlBase base cclass and prepare to_plain_scxml method
MarcoLm993 Jul 1, 2024
364a001
Implement basic structure of scxml de-rosification
MarcoLm993 Jul 1, 2024
3d7849c
Move utils to separate file for easier dependency tree
MarcoLm993 Jul 2, 2024
d547a1c
Finish conversion to plain scxml and replace previous one
MarcoLm993 Jul 2, 2024
da05638
Add condition for topic and rate callbacks
MarcoLm993 Jul 3, 2024
0e1a689
changing name to location in assign tag
ct2034 Jul 3, 2024
d7296da
implementing if's
ct2034 Jul 3, 2024
6bd9588
event fixes
ct2034 Jul 3, 2024
2f621b1
Make sure smc_storm terminates in the tests
MarcoLm993 Jul 4, 2024
13f63fb
First version passing the old tests
MarcoLm993 Jul 4, 2024
7b2f533
Green!
MarcoLm993 Jul 4, 2024
568c311
First complete and green version! Wohoo
MarcoLm993 Jul 4, 2024
8012a72
Re-enable timer in bt scxml and spotting more bugs
MarcoLm993 Jul 4, 2024
305f51b
correct expected output
ct2034 Jul 4, 2024
402491d
fix for if problem
ct2034 Jul 4, 2024
8db7e90
Fix GT file for in bt test and first battery drained and charged
MarcoLm993 Jul 4, 2024
56b11bf
Some more tests
MarcoLm993 Jul 4, 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
Write system test
Signed-off-by: Marco Lampacrescia <marco.lampacrescia@de.bosch.com>
MarcoLm993 committed Jun 17, 2024
commit 47fd779bbf0099ee4739e6d9ee3576a8d2285c41
Original file line number Diff line number Diff line change
@@ -32,8 +32,12 @@ def __init__(self, name: str):
self._states: List[ScxmlState] = []
self._data_model: ScxmlDataModel = None

def add_state(self, state: ScxmlState, initial: bool = False):
def add_state(self, state: ScxmlState, *, initial: bool = False):
"""Append a state to the list of states. If initial is True, set it as the initial state."""
self._states.append(state)
if initial:
assert self._initial_state is None, "Error: SCXML root: Initial state already set"
self._initial_state = state.get_id()

def set_data_model(self, data_model: ScxmlDataModel):
assert self._data_model is None, "Data model already set"
Original file line number Diff line number Diff line change
@@ -36,6 +36,9 @@ def __init__(self, id: str, *,
self._on_exit = on_exit
self._body = body

def get_id(self) -> str:
return self._id

def check_validity(self) -> bool:
valid_id = isinstance(self._id, str) and len(self._id) > 0
valid_on_entry = self._on_entry is None or valid_execution_body(self._on_entry)
45 changes: 43 additions & 2 deletions scxml_converter/test/test_systemtest_scxml_entries.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,46 @@
# Copyright (c) 2024 - for information on the respective copyright owner
# see the NOTICE file

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
from xml.etree import ElementTree as ET
from test_utils import canonicalize_xml
from scxml_converter.scxml_entries import ScxmlRoot, ScxmlDataModel, ScxmlState, ScxmlSend, ScxmlParam, \
ScxmlTransition, ScxmlAssign


def test_battery_drainer_from_code():
battery_drainer_scxml = ScxmlRoot("BatteryDrainer")
battery_drainer_scxml.set_data_model(ScxmlDataModel([("battery", "100")]))
use_battery_state = ScxmlState("use_battery",
onentry=[ScxmlSend("ros_topic.level", "BatteryManager",
[ScxmlParam("data", expr="battery_percent")])],
body=[ScxmlTransition("use_battery", "ros_time_rate.my_timer",
body=[ScxmlAssign("battery_percent", "battery_percent - 1")]),
ScxmlTransition("use_battery", "ros_topic.charge",
body=[ScxmlAssign("battery_percent", "100")])])
battery_drainer_scxml.add_state(use_battery_state, initial=True)
# Check output xml
ref_file = os.path.join(os.path.dirname(__file__), '_test_data', 'expected_output', 'battery_drainer.scxml')
with open(ref_file, 'r', encoding='utf-8') as f_o:
expected_output = f_o.read()
test_output = ET.dump(battery_drainer_scxml.as_xml())
assert canonicalize_xml(test_output) == canonicalize_xml(expected_output)


if __name__ == '__main__':
test_battery_drainer_from_code()

# We want to support ..

@@ -17,8 +59,7 @@
# - send
# - param
# - if / elseif / else
# - assign
# - assign

# dump to scxml file
# (read scxml file)

14 changes: 3 additions & 11 deletions scxml_converter/test/test_systemtest_xml.py
Original file line number Diff line number Diff line change
@@ -14,20 +14,11 @@
# limitations under the License.

import os
import xml.etree.ElementTree as ET
from test_utils import canonicalize_xml

from scxml_converter.scxml_converter import scxml_converter


def _canonicalize_xml(xml: str) -> str:
"""Helper function to make XML comparable."""
# sort attributes
et = ET.fromstring(xml)
for elem in et.iter():
elem.attrib = {k: elem.attrib[k] for k in sorted(elem.attrib.keys())}
return ET.tostring(et, encoding='unicode')


def test_scxml_w_ros_to_plain_jani():
for fname in ['battery_manager.scxml', 'battery_drainer.scxml']:
input_file = os.path.join(os.path.dirname(__file__),
@@ -40,12 +31,13 @@ def test_scxml_w_ros_to_plain_jani():
out = sms[0]
with open(output_file, 'r', encoding='utf-8') as f_o:
expected_output = f_o.read()
assert _canonicalize_xml(out) == _canonicalize_xml(expected_output)
assert canonicalize_xml(out) == canonicalize_xml(expected_output)

# if fname == 'battery_drainer.scxml':
# assert len(sms) == 2, "Must also have the time state machine."
# elif fname == 'battery_manager.scxml':
# assert len(sms) == 1, "Must only have the battery state machine."


if __name__ == '__main__':
test_scxml_w_ros_to_plain_jani()
25 changes: 25 additions & 0 deletions scxml_converter/test/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) 2024 - for information on the respective copyright owner
# see the NOTICE file

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from xml.etree import ElementTree as ET


def canonicalize_xml(xml: str) -> str:
"""Helper function to make XML comparable."""
# sort attributes
et = ET.fromstring(xml)
for elem in et.iter():
elem.attrib = {k: elem.attrib[k] for k in sorted(elem.attrib.keys())}
return ET.tostring(et, encoding='unicode')