{"id":9311,"date":"2023-04-15T11:11:00","date_gmt":"2023-04-15T11:11:00","guid":{"rendered":"https:\/\/www.fambach.net\/?p=9311"},"modified":"2023-04-22T09:43:13","modified_gmt":"2023-04-22T09:43:13","slug":"ros-nachrichten-erstellen","status":"publish","type":"post","link":"https:\/\/www.fambach.net\/en\/ros-nachrichten-erstellen\/","title":{"rendered":"ROS: Creating Messages"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 ez-toc-wrap-left counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Contents\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewbox=\"0 0 24 24\" version=\"1.2\" baseprofile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.fambach.net\/en\/ros-catkin\/#Installation\" >Installation<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.fambach.net\/en\/ros-catkin\/#Ubuntu_1804\" >Ubuntu 18.04<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.fambach.net\/en\/ros-catkin\/#Abhangigkeiten_auflosen\" >Abh&auml;ngigkeiten aufl&ouml;sen<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.fambach.net\/en\/ros-catkin\/#Catkin_installieren\" >Install Catkin<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.fambach.net\/en\/ros-catkin\/#Befehle\" >Commands<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.fambach.net\/en\/ros-catkin\/#Bauen\" >Build<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.fambach.net\/en\/ros-catkin\/#Installieren\" >Install<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.fambach.net\/en\/ros-catkin\/#Quellen\" >Sources<\/a><\/li><\/ul><\/nav><\/div>\n\n<p class=\"wp-block-paragraph\">F&uuml;r den Austausch von Daten zwischen verschiedenen Knoten werden Nachrichten ben&ouml;tigt. Diese werden in .msg Dateien definiert und dann mittels catkin generiert. Das Ergebnis ist eine .h Datei mit C-Code und gleichen Namen. Jeder Knoten kann diese Nachrichten dann abbonieren. Die Nachrichten werden automatisch vom sendenden Knoten ausgesandt und alle Abbonenten bekommen sie. Dies unterscheidet die Nachricht vom Server, bei dem der Empf&auml;nger Informationen explizit anfragt.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Wie das funktioniert soll hier kurz beschrieben werden. F&uuml;r eine auf&uuml;hrliche Anleitung sei auf https:\/\/wiki.ros.org\/ROS\/Tutorials\/CreatingMsgAndSrv verwiesen.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Prerequisite<\/h1>\n\n\n<div class=\"display-posts-listing\">\n<div class=\"listing-item\"><a class=\"title\" href=\"https:\/\/www.fambach.net\/en\/ros-einfachen-publisher-subscriber-in-c-erstellen\/\">ROS: Create a Simple Publisher\/Subscriber in C++<\/a><\/div>\n<div class=\"listing-item\"><a class=\"title\" href=\"https:\/\/www.fambach.net\/en\/ros-service-erstellen\/\">ROS: Create Service<\/a><\/div>\n<div class=\"listing-item\"><a class=\"title\" href=\"https:\/\/www.fambach.net\/en\/ros-nachrichten-erstellen\/\">ROS: Creating Messages<\/a><\/div>\n<div class=\"listing-item\"><a class=\"title\" href=\"https:\/\/www.fambach.net\/en\/ros-catkin\/\">ROS: Catkin<\/a><\/div>\n<\/div>\n\n\n\n<h1 class=\"wp-block-heading\">Folder structure<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Messages are always in the msg folder of the package.<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code class=\"\">cd ~\/\/src\/\/\nmkdir msg<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">Create Message<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">In  Nachrichtendateien werden untereinander die Nachrichteninhalte angegeben. Jede Zeile enth&auml;lt einen Datentype und einen Namen. Eine Nachricht mit nur einem Datum in Form einer Ganzzahl kann wie folgt erstellt werden.<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code class=\"\">echo \"int64 num\" &gt; msg\/Num.msg<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">Adjust build files<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Nun m&uuml;ssen wir noch sicherstellen, dass die Nachricht auch generiert wird. Hierzu &ouml;ffnen wir die package.xml Datei im eigenen Paket und schauen ob der folgenden Code enthalten ist.<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"xml\" class=\"language-xml\">  message_generation\n  message_runtime<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">With me, they were only documented.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Zum Schluss m&uuml;ssen wir daf&uuml;r sorgen, dass Make die Dateie bauen kann. Hierf&uuml;r die CMakeLists.txt Datei &ouml;ffnen und den folgenden Code vervollst&auml;ndigen.<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash\">cmake_minimum_required(VERSION 3.0.2)\nproject()\n\n\ninclude_directories(\n include\n  ${catkin_INCLUDE_DIRS}ros melodie \n)\n\n\nfind_package(catkin REQUIRED COMPONENTS\n  roscpp\n  rospy\n  std_msgs\n  message_generation\n)\n\nadd_message_files(\n  FILES\n  Num.msg\n)\n\ngenerate_messages(\n   DEPENDENCIES std_msgs\n)\n\ncatkin_package(\n  CATKIN_DEPENDS roscpp rospy message_runtime std_msgs\n)\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The message is now built with catkin_make. The header file can be found in the following directory<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code lang=\"bash\" class=\"language-bash\">~\/\/devel\/include\/\/Num.h<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Mit dem rosmsg Befehlt kann &uuml;berpr&uuml;ft werden ob ROS die Nachricht findet<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code class=\"\">rosmsg show Num<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">Help<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Is there with -h<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code class=\"\">rosmsg -h<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This shows all commands of rosmsg<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code class=\"\">rosmsg is a command-line tool for displaying information about ROS message types.\n\nCommands:\n    rosmsg show    Show message description\n    rosmsg info    Alias for rosmsg show\n    rosmsg list    List all messages\n\trosmsg md5    Display the message\u2019s MD5 sum\n    rosmsg package    List messages in a package\n    rosmsg packages    List packages that contain messages\n\nType rosmsg  -h for more detailed usage<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">Verwandte Beitr&auml;ge<\/h1>\n\n\n<div class=\"display-posts-listing\">\n<div class=\"listing-item\"><a class=\"image\" href=\"https:\/\/www.fambach.net\/en\/ros-einfachen-publisher-subscriber-in-c-erstellen\/\"><img loading=\"lazy\" decoding=\"async\" width=\"200\" height=\"58\" src=\"https:\/\/www.fambach.net\/wp-content\/uploads\/ROS_logo_black2.jpg\" class=\"attachment-thumbnail size-thumbnail wp-post-image\" alt=\"\" \/><\/a> <a class=\"title\" href=\"https:\/\/www.fambach.net\/en\/ros-einfachen-publisher-subscriber-in-c-erstellen\/\">ROS: Create a Simple Publisher\/Subscriber in C++<\/a><\/div>\n<div class=\"listing-item\"><a class=\"image\" href=\"https:\/\/www.fambach.net\/en\/ros-service-erstellen\/\"><img loading=\"lazy\" decoding=\"async\" width=\"200\" height=\"58\" src=\"https:\/\/www.fambach.net\/wp-content\/uploads\/ROS_logo_black2.jpg\" class=\"attachment-thumbnail size-thumbnail wp-post-image\" alt=\"\" \/><\/a> <a class=\"title\" href=\"https:\/\/www.fambach.net\/en\/ros-service-erstellen\/\">ROS: Create Service<\/a><\/div>\n<div class=\"listing-item\"><a class=\"image\" href=\"https:\/\/www.fambach.net\/en\/ros-nachrichten-erstellen\/\"><img loading=\"lazy\" decoding=\"async\" width=\"200\" height=\"58\" src=\"https:\/\/www.fambach.net\/wp-content\/uploads\/ROS_logo_black2.jpg\" class=\"attachment-thumbnail size-thumbnail wp-post-image\" alt=\"\" \/><\/a> <a class=\"title\" href=\"https:\/\/www.fambach.net\/en\/ros-nachrichten-erstellen\/\">ROS: Creating Messages<\/a><\/div>\n<div class=\"listing-item\"><a class=\"image\" href=\"https:\/\/www.fambach.net\/en\/ros-unified-robot-description-format-urdf\/\"><img loading=\"lazy\" decoding=\"async\" width=\"200\" height=\"58\" src=\"https:\/\/www.fambach.net\/wp-content\/uploads\/Screenshot-from-2023-03-26-15-42-59.jpg\" class=\"attachment-thumbnail size-thumbnail wp-post-image\" alt=\"\" \/><\/a> <a class=\"title\" href=\"https:\/\/www.fambach.net\/en\/ros-unified-robot-description-format-urdf\/\">ROS URDF: Setting up a Project<\/a><\/div>\n<div class=\"listing-item\"><a class=\"image\" href=\"https:\/\/www.fambach.net\/en\/ros-catkin\/\"><img loading=\"lazy\" decoding=\"async\" width=\"200\" height=\"58\" src=\"https:\/\/www.fambach.net\/wp-content\/uploads\/ROS_logo_black2.jpg\" class=\"attachment-thumbnail size-thumbnail wp-post-image\" alt=\"\" \/><\/a> <a class=\"title\" href=\"https:\/\/www.fambach.net\/en\/ros-catkin\/\">ROS: Catkin<\/a><\/div>\n<\/div>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Quellen\"><\/span>Sources<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">http:\/\/wiki.ros.org\/ROS\/Tutorials\/CreatingMsgAndSrv<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">http:\/\/wiki.ros.org\/melodic\/Installation\/Ubuntu<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/wiki.ros.org\/ROS\/Tutorials\/CreatingMsgAndSrv\">https:\/\/wiki.ros.org\/ROS\/Tutorials\/CreatingMsgAndSrv<\/a><\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">","protected":false},"excerpt":{"rendered":"<p>F&uuml;r den Austausch von Daten zwischen verschiedenen Knoten werden Nachrichten ben&ouml;tigt. Diese werden in .msg Dateien definiert und dann mittels catkin generiert. Das Ergebnis ist eine .h Datei mit C-Code und gleichen Namen. Jeder Knoten kann diese Nachrichten dann abbonieren. Die Nachrichten werden automatisch vom sendenden Knoten ausgesandt und alle Abbonenten bekommen sie. Dies unterscheidet &#8230;<\/p>\n<a href=\"https:\/\/www.fambach.net\/en\/ros-catkin\/\" class=\"read-more-link\">Carry on reading <span class=\"screen-reader-text\">\"ROS: Catkin\"<\/span> <span class=\"meta-nav\">\u2192<\/span><\/a>","protected":false},"author":1,"featured_media":9227,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"no","_lmt_disable":"","footnotes":""},"categories":[157,254,699],"tags":[697,696,678],"class_list":["post-9311","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-atnrob","category-betriebssysteme","category-ros-melody","tag-messages","tag-nachrichten","tag-ros","penguin-post","penguin-post-not-sticky"],"modified_by":"sfambach","_links":{"self":[{"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/posts\/9311","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/comments?post=9311"}],"version-history":[{"count":12,"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/posts\/9311\/revisions"}],"predecessor-version":[{"id":9374,"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/posts\/9311\/revisions\/9374"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/media\/9227"}],"wp:attachment":[{"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/media?parent=9311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/categories?post=9311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fambach.net\/en\/wp-json\/wp\/v2\/tags?post=9311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}