Skip to content

Commit 594c97a

Browse files
authored
Expose .msg/.srv/.action to .idl conversion via rosidl translate CLI (#576)
Signed-off-by: Michel Hidalgo <[email protected]>
1 parent 15c7150 commit 594c97a

File tree

14 files changed

+331
-8
lines changed

14 files changed

+331
-8
lines changed

rosidl_adapter/CMakeLists.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ find_package(ament_cmake_python REQUIRED)
88
ament_python_install_package(${PROJECT_NAME})
99

1010
if(BUILD_TESTING)
11+
find_package(ament_cmake_pytest REQUIRED)
1112
find_package(ament_lint_auto REQUIRED)
1213
ament_lint_auto_find_test_dependencies()
14+
ament_add_pytest_test(pytest test)
1315
endif()
1416

1517
ament_package(
@@ -25,8 +27,3 @@ install(PROGRAMS
2527
scripts/msg2idl.py
2628
scripts/srv2idl.py
2729
DESTINATION lib/${PROJECT_NAME})
28-
29-
if(BUILD_TESTING)
30-
find_package(ament_cmake_pytest REQUIRED)
31-
ament_add_pytest_test(pytest test)
32-
endif()

rosidl_adapter/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<build_depend>ament_cmake</build_depend>
1515

1616
<exec_depend>python3-empy</exec_depend>
17+
<exec_depend>rosidl_cli</exec_depend>
1718

1819
<test_depend>ament_cmake_pytest</test_depend>
1920
<test_depend>ament_lint_common</test_depend>

rosidl_adapter/rosidl_adapter/action/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def convert_action_to_idl(package_dir, package_name, input_file, output_dir):
3232
print(f'Writing output file: {abs_output_file}')
3333
data = {
3434
'pkg_name': package_name,
35-
'relative_input_file': input_file,
35+
'relative_input_file': input_file.as_posix(),
3636
'action': action,
3737
}
3838

rosidl_adapter/rosidl_adapter/cli.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
from catkin_pkg.package import package_exists_at
2020
from catkin_pkg.package import parse_package
2121

22+
from rosidl_adapter.action import convert_action_to_idl
23+
from rosidl_adapter.msg import convert_msg_to_idl
24+
from rosidl_adapter.srv import convert_srv_to_idl
25+
26+
from rosidl_cli.command.helpers import interface_path_as_tuple
27+
from rosidl_cli.command.translate.extensions import TranslateCommandExtension
28+
2229

2330
def convert_files_to_idl(extension, conversion_function, argv=sys.argv[1:]):
2431
parser = argparse.ArgumentParser(
@@ -48,3 +55,54 @@ def convert_files_to_idl(extension, conversion_function, argv=sys.argv[1:]):
4855
package_dir, pkg.name,
4956
interface_file.absolute().relative_to(package_dir),
5057
interface_file.parent)
58+
59+
60+
class TranslateToIDL(TranslateCommandExtension):
61+
62+
output_format = 'idl'
63+
64+
def translate(
65+
self,
66+
package_name,
67+
interface_files,
68+
include_paths,
69+
output_path
70+
):
71+
translated_interface_files = []
72+
for interface_file in interface_files:
73+
prefix, interface_file = interface_path_as_tuple(interface_file)
74+
output_dir = output_path / interface_file.parent
75+
translated_interface_file = self.conversion_function(
76+
prefix, package_name, interface_file, output_dir)
77+
translated_interface_file = \
78+
translated_interface_file.relative_to(output_path)
79+
translated_interface_files.append(
80+
f'{output_path}:{translated_interface_file.as_posix()}'
81+
)
82+
return translated_interface_files
83+
84+
85+
class TranslateMsgToIDL(TranslateToIDL):
86+
87+
input_format = 'msg'
88+
89+
@property
90+
def conversion_function(self):
91+
return convert_msg_to_idl
92+
93+
94+
class TranslateSrvToIDL(TranslateToIDL):
95+
96+
input_format = 'srv'
97+
98+
@property
99+
def conversion_function(self):
100+
return convert_srv_to_idl
101+
102+
103+
class TranslateActionToIDL(TranslateToIDL):
104+
input_format = 'action'
105+
106+
@property
107+
def conversion_function(self):
108+
return convert_action_to_idl

rosidl_adapter/rosidl_adapter/msg/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def convert_msg_to_idl(package_dir, package_name, input_file, output_dir):
3232
print(f'Writing output file: {abs_output_file}')
3333
data = {
3434
'pkg_name': package_name,
35-
'relative_input_file': input_file,
35+
'relative_input_file': input_file.as_posix(),
3636
'msg': msg,
3737
}
3838

rosidl_adapter/rosidl_adapter/srv/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def convert_srv_to_idl(package_dir, package_name, input_file, output_dir):
3232
print(f'Writing output file: {abs_output_file}')
3333
data = {
3434
'pkg_name': package_name,
35-
'relative_input_file': input_file,
35+
'relative_input_file': input_file.as_posix(),
3636
'srv': srv,
3737
}
3838

rosidl_adapter/setup.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[options.entry_points]
2+
rosidl_cli.command.translate.extensions =
3+
msg2idl = rosidl_adapter.cli:TranslateMsgToIDL
4+
srv2idl = rosidl_adapter.cli:TranslateSrvToIDL
5+
action2idl = rosidl_adapter.cli:TranslateActionToIDL
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# goal definition
2+
bool bool_value
3+
byte byte_value
4+
char char_value
5+
float32 float32_value
6+
float64 float64_value
7+
int8 int8_value
8+
uint8 uint8_value
9+
int16 int16_value
10+
uint16 uint16_value
11+
int32 int32_value
12+
uint32 uint32_value
13+
int64 int64_value
14+
uint64 uint64_value
15+
string string_value
16+
---
17+
# result definition
18+
bool ok
19+
---
20+
# feedback definition
21+
int32[] sequence
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// generated from rosidl_adapter/resource/action.idl.em
2+
// with input from test_msgs/action/Test.action
3+
// generated code does not contain a copyright notice
4+
5+
6+
module test_msgs {
7+
module action {
8+
@verbatim (language="comment", text=
9+
" goal definition")
10+
struct Test_Goal {
11+
boolean bool_value;
12+
13+
octet byte_value;
14+
15+
uint8 char_value;
16+
17+
float float32_value;
18+
19+
double float64_value;
20+
21+
int8 int8_value;
22+
23+
uint8 uint8_value;
24+
25+
int16 int16_value;
26+
27+
uint16 uint16_value;
28+
29+
int32 int32_value;
30+
31+
uint32 uint32_value;
32+
33+
int64 int64_value;
34+
35+
uint64 uint64_value;
36+
37+
string string_value;
38+
};
39+
struct Test_Result {
40+
@verbatim (language="comment", text=
41+
" result definition")
42+
boolean ok;
43+
};
44+
struct Test_Feedback {
45+
@verbatim (language="comment", text=
46+
" feedback definition")
47+
sequence<int32> sequence;
48+
};
49+
};
50+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// generated from rosidl_adapter/resource/msg.idl.em
2+
// with input from test_msgs/msg/Test.msg
3+
// generated code does not contain a copyright notice
4+
5+
6+
module test_msgs {
7+
module msg {
8+
struct Test {
9+
boolean bool_value;
10+
11+
octet byte_value;
12+
13+
uint8 char_value;
14+
15+
float float32_value;
16+
17+
double float64_value;
18+
19+
int8 int8_value;
20+
21+
uint8 uint8_value;
22+
23+
int16 int16_value;
24+
25+
uint16 uint16_value;
26+
27+
int32 int32_value;
28+
29+
uint32 uint32_value;
30+
31+
int64 int64_value;
32+
33+
uint64 uint64_value;
34+
};
35+
};
36+
};

0 commit comments

Comments
 (0)