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.
Originally posted by William with karma: 17335 on 2018-03-21
This answer was ACCEPTED on the original site
Post score: 1
Original comments
Comment by nbro on 2018-03-22:
In this article, https://wiki.ros.org/ROS/Tutorials/CreatingMsgAndSrv#Using_msg, 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?
Comment by William on 2018-03-22:
This is sort of a different question, in the future please edit your question, or if it's different enough, ask a new one.
Comment by William on 2018-03-22:
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/conceptual_overview#Dependency_Management
Comment by William on 2018-03-22:
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.
Comment by nbro on 2018-03-22:
If you want, I can ask another question, and you can (re)-answer there.
Comment by nbro on 2018-03-22:
You didn't answer one of my questions: "Why don't we also have generate_services or generate_actions?".
Comment by gvdhoorn on 2018-03-22:\
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.