{"id":2399,"date":"2025-07-07T09:36:10","date_gmt":"2025-07-07T09:36:10","guid":{"rendered":"https:\/\/learnbydoing.dev\/?p=2399"},"modified":"2026-01-10T22:29:26","modified_gmt":"2026-01-10T22:29:26","slug":"how-to-create-a-simple-subscriber-node-with-c-ros2","status":"publish","type":"post","link":"https:\/\/learnbydoing.dev\/how-to-create-a-simple-subscriber-node-with-c-ros2\/","title":{"rendered":"How to create a simple Subscriber Node with C++ &#8211; ROS2"},"content":{"rendered":"<div data-elementor-type=\"wp-post\" data-elementor-id=\"2399\" class=\"elementor elementor-2399\" data-elementor-post-type=\"post\">\n\t\t\t\t<div class=\"elementor-element elementor-element-e28ab35 e-flex e-con-boxed e-con e-parent\" data-id=\"e28ab35\" data-element_type=\"container\" data-e-type=\"container\" id=\"content\" data-settings=\"{&quot;background_background&quot;:&quot;classic&quot;}\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t<div class=\"elementor-element elementor-element-62ab6e3 e-con-full e-flex e-con e-child\" data-id=\"62ab6e3\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t<div class=\"elementor-element elementor-element-62ab203 elementor-align-center elementor-widget elementor-widget-post-info\" data-id=\"62ab203\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"post-info.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<ul class=\"elementor-inline-items elementor-icon-list-items elementor-post-info\">\n\t\t\t\t\t\t\t\t<li class=\"elementor-icon-list-item elementor-repeater-item-2c98363 elementor-inline-item\" itemprop=\"about\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-icon-list-text elementor-post-info__item elementor-post-info__item--type-terms\">\n\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-post-info__terms-list\">\n\t\t\t\t<span class=\"elementor-post-info__terms-list-item\">Linux<\/span>, <span class=\"elementor-post-info__terms-list-item\">ROS 2<\/span>, <span class=\"elementor-post-info__terms-list-item\">Tutoriales<\/span>\t\t\t\t<\/span>\n\t\t\t\t\t<\/span>\n\t\t\t\t\t\t\t\t<\/li>\n\t\t\t\t<\/ul>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-0650e10 e-con-full e-flex e-con e-child\" data-id=\"0650e10\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t<div class=\"elementor-element elementor-element-ac19582 elementor-view-default elementor-widget elementor-widget-icon\" data-id=\"ac19582\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"icon.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-icon-wrapper\">\n\t\t\t<div class=\"elementor-icon\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"75\" height=\"75\" viewbox=\"0 0 75 75\" fill=\"none\"><path d=\"M74.9999 75H13.1889V73.0002H71.5859L0.460938 1.87521L1.87515 0.460999L73.0001 71.586V13.1889H74.9999V75Z\" fill=\"white\"><\/path><\/svg>\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-47aa245d e-flex e-con-boxed e-con e-parent\" data-id=\"47aa245d\" data-element_type=\"container\" data-e-type=\"container\" data-settings=\"{&quot;background_background&quot;:&quot;classic&quot;}\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-206a001 elementor-widget elementor-widget-image\" data-id=\"206a001\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img fetchpriority=\"high\" decoding=\"async\" width=\"1920\" height=\"1080\" src=\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/07\/Node-c-5.webp\" class=\"attachment-full size-full wp-image-2405\" alt=\"\" srcset=\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/07\/Node-c-5.webp 1920w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/07\/Node-c-5-300x169.webp 300w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/07\/Node-c-5-1024x576.webp 1024w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/07\/Node-c-5-768x432.webp 768w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/07\/Node-c-5-1536x864.webp 1536w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/07\/Node-c-5-18x10.webp 18w\" sizes=\"(max-width: 1920px) 100vw, 1920px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-4bc31ca3 elementor-widget elementor-widget-text-editor\" data-id=\"4bc31ca3\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>In this tutorial, we\u2019ll create a simple <strong>ROS 2<\/strong> node in C++ that <strong data-start=\"443\" data-end=\"468\">subscribes to a topic<\/strong> and listens for messages published on it. If you haven\u2019t checked out the <a class=\"\" href=\"https:\/\/learnbydoing.dev\/es\/cpp-simple-publisher\/\" target=\"_new\" rel=\"noopener\" data-start=\"542\" data-end=\"617\">simple publisher tutorial<\/a>, I recommend starting there first.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-12a4ca0 elementor-widget elementor-widget-text-editor\" data-id=\"12a4ca0\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h3 data-start=\"1857\" data-end=\"1885\">\ud83d\udd0d\u00a0 What is a ROS Node and a Topic?<\/h3><p data-start=\"631\" data-end=\"857\">In <strong data-start=\"634\" data-end=\"666\">ROS (Robot Operating System)<\/strong>, software is organized into small, independent processes called <strong data-start=\"731\" data-end=\"740\">nodes<\/strong>.<br data-start=\"741\" data-end=\"744\" \/>Nodes communicate by publishing and subscribing to <strong data-start=\"795\" data-end=\"805\">topics<\/strong> \u2014 named channels that carry specific types of data.<\/p><p data-start=\"859\" data-end=\"871\">For example:<\/p><ul data-start=\"872\" data-end=\"1012\"><li data-start=\"872\" data-end=\"931\"><p data-start=\"874\" data-end=\"931\">A camera node might publish images on <code data-start=\"912\" data-end=\"931\">\/camera\/image_raw<\/code><\/p><\/li><li data-start=\"932\" data-end=\"1012\"><p data-start=\"934\" data-end=\"1012\">A motor controller might subscribe to <code data-start=\"972\" data-end=\"982\">\/cmd_vel<\/code> to receive movement commands.<\/p><\/li><\/ul><p data-start=\"1014\" data-end=\"1155\"><strong data-start=\"1014\" data-end=\"1057\">Nodes and topics decouple your software<\/strong>, so different parts of your robot can evolve independently and work together via message passing.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-821f703 elementor-widget elementor-widget-image\" data-id=\"821f703\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" width=\"1920\" height=\"1080\" src=\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/07\/Node-c-4.webp\" class=\"attachment-full size-full wp-image-2401\" alt=\"\" srcset=\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/07\/Node-c-4.webp 1920w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/07\/Node-c-4-300x169.webp 300w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/07\/Node-c-4-1024x576.webp 1024w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/07\/Node-c-4-768x432.webp 768w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/07\/Node-c-4-1536x864.webp 1536w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/07\/Node-c-4-18x10.webp 18w\" sizes=\"(max-width: 1920px) 100vw, 1920px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-324d52d elementor-widget elementor-widget-text-editor\" data-id=\"324d52d\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h3 data-start=\"1857\" data-end=\"1885\">\ud83d\udce6 Prerequisite: A ROS Workspace<\/h3><p data-start=\"1547\" data-end=\"1722\">If you haven\u2019t created a ROS2 workspace yet, follow this clear tutorial first:<br data-start=\"1624\" data-end=\"1627\" \/><a class=\"\" href=\"https:\/\/learnbydoing.dev\/es\/how-to-create-a-ros2-workspace\/\" target=\"_new\" rel=\"noopener\" data-start=\"1630\" data-end=\"1720\">How to Create a ROS2 Workspace<\/a><\/p><p data-start=\"1724\" data-end=\"1785\">Once your workspace is ready and sourced, continue from here.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-e1ef5c9 elementor-widget elementor-widget-text-editor\" data-id=\"e1ef5c9\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h2 data-start=\"1792\" data-end=\"1824\">\ud83d\udce6 Create a New Package<\/h2><p data-start=\"1826\" data-end=\"1863\">If you haven\u2019t already, create a new ROS 2 package:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-1ba2cef elementor-widget elementor-widget-code-highlight\" data-id=\"1ba2cef\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-bash\">\n\t\t\t\t<code readonly=\"true\" class=\"language-bash\">\n\t\t\t\t\t<xmp>ros2 pkg create --build-type ament_cmake cpp_simple_subscriber --dependencies rclcpp std_msgs\r\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-7a888ec elementor-widget elementor-widget-text-editor\" data-id=\"7a888ec\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>This will generate a new package with the necessary <code data-start=\"1046\" data-end=\"1062\">CMakeLists.txt<\/code> and <code data-start=\"1067\" data-end=\"1080\">package.xml<\/code> files.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-455a2f8 elementor-widget elementor-widget-text-editor\" data-id=\"455a2f8\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h2 data-start=\"2302\" data-end=\"2336\">\ud83d\udcc4 Write the Publisher Node<\/h2><p data-start=\"2338\" data-end=\"2380\">Let\u2019s create a new C++ file inside <code data-start=\"2373\" data-end=\"2379\">src\/<\/code>:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-01f8801 elementor-widget elementor-widget-code-highlight\" data-id=\"01f8801\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-bash\">\n\t\t\t\t<code readonly=\"true\" class=\"language-bash\">\n\t\t\t\t\t<xmp>cd ~\/ros2_cpp_ws\/src\/tutorial_publisher\/src\r\ntouch simple_subscriber.cpp\r\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8141c6a elementor-widget elementor-widget-text-editor\" data-id=\"8141c6a\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Open it in your text editor, and paste the following code:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6503883 elementor-widget elementor-widget-code-highlight\" data-id=\"6503883\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-cpp line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>#include \"rclcpp\/rclcpp.hpp\"\r\n#include \"std_msgs\/msg\/string.hpp\"\r\n\r\nusing std::placeholders::_1;\r\n\r\nclass SimpleSubscriber : public rclcpp::Node\r\n{\r\npublic:\r\n  SimpleSubscriber() : Node(\"simple_subscriber\")\r\n  {\r\n    subscription_ = this->create_subscription<std_msgs::msg::String>(\r\n      \"topic\", 10, std::bind(&SimpleSubscriber::topic_callback, this, _1));\r\n  }\r\n\r\nprivate:\r\n  void topic_callback(const std_msgs::msg::String::SharedPtr msg) const\r\n  {\r\n    RCLCPP_INFO(this->get_logger(), \"I heard: '%s'\", msg->data.c_str());\r\n  }\r\n\r\n  rclcpp::Subscription<std_msgs::msg::String>::SharedPtr subscription_;\r\n};\r\n\r\nint main(int argc, char * argv[])\r\n{\r\n  rclcpp::init(argc, argv);\r\n  rclcpp::spin(std::make_shared<SimpleSubscriber>());\r\n  rclcpp::shutdown();\r\n  return 0;\r\n}\r\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2547d99 elementor-widget elementor-widget-text-editor\" data-id=\"2547d99\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h2 data-start=\"3173\" data-end=\"3210\">\ud83d\udd0d Code Explained Step by Step<\/h2><p data-start=\"3212\" data-end=\"3262\">Let\u2019s carefully go through this code line by line.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-bdbed67 elementor-widget elementor-widget-text-editor\" data-id=\"bdbed67\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><strong>Include Required Headers<\/strong><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-d361b1c elementor-widget elementor-widget-code-highlight\" data-id=\"d361b1c\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-cpp line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>#include \"rclcpp\/rclcpp.hpp\"\r\n#include \"std_msgs\/msg\/string.hpp\"\r\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-b51cf90 elementor-widget elementor-widget-text-editor\" data-id=\"b51cf90\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>We bring in ROS\u202f2 C++ APIs, the standard string message type, and chrono utilities for timing.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-7715a7b elementor-widget elementor-widget-text-editor\" data-id=\"7715a7b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><strong>Create a Node Class<\/strong><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-85beade elementor-widget elementor-widget-code-highlight\" data-id=\"85beade\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-cpp line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>class SimpleSubscriber : public rclcpp::Node\r\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8c151f2 elementor-widget elementor-widget-text-editor\" data-id=\"8c151f2\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>We define a class <code data-start=\"2443\" data-end=\"2461\">SimpleSubscriber<\/code> that inherits from <code data-start=\"2481\" data-end=\"2495\">rclcpp::Node<\/code>.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-21e3fca elementor-widget elementor-widget-text-editor\" data-id=\"21e3fca\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><strong>Define the Subscription<\/strong><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-b11d22b elementor-widget elementor-widget-code-highlight\" data-id=\"b11d22b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-cpp line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>subscription_ = this->create_subscription<std_msgs::msg::String>(\r\n  \"topic\", 10, std::bind(&SimpleSubscriber::topic_callback, this, _1));\r\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-e7a0dfa elementor-widget elementor-widget-text-editor\" data-id=\"e7a0dfa\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p data-start=\"2688\" data-end=\"2766\">Inside the constructor, we create a subscription to a topic named <code data-start=\"2754\" data-end=\"2763\">\"topic\"<\/code>.<\/p><ul data-start=\"2768\" data-end=\"2901\"><li data-start=\"2768\" data-end=\"2804\"><p data-start=\"2770\" data-end=\"2804\">The queue size is set to <strong data-start=\"2795\" data-end=\"2801\">10<\/strong>.<\/p><\/li><li data-start=\"2805\" data-end=\"2901\"><p data-start=\"2807\" data-end=\"2901\"><code data-start=\"2807\" data-end=\"2818\">std::bind<\/code> is used to associate the <code data-start=\"2844\" data-end=\"2860\">topic_callback<\/code> method with the subscription\u2019s callback.<\/p><\/li><\/ul>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6ebf0aa elementor-widget elementor-widget-text-editor\" data-id=\"6ebf0aa\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><strong>Implement the Callback<\/strong><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-336d61d elementor-widget elementor-widget-code-highlight\" data-id=\"336d61d\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-cpp line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>void topic_callback(const std_msgs::msg::String::SharedPtr msg) const\r\n{\r\n  RCLCPP_INFO(this->get_logger(), \"I heard: '%s'\", msg->data.c_str());\r\n}\r\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3c9dd89 elementor-widget elementor-widget-text-editor\" data-id=\"3c9dd89\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>This function will be called each time a message is received on the subscribed topic. It simply logs the message content.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-5f43eda elementor-widget elementor-widget-text-editor\" data-id=\"5f43eda\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><strong>Main Function<\/strong><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9b94e7a elementor-widget elementor-widget-code-highlight\" data-id=\"9b94e7a\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-cpp line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>rclcpp::init(argc, argv);\r\nrclcpp::spin(std::make_shared<SimpleSubscriber>());\r\nrclcpp::shutdown();\r\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-4cc9ac5 elementor-widget elementor-widget-text-editor\" data-id=\"4cc9ac5\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>The <code data-start=\"3366\" data-end=\"3372\">main<\/code> function initializes ROS 2, spins the node (which keeps it alive to listen for messages), and then shuts down cleanly when done.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-fa297d4 elementor-widget elementor-widget-text-editor\" data-id=\"fa297d4\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h2 data-start=\"2302\" data-end=\"2336\">\ud83c\udfd7\ufe0f\u00a0Update CMakeLists.txt<\/h2><p data-start=\"3540\" data-end=\"3597\">Open <code data-start=\"3545\" data-end=\"3561\">CMakeLists.txt<\/code> and add the subscriber source file:<br \/><br \/><\/p><p data-start=\"3599\" data-end=\"3637\"><strong data-start=\"3599\" data-end=\"3637\">Add executable and link libraries:<\/strong><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9f65454 elementor-widget elementor-widget-code-highlight\" data-id=\"9f65454\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-bash\">\n\t\t\t\t<code readonly=\"true\" class=\"language-bash\">\n\t\t\t\t\t<xmp>add_executable(simple_subscriber src\/simple_subscriber.cpp)\r\nament_target_dependencies(simple_subscriber rclcpp std_msgs)\r\ninstall(TARGETS\r\n  simple_subscriber\r\n  DESTINATION lib\/${PROJECT_NAME}\r\n)\r\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-69c8991 elementor-widget elementor-widget-text-editor\" data-id=\"69c8991\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>This tells CMake how to build your program and link it with ROS libraries.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-66e04df elementor-widget elementor-widget-text-editor\" data-id=\"66e04df\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h2 data-start=\"6581\" data-end=\"6611\">\ud83d\udee0\ufe0f Build the Package<\/h2><p data-start=\"6613\" data-end=\"6638\">From your workspace root:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-aee886c elementor-widget elementor-widget-code-highlight\" data-id=\"aee886c\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-bash\">\n\t\t\t\t<code readonly=\"true\" class=\"language-bash\">\n\t\t\t\t\t<xmp>cd ~\/ros2_cpp_ws\r\ncolcon build --packages-select cpp_simple_subscriber\r\nsource install\/setup.bash\r\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2b8e663 elementor-widget elementor-widget-text-editor\" data-id=\"2b8e663\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h2 data-start=\"6710\" data-end=\"6739\">\ud83d\ude80 Run the Publisher<\/h2><p data-start=\"6741\" data-end=\"6769\">In a new terminal:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-4acb228 elementor-widget elementor-widget-code-highlight\" data-id=\"4acb228\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-bash\">\n\t\t\t\t<code readonly=\"true\" class=\"language-bash\">\n\t\t\t\t\t<xmp>source install\/setup.bash\r\nros2 run tutorial_publisher simple_cpp_publisher\r\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-34c5f31 elementor-widget elementor-widget-text-editor\" data-id=\"34c5f31\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h2 data-start=\"6920\" data-end=\"6949\">\ud83d\udce1 Monitor the Topic<\/h2><p data-start=\"6951\" data-end=\"6971\">In another terminal (after sourcing the workspace), run the ROS 2 CLI to publish a test message:<\/p><div class=\"contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary\"><div class=\"overflow-y-auto p-4\" dir=\"ltr\">\u00a0<\/div><\/div>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-19b67b3 elementor-widget elementor-widget-code-highlight\" data-id=\"19b67b3\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-bash\">\n\t\t\t\t<code readonly=\"true\" class=\"language-bash\">\n\t\t\t\t\t<xmp>ros2 topic pub \/topic std_msgs\/msg\/String \"{data: 'Hello from ROS 2!'}\"\r\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-be53046 elementor-widget elementor-widget-text-editor\" data-id=\"be53046\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>You should see the subscriber log the received message.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-c5d20e7 e-con-full e-flex e-con e-parent\" data-id=\"c5d20e7\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t<div class=\"elementor-element elementor-element-0741169 elementor-bg-transform elementor-bg-transform-move-left elementor-cta--layout-image-left elementor-cta--mobile-layout-image-above elementor-cta--skin-classic elementor-animated-content elementor-widget elementor-widget-call-to-action\" data-id=\"0741169\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"call-to-action.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-cta\">\n\t\t\t\t\t<div class=\"elementor-cta__bg-wrapper\">\n\t\t\t\t<div class=\"elementor-cta__bg elementor-bg\" style=\"background-image: url(https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/06\/manipulation-ros2.webp);\" role=\"img\" aria-label=\"manipulation ros2\"><\/div>\n\t\t\t\t<div class=\"elementor-cta__bg-overlay\"><\/div>\n\t\t\t<\/div>\n\t\t\t\t\t\t\t<div class=\"elementor-cta__content\">\n\t\t\t\t\n\t\t\t\t\t\t\t\t\t<h2 class=\"elementor-cta__title elementor-cta__content-item elementor-content-item\">\n\t\t\t\t\t\tWant to learn more?\t\t\t\t\t<\/h2>\n\t\t\t\t\n\t\t\t\t\t\t\t\t\t<div class=\"elementor-cta__description elementor-cta__content-item elementor-content-item\">\n\t\t\t\t\t\tYou can find a detailed explaination of the workspace in  the \"Robotics and ROS 2 - Learn by Doing! Manipulators\" course\t\t\t\t\t<\/div>\n\t\t\t\t\n\t\t\t\t\t\t\t\t\t<div class=\"elementor-cta__button-wrapper elementor-cta__content-item elementor-content-item\">\n\t\t\t\t\t<a class=\"elementor-cta__button elementor-button elementor-size-\" href=\"\" target=\"_blank\">\n\t\t\t\t\t\tEnroll Now\t\t\t\t\t<\/a>\n\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t<div class=\"elementor-ribbon elementor-ribbon-right\">\n\t\t\t\t<div class=\"elementor-ribbon-inner\">\n\t\t\t\t\tDISCOUNT\t\t\t\t<\/div>\n\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-180426a elementor-widget elementor-widget-spacer\" data-id=\"180426a\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"spacer.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-spacer\">\n\t\t\t<div class=\"elementor-spacer-inner\"><\/div>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we\u2019ll create a simple ROS 2 node in C++ that subscribes to a topic and listens for messages published on it. If you haven\u2019t checked out the simple publisher tutorial, I recommend starting there first. \ud83d\udd0d\u00a0 What is a ROS Node and a Topic? In ROS (Robot Operating System), software is organized [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":2405,"comment_status":"closed","ping_status":"open","sticky":false,"template":"elementor_header_footer","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[47,45,43],"tags":[126,84,133,66,74,131,100,75,71,107,72,177,130],"class_list":["post-2399","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-ros-2","category-tutorials","tag-base","tag-c","tag-chatter","tag-learn-by-doing","tag-linux","tag-node","tag-robot","tag-robotics","tag-ros","tag-ros-2","tag-ros2","tag-subscriber","tag-topic"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to create a simple Subscriber Node with C++ - ROS2 - Learn by Doing!<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/learnbydoing.dev\/es\/how-to-create-a-simple-subscriber-node-with-c-ros2\/\" \/>\n<meta property=\"og:locale\" content=\"es_ES\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Installing ROS 2 Jazzy on Ubuntu 24.04: Step-by-Step Tutorial\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, we\u2019ll create a simple ROS 2 node in C++ that subscribes to a topic and listens for messages published on it. If you haven\u2019t checked out the simple publisher tutorial, I recommend starting there first. \ud83d\udd0d\u00a0 What is a ROS Node and a Topic? In ROS (Robot Operating System), software is organized [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/learnbydoing.dev\/es\/how-to-create-a-simple-subscriber-node-with-c-ros2\/\" \/>\n<meta property=\"og:site_name\" content=\"Learn by Doing!\" \/>\n<meta property=\"article:published_time\" content=\"2025-07-07T09:36:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-01-10T22:29:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/06\/Progetto-senza-titolo-14.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tiempo de lectura\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/learnbydoing.dev\/how-to-create-a-simple-subscriber-node-with-c-ros2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/learnbydoing.dev\/how-to-create-a-simple-subscriber-node-with-c-ros2\/\"},\"author\":{\"name\":\"\",\"@id\":\"\"},\"headline\":\"How to create a simple Subscriber Node with C++ &#8211; ROS2\",\"datePublished\":\"2025-07-07T09:36:10+00:00\",\"dateModified\":\"2026-01-10T22:29:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/learnbydoing.dev\/how-to-create-a-simple-subscriber-node-with-c-ros2\/\"},\"wordCount\":432,\"publisher\":{\"@id\":\"https:\/\/learnbydoing.dev\/es\/#organization\"},\"image\":{\"@id\":\"https:\/\/learnbydoing.dev\/how-to-create-a-simple-subscriber-node-with-c-ros2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/07\/Node-c-5.webp\",\"keywords\":[\"Base\",\"c++\",\"chatter\",\"learn by doing\",\"Linux\",\"node\",\"robot\",\"Robotics\",\"ROS\",\"ROS 2\",\"ROS2\",\"subscriber\",\"topic\"],\"articleSection\":[\"Linux\",\"ROS 2\",\"Tutorials\"],\"inLanguage\":\"es\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/learnbydoing.dev\/how-to-create-a-simple-subscriber-node-with-c-ros2\/\",\"url\":\"https:\/\/learnbydoing.dev\/how-to-create-a-simple-subscriber-node-with-c-ros2\/\",\"name\":\"How to create a simple Subscriber Node with C++ - ROS2 - Learn by Doing!\",\"isPartOf\":{\"@id\":\"https:\/\/learnbydoing.dev\/es\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/learnbydoing.dev\/how-to-create-a-simple-subscriber-node-with-c-ros2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/learnbydoing.dev\/how-to-create-a-simple-subscriber-node-with-c-ros2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/07\/Node-c-5.webp\",\"datePublished\":\"2025-07-07T09:36:10+00:00\",\"dateModified\":\"2026-01-10T22:29:26+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/learnbydoing.dev\/how-to-create-a-simple-subscriber-node-with-c-ros2\/#breadcrumb\"},\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/learnbydoing.dev\/how-to-create-a-simple-subscriber-node-with-c-ros2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\/\/learnbydoing.dev\/how-to-create-a-simple-subscriber-node-with-c-ros2\/#primaryimage\",\"url\":\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/07\/Node-c-5.webp\",\"contentUrl\":\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/07\/Node-c-5.webp\",\"width\":1920,\"height\":1080},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/learnbydoing.dev\/how-to-create-a-simple-subscriber-node-with-c-ros2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/learnbydoing.dev\/es\/learn-by-doing-es\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to create a simple Subscriber Node with C++ &#8211; ROS2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/learnbydoing.dev\/es\/#website\",\"url\":\"https:\/\/learnbydoing.dev\/es\/\",\"name\":\"Learn by Doing!\",\"description\":\"Learn Robotics the fun way\",\"publisher\":{\"@id\":\"https:\/\/learnbydoing.dev\/es\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/learnbydoing.dev\/es\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"es\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/learnbydoing.dev\/es\/#organization\",\"name\":\"Learn by Doing!\",\"url\":\"https:\/\/learnbydoing.dev\/es\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\/\/learnbydoing.dev\/es\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/06\/cropped-cropped-cropped-Progetto-senza-titolo-6-1.png\",\"contentUrl\":\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/06\/cropped-cropped-cropped-Progetto-senza-titolo-6-1.png\",\"width\":512,\"height\":512,\"caption\":\"Learn by Doing!\"},\"image\":{\"@id\":\"https:\/\/learnbydoing.dev\/es\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/antonio-brandi-512166bb\/\"]},{\"@type\":\"Person\",\"@id\":\"\",\"url\":\"https:\/\/learnbydoing.dev\/es\/author\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to create a simple Subscriber Node with C++ - ROS2 - Learn by Doing!","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:\/\/learnbydoing.dev\/es\/how-to-create-a-simple-subscriber-node-with-c-ros2\/","og_locale":"es_ES","og_type":"article","og_title":"Installing ROS 2 Jazzy on Ubuntu 24.04: Step-by-Step Tutorial","og_description":"In this tutorial, we\u2019ll create a simple ROS 2 node in C++ that subscribes to a topic and listens for messages published on it. If you haven\u2019t checked out the simple publisher tutorial, I recommend starting there first. \ud83d\udd0d\u00a0 What is a ROS Node and a Topic? In ROS (Robot Operating System), software is organized [&hellip;]","og_url":"https:\/\/learnbydoing.dev\/es\/how-to-create-a-simple-subscriber-node-with-c-ros2\/","og_site_name":"Learn by Doing!","article_published_time":"2025-07-07T09:36:10+00:00","article_modified_time":"2026-01-10T22:29:26+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/06\/Progetto-senza-titolo-14.webp","type":"image\/webp"}],"twitter_card":"summary_large_image","twitter_misc":{"Escrito por":"","Tiempo de lectura":"5 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/learnbydoing.dev\/how-to-create-a-simple-subscriber-node-with-c-ros2\/#article","isPartOf":{"@id":"https:\/\/learnbydoing.dev\/how-to-create-a-simple-subscriber-node-with-c-ros2\/"},"author":{"name":"","@id":""},"headline":"How to create a simple Subscriber Node with C++ &#8211; ROS2","datePublished":"2025-07-07T09:36:10+00:00","dateModified":"2026-01-10T22:29:26+00:00","mainEntityOfPage":{"@id":"https:\/\/learnbydoing.dev\/how-to-create-a-simple-subscriber-node-with-c-ros2\/"},"wordCount":432,"publisher":{"@id":"https:\/\/learnbydoing.dev\/es\/#organization"},"image":{"@id":"https:\/\/learnbydoing.dev\/how-to-create-a-simple-subscriber-node-with-c-ros2\/#primaryimage"},"thumbnailUrl":"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/07\/Node-c-5.webp","keywords":["Base","c++","chatter","learn by doing","Linux","node","robot","Robotics","ROS","ROS 2","ROS2","subscriber","topic"],"articleSection":["Linux","ROS 2","Tutorials"],"inLanguage":"es"},{"@type":"WebPage","@id":"https:\/\/learnbydoing.dev\/how-to-create-a-simple-subscriber-node-with-c-ros2\/","url":"https:\/\/learnbydoing.dev\/how-to-create-a-simple-subscriber-node-with-c-ros2\/","name":"How to create a simple Subscriber Node with C++ - ROS2 - Learn by Doing!","isPartOf":{"@id":"https:\/\/learnbydoing.dev\/es\/#website"},"primaryImageOfPage":{"@id":"https:\/\/learnbydoing.dev\/how-to-create-a-simple-subscriber-node-with-c-ros2\/#primaryimage"},"image":{"@id":"https:\/\/learnbydoing.dev\/how-to-create-a-simple-subscriber-node-with-c-ros2\/#primaryimage"},"thumbnailUrl":"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/07\/Node-c-5.webp","datePublished":"2025-07-07T09:36:10+00:00","dateModified":"2026-01-10T22:29:26+00:00","breadcrumb":{"@id":"https:\/\/learnbydoing.dev\/how-to-create-a-simple-subscriber-node-with-c-ros2\/#breadcrumb"},"inLanguage":"es","potentialAction":[{"@type":"ReadAction","target":["https:\/\/learnbydoing.dev\/how-to-create-a-simple-subscriber-node-with-c-ros2\/"]}]},{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/learnbydoing.dev\/how-to-create-a-simple-subscriber-node-with-c-ros2\/#primaryimage","url":"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/07\/Node-c-5.webp","contentUrl":"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/07\/Node-c-5.webp","width":1920,"height":1080},{"@type":"BreadcrumbList","@id":"https:\/\/learnbydoing.dev\/how-to-create-a-simple-subscriber-node-with-c-ros2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/learnbydoing.dev\/es\/learn-by-doing-es\/"},{"@type":"ListItem","position":2,"name":"How to create a simple Subscriber Node with C++ &#8211; ROS2"}]},{"@type":"WebSite","@id":"https:\/\/learnbydoing.dev\/es\/#website","url":"https:\/\/learnbydoing.dev\/es\/","name":"Learn by Doing!","description":"Learn Robotics the fun way","publisher":{"@id":"https:\/\/learnbydoing.dev\/es\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/learnbydoing.dev\/es\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"es"},{"@type":"Organization","@id":"https:\/\/learnbydoing.dev\/es\/#organization","name":"Learn by Doing!","url":"https:\/\/learnbydoing.dev\/es\/","logo":{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/learnbydoing.dev\/es\/#\/schema\/logo\/image\/","url":"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/06\/cropped-cropped-cropped-Progetto-senza-titolo-6-1.png","contentUrl":"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/06\/cropped-cropped-cropped-Progetto-senza-titolo-6-1.png","width":512,"height":512,"caption":"Learn by Doing!"},"image":{"@id":"https:\/\/learnbydoing.dev\/es\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.linkedin.com\/in\/antonio-brandi-512166bb\/"]},{"@type":"Person","@id":"","url":"https:\/\/learnbydoing.dev\/es\/author\/"}]}},"_links":{"self":[{"href":"https:\/\/learnbydoing.dev\/es\/wp-json\/wp\/v2\/posts\/2399","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/learnbydoing.dev\/es\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learnbydoing.dev\/es\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learnbydoing.dev\/es\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/learnbydoing.dev\/es\/wp-json\/wp\/v2\/comments?post=2399"}],"version-history":[{"count":19,"href":"https:\/\/learnbydoing.dev\/es\/wp-json\/wp\/v2\/posts\/2399\/revisions"}],"predecessor-version":[{"id":5574,"href":"https:\/\/learnbydoing.dev\/es\/wp-json\/wp\/v2\/posts\/2399\/revisions\/5574"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/learnbydoing.dev\/es\/wp-json\/wp\/v2\/media\/2405"}],"wp:attachment":[{"href":"https:\/\/learnbydoing.dev\/es\/wp-json\/wp\/v2\/media?parent=2399"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learnbydoing.dev\/es\/wp-json\/wp\/v2\/categories?post=2399"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learnbydoing.dev\/es\/wp-json\/wp\/v2\/tags?post=2399"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}