{"id":2474,"date":"2020-07-20T13:08:15","date_gmt":"2020-07-20T13:08:15","guid":{"rendered":"https:\/\/roboticsbackend.com\/?p=2474"},"modified":"2023-02-01T10:47:58","modified_gmt":"2023-02-01T10:47:58","slug":"ros2-python-publisher-example","status":"publish","type":"post","link":"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/","title":{"rendered":"ROS2 Python Publisher Example"},"content":{"rendered":"<p>In this tutorial I will show you a ROS2 Python publisher example. I will break down the code so you can learn how to create your own ROS2 publisher node in Python.<\/p>\n<p>So, here we&#8217;ll suppose we have a temperature sensor, and we want to publish the measured temperature every 2 seconds (at 0.5 Hz). We will simulate the temperature measurement so we don&#8217;t have to use a real sensor.<\/p>\n<p>&gt;&gt; I&#8217;ve also made a video tutorial &#8211; using a different example, but the principle is the same. Watch this as an additional resource to this article:<\/p>\n<p><iframe loading=\"lazy\" title=\"Write a ROS2 Publisher with Python - ROS2 Tutorial 7\" width=\"1200\" height=\"675\" src=\"https:\/\/www.youtube.com\/embed\/Yy4OgGwEAj8?feature=oembed&#038;rel=0\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen><\/iframe><\/p>\n<p>After watching the video,\u00a0<a href=\"https:\/\/www.youtube.com\/c\/RoboticsBackEnd?sub_confirmation=1\">subscribe to the Robotics Back-End Youtube channel<\/a>\u00a0so you don\u2019t miss the next tutorials!<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_81 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69fcb3ab962e3\" class=\"ez-toc-cssicon-toggle-label\"><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><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69fcb3ab962e3\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/#ROS2_Python_publisher_code\" >ROS2 Python publisher code<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/#Code_explanation\" >Code explanation<\/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:\/\/roboticsbackend.com\/ros2-python-publisher-example\/#Imports\" >Imports<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/#Python_publisher_%E2%80%93_node_class\" >Python publisher &#8211; node class<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/#Initialize_the_ROS2_Python_publisher\" >Initialize the ROS2 Python publisher<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/#Add_a_method_to_publish_a_message\" >Add a method to publish a message<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/#Add_a_timer_to_publish_the_message_at_a_given_rate\" >Add a timer to publish the message at a given rate<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/#Programs_main\" >Program&#8217;s main<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/#Install_and_run_your_ROS2_Python_publisher\" >Install and run your ROS2 Python publisher<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/#Install_your_publisher\" >Install your publisher<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/#Run_and_test_the_publisher\" >Run and test the publisher<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"ROS2_Python_publisher_code\"><\/span>ROS2 Python publisher code<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Here&#8217;s the complete Python code we&#8217;ll use for this tutorial.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">#!\/usr\/bin\/env python3\nimport rclpy\nfrom rclpy.node import Node\n\nfrom example_interfaces.msg import Int64\nimport random\n\nclass TemperatureSensorNode(Node):\n    def __init__(self):\n        super().__init__(\"temperature_sensor\")\n        self.temperature_publisher_ = self.create_publisher(\n            Int64, \"temperature\", 10)\n        self.temperature_timer_ = self.create_timer(\n            2.0, self.publish_temperature)\n\n    def publish_temperature(self):\n        temperature = random.randint(20, 30)\n        msg = Int64()\n        msg.data = temperature\n        self.temperature_publisher_.publish(msg)\n\ndef main(args=None):\n    rclpy.init(args=args)\n    node = TemperatureSensorNode()\n    rclpy.spin(node)\n    rclpy.shutdown()\n\nif __name__ == \"__main__\":\n    main()<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Code_explanation\"><\/span>Code explanation<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Let&#8217;s now break this code down, line by line.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Imports\"><\/span>Imports<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">#!\/usr\/bin\/env python3\nimport rclpy\nfrom rclpy.node import Node<\/pre>\n<p>First we add the Python3 shebang line. Then we import the rclpy library, from which we&#8217;ll create the publisher. We also import the Node class from rclpy.<\/p>\n<p>For almost any node you create you&#8217;ll have those 3 lines first.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-lineoffset=\"5\">from example_interfaces.msg import Int64\nimport random<\/pre>\n<p>Those are 2 new import lines specific to the functionalities of this program.<\/p>\n<p>To publish a message, well, we need to import a ROS2 message interface. Here we simply use Int64 from the example_interfaces package, which should had been installed when you installed ROS2. Int64 contains one field named &#8220;data&#8221;, which is an int64 number. You can check that on a terminal by executing <code class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">ros2 interface show example_interfaces\/msg\/Int64<\/code>.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Python_publisher_%E2%80%93_node_class\"><\/span>Python publisher &#8211; node class<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-lineoffset=\"8\">class TemperatureSensorNode(Node):\n    def __init__(self):\n        super().__init__(\"temperature_sensor\")<\/pre>\n<p>As we use OOP in ROS2, we first create a class which inherits from the Node class. The first thing we do is to call super() and pass the name of the node.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Initialize_the_ROS2_Python_publisher\"><\/span>Initialize the ROS2 Python publisher<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-lineoffset=\"11\">        self.temperature_publisher_ = self.create_publisher(\n            Int64, \"temperature\", 10)<\/pre>\n<p>So, here is the ROS2 Python publisher!<\/p>\n<p>Before we can actually use the publisher, we need to initialize it. We&#8217;ll do that in the constructor of the class, just after the node has been initialized.<\/p>\n<p>To create a publisher with rclpy you simply have to call the create_publisher() function from rclpy. This function takes at least 3 arguments:<\/p>\n<ol>\n<li>Message (or interface) type. We use the Int64 type we&#8217;ve just imported before.<\/li>\n<li>Topic name.<\/li>\n<li>Queue size. This is kind of a buffer for messages in case some of them are late. Unless you send a lot of data at a high frequency, you probably don&#8217;t need to worry about that. I often use 10 as a default value.<\/li>\n<\/ol>\n<h3><span class=\"ez-toc-section\" id=\"Add_a_method_to_publish_a_message\"><\/span>Add a method to publish a message<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-lineoffset=\"16\">    def publish_temperature(self):\n        temperature = random.randint(20, 30)\n        msg = Int64()\n        msg.data = temperature\n        self.temperature_publisher_.publish(msg)<\/pre>\n<p>OK, we have a publisher, which will be initialized when the node is initialized. Now, we need to be able to use the publisher to actually publish some messages on the topic.<\/p>\n<p>To do that, we&#8217;ll first create a method that we can call from anywhere within the class.<\/p>\n<p>In this method we first create a random number for the temperature, since this is a simulation. In a real temperature sensor node, you&#8217;d have another function which reads the data from the sensor. So, this first line wouldn&#8217;t be here. The 3 following lines represent the core of this method:<\/p>\n<ul>\n<li>Instantiate an Int64 message object.<\/li>\n<li>Fill the &#8220;data&#8221; field of the message with an integer &#8211; here the temperature data.<\/li>\n<li>Use the publish() function from the publisher object to actually publish on the topic.<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Add_a_timer_to_publish_the_message_at_a_given_rate\"><\/span>Add a timer to publish the message at a given rate<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-lineoffset=\"13\">        self.temperature_timer_ = self.create_timer(\n            2.0, self.publish_temperature)<\/pre>\n<p>Even if this line was before the publish_temperature() method, I&#8217;ve put it after in the explanation, because that&#8217;s usually the order in which you&#8217;ll write your code:<\/p>\n<ol>\n<li>Initialize the publisher.<\/li>\n<li>Create a function to publish on the topic.<\/li>\n<li>Call this function from within your code &#8211; here as a callback in a timer.<\/li>\n<\/ol>\n<p>So, the create_timer() function from rclpy, as it name suggests, will create a timer. Don&#8217;t forget to store this timer in a class attribute so it stays in scope. You need to give 2 arguments:<\/p>\n<ul>\n<li>Period to wait between 2 triggers: here 2 seconds (which corresponds to 0.5 Hz).<\/li>\n<li>Callback function.<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Programs_main\"><\/span>Program&#8217;s main<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-lineoffset=\"22\">def main(args=None):\n    rclpy.init(args=args)\n    node = TemperatureSensorNode()\n    rclpy.spin(node)\n    rclpy.shutdown()\nif __name__ == \"__main__\":\n    main()<\/pre>\n<p>Nothing special here: we just init ROS2 communications, initialize the node, make the node spin, and finally shutdown ROS2 communications. For more details about this sequence, check out how to write a <a href=\"https:\/\/roboticsbackend.com\/write-minimal-ros2-python-node\/\">minimal Python node with rclpy<\/a>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Install_and_run_your_ROS2_Python_publisher\"><\/span>Install and run your ROS2 Python publisher<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>First, if you don&#8217;t really know where to put your code: <a href=\"https:\/\/roboticsbackend.com\/create-a-ros2-python-package\/\">create a ROS2 Python package<\/a>, and place the Python file inside the folder that has the same name as the package. You can also make this file executable.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"beyond\" data-enlighter-linenumbers=\"false\">$ cd ~\/ros2_ws\/src\/\n$ ros2 pkg create ros2_tutorials_py --build-type ament_python --dependencies rclpy\n$ cd ros2_tutorials_py\/ros2_tutorials_py\/\n$ touch temperature_sensor.py\n$ chmod +x temperature_sensor.py<\/pre>\n<p>Now that you&#8217;ve written the file, let&#8217;s install the node so we can use it with the <code class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">ros2 run<\/code> command line tool.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Install_your_publisher\"><\/span>Install your publisher<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Add one line inside the &#8220;console_scripts&#8221; array of your package&#8217;s setup.py file.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-highlight=\"5\" data-enlighter-linenumbers=\"false\">...\n    entry_points={\n        'console_scripts': [\n            ...\n            \"temperature_sensor = ros2_tutorials_py.temperature_sensor:main\"\n        ],\n...<\/pre>\n<p>Now, go to your ROS2 workspace and install with colcon.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"beyond\" data-enlighter-linenumbers=\"false\">$ cd ~\/ros2_ws\/\n$ colcon build --packages-select ros2_tutorials_py \nStarting &gt;&gt;&gt; ros2_tutorials_py\nFinished &lt;&lt;&lt; ros2_tutorials_py [0.50s]          \n\nSummary: 1 package finished [0.59s]<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Run_and_test_the_publisher\"><\/span>Run and test the publisher<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>In another terminal, source your ROS2 workspace, and start the node with <code class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">ros2 run<\/code>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"beyond\" data-enlighter-linenumbers=\"false\">$ ros2 run ros2_tutorials_py temperature_sensor<\/pre>\n<p>Nothing will appear on this terminal.<\/p>\n<p>Open yet another terminal, and now you can see what is published on the topic with <a href=\"https:\/\/roboticsbackend.com\/ros2-topic-cmd-line-tool-debug-ros2-topics-from-the-terminal\/\">ros2 topic<\/a>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"beyond\" data-enlighter-linenumbers=\"false\">$ ros2 topic echo \/temperature \ndata: 25\n---\ndata: 20\n---\ndata: 22\n---<\/pre>\n<p>Great, the ROS2 Python publisher is working, and you can directly subscribe to it from the terminal.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In this tutorial you&#8217;ve learned how to create, write, and install a ROS2 Python publisher.<\/p>\n<p>In most cases the code structure will be similar: first you initialize the publisher in your node&#8217;s constructor, then you create a method to publish a message (<a href=\"https:\/\/roboticsbackend.com\/ros2-create-custom-message\/\">see how to create your custom ROS2 messages<\/a>), and finally you call this method from within your code, when it&#8217;s relevant to do so.<\/p>\n<p>As you saw here, even if we didn&#8217;t create a subscriber node, we can still see what&#8217;s published to the topic with ROS2 command line tools.<\/p>\n<p>And now, the next logical step is to write a ROS2 Subscriber node to listen to the data published on the topic.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial I will show you a ROS2 Python publisher example. I will break down the code so you can learn how to create your own ROS2 publisher node in Python. So, here we&#8217;ll suppose we have a temperature sensor, and we want to publish the measured temperature every 2 seconds (at 0.5 Hz). &#8230; <a title=\"ROS2 Python Publisher Example\" class=\"read-more\" href=\"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/\" aria-label=\"Read more about ROS2 Python Publisher Example\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-2474","post","type-post","status-publish","format-standard","hentry","category-ros2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>ROS2 Python Publisher Example - The Robotics Back-End<\/title>\n<meta name=\"description\" content=\"ROS2 Python publisher example with complete code explanation, line by line. Learn how to create, write, install and test your ROS2 Python publisher node.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"ROS2 Python Publisher Example - The Robotics Back-End\" \/>\n<meta property=\"og:description\" content=\"ROS2 Python publisher example with complete code explanation, line by line. Learn how to create, write, install and test your ROS2 Python publisher node.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/\" \/>\n<meta property=\"og:site_name\" content=\"The Robotics Back-End\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-20T13:08:15+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-02-01T10:47:58+00:00\" \/>\n<meta name=\"author\" content=\"ed\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@RoboticsBackend\" \/>\n<meta name=\"twitter:site\" content=\"@RoboticsBackend\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"ed\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/\"},\"author\":{\"name\":\"ed\",\"@id\":\"https:\/\/roboticsbackend.com\/#\/schema\/person\/a20832f15e39847d8eea5be981767353\"},\"headline\":\"ROS2 Python Publisher Example\",\"datePublished\":\"2020-07-20T13:08:15+00:00\",\"dateModified\":\"2023-02-01T10:47:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/\"},\"wordCount\":1000,\"publisher\":{\"@id\":\"https:\/\/roboticsbackend.com\/#organization\"},\"articleSection\":[\"ROS2 Tutorials\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/\",\"url\":\"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/\",\"name\":\"ROS2 Python Publisher Example - The Robotics Back-End\",\"isPartOf\":{\"@id\":\"https:\/\/roboticsbackend.com\/#website\"},\"datePublished\":\"2020-07-20T13:08:15+00:00\",\"dateModified\":\"2023-02-01T10:47:58+00:00\",\"description\":\"ROS2 Python publisher example with complete code explanation, line by line. Learn how to create, write, install and test your ROS2 Python publisher node.\",\"breadcrumb\":{\"@id\":\"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/roboticsbackend.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"ROS2 Python Publisher Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/roboticsbackend.com\/#website\",\"url\":\"https:\/\/roboticsbackend.com\/\",\"name\":\"The Robotics Back-End\",\"description\":\"Program Robots, Step by Step\",\"publisher\":{\"@id\":\"https:\/\/roboticsbackend.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/roboticsbackend.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/roboticsbackend.com\/#organization\",\"name\":\"Robotics Back-End\",\"url\":\"https:\/\/roboticsbackend.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/roboticsbackend.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/roboticsbackend.com\/wp-content\/uploads\/2020\/02\/logo_hd.png\",\"contentUrl\":\"https:\/\/roboticsbackend.com\/wp-content\/uploads\/2020\/02\/logo_hd.png\",\"width\":2500,\"height\":1875,\"caption\":\"Robotics Back-End\"},\"image\":{\"@id\":\"https:\/\/roboticsbackend.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/RoboticsBackend\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/roboticsbackend.com\/#\/schema\/person\/a20832f15e39847d8eea5be981767353\",\"name\":\"ed\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/roboticsbackend.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/7b666620f11fb12df5674e1e1ee525afe3d4ceecdaa57f8c60f6a937a33e3427?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/7b666620f11fb12df5674e1e1ee525afe3d4ceecdaa57f8c60f6a937a33e3427?s=96&d=identicon&r=g\",\"caption\":\"ed\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"ROS2 Python Publisher Example - The Robotics Back-End","description":"ROS2 Python publisher example with complete code explanation, line by line. Learn how to create, write, install and test your ROS2 Python publisher node.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/","og_locale":"en_US","og_type":"article","og_title":"ROS2 Python Publisher Example - The Robotics Back-End","og_description":"ROS2 Python publisher example with complete code explanation, line by line. Learn how to create, write, install and test your ROS2 Python publisher node.","og_url":"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/","og_site_name":"The Robotics Back-End","article_published_time":"2020-07-20T13:08:15+00:00","article_modified_time":"2023-02-01T10:47:58+00:00","author":"ed","twitter_card":"summary_large_image","twitter_creator":"@RoboticsBackend","twitter_site":"@RoboticsBackend","twitter_misc":{"Written by":"ed","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/#article","isPartOf":{"@id":"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/"},"author":{"name":"ed","@id":"https:\/\/roboticsbackend.com\/#\/schema\/person\/a20832f15e39847d8eea5be981767353"},"headline":"ROS2 Python Publisher Example","datePublished":"2020-07-20T13:08:15+00:00","dateModified":"2023-02-01T10:47:58+00:00","mainEntityOfPage":{"@id":"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/"},"wordCount":1000,"publisher":{"@id":"https:\/\/roboticsbackend.com\/#organization"},"articleSection":["ROS2 Tutorials"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/","url":"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/","name":"ROS2 Python Publisher Example - The Robotics Back-End","isPartOf":{"@id":"https:\/\/roboticsbackend.com\/#website"},"datePublished":"2020-07-20T13:08:15+00:00","dateModified":"2023-02-01T10:47:58+00:00","description":"ROS2 Python publisher example with complete code explanation, line by line. Learn how to create, write, install and test your ROS2 Python publisher node.","breadcrumb":{"@id":"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/roboticsbackend.com\/ros2-python-publisher-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/roboticsbackend.com\/"},{"@type":"ListItem","position":2,"name":"ROS2 Python Publisher Example"}]},{"@type":"WebSite","@id":"https:\/\/roboticsbackend.com\/#website","url":"https:\/\/roboticsbackend.com\/","name":"The Robotics Back-End","description":"Program Robots, Step by Step","publisher":{"@id":"https:\/\/roboticsbackend.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/roboticsbackend.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/roboticsbackend.com\/#organization","name":"Robotics Back-End","url":"https:\/\/roboticsbackend.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/roboticsbackend.com\/#\/schema\/logo\/image\/","url":"https:\/\/roboticsbackend.com\/wp-content\/uploads\/2020\/02\/logo_hd.png","contentUrl":"https:\/\/roboticsbackend.com\/wp-content\/uploads\/2020\/02\/logo_hd.png","width":2500,"height":1875,"caption":"Robotics Back-End"},"image":{"@id":"https:\/\/roboticsbackend.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/RoboticsBackend"]},{"@type":"Person","@id":"https:\/\/roboticsbackend.com\/#\/schema\/person\/a20832f15e39847d8eea5be981767353","name":"ed","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/roboticsbackend.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/7b666620f11fb12df5674e1e1ee525afe3d4ceecdaa57f8c60f6a937a33e3427?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/7b666620f11fb12df5674e1e1ee525afe3d4ceecdaa57f8c60f6a937a33e3427?s=96&d=identicon&r=g","caption":"ed"}}]}},"_links":{"self":[{"href":"https:\/\/roboticsbackend.com\/wp-json\/wp\/v2\/posts\/2474","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/roboticsbackend.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/roboticsbackend.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/roboticsbackend.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/roboticsbackend.com\/wp-json\/wp\/v2\/comments?post=2474"}],"version-history":[{"count":0,"href":"https:\/\/roboticsbackend.com\/wp-json\/wp\/v2\/posts\/2474\/revisions"}],"wp:attachment":[{"href":"https:\/\/roboticsbackend.com\/wp-json\/wp\/v2\/media?parent=2474"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/roboticsbackend.com\/wp-json\/wp\/v2\/categories?post=2474"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/roboticsbackend.com\/wp-json\/wp\/v2\/tags?post=2474"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}