Skip to content

Commit 2ed864b

Browse files
feat: Add interface and service for retrieving action type (#1046)
* Added ActionType service and related functionality - Introduced ActionType service to retrieve the type of a specified ROS action. - Updated proxy to include logic for determining action types based on existing action servers. - Modified rosapi_node to create the new ActionType service endpoint. - Added ActionType message definition in rosapi_msgs. * Fix pre-commit hook issues: end-of-file and trailing-whitespace * reverted back vscode settings.json * Refactor get_action_type to use get_action_names_and_types for improved action type retrieval. Removed outdated logic for action server filtering and topic name extraction. * Update get_action_type function to set include_hidden parameter default to False for consistency with other functions. * Added ros2action as a runtime dependency in package.xml
1 parent fb157a0 commit 2ed864b

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed

rosapi/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<exec_depend>rosbridge_library</exec_depend>
2626
<exec_depend>ros2node</exec_depend>
2727
<exec_depend>ros2service</exec_depend>
28+
<exec_depend>ros2action</exec_depend>
2829
<exec_depend>ros2topic</exec_depend>
2930

3031
<test_depend>ament_cmake_mypy</test_depend>

rosapi/scripts/rosapi_node

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ from rosapi_msgs.srv import (
4747
ActionFeedbackDetails,
4848
ActionGoalDetails,
4949
ActionResultDetails,
50+
ActionType,
5051
DeleteParam,
5152
GetActionServers,
5253
GetParam,
@@ -112,6 +113,7 @@ class Rosapi(Node):
112113
self.create_service(Nodes, "~/nodes", self.get_nodes)
113114
self.create_service(NodeDetails, "~/node_details", self.get_node_details)
114115
self.create_service(GetActionServers, "~/action_servers", self.get_action_servers)
116+
self.create_service(ActionType, "~/action_type", self.get_action_type)
115117
self.create_service(TopicType, "~/topic_type", self.get_topic_type)
116118
self.create_service(ServiceType, "~/service_type", self.get_service_type)
117119
self.create_service(Publishers, "~/publishers", self.get_publishers)
@@ -335,6 +337,12 @@ class Rosapi(Node):
335337
]
336338
return response
337339

340+
def get_action_type(self, request, response):
341+
"""Called by the rosapi/ActionType service. Given the name of an action, returns its type.
342+
If the action does not exist, an empty string is returned."""
343+
response.type = proxy.get_action_type(request.action)
344+
return response
345+
338346
async def set_param(self, request, response):
339347
try:
340348
node_name, param_name = self._get_node_and_param_name(request.name)

rosapi/src/rosapi/proxy.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3232
# POSSIBILITY OF SUCH DAMAGE.
3333

34+
from ros2action.api import get_action_names_and_types
3435
from ros2interface.api import type_completer
3536
from ros2node.api import (
3637
get_node_names,
@@ -264,3 +265,16 @@ def get_service_node(queried_type, services_glob, include_hidden=False):
264265
return node_name[0]
265266
else:
266267
return ""
268+
269+
270+
def get_action_type(action_name, include_hidden=False):
271+
"""Returns the type of the specified ROS action.
272+
If the action does not exist, an empty string is returned."""
273+
274+
names_and_types = get_action_names_and_types(node=_node, include_hidden_actions=include_hidden)
275+
276+
for name, types in names_and_types:
277+
if name == action_name and types:
278+
return types[0]
279+
280+
return ""

rosapi_msgs/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ rosidl_generate_interfaces(${PROJECT_NAME}
2626
srv/ActionGoalDetails.srv
2727
srv/ActionResultDetails.srv
2828
srv/ActionFeedbackDetails.srv
29+
srv/ActionType.srv
2930
srv/Services.srv
3031
srv/ServicesForType.srv
3132
srv/ServiceType.srv

rosapi_msgs/srv/ActionType.srv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
string action
2+
---
3+
string type

0 commit comments

Comments
 (0)