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

Service_call_qos (#161) #163

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#
# SPDX-License-Identifier: Apache-2.0

def factorial(n: int):
def factorial(n: int): # pylint: disable=invalid-name
fact = 1
for i in range(1, n+1):
fact = fact * i
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self, associated_actor, goal_poses: list, action_topic: str, namesp
self.goal_poses = None
super().__init__(self.namespace + '/' + action_topic, "nav2_msgs.action.NavigateThroughPoses", "")

def execute(self, associated_actor, goal_poses: list, action_topic: str, namespace_override: str) -> None: # pylint: disable=arguments-differ
def execute(self, associated_actor, goal_poses: list, action_topic: str, namespace_override: str) -> None: # pylint: disable=arguments-differ,arguments-renamed
self.namespace = associated_actor["namespace"]
if namespace_override:
self.namespace = namespace_override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self, associated_actor, goal_pose: list, action_topic: str, namespa
self.goal_pose = None
super().__init__(self.namespace + '/' + action_topic, "nav2_msgs.action.NavigateToPose", "")

def execute(self, associated_actor, goal_pose: list, action_topic: str, namespace_override: str) -> None: # pylint: disable=arguments-differ
def execute(self, associated_actor, goal_pose: list, action_topic: str, namespace_override: str) -> None: # pylint: disable=arguments-differ,arguments-renamed
self.namespace = associated_actor["namespace"]
if namespace_override:
self.namespace = namespace_override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def initialise(self):
if self._model.actor:
final_args["associated_actor"] = self._model.actor.get_resolved_value(self.get_blackboard_client())
final_args["associated_actor"]["name"] = self._model.actor.name
self.execute(**final_args)
self.execute(**final_args) # pylint: disable=no-member

def _set_base_properities(self, name, model, logger):
self.name = name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from rclpy.node import Node
from rclpy.callback_groups import ReentrantCallbackGroup
from rclpy.action import ActionClient
from rclpy.qos import QoSProfile, DurabilityPolicy
from rosidl_runtime_py.set_message import set_message_fields
import py_trees # pylint: disable=import-error
from action_msgs.msg import GoalStatus
Expand All @@ -42,7 +43,7 @@ class RosActionCall(BaseAction):
ros service call behavior
"""

def __init__(self, action_name: str, action_type: str, data: str):
def __init__(self, action_name: str, action_type: str, data: str, transient_local: bool = False):
super().__init__()
self.node = None
self.client = None
Expand All @@ -56,6 +57,7 @@ def __init__(self, action_name: str, action_type: str, data: str):
self.parse_data(data)
self.current_state = ActionCallActionState.IDLE
self.cb_group = ReentrantCallbackGroup()
self.transient_local = transient_local

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

self.client = ActionClient(self.node, self.action_type, self.action_name, callback_group=self.cb_group)
client_kwargs = {
"callback_group": self.cb_group,
}

def execute(self, action_name: str, action_type: str, data: str):
if self.action_name != action_name or self.action_type_string != action_type:
if self.transient_local:
qos_profile = QoSProfile(depth=1)
qos_profile.durability = DurabilityPolicy.TRANSIENT_LOCAL
client_kwargs["result_service_qos_profile"] = qos_profile

self.client = ActionClient(self.node, self.action_type, self.action_name, **client_kwargs)

def execute(self, action_name: str, action_type: str, data: str, transient_local: bool = False):
if self.action_name != action_name or self.action_type_string != action_type or self.transient_local != transient_local:
raise ValueError(f"Updating action_name or action_type_string not supported.")

self.parse_data(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from enum import Enum
from rclpy.node import Node
from rclpy.callback_groups import ReentrantCallbackGroup
from rclpy.qos import QoSProfile, DurabilityPolicy
from rosidl_runtime_py.set_message import set_message_fields
import py_trees # pylint: disable=import-error
from scenario_execution.actions.base_action import BaseAction
Expand All @@ -39,7 +40,7 @@ class RosServiceCall(BaseAction):
ros service call behavior
"""

def __init__(self, service_name: str, service_type: str, data: str):
def __init__(self, service_name: str, service_type: str, data: str, transient_local: bool = False):
super().__init__()
self.node = None
self.client = None
Expand All @@ -55,6 +56,7 @@ def __init__(self, service_name: str, service_type: str, data: str):
raise ValueError(f"Error while parsing sevice call data:") from e
self.current_state = ServiceCallActionState.IDLE
self.cb_group = ReentrantCallbackGroup()
self.transient_local = transient_local

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

client_kwargs = {
"callback_group": self.cb_group,
}

if self.transient_local:
qos_profile = QoSProfile(depth=1)
qos_profile.durability = DurabilityPolicy.TRANSIENT_LOCAL
client_kwargs["qos_profile"] = qos_profile

self.client = self.node.create_client(
self.service_type, self.service_name, callback_group=self.cb_group)
self.service_type,
self.service_name,
**client_kwargs
)

def execute(self, service_name: str, service_type: str, data: str):
if self.service_name != service_name or self.service_type_str != service_type or self.data_str != data:
def execute(self, service_name: str, service_type: str, data: str, transient_local: bool):
if self.service_name != service_name or self.service_type_str != service_type or self.data_str != data or self.transient_local != transient_local:
raise ValueError("service_name, service_type and data arguments are not changeable during runtime.")
self.current_state = ServiceCallActionState.IDLE

Expand Down
2 changes: 2 additions & 0 deletions scenario_execution_ros/scenario_execution_ros/lib_osc/ros.osc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ action action_call:
action_name: string # name of the action to connect to
action_type: string # class of the message type
data: string # call content
transient_local: bool = false

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

action set_node_parameter:
# Set a parameter of a node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def main(args=None):
rclpy.spin(node)
except SystemExit:
pass
except BaseException: # pylint: disable=broad-exception-caught
except BaseException: # pylint: disable=broad-except
result = False

if result:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#
# SPDX-License-Identifier: Apache-2.0

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

class ScenarioStatus(Node):

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

def __init__(self):
Expand Down