Skip to content

Commit

Permalink
Remove flag for input blackboards in the full model
Browse files Browse the repository at this point in the history
Signed-off-by: Marco Lampacrescia <[email protected]>
  • Loading branch information
MarcoLm993 committed Dec 16, 2024
1 parent c4d6236 commit ff26900
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 67 deletions.
9 changes: 0 additions & 9 deletions src/as2fm/scxml_converter/scxml_entries/bt_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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."""
Expand Down
4 changes: 4 additions & 0 deletions src/as2fm/scxml_converter/scxml_entries/scxml_bt_ticks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
49 changes: 24 additions & 25 deletions src/as2fm/scxml_converter/scxml_entries/scxml_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
]
}

0 comments on commit ff26900

Please sign in to comment.