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

Commit af67a52

Browse files
Service_call_qos (#161)
1 parent 50b4bde commit af67a52

File tree

10 files changed

+43
-16
lines changed

10 files changed

+43
-16
lines changed

examples/example_external_method/example_external_method/external_methods/factorial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#
1515
# SPDX-License-Identifier: Apache-2.0
1616

17-
def factorial(n: int):
17+
def factorial(n: int): # pylint: disable=invalid-name
1818
fact = 1
1919
for i in range(1, n+1):
2020
fact = fact * i

libs/scenario_execution_nav2/scenario_execution_nav2/actions/nav_through_poses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(self, associated_actor, goal_poses: list, action_topic: str, namesp
3232
self.goal_poses = None
3333
super().__init__(self.namespace + '/' + action_topic, "nav2_msgs.action.NavigateThroughPoses", "")
3434

35-
def execute(self, associated_actor, goal_poses: list, action_topic: str, namespace_override: str) -> None: # pylint: disable=arguments-differ
35+
def execute(self, associated_actor, goal_poses: list, action_topic: str, namespace_override: str) -> None: # pylint: disable=arguments-differ,arguments-renamed
3636
self.namespace = associated_actor["namespace"]
3737
if namespace_override:
3838
self.namespace = namespace_override

libs/scenario_execution_nav2/scenario_execution_nav2/actions/nav_to_pose.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(self, associated_actor, goal_pose: list, action_topic: str, namespa
3333
self.goal_pose = None
3434
super().__init__(self.namespace + '/' + action_topic, "nav2_msgs.action.NavigateToPose", "")
3535

36-
def execute(self, associated_actor, goal_pose: list, action_topic: str, namespace_override: str) -> None: # pylint: disable=arguments-differ
36+
def execute(self, associated_actor, goal_pose: list, action_topic: str, namespace_override: str) -> None: # pylint: disable=arguments-differ,arguments-renamed
3737
self.namespace = associated_actor["namespace"]
3838
if namespace_override:
3939
self.namespace = namespace_override

scenario_execution/scenario_execution/actions/base_action.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def initialise(self):
5353
if self._model.actor:
5454
final_args["associated_actor"] = self._model.actor.get_resolved_value(self.get_blackboard_client())
5555
final_args["associated_actor"]["name"] = self._model.actor.name
56-
self.execute(**final_args)
56+
self.execute(**final_args) # pylint: disable=no-member
5757

5858
def _set_base_properities(self, name, model, logger):
5959
self.name = name

scenario_execution_ros/scenario_execution_ros/actions/ros_action_call.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from rclpy.node import Node
2121
from rclpy.callback_groups import ReentrantCallbackGroup
2222
from rclpy.action import ActionClient
23+
from rclpy.qos import QoSProfile, DurabilityPolicy
2324
from rosidl_runtime_py.set_message import set_message_fields
2425
import py_trees # pylint: disable=import-error
2526
from action_msgs.msg import GoalStatus
@@ -42,7 +43,7 @@ class RosActionCall(BaseAction):
4243
ros service call behavior
4344
"""
4445

45-
def __init__(self, action_name: str, action_type: str, data: str):
46+
def __init__(self, action_name: str, action_type: str, data: str, transient_local: bool = False):
4647
super().__init__()
4748
self.node = None
4849
self.client = None
@@ -56,6 +57,7 @@ def __init__(self, action_name: str, action_type: str, data: str):
5657
self.parse_data(data)
5758
self.current_state = ActionCallActionState.IDLE
5859
self.cb_group = ReentrantCallbackGroup()
60+
self.transient_local = transient_local
5961

6062
def setup(self, **kwargs):
6163
"""
@@ -77,10 +79,19 @@ def setup(self, **kwargs):
7779
except ValueError as e:
7880
raise ValueError(f"Invalid action_type '{self.action_type}':") from e
7981

80-
self.client = ActionClient(self.node, self.action_type, self.action_name, callback_group=self.cb_group)
82+
client_kwargs = {
83+
"callback_group": self.cb_group,
84+
}
8185

82-
def execute(self, action_name: str, action_type: str, data: str):
83-
if self.action_name != action_name or self.action_type_string != action_type:
86+
if self.transient_local:
87+
qos_profile = QoSProfile(depth=1)
88+
qos_profile.durability = DurabilityPolicy.TRANSIENT_LOCAL
89+
client_kwargs["result_service_qos_profile"] = qos_profile
90+
91+
self.client = ActionClient(self.node, self.action_type, self.action_name, **client_kwargs)
92+
93+
def execute(self, action_name: str, action_type: str, data: str, transient_local: bool = False):
94+
if self.action_name != action_name or self.action_type_string != action_type or self.transient_local != transient_local:
8495
raise ValueError(f"Updating action_name or action_type_string not supported.")
8596

8697
self.parse_data(data)

scenario_execution_ros/scenario_execution_ros/actions/ros_service_call.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from enum import Enum
2020
from rclpy.node import Node
2121
from rclpy.callback_groups import ReentrantCallbackGroup
22+
from rclpy.qos import QoSProfile, DurabilityPolicy
2223
from rosidl_runtime_py.set_message import set_message_fields
2324
import py_trees # pylint: disable=import-error
2425
from scenario_execution.actions.base_action import BaseAction
@@ -39,7 +40,7 @@ class RosServiceCall(BaseAction):
3940
ros service call behavior
4041
"""
4142

42-
def __init__(self, service_name: str, service_type: str, data: str):
43+
def __init__(self, service_name: str, service_type: str, data: str, transient_local: bool = False):
4344
super().__init__()
4445
self.node = None
4546
self.client = None
@@ -55,6 +56,7 @@ def __init__(self, service_name: str, service_type: str, data: str):
5556
raise ValueError(f"Error while parsing sevice call data:") from e
5657
self.current_state = ServiceCallActionState.IDLE
5758
self.cb_group = ReentrantCallbackGroup()
59+
self.transient_local = transient_local
5860

5961
def setup(self, **kwargs):
6062
"""
@@ -76,11 +78,23 @@ def setup(self, **kwargs):
7678
except ValueError as e:
7779
raise ValueError(f"Invalid service_type '{self.service_type}':") from e
7880

81+
client_kwargs = {
82+
"callback_group": self.cb_group,
83+
}
84+
85+
if self.transient_local:
86+
qos_profile = QoSProfile(depth=1)
87+
qos_profile.durability = DurabilityPolicy.TRANSIENT_LOCAL
88+
client_kwargs["qos_profile"] = qos_profile
89+
7990
self.client = self.node.create_client(
80-
self.service_type, self.service_name, callback_group=self.cb_group)
91+
self.service_type,
92+
self.service_name,
93+
**client_kwargs
94+
)
8195

82-
def execute(self, service_name: str, service_type: str, data: str):
83-
if self.service_name != service_name or self.service_type_str != service_type or self.data_str != data:
96+
def execute(self, service_name: str, service_type: str, data: str, transient_local: bool):
97+
if self.service_name != service_name or self.service_type_str != service_type or self.data_str != data or self.transient_local != transient_local:
8498
raise ValueError("service_name, service_type and data arguments are not changeable during runtime.")
8599
self.current_state = ServiceCallActionState.IDLE
86100

scenario_execution_ros/scenario_execution_ros/lib_osc/ros.osc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ action action_call:
3232
action_name: string # name of the action to connect to
3333
action_type: string # class of the message type
3434
data: string # call content
35+
transient_local: bool = false
3536

3637
action assert_lifecycle_state:
3738
# Checks for the state of a lifecycle-managed node.
@@ -115,6 +116,7 @@ action service_call:
115116
service_name: string # name of the service to connect to
116117
service_type: string # class of the message type (e.g. std_srvs.msg.Empty)
117118
data: string # call content
119+
transient_local: bool = false
118120

119121
action set_node_parameter:
120122
# Set a parameter of a node.

test/scenario_execution_ros_test/scenario_execution_ros_test/workload_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def main(args=None):
5858
rclpy.spin(node)
5959
except SystemExit:
6060
pass
61-
except BaseException: # pylint: disable=broad-exception-caught
61+
except BaseException: # pylint: disable=broad-except
6262
result = False
6363

6464
if result:

test/scenario_execution_test/scenario_execution_test/external_methods/external_methods.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
#
1515
# SPDX-License-Identifier: Apache-2.0
1616

17-
def test(n: int, text: str):
18-
if n == 99:
17+
def test(n: int, text: str): # pylint: disable=invalid-name
18+
if n == 99: # pylint: disable=invalid-name
1919
raise ValueError("External Function Error!")
2020
return text
2121

tools/scenario_status/scenario_status/scenario_status_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
class ScenarioStatus(Node):
3131

32-
"""Simple node subscribing to the py-trees-behaviour tree snapshot. The output is a
32+
"""Simple node subscribing to the py-trees-behaviour tree snapshot. The output is a
3333
string that describes any behavior state changes and timestamps."""
3434

3535
def __init__(self):

0 commit comments

Comments
 (0)