-
Notifications
You must be signed in to change notification settings - Fork 0
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
Prepare RosConn Deliberation workshop example #32
Merged
Merged
Changes from 45 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
d5f6734
new names for action results
ct2034 91dcdfb
workshop problem 1
ct2034 088ef48
Small doc image adjustment
MarcoLm993 a0d7e08
Prepend additional string converting ROS fields
MarcoLm993 cfc3cd5
New pattern to define additional arguments in ROS SCXML entries. Move…
MarcoLm993 edf7429
Improve conversion of ROS scxml expression to plain SCXML
MarcoLm993 a733415
Improve regex in expression conversion
MarcoLm993 d13d4a1
Introduce CallbackType in Scxml entries for enforcing ROS events in e…
MarcoLm993 64a77ae
Remove deprecated ROS callback and trigger reading and continue CB ty…
MarcoLm993 b66cfa9
Change implementation of cb type, not constructor based anymore
MarcoLm993 2f50848
Test adjustments
MarcoLm993 900b123
Address leftover for callback type integration
MarcoLm993 f71d738
scxml_converter tests green
MarcoLm993 7b10c3d
Working version of scxml ROS action
MarcoLm993 3753c65
Fix service handler in jani conversion, too
MarcoLm993 d6328ae
Fixed all remaining tests
MarcoLm993 2f43158
Update robotics example, too
MarcoLm993 e82ce37
Introduce canceled and aborted actions
MarcoLm993 7a4553a
Add unit test for expression conversion
MarcoLm993 08c32df
Additional check for expr test
MarcoLm993 cd94dc8
Add missing test cases for ROS action expressions
MarcoLm993 62a2bb5
Prepare test for extended array support
MarcoLm993 8b258e7
Disable test for advanced array features
MarcoLm993 1258acb
Implement BT-based nav controller for demo
MarcoLm993 f3fe227
Handle comments in tags' children
MarcoLm993 79c8d4b
Refine scxml in example
MarcoLm993 2683988
Handle possible function calls in params expressions
MarcoLm993 02195fd
Working BT based robotic navigation
MarcoLm993 107003f
Configurable bt tick rate
MarcoLm993 3d2b495
Customize rate frequencies
MarcoLm993 076b9b1
Fix timers handle and unit tests
MarcoLm993 ceab29c
Improve type handling functionalities in scxml utils
MarcoLm993 86c8d54
Add missing array types and start using new data related functions
MarcoLm993 306c62b
Integrate functionalities for array init using ecmascript expressions
MarcoLm993 fc791e7
First successful translation
MarcoLm993 e175ce3
Fix bugs preventing new test to pass
MarcoLm993 c322b2d
Move some utilities to separated file
MarcoLm993 d1ad9f8
Add support for explicit array in send_event
MarcoLm993 9bbf56a
Introduce actions used in the example
MarcoLm993 3240b9d
Fix models implementation and update tags
MarcoLm993 178551a
Enable delib-example test and bugfixes
MarcoLm993 9430012
First compiling example
MarcoLm993 1daa086
Fix missing jani variables
MarcoLm993 83d7467
Disable delib test, since it requires some work
MarcoLm993 7e1e394
Remove unused argument in main.xml BT example
MarcoLm993 646d669
using enum auto
ct2034 e6993da
Apply review changes
MarcoLm993 a0d0555
Allow SMC step skip in unit test
MarcoLm993 2a79fbb
Change expressions to match javascript syntax. Add tests
MarcoLm993 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ classifiers = [ | |
] | ||
keywords = [] | ||
dependencies = [ | ||
|
||
"js2py" | ||
] | ||
requires-python = ">=3.10" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
jani_generator/src/jani_generator/jani_entries/jani_utils.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# 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. | ||
|
||
"""Collection of various utilities for Jani entries.""" | ||
|
||
from typing import Any, Dict, Optional, MutableSequence, Tuple, Type, get_args | ||
from as2fm_common.common import get_default_expression_for_type, is_array_type | ||
from jani_generator.jani_entries import JaniAutomaton | ||
|
||
|
||
def get_variable_type(jani_automaton: JaniAutomaton, variable_name: Optional[str]) -> type: | ||
""" | ||
Retrieve the variable type from the Jani automaton. | ||
|
||
:param jani_automaton: The Jani automaton to check the variable in. | ||
:param variable_name: The name of the variable to check. | ||
:return: The retrieved type. | ||
""" | ||
assert variable_name is not None, "Variable name must be provided." | ||
variable = jani_automaton.get_variables().get(variable_name) | ||
assert variable is not None, \ | ||
f"Variable {variable_name} not found in {jani_automaton.get_variables()}." | ||
return variable.get_type() | ||
|
||
|
||
def is_variable_array(jani_automaton: JaniAutomaton, variable_name: Optional[str]) -> bool: | ||
"""Check if a variable is an array. | ||
|
||
:param jani_automaton: The Jani automaton to check the variable in. | ||
:param variable_name: The name of the variable to check. | ||
:return: True if the variable is an array, False otherwise. | ||
""" | ||
return is_array_type(get_variable_type(jani_automaton, variable_name)) | ||
|
||
|
||
def get_array_type_and_size(jani_automaton: JaniAutomaton, var_name: str) -> Tuple[Type, int]: | ||
""" | ||
Generate the ArrayInfo obj. related to the provided variable. | ||
|
||
:param jani_automaton: The Jani automaton to get the variable from. | ||
:param var_name: The name of the variable to generate the info from. | ||
:return: The ArrayInfo obj. with array type and max size. | ||
""" | ||
assert var_name is not None, "Variable name must be provided." | ||
variable = jani_automaton.get_variables().get(var_name) | ||
var_type = variable.get_type() | ||
assert is_array_type(var_type), f"Variable {var_name} not an array, cannot extract array info." | ||
array_type = get_args(var_type)[0] | ||
assert array_type in (int, float), f"Array type {array_type} not supported." | ||
init_operator = variable.get_init_expr().as_operator() | ||
assert init_operator is not None, f"Expected init expr of {var_name} to be an operator expr." | ||
if init_operator[0] == "av": | ||
max_size = len(init_operator[1]['elements'].as_literal().value()) | ||
elif init_operator[0] == "ac": | ||
max_size = init_operator[1]['length'].as_literal().value() | ||
else: | ||
raise ValueError(f"Unexpected operator {init_operator[0]} for {var_name} init expr.") | ||
return (array_type, max_size) | ||
|
||
|
||
def get_all_variables_and_instantiations(jani_automaton: JaniAutomaton) -> Dict[str, Any]: | ||
""" | ||
Retrieve all variables and their instantiations from the Jani automaton. | ||
|
||
:param jani_automaton: The Jani automaton to retrieve the variables from. | ||
:return: A dictionary mapping each variable to a dummy value | ||
""" | ||
variables: Dict[str, Any] = {} | ||
for n, v in jani_automaton.get_variables().items(): | ||
variables[n] = get_default_expression_for_type(v.get_type()) | ||
# Hack to solve issue for expressions with explicit access to array entries | ||
if isinstance(variables[n], MutableSequence): | ||
for _ in range(50): | ||
variables[n].append(0) | ||
# Another hack, since javascript interprets 0.0 as int... | ||
if isinstance(variables[n], float): | ||
variables[n] = 0.1 | ||
return variables |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, I would prefer to keep the
Math.
, because that's how js worksThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that makes sense. I will change this tomorrow. FYI: @m-morelli @SofiaFaraci