From ff2690030accd0f5ff809ce135d9a669ed5606b3 Mon Sep 17 00:00:00 2001 From: Marco Lampacrescia Date: Mon, 16 Dec 2024 14:02:52 +0100 Subject: [PATCH] Remove flag for input blackboards in the full model Signed-off-by: Marco Lampacrescia --- .../scxml_converter/scxml_entries/bt_utils.py | 9 ---- .../scxml_entries/scxml_bt_ticks.py | 4 ++ .../scxml_entries/scxml_state.py | 49 +++++++++---------- .../properties.jani | 33 ------------- 4 files changed, 28 insertions(+), 67 deletions(-) diff --git a/src/as2fm/scxml_converter/scxml_entries/bt_utils.py b/src/as2fm/scxml_converter/scxml_entries/bt_utils.py index 581d6357..45bb2fcf 100644 --- a/src/as2fm/scxml_converter/scxml_entries/bt_utils.py +++ b/src/as2fm/scxml_converter/scxml_entries/bt_utils.py @@ -136,11 +136,6 @@ def __init__(self): # For each port name, store the port type string and value. self._in_ports: Dict[str, Tuple[str, str]] = {} self._out_ports: Dict[str, Tuple[str, str]] = {} - self._has_blackboard_inputs: bool = False - - def has_blackboard_inputs(self) -> bool: - """Boolean check reporting whether any input port references blackboard variables.""" - return self._has_blackboard_inputs def in_port_exists(self, port_name: str) -> bool: """Check if an input port exists.""" @@ -232,10 +227,6 @@ def _set_in_port_value(self, port_name: str, port_value: str): ), f"Error: Value of port {port_name} already assigned." port_type = self._in_ports[port_name][0] self._in_ports[port_name] = (port_type, port_value) - # Update flag to track whether we added a blackboard variable or not - self._has_blackboard_inputs = self._has_blackboard_inputs or is_blackboard_reference( - port_value - ) def _set_out_port_value(self, port_name: str, port_value: str): """Set the value of an output port.""" diff --git a/src/as2fm/scxml_converter/scxml_entries/scxml_bt_ticks.py b/src/as2fm/scxml_converter/scxml_entries/scxml_bt_ticks.py index 7a9ba005..f5ed8e5c 100644 --- a/src/as2fm/scxml_converter/scxml_entries/scxml_bt_ticks.py +++ b/src/as2fm/scxml_converter/scxml_entries/scxml_bt_ticks.py @@ -133,6 +133,10 @@ def __init__(self, child_seq_id: Union[str, int]): def check_validity(self) -> bool: return True + def has_bt_blackboard_input(self, _): + """Check whether the If entry reads content from the BT Blackboard.""" + return False + def instantiate_bt_events( self, instance_id: int, children_ids: List[int] ) -> Union[ScxmlIf, ScxmlSend]: diff --git a/src/as2fm/scxml_converter/scxml_entries/scxml_state.py b/src/as2fm/scxml_converter/scxml_entries/scxml_state.py index d2c60aa2..10b5272a 100644 --- a/src/as2fm/scxml_converter/scxml_entries/scxml_state.py +++ b/src/as2fm/scxml_converter/scxml_entries/scxml_state.py @@ -152,31 +152,30 @@ def _generate_blackboard_retrieval( self, bt_ports_handler: BtPortsHandler ) -> List["ScxmlState"]: generated_states: List[ScxmlState] = [self] - if bt_ports_handler.has_blackboard_inputs(): - assert not has_bt_blackboard_input(self._on_entry, bt_ports_handler), ( - f"Error: SCXML state {self.get_id()}: reading blackboard variables from onentry. " - "This isn't yet supported." - ) - assert not has_bt_blackboard_input(self._on_exit, bt_ports_handler), ( - f"Error: SCXML state {self.get_id()}: reading blackboard variables from onexit. " - "This isn't yet supported." - ) - for transition in self._body: - if transition.has_bt_blackboard_input(bt_ports_handler): - # Prepare the new state using the received BT info - states_count = len(generated_states) - new_state_id = f"{self.get_id()}_{transition.get_tag_name()}_{states_count}" - new_state = ScxmlState(new_state_id) - blackboard_transition = ScxmlTransition( - transition.get_target_state_id(), - [BT_BLACKBOARD_GET], - body=transition.get_body(), - ) - new_state.add_transition(blackboard_transition) - generated_states.append(new_state) - # Set the new target and body to the original transition - transition.set_target_state_id(new_state_id) - transition.set_body([ScxmlSend(BT_BLACKBOARD_REQUEST)]) + assert not has_bt_blackboard_input(self._on_entry, bt_ports_handler), ( + f"Error: SCXML state {self.get_id()}: reading blackboard variables from onentry. " + "This isn't yet supported." + ) + assert not has_bt_blackboard_input(self._on_exit, bt_ports_handler), ( + f"Error: SCXML state {self.get_id()}: reading blackboard variables from onexit. " + "This isn't yet supported." + ) + for transition in self._body: + if transition.has_bt_blackboard_input(bt_ports_handler): + # Prepare the new state using the received BT info + states_count = len(generated_states) + new_state_id = f"{self.get_id()}_{transition.get_tag_name()}_{states_count}" + new_state = ScxmlState(new_state_id) + blackboard_transition = ScxmlTransition( + transition.get_target_state_id(), + [BT_BLACKBOARD_GET], + body=transition.get_body(), + ) + new_state.add_transition(blackboard_transition) + generated_states.append(new_state) + # Set the new target and body to the original transition + transition.set_target_state_id(new_state_id) + transition.set_body([ScxmlSend(BT_BLACKBOARD_REQUEST)]) return generated_states def _substitute_bt_events_and_ports( diff --git a/test/jani_generator/_test_data/grid_robot_blackboard_simple/properties.jani b/test/jani_generator/_test_data/grid_robot_blackboard_simple/properties.jani index 591adf9f..1094fe1c 100644 --- a/test/jani_generator/_test_data/grid_robot_blackboard_simple/properties.jani +++ b/test/jani_generator/_test_data/grid_robot_blackboard_simple/properties.jani @@ -21,39 +21,6 @@ "op": "initial" } } - }, - { - "name": "at_goal", - "expression": { - "op": "filter", - "fun": "values", - "values": { - "op": "Pmin", - "exp": { - "op": "F", - "exp": { - "op": "∧", - "left": "topic_goal_msg.valid", - "right": { - "op": "∧", - "left": { - "op": "=", - "left": "topic_pose_msg.ros_fields__x", - "right": "topic_goal_msg.ros_fields__x" - }, - "right": { - "op": "=", - "left": "topic_pose_msg.ros_fields__y", - "right": "topic_goal_msg.ros_fields__y" - } - } - } - } - }, - "states": { - "op": "initial" - } - } } ] }