Skip to content

Commit

Permalink
Add send_action_goals_in_new_thread param
Browse files Browse the repository at this point in the history
  • Loading branch information
sea-bass committed Nov 1, 2023
1 parent 5d93ca0 commit b248cd0
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,21 @@ def __init__(self, protocol):
Capability.__init__(self, protocol)

# Register the operations that this capability provides
call_services_in_new_thread = (
protocol.node_handle.get_parameter("call_services_in_new_thread")
send_action_goals_in_new_thread = (
protocol.node_handle.get_parameter("send_action_goals_in_new_thread")
.get_parameter_value()
.bool_value
)
if call_services_in_new_thread:
if send_action_goals_in_new_thread:
# Sends the action goal in a separate thread so multiple actions can be processed simultaneously.
protocol.node_handle.get_logger().info("Sending action goal in new thread")
protocol.node_handle.get_logger().info("Sending action goals in new thread")
protocol.register_operation(
"send_action_goal",
lambda msg: Thread(target=self.send_action_goal, args=(msg,)).start(),
)
else:
# Sends the actions goal in this thread, so actions block and must be processed sequentially.
protocol.node_handle.get_logger().info("Sending action goal in existing thread")
protocol.node_handle.get_logger().info("Sending action goals in existing thread")
protocol.register_operation("send_action_goal", self.send_action_goal)

protocol.register_operation("cancel_action_goal", self.cancel_action_goal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def setUp(self):
self.executor.add_node(self.node)

self.node.declare_parameter("call_services_in_new_thread", False)
self.node.declare_parameter("send_action_goals_in_new_thread", False)

self.proto = Protocol(self._testMethodName, self.node)
# change the log function so we can verify errors are logged
Expand Down
1 change: 1 addition & 0 deletions rosbridge_library/test/capabilities/test_call_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def setUp(self):
self.executor.add_node(self.node)

self.node.declare_parameter("call_services_in_new_thread", False)
self.node.declare_parameter("send_action_goals_in_new_thread", False)

# Create service servers with a separate callback group
self.cb_group = ReentrantCallbackGroup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def setUp(self):
self.node = Node("test_service_capabilities")

self.node.declare_parameter("call_services_in_new_thread", False)
self.node.declare_parameter("send_action_goals_in_new_thread", False)

self.proto = Protocol(self._testMethodName, self.node)
# change the log function so we can verify errors are logged
Expand Down
3 changes: 3 additions & 0 deletions rosbridge_server/launch/rosbridge_websocket_launch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

<arg name="use_compression" default="false" />
<arg name="call_services_in_new_thread" default="false" />
<arg name="send_action_goals_in_new_thread" default="false" />

<arg name="topics_glob" default="" />
<arg name="services_glob" default="" />
Expand All @@ -35,6 +36,7 @@
<param name="unregister_timeout" value="$(var unregister_timeout)"/>
<param name="use_compression" value="$(var use_compression)"/>
<param name="call_services_in_new_thread" value="$(var call_services_in_new_thread)"/>
<param name="send_action_goals_in_new_thread" value="$(var send_action_goals_in_new_thread)"/>

<param name="topics_glob" value="$(var topics_glob)"/>
<param name="services_glob" value="$(var services_glob)"/>
Expand All @@ -52,6 +54,7 @@
<param name="unregister_timeout" value="$(var unregister_timeout)"/>
<param name="use_compression" value="$(var use_compression)"/>
<param name="call_services_in_new_thread" value="$(var call_services_in_new_thread)"/>
<param name="send_action_goals_in_new_thread" value="$(var send_action_goals_in_new_thread)"/>

<param name="topics_glob" value="$(var topics_glob)"/>
<param name="services_glob" value="$(var services_glob)"/>
Expand Down
4 changes: 4 additions & 0 deletions rosbridge_server/scripts/rosbridge_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ def protocol_parameter_handling(self):
"call_services_in_new_thread", False
).value

RosbridgeWebSocket.send_action_goals_in_new_thread = self.declare_parameter(
"send_action_goals_in_new_thread", False
).value

# get RosbridgeProtocol parameters
RosbridgeWebSocket.fragment_timeout = self.declare_parameter(
"fragment_timeout", RosbridgeWebSocket.fragment_timeout
Expand Down

0 comments on commit b248cd0

Please sign in to comment.