ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How to hook a new IDL generator

asked 2018-05-21 13:51:42 -0600

amosteo gravatar image

I'm trying to understand how to add a new generator for the Ada language. I've been trying to make sense of the different CMake files in the different packages, ament, rosidl, etc. I've also checked the case of the rosidl_java_generator. Still, I have a general idea of what's happening but I'm failing to pin down the details. Two questions:

I see that the java case requires patching the CMakeLists.txt and package.xml of the rosidl_default_generators package. Is this mandatory? I.e., cannot one add a new generator in a new package without having to patch other people's packages?

Be it possible or not, I'm failing to understand when/how exactly a new generator is called and what information it receives. I guess at some point dependencies are added to the .msg files on some cmake targets, but I have not found where. Any help with these questions will be much appreciated, thanks.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2018-05-21 15:50:25 -0600

Dirk Thomas gravatar image

I see that the java case requires patching the CMakeLists.txt and package.xml of the rosidl_default_generators package. Is this mandatory? I.e., cannot one add a new generator in a new package without having to patch other people's packages?

That should not be necessary anymore. I don't know which exact change you are referring to but I assume adding the new generator as a dependency? With REP 149 group dependencies were added and those are now being used by the message generators. Using those it should be possible to create a new package containing a message generator and declare the group membership in that package in order to be picked up during the build and being processed before message packages.

In general whenever a message package calls rosidl_generate_interfaces all registered message generators are being run. That happens by including the CMake file each message generator has registered as an extension, e.g. https://github.com/ros2/rosidl/blob/c...

Each message generator decides how it wants to perform the code generation. Most of them are invoking Python to generate files based on templates and the msg/srv files passed. The CMake code for it is pretty lengthy since it also needs to track what files are expected to be generated and what files are involved in that (in order to regenerate files if and only if any of the involved files changes). Some generators also additionally run code linter on the generated code. E.g. https://github.com/ros2/rosidl/blob/m...

I hope this give a high level overview of the process. Please feel free to add more concrete questions.

edit flag offensive delete link more

Comments

Thanks, Dirk, this helps me greatly in putting all pieces together.

In the example you link to, the macro ament_register_extension is used. What if one is using plain CMake packages? I was trying to stay away from ament until colcon is in place.

amosteo gravatar image amosteo  ( 2018-05-22 03:36:38 -0600 )edit

The extension registry is based on the ament resource index. At the end it is stored in files (often empty ones) in the file system. If you don't want to use the simple CMake functions provided by ament you could implement the same functionality yourself.

Dirk Thomas gravatar image Dirk Thomas  ( 2018-05-22 12:08:42 -0600 )edit

Regarding "trying to stay away from ament until colcon is in place": ament_cmake will stay around just as it is - that part represents the build system. Only the build tool part (aka ament_tools) will be substituted by colcon. Nothing in the CMake code of ROS 2 packages is going to change.

Dirk Thomas gravatar image Dirk Thomas  ( 2018-05-22 12:10:15 -0600 )edit

Ah, great. Then I will take the easy route, thanks.

amosteo gravatar image amosteo  ( 2018-05-23 06:24:03 -0600 )edit

Wasn't the mechanism in REP-149 only used for typesupports? It seems to me that messages still depend on rosidl_default_generators, hence the patch to add the ros2_java generator.

esteve gravatar image esteve  ( 2018-06-10 15:54:50 -0600 )edit

The group dependencies are being used in a variety of cases - not only for typesupport. E.g. https://github.com/ros2/ros1_bridge/b...

Dirk Thomas gravatar image Dirk Thomas  ( 2018-06-11 15:51:29 -0600 )edit

In that case, is still necessary to explicitly list the generators in rosidl_default_generators? Are they automatically discovered thanks to REP-149? https://github.com/ros2/rosidl_typesu...

esteve gravatar image esteve  ( 2018-06-13 11:40:30 -0600 )edit

No, it isn't necessary to explicitly list them in rosidl_default_generators. If the package is in the workspace it is being processed before the rosidl_default_generators due to the group membership.

Dirk Thomas gravatar image Dirk Thomas  ( 2018-06-13 11:42:48 -0600 )edit
0

answered 2018-06-14 13:46:07 -0600

esteve gravatar image

Just a followup to Dirk's answer. The language generators are not automatically discovered currently, so it's still necessary to patch rosidl_default_generators to add extra generators (see https://github.com/esteve/ros2_java#d... ). I've submitted https://github.com/ros2/rosidl_typesu... and https://github.com/ros2/rosidl_typesu... to address that.

edit flag offensive delete link more

Comments

Unfortunately I have worked on the same thing: see https://github.com/ros2/rosidl/pull/283 and https://github.com/ros2/rosidl_typesu... .

Dirk Thomas gravatar image Dirk Thomas  ( 2018-06-14 13:49:27 -0600 )edit

Could you withdraw your answer or update it to mention that patching was still necessary? With either your pull requests or mine that'd be no longer an issue. Thanks.

esteve gravatar image esteve  ( 2018-06-14 13:52:33 -0600 )edit

@esteve @dirk-thomas Do you have any updates on this in Foxy? Having issues with the same thing, question here: https://answers.ros.org/question/3573...

atyshka gravatar image atyshka  ( 2020-07-16 17:04:16 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2018-05-21 13:51:42 -0600

Seen: 1,349 times

Last updated: Jun 14 '18