Ask Your Question
0

Why do we need to add generators for messages, services and actions, but only generate messages (in the CMakeLists.txt file)?

asked 2018-03-21 09:29:31 -0600

nbro gravatar image

updated 2018-03-21 09:38:05 -0600

In the following article http://wiki.ros.org/catkin/CMakeLists... , it is stated that, for a package to be correctly built, we must follow a certain format for the CMakeLists.txt file. In particular, point 5 is

Message/Service/Action Generators (add_message_files(), add_service_files(), add_action_files())

and point 6 is

Invoke message/service/action generation (generate_messages())

I have no idea what these generators are. What are they exactly? Why do we need them?

Furthermore, I infer that we first need to add generators for messages, services and actions. Later, eventually, we can also generate messages. I have no idea what the difference between creating a generator for messages and generating messages is. Why do we need these two separate steps? Why don't we also have generate_services or generate_actions (even though the documentation says "Invoke message/service/ action generation")? Why on earth do we even need to have generators or generate files related to messages, services and actions?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-03-21 20:09:15 -0600

William gravatar image

I'll try to answer your questions by linking to tutorials and docs, rather than repeating here.

I have no idea what these generators are. What are they exactly? Why do we need them?

and

Why on earth do we even need to have generators or generate files related to messages, services and actions?

They are used to generate code based on ROS interfaces which are used to exchange information over topics and services even between different languages. Because this is defined in a .msg file (which is a custom DSL) and needs to be used in each language (C++, Python, etc...) there is a necessary code generation step. You only need to do this if you have custom message or service definitions:

I have no idea what the difference between creating a generator for messages and generating messages is.

Well, creating a generator is where you define how a message definition should be expanded into code. That's handled by genmsg and is implemented for several languages: C++ gencpp, Python genpy, Lisp genlisp:

Where as generating messages is where you provide a message definition, and then the available message generators turn that message definition into language specific code. Again see:

Why do we need these two separate steps?

The two things you mentioned add_message_files() and generate_messages() are separate steps because you can call the first kind of macro many times (you can think of it as building up a list of things that your package should generate code for), and the later is called once to actual generate the code. You should not call the latter after calling the former if you want it to work correctly.

edit flag offensive delete link more

Comments

In this article, https://wiki.ros.org/ROS/Tutorials/Cr... , you link us to, "message_generation" is added as a build dependency to the package.xml (<build_depend>message_generation</build_depend>) and to CMakeLists.txt. Why specifying the same thing in different places?

nbro gravatar imagenbro ( 2018-03-22 03:51:47 -0600 )edit
1

This is sort of a different question, in the future please edit your question, or if it's different enough, ask a new one.

William gravatar imageWilliam ( 2018-03-22 05:00:07 -0600 )edit

The reason is that each place you add it serves a different purpose, this page describes the various roles each of these locations serves when declaring/using dependencies: https://wiki.ros.org/catkin/conceptua...

William gravatar imageWilliam ( 2018-03-22 05:01:15 -0600 )edit
1

It could be possible to automate this, which is the goal of something like catkin_simple ( https://github.com/catkin/catkin_simple ), but there are common cases this automation cannot handle well due to the limitations of cmake and how we use it in ROS.

William gravatar imageWilliam ( 2018-03-22 05:02:48 -0600 )edit

If you want, I can ask another question, and you can (re)-answer there.

nbro gravatar imagenbro ( 2018-03-22 05:15:23 -0600 )edit

You didn't answer one of my questions: "Why don't we also have generate_services or generate_actions?".

nbro gravatar imagenbro ( 2018-03-22 05:16:25 -0600 )edit
1

Why specifying the same thing in different places?

With the risk of side-tracking this a bit, see whether #q217475 can explain this.

I do agree with @William though: ROS Answers is a 1-to-1 Q&A site. It's not well suited for follow-up questions or even multiple questions in a single post.

gvdhoorn gravatar imagegvdhoorn ( 2018-03-22 05:53:15 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

3 followers

Stats

Asked: 2018-03-21 09:29:31 -0600

Seen: 167 times

Last updated: Mar 21 '18