Skip to content

Commit f1edcc5

Browse files
committed
Mirror actions using ros1_tools/ros1_message_mirror
1 parent 2822810 commit f1edcc5

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

Diff for: ros1_message_mirror/cmake/rosidl_from_ros1_package.cmake

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ macro(rosidl_from_ros1_package package)
1212
# TODO(pbovbel) register bin path
1313
set(bin_path ${CMAKE_INSTALL_PREFIX}/lib/ros1_message_mirror)
1414

15-
set(message_types "msg" "srv")
15+
set(message_types "msg" "srv" "action")
1616

1717
foreach(message_type ${message_types})
1818
execute_process(COMMAND ${bin_path}/get_ros1_messages ${package} --type ${message_type}
@@ -47,10 +47,11 @@ macro(rosidl_from_ros1_package package)
4747
# How does rosidl know if something's a srv or msg? By the file extension?
4848
# No! by the containing directory! *facepalm*
4949
# https://github.com/ros2/rosidl/issues/213
50-
if(msg_ROS2_LIST OR srv_ROS2_LIST)
50+
if(msg_ROS2_LIST OR srv_ROS2_LIST OR action_ROS2_LIST)
5151
rosidl_generate_interfaces(${package}
5252
${msg_ROS2_LIST}
5353
${srv_ROS2_LIST}
54+
${action_ROS2_LIST}
5455
DEPENDENCIES ${args_DEPENDENCIES} builtin_interfaces
5556
ADD_LINTER_TESTS
5657
)

Diff for: ros1_message_mirror/ros1_message_mirror/__init__.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,30 @@
5656
extension_to_rosmsg_mode = {
5757
'msg': rosmsg.MODE_MSG,
5858
'srv': rosmsg.MODE_SRV,
59+
'action': rosmsg.MODE_MSG,
5960
}
6061

6162

6263
def get_ros1_message_paths(package, extension):
6364
rospack = rospkg.RosPack()
6465
mode = extension_to_rosmsg_mode[extension]
65-
path = os.path.join(rospack.get_path(package), extension)
6666
msgs = rosmsg.list_types(package, mode, rospack)
67-
return [os.path.join(path, msg.split('/')[-1] + '.' + extension) for msg in msgs]
67+
msg_dir = os.path.join(rospack.get_path(package), extension)
68+
69+
if extension == 'action':
70+
# find actions via ActionGoal messages
71+
filename_marker = "ActionGoal"
72+
msgs = [msg[:-len(filename_marker)] for msg in msgs if msg.endswith(filename_marker)]
73+
74+
msg_paths = [os.path.join(msg_dir, msg.split('/')[-1] + '.' + extension) for msg in msgs]
75+
76+
if extension != 'action':
77+
# don't copy autogenerated action messages from ROS1 to ROS2
78+
content_marker = "# ====== DO NOT MODIFY! AUTOGENERATED FROM AN ACTION DEFINITION ======"
79+
msg_paths = [
80+
msg_path
81+
for msg_path in msg_paths
82+
if not open(msg_path, "r", encoding="utf-8").read().startswith(content_marker)
83+
]
84+
85+
return msg_paths

Diff for: ros1_message_mirror/scripts/get_ros1_messages

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def main(argv=sys.argv[1:]):
2222
'--type',
2323
required=True,
2424
type=str,
25-
choices=['msg', 'srv'],
25+
choices=['msg', 'srv', 'action'],
2626
help='The type of message to search for.')
2727
args = parser.parse_args(argv)
2828

0 commit comments

Comments
 (0)