Difference between revisions of "Defining Custom Messages"

From Lofaro Lab Wiki
Jump to: navigation, search
m
m
 
Line 8: Line 8:
  
 
For C++, an example would be
 
For C++, an example would be
  <nowiki>   1 #include <std_msgs/String.h>
+
  <nowiki>#include <std_msgs/String.h>
  2
+
 
  3 std_msgs::String msg;</nowiki>
+
std_msgs::String msg;</nowiki>
  
 
For Python:
 
For Python:
  <nowiki>   1 from std_msgs.msg import String
+
  <nowiki>from std_msgs.msg import String
  2
+
  3 msg = String()</nowiki>
+
msg = String()</nowiki>
  
 
*If you are using a msg from one package (package 1) in another (new package 2), don't forget these changes to your package.xml file of package 2:
 
*If you are using a msg from one package (package 1) in another (new package 2), don't forget these changes to your package.xml file of package 2:
 
  <nowiki><build_depend>name_of_package_1</build_depend>
 
  <nowiki><build_depend>name_of_package_1</build_depend>
 
<run_depend>name_of_package_1</run_depend></nowiki>
 
<run_depend>name_of_package_1</run_depend></nowiki>

Latest revision as of 14:35, 23 October 2014

The majority of the information needed to create a message can be found by viewing the earlier tutorial on msg:

Creating a ROS msg and srv

Some other notes:

  • The msg file should be added to the msg folder of the package you are creating it for.
  • Messages are put into a namespace which matches the name of the package.

For C++, an example would be

#include <std_msgs/String.h>
  
std_msgs::String msg;

For Python:

from std_msgs.msg import String
 
msg = String()
  • If you are using a msg from one package (package 1) in another (new package 2), don't forget these changes to your package.xml file of package 2:
<build_depend>name_of_package_1</build_depend>
<run_depend>name_of_package_1</run_depend>