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

Hi what does #include <std_msgs/String.h> mean?

asked 2022-04-26 21:25:03 -0600

sajid1122 gravatar image

Hello! i have general knowledge with c and c++ but quite new to ros. I know #include includes libraries and headers such as #include <ros.h> etc. But i dont get what #include <std_msgs string.h=""> means, im guessing we are importing Sting.h library/header from std_msgs library? Somewhat like in python we use from ___ import ___. i dont even know what std_msgs is. I did my fair share of digging online but couldn't find any satisfactory answers. Also i have never seen a '/' inbetween an include before. Thanks for whoever has read this. And thanks in advance to whoever replied. This is my first ever question in this page, dont know what to expect. I got this question when i was doing the ros-arduino tutorials. The hello world one. rosserial_arduino/Tutorials/Hello World

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2022-04-27 04:06:36 -0600

Robo_guy gravatar image

Hi @sajid1122, so the line #include "std_msgs/String.h includes the std_msgs/String message, which resides in the std_msgs ros package. This is a header that is generated automatically from the String.msgfile in that package. This is the way how ros works. If you want to understand this more deeply, you can refer these links - http://wiki.ros.org/std_msgs. This is the std_msgs package which consists of all the common message types which you can use like int, float, string, boolean etc.

You can refer to this link to understand what exactly a ros msg is - http://wiki.ros.org/msg. Regarding the use of '/' in the include statement, that is because message types in ros are referred to using package resource names meaning we need to specify the ros package that contains these messages followed by a '/' and the message type.

For example, the file geometry_msgs/msg/Twist.msg is commonly referred to as geometry_msgs/Twist. Similar is the case for std_msgs/String but by writing #include "std_msgs/String.h, the string message gets imported in our code like I mentioned earlier.

I suggest reading the documentation given in the links I have provided which can help you in understanding better. Hope this helps you in understanding the meaning of the statement.

edit flag offensive delete link more

Comments

Thank you so much! You clarified my doubts immensely :)

sajid1122 gravatar image sajid1122  ( 2022-04-27 19:58:14 -0600 )edit

Welcome, I am glad your doubts have been cleared !!

Robo_guy gravatar image Robo_guy  ( 2022-04-28 02:10:29 -0600 )edit

@sajid1122 If Robo_guy has answered your question, please tap that grey checkmark on the left of his answer, that's how you mark it as the correct answer and moves this question to "answered"

Joe28965 gravatar image Joe28965  ( 2022-04-28 03:34:17 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2022-04-26 21:25:03 -0600

Seen: 1,209 times

Last updated: Apr 27 '22