Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.

Commit 6f09cff

Browse files
author
fred-labs
authored
Merge branch 'main' into moveit_generic
2 parents 807921d + e797633 commit 6f09cff

File tree

18 files changed

+590
-62
lines changed

18 files changed

+590
-62
lines changed

docs/libraries.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,47 @@ Be depressed, always fail.
285285
The tickling never ends...
286286

287287

288+
289+
``decrement()``
290+
^^^^^^^^^^^^^^^
291+
292+
Decrement the value of a variable.
293+
294+
.. list-table::
295+
:widths: 15 15 5 65
296+
:header-rows: 1
297+
:class: tight-table
298+
299+
* - Parameter
300+
- Type
301+
- Default
302+
- Description
303+
* - ``target_variable``
304+
- ``variable``
305+
-
306+
- Variable to decrement
307+
308+
309+
``increment()``
310+
^^^^^^^^^^^^^^^
311+
312+
Increment the value of a variable.
313+
314+
.. list-table::
315+
:widths: 15 15 5 65
316+
:header-rows: 1
317+
:class: tight-table
318+
319+
* - Parameter
320+
- Type
321+
- Default
322+
- Description
323+
* - ``target_variable``
324+
- ``variable``
325+
-
326+
- Variable to increment
327+
328+
288329
``log()``
289330
^^^^^^^^^
290331

@@ -924,6 +965,10 @@ Play back a ROS bag.
924965
- ``float``
925966
- ``1.0``
926967
- if ``publish_clock`` is true, publish to ``/clock`` at the specified frequency in Hz, to act as a ROS Time Source.
968+
* - ``start_offset``
969+
- ``float``
970+
- ``0.0``
971+
- start the playback this many seconds into the bag file
927972

928973

929974
``bag_record()``

scenario_execution/scenario_execution/actions/base_action.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
# SPDX-License-Identifier: Apache-2.0
1616

1717
import py_trees
18-
from scenario_execution.model.types import ParameterDeclaration, ScenarioDeclaration
1918
from scenario_execution.model.error import OSC2Error
2019
import inspect
2120

@@ -55,8 +54,11 @@ def initialise(self):
5554
if self.resolve_variable_reference_arguments_in_execute:
5655
final_args = self._model.get_resolved_value(self.get_blackboard_client(), skip_keys=self.execute_skip_args)
5756
else:
58-
final_args = self._model.get_resolved_value_with_variable_references(
59-
self.get_blackboard_client(), skip_keys=self.execute_skip_args)
57+
try:
58+
final_args = self._model.get_resolved_value_with_variable_references(
59+
self.get_blackboard_client(), skip_keys=self.execute_skip_args)
60+
except ValueError as e:
61+
raise ActionError(f"Error initializing action: {e}", action=self) from e
6062

6163
if self._model.actor:
6264
final_args["associated_actor"] = self._model.actor.get_resolved_value(self.get_blackboard_client())
@@ -71,24 +73,14 @@ def _set_base_properities(self, name, model, logger):
7173
def get_blackboard_client(self):
7274
if self.blackboard:
7375
return self.blackboard
74-
75-
def get_blackboard_namespace(node: ParameterDeclaration):
76-
parent = node.get_parent()
77-
while parent is not None and not isinstance(parent, ScenarioDeclaration):
78-
parent = parent.get_parent()
79-
if parent:
80-
return parent.name
81-
else:
82-
return None
83-
84-
self.blackboard = self.attach_blackboard_client(name=self.name, namespace=get_blackboard_namespace(self._model))
76+
self.blackboard = self.attach_blackboard_client(name=self.name)
8577
return self.blackboard
8678

8779
def register_access_to_associated_actor_variable(self, variable_name):
8880
if not self._model.actor:
8981
raise ActionError("Model does not have 'actor'.", action=self)
9082
blackboard = self.get_blackboard_client()
91-
model_blackboard_name = self._model.actor.get_fully_qualified_var_name(include_scenario=False)
83+
model_blackboard_name = self._model.actor.get_qualified_name()
9284
model_blackboard_name += "/" + variable_name
9385
blackboard.register_key(model_blackboard_name, access=py_trees.common.Access.WRITE)
9486
return model_blackboard_name
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing,
10+
# software distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions
13+
# and limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
17+
import py_trees # pylint: disable=import-error
18+
from scenario_execution.actions.base_action import BaseAction, ActionError
19+
from scenario_execution.model.types import VariableReference
20+
21+
22+
class Decrement(BaseAction):
23+
"""
24+
Class to decrement the value of a variable
25+
"""
26+
27+
def __init__(self):
28+
super().__init__(resolve_variable_reference_arguments_in_execute=False)
29+
self.target_variable = None
30+
31+
def execute(self, target_variable: object):
32+
if not isinstance(target_variable, VariableReference):
33+
raise ActionError(
34+
f"'target_variable' is expected to be a variable reference but is {type(target_variable).__name__}.", action=self)
35+
self.target_variable = target_variable
36+
37+
def update(self) -> py_trees.common.Status:
38+
self.target_variable.set_value(self.target_variable.get_value() - 1)
39+
return py_trees.common.Status.SUCCESS
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing,
10+
# software distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions
13+
# and limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
17+
import py_trees # pylint: disable=import-error
18+
from scenario_execution.actions.base_action import BaseAction, ActionError
19+
from scenario_execution.model.types import VariableReference
20+
21+
22+
class Increment(BaseAction):
23+
"""
24+
Class to increment the value of a variable
25+
"""
26+
27+
def __init__(self):
28+
super().__init__(resolve_variable_reference_arguments_in_execute=False)
29+
self.target_variable = None
30+
31+
def execute(self, target_variable: object):
32+
if not isinstance(target_variable, VariableReference):
33+
raise ActionError(
34+
f"'target_variable' is expected to be a variable reference but is {type(target_variable).__name__}.", action=self)
35+
self.target_variable = target_variable
36+
37+
def update(self) -> py_trees.common.Status:
38+
self.target_variable.set_value(self.target_variable.get_value() + 1)
39+
return py_trees.common.Status.SUCCESS

scenario_execution/scenario_execution/lib_osc/helpers.osc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ enum signal: [
99
sigterm = 15
1010
]
1111

12+
action increment:
13+
# Increment the value of a variable
14+
target_variable: string # variable to increment
15+
16+
action decrement:
17+
# Decrement the value of a variable
18+
target_variable: string # variable to decrement
19+
1220
action log:
1321
# Print out a message
1422
msg: string # Message to print

scenario_execution/scenario_execution/model/model_blackboard.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import py_trees
1818

19-
from scenario_execution.model.types import ParameterDeclaration, StructuredDeclaration, VariableDeclaration
19+
from scenario_execution.model.types import ParameterDeclaration, StructuredDeclaration, VariableDeclaration, ScenarioDeclaration, Declaration
2020
from scenario_execution.model.model_base_visitor import ModelBaseVisitor
2121
from scenario_execution.model.error import OSC2ParsingError
2222

@@ -47,12 +47,32 @@ def __init__(self, logger, tree) -> None:
4747
self.blackboard = tree.attach_blackboard_client(name="ModelToPyTree")
4848

4949
def visit_parameter_declaration(self, node: ParameterDeclaration):
50-
super().visit_parameter_declaration(node)
5150
parameter_type = node.get_type()[0]
52-
if isinstance(parameter_type, StructuredDeclaration):
53-
for variable_dec in parameter_type.find_children_of_type(VariableDeclaration):
54-
prefix = node.get_fully_qualified_var_name(include_scenario=True)
55-
blackboard_var_name = prefix + "/" + variable_dec.name
5651

57-
self.blackboard.register_key(blackboard_var_name, access=py_trees.common.Access.WRITE)
58-
setattr(self.blackboard, blackboard_var_name, variable_dec.get_resolved_value())
52+
if isinstance(parameter_type, StructuredDeclaration) and self.needs_blackboard_entry(node):
53+
self.create_blackboard_entries(parameter_type, node.get_qualified_name())
54+
55+
def create_blackboard_entries(self, elem, prefix):
56+
for variable_dec in elem.find_children_of_type(VariableDeclaration):
57+
fqn = prefix + "/" + variable_dec.name
58+
self.blackboard.register_key(fqn, access=py_trees.common.Access.WRITE)
59+
setattr(self.blackboard, fqn, variable_dec.get_resolved_value())
60+
61+
for child in elem.find_children_of_type(ParameterDeclaration):
62+
child_type = child.get_type()[0]
63+
if isinstance(child_type, Declaration):
64+
self.create_blackboard_entries(child_type, prefix + "/" + child.name)
65+
66+
def needs_blackboard_entry(self, node):
67+
current = node.get_parent()
68+
while current:
69+
if isinstance(current, ScenarioDeclaration):
70+
return True
71+
current = current.get_parent()
72+
return False
73+
74+
def visit_variable_declaration(self, node: VariableDeclaration):
75+
if self.needs_blackboard_entry(node):
76+
blackboard_var_name = node.get_fully_qualified_var_name()
77+
self.blackboard.register_key(blackboard_var_name, access=py_trees.common.Access.WRITE)
78+
setattr(self.blackboard, blackboard_var_name, node.get_resolved_value())

scenario_execution/scenario_execution/model/model_to_py_tree.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def update(self):
104104
class ExpressionBehavior(BaseAction): # py_trees.behaviour.Behaviour):
105105

106106
def __init__(self, name: "ExpressionBehavior", expression: Expression, model, logger):
107-
super().__init__()
107+
super().__init__(resolve_variable_reference_arguments_in_execute=False)
108108
self._set_base_properities(name, model, logger)
109109
self.expression = expression
110110

@@ -146,8 +146,7 @@ def visit_scenario_declaration(self, node: ScenarioDeclaration):
146146
self.__cur_behavior.name = scenario_name
147147

148148
self.blackboard = self.__cur_behavior.attach_blackboard_client(
149-
name="ModelToPyTree",
150-
namespace=scenario_name)
149+
name="ModelToPyTree")
151150

152151
super().visit_scenario_declaration(node)
153152

scenario_execution/scenario_execution/model/types.py

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -968,16 +968,6 @@ def accept(self, visitor):
968968
else:
969969
return visitor.visit_children(self)
970970

971-
def get_fully_qualified_var_name(self, include_scenario):
972-
name = self.name
973-
parent = self.get_parent()
974-
while parent and not isinstance(parent, ScenarioDeclaration):
975-
name = parent.name + "/" + name
976-
parent = parent.get_parent()
977-
if include_scenario and parent and parent.name:
978-
name = parent.name + "/" + name
979-
return name
980-
981971

982972
class ParameterReference(ModelElement):
983973

@@ -1277,6 +1267,14 @@ def accept(self, visitor):
12771267
else:
12781268
return visitor.visit_children(self)
12791269

1270+
def get_fully_qualified_var_name(self):
1271+
name = self.name
1272+
parent = self.get_parent()
1273+
while parent:
1274+
name = parent.name + "/" + name
1275+
parent = parent.get_parent()
1276+
return name
1277+
12801278

12811279
class KeepConstraintDeclaration(Declaration):
12821280

@@ -2245,20 +2243,29 @@ def get_type_string(self):
22452243
return self.ref.get_type_string()
22462244

22472245
def get_blackboard_reference(self, blackboard):
2248-
if not isinstance(self.ref, list) or len(self.ref) == 0:
2249-
raise ValueError("Variable Reference only supported if reference is list with at least one element")
2250-
if not isinstance(self.ref[0], ParameterDeclaration):
2251-
raise ValueError("Variable Reference only supported if reference is part of a parameter declaration")
2252-
fqn = self.ref[0].get_fully_qualified_var_name(include_scenario=False)
2253-
if blackboard is None:
2254-
raise ValueError("Variable Reference found, but no blackboard client available.")
2255-
for sub_elem in self.ref[1:]:
2256-
fqn += "/" + sub_elem.name
2246+
if isinstance(self.ref, list):
2247+
if len(self.ref) == 0:
2248+
raise ValueError("Variable Reference only supported if reference is list with at least one element")
2249+
if not isinstance(self.ref[0], ParameterDeclaration):
2250+
raise ValueError("Variable Reference only supported if reference is part of a parameter declaration")
2251+
fqn = self.ref[0].get_qualified_name()
2252+
var_found = False
2253+
for elem in self.ref[1:]:
2254+
if isinstance(elem, VariableDeclaration):
2255+
var_found = True
2256+
fqn += "/" + elem.name
2257+
if not var_found:
2258+
raise ValueError(f"No variable found in '{fqn}.")
2259+
elif isinstance(self.ref, VariableDeclaration):
2260+
fqn = self.ref.get_fully_qualified_var_name()
2261+
else:
2262+
raise ValueError(f"Only references to VariableDeclaration supported, not '{type(self.ref).__name__}'.")
2263+
22572264
blackboard.register_key(fqn, access=py_trees.common.Access.WRITE)
22582265
return VariableReference(blackboard, fqn)
22592266

22602267
def get_variable_reference(self, blackboard):
2261-
if isinstance(self.ref, list) and any(isinstance(x, VariableDeclaration) for x in self.ref):
2268+
if (isinstance(self.ref, list) and any(isinstance(x, VariableDeclaration) for x in self.ref)) or isinstance(self.ref, VariableDeclaration):
22622269
return self.get_blackboard_reference(blackboard)
22632270
else:
22642271
return None

scenario_execution/setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@
7070
'scenario_execution = scenario_execution.scenario_execution_base:main',
7171
],
7272
'scenario_execution.actions': [
73+
'increment = scenario_execution.actions.increment:Increment',
74+
'decrement = scenario_execution.actions.decrement:Decrement',
7375
'log = scenario_execution.actions.log:Log',
7476
'run_process = scenario_execution.actions.run_process:RunProcess',
7577
],

0 commit comments

Comments
 (0)