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
STart implementing new scxml bt tags
Signed-off-by: Marco Lampacrescia <marco.lampacrescia@de.bosch.com>
MarcoLm993 committed Oct 14, 2024
commit 8bd28edcc737d11c82a1ca0b67fa063774467a5b
75 changes: 75 additions & 0 deletions src/as2fm/scxml_converter/scxml_entries/scxml_bt_ticks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# 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.

"""
SCXML entries related to Behavior Tree Ticks and related responses.
"""

from typing import Optional, Union

from lxml import etree as ET

from as2fm.scxml_converter.scxml_entries import ScxmlSend, ScxmlTransition
from as2fm.scxml_converter.scxml_entries.xml_utils import assert_xml_tag_ok, get_xml_argument


class BtTick(ScxmlTransition):
"""
Tick a BT plugin/control node, triggering the related transition.
"""

@staticmethod
def get_tag_name() -> str:
return "bt_tick"

@staticmethod
def from_xml_tree(xml_tree: ET.Element) -> "BtTick":
assert_xml_tag_ok(BtTick, xml_tree)
target: str = get_xml_argument(BtTick, xml_tree, "target")
condition: Optional[str] = get_xml_argument(BtTick, xml_tree, "cond", none_allowed=True)
return BtTick(target, condition)

def __init__(self, target: str, condition: Optional[str] = None):
super().__init__(target, ["bt_tick"], condition)

def as_xml(self) -> ET.Element:
xml_bt_tick = ET.Element(BtTick.get_tag_name(), {"target": self._target})
if self._condition is not None:
xml_bt_tick.set("cond", self._condition)
return xml_bt_tick


class BtTickChild(ScxmlSend):
"""Tick one child of a control node."""

@staticmethod
def get_tag_name() -> str:
return "bt_tick_child"

@staticmethod
def from_xml_tree(xml_tree: ET.Element) -> "BtTickChild":
assert_xml_tag_ok(BtTickChild, xml_tree)
child_id: str = get_xml_argument(BtTickChild, xml_tree, "id")
return BtTickChild(child_id)

def __init__(self, child_id: Union[str, int]):
assert isinstance(
child_id, (str, int)
), f"Error: SCXML BT Tick Child: invalid child id type {type(child_id)}."
self._child = child_id

def as_xml(self) -> ET.Element:
xml_bt_tick_child = ET.Element(BtTickChild.get_tag_name(), {"id": str(self._child)})
return xml_bt_tick_child