Difference between revisions of "Defining Custom Messages"

From Lofaro Lab Wiki
Jump to: navigation, search
(Created page with "The majority of the information needed to create a message can be found by viewing the earlier tutorial on msg: [http://wiki.lofarolabs.com/index.php/Creating_a_ROS_msg_and_s...")
 
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>   1 #include <std_msgs/String.h>
 
   2  
 
   2  
 
   3 std_msgs::String msg;</nowiki>
 
   3 std_msgs::String msg;</nowiki>
  
 
For Python:
 
For Python:
  <nowiki>1 from std_msgs.msg import String
+
  <nowiki>   1 from std_msgs.msg import String
 
   2  
 
   2  
 
   3 msg = String()</nowiki>
 
   3 msg = String()</nowiki>

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

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

For Python:

   1 from std_msgs.msg import String
   2 
   3 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>