{"id":4323,"date":"2025-10-31T14:04:37","date_gmt":"2025-10-31T14:04:37","guid":{"rendered":"https:\/\/learnbydoing.dev\/?p=4323"},"modified":"2026-01-10T21:53:25","modified_gmt":"2026-01-10T21:53:25","slug":"creating-and-managing-a-lifecycle-node-in-ros-2-with-c","status":"publish","type":"post","link":"https:\/\/learnbydoing.dev\/creating-and-managing-a-lifecycle-node-in-ros-2-with-c\/","title":{"rendered":"Creating and Managing a Lifecycle Node in ROS 2 with C++"},"content":{"rendered":"<div data-elementor-type=\"wp-post\" data-elementor-id=\"4323\" class=\"elementor elementor-4323\" 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\">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-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 data-start=\"335\" data-end=\"564\">When developing complex robotic systems, managing the operational state of each node precisely is essential to ensure stability, safety, and predictability.<br data-start=\"491\" data-end=\"494\" \/>ROS 2 introduces a key concept to meet this need: <strong data-start=\"544\" data-end=\"563\">Lifecycle Nodes<\/strong>.<\/p>\n<p data-start=\"335\" data-end=\"564\">\u00a0<\/p>\n<p data-start=\"566\" data-end=\"959\">Unlike standard nodes, which start operating as soon as they are launched, Lifecycle Nodes allow you to <strong data-start=\"670\" data-end=\"707\">explicitly control their behavior<\/strong> through a series of well-defined states and transitions.<\/p>\n<p data-start=\"566\" data-end=\"959\"><br data-start=\"764\" data-end=\"767\" \/>This approach enables developers to decide <em data-start=\"810\" data-end=\"816\">when<\/em> a node should activate, <em data-start=\"841\" data-end=\"847\">when<\/em> it should stop, and <em data-start=\"868\" data-end=\"874\">when<\/em> it should release its resources \u2014 offering total control over the system\u2019s behavior.<\/p>\n<p data-start=\"566\" data-end=\"959\">\u00a0<\/p>\n<p data-start=\"961\" data-end=\"1187\">If you want to first understand the theory behind Lifecycle Nodes and see a Python implementation, check out the related article <em data-start=\"1090\" data-end=\"1118\">\u201cLifecycle Node in Python\u201d<\/em>, where we explain the core principles of the ROS 2 Lifecycle system.<\/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-017f146 elementor-widget elementor-widget-image\" data-id=\"017f146\" 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=\"800\" height=\"450\" src=\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/3-1024x576.png\" class=\"attachment-large size-large wp-image-4095\" alt=\"\" srcset=\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/3-1024x576.png 1024w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/3-300x169.png 300w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/3-768x432.png 768w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/3-1536x864.png 1536w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/3-18x10.png 18w, https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/3.png 1920w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\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-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=\"938\" data-end=\"970\"><strong>\ud83e\uddd0 Lifecycle Nodes in ROS 2 \u2014 theoretical background<\/strong><\/h3>\n<p data-start=\"1252\" data-end=\"1323\">A <strong data-start=\"1254\" data-end=\"1272\">Lifecycle Node<\/strong> (or managed node) goes through a series of states:<\/p>\n<p data-start=\"1252\" data-end=\"1323\">\u00a0<\/p>\n<ul data-start=\"1324\" data-end=\"1667\">\n<li data-start=\"1324\" data-end=\"1409\">\n<p data-start=\"1326\" data-end=\"1409\"><strong data-start=\"1326\" data-end=\"1342\">Unconfigured<\/strong> \u2013 the node is created but has not yet initialized its resources.<\/p>\n<\/li>\n<li data-start=\"1410\" data-end=\"1485\">\n<p data-start=\"1412\" data-end=\"1485\"><strong data-start=\"1412\" data-end=\"1424\">Inactive<\/strong> \u2013 the node is configured but not yet publishing or acting.<\/p>\n<\/li>\n<li data-start=\"1486\" data-end=\"1580\">\n<p data-start=\"1488\" data-end=\"1580\"><strong data-start=\"1488\" data-end=\"1498\">Active<\/strong> \u2013 the node is fully operational and communicating with other system components.<\/p>\n<\/li>\n<li data-start=\"1581\" data-end=\"1667\">\n<p data-start=\"1583\" data-end=\"1667\"><strong data-start=\"1583\" data-end=\"1607\">Finalized \/ Shutdown<\/strong> \u2013 the node releases its resources in a controlled shutdown.<\/p>\n<\/li>\n<\/ul>\n<p>\u00a0<\/p>\n<p data-start=\"1669\" data-end=\"1992\">Each transition between states can be linked to a <strong data-start=\"1719\" data-end=\"1731\">callback<\/strong> \u2014 a function that defines what happens when the node enters or exits a particular state.<\/p>\n<p data-start=\"1669\" data-end=\"1992\"><br data-start=\"1820\" data-end=\"1823\" \/>This structured model allows developers to build systems that are more reliable, predictable, and easier to manage, especially in distributed or industrial applications.<\/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-4229593 elementor-widget elementor-widget-text-editor\" data-id=\"4229593\" 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=\"1999\" data-end=\"2038\"><strong>Creating a Lifecycle Node in C++<\/strong><\/h3>\n<p data-start=\"2040\" data-end=\"2209\">Let\u2019s now see how to implement a Lifecycle Node in <strong data-start=\"2091\" data-end=\"2098\">C++<\/strong> using the native ROS 2 API.<br data-start=\"2126\" data-end=\"2129\" \/>The following code example comes from the lab <em data-start=\"2175\" data-end=\"2208\">L37_C++_Create a Lifecycle Node<\/em>.<\/p>\n<p data-start=\"1530\" data-end=\"1656\"><code data-start=\"1690\" data-end=\"1695\"><\/code><\/p>\n<p data-start=\"1530\" data-end=\"1656\"><code data-start=\"1690\" data-end=\"1695\"><\/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-c39e8e2 elementor-widget elementor-widget-code-highlight\" data-id=\"c39e8e2\" 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 \"rclcpp_lifecycle\/lifecycle_node.hpp\"\r\n\r\nusing rclcpp_lifecycle::LifecycleNode;\r\nusing CallbackReturn = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;\r\n\r\nclass MyLifecycleNode : public LifecycleNode\r\n{\r\npublic:\r\n    explicit MyLifecycleNode(const rclcpp::NodeOptions & options)\r\n    : LifecycleNode(\"my_lifecycle_node\", options)\r\n    {\r\n    }\r\n\r\n    CallbackReturn on_configure(const rclcpp_lifecycle::State &)\r\n    {\r\n        RCLCPP_INFO(get_logger(), \"Configuring...\");\r\n        return CallbackReturn::SUCCESS;\r\n    }\r\n\r\n    CallbackReturn on_activate(const rclcpp_lifecycle::State &)\r\n    {\r\n        RCLCPP_INFO(get_logger(), \"Activating...\");\r\n        return CallbackReturn::SUCCESS;\r\n    }\r\n\r\n    CallbackReturn on_deactivate(const rclcpp_lifecycle::State &)\r\n    {\r\n        RCLCPP_INFO(get_logger(), \"Deactivating...\");\r\n        return CallbackReturn::SUCCESS;\r\n    }\r\n\r\n    CallbackReturn on_cleanup(const rclcpp_lifecycle::State &)\r\n    {\r\n        RCLCPP_INFO(get_logger(), \"Cleaning up...\");\r\n        return CallbackReturn::SUCCESS;\r\n    }\r\n\r\n    CallbackReturn on_shutdown(const rclcpp_lifecycle::State &)\r\n    {\r\n        RCLCPP_INFO(get_logger(), \"Shutting down...\");\r\n        return CallbackReturn::SUCCESS;\r\n    }\r\n};\r\n\r\nint main(int argc, char * argv[])\r\n{\r\n    rclcpp::init(argc, argv);\r\n    auto lc_node = std::make_shared<MyLifecycleNode>(rclcpp::NodeOptions());\r\n    rclcpp::spin(lc_node->get_node_base_interface());\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-961c2f7 elementor-widget elementor-widget-text-editor\" data-id=\"961c2f7\" 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=\"2586\" data-end=\"2639\"><strong>\ud83e\udde0 Breaking Down the Code<\/strong><\/h3>\n<p data-start=\"1530\" data-end=\"1656\"><code data-start=\"1690\" data-end=\"1695\"><\/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-635f0ee elementor-widget elementor-widget-code-highlight\" data-id=\"635f0ee\" 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 \"rclcpp_lifecycle\/lifecycle_node.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-424d237 elementor-widget elementor-widget-text-editor\" data-id=\"424d237\" 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=\"4742\" data-end=\"4808\">These lines include the core ROS 2 libraries and the lifecycle extension <code data-start=\"3927\" data-end=\"3945\">rclcpp_lifecycle<\/code>, which provides all the tools needed to manage node life cycles.<\/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-34e2893 elementor-widget elementor-widget-code-highlight\" data-id=\"34e2893\" 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\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>using rclcpp_lifecycle::LifecycleNode;\r\nusing CallbackReturn = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;\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-0ed0bb9 elementor-widget elementor-widget-text-editor\" data-id=\"0ed0bb9\" 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=\"3907\" data-end=\"4070\">Here we define shorthand aliases for convenience.<br data-start=\"4214\" data-end=\"4217\" \/><code data-start=\"4217\" data-end=\"4232\">LifecycleNode<\/code> is the base class for managed nodes, while <code data-start=\"4276\" data-end=\"4292\">CallbackReturn<\/code> defines the type that transition callbacks must return.<\/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-fbbfe30 elementor-widget elementor-widget-code-highlight\" data-id=\"fbbfe30\" 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\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>class MyLifecycleNode : public LifecycleNode\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-dc28add elementor-widget elementor-widget-text-editor\" data-id=\"dc28add\" 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=\"4153\" data-end=\"4283\">We declare a class named <code data-start=\"4436\" data-end=\"4453\">MyLifecycleNode<\/code> that inherits from <code data-start=\"4473\" data-end=\"4488\">LifecycleNode<\/code>.<br data-start=\"4489\" data-end=\"4492\" \/>This allows us to override the lifecycle callback methods and define custom behaviors for each transition.<\/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-7da3562 elementor-widget elementor-widget-code-highlight\" data-id=\"7da3562\" 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\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>explicit MyLifecycleNode(const rclcpp::NodeOptions & options)\r\n: LifecycleNode(\"my_lifecycle_node\", options)\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-a73b77a elementor-widget elementor-widget-text-editor\" data-id=\"a73b77a\" 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 constructor initializes the node with the name <code data-start=\"4776\" data-end=\"4795\">my_lifecycle_node<\/code> and applies configuration options.<br data-start=\"4830\" data-end=\"4833\" \/>The <code data-start=\"4837\" data-end=\"4847\">explicit<\/code> keyword prevents implicit conversions, improving code safety.<\/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-9790003 elementor-widget elementor-widget-code-highlight\" data-id=\"9790003\" 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\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>CallbackReturn on_configure(const rclcpp_lifecycle::State &)\r\n{\r\n    RCLCPP_INFO(get_logger(), \"Configuring...\");\r\n    return CallbackReturn::SUCCESS;\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-09ad431 elementor-widget elementor-widget-text-editor\" data-id=\"09ad431\" 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=\"1569\" data-end=\"1754\">The <code data-start=\"5081\" data-end=\"5097\">on_configure()<\/code> callback is triggered when the node transitions from <em data-start=\"5151\" data-end=\"5165\">unconfigured<\/em> to <em data-start=\"5169\" data-end=\"5179\">inactive<\/em>.<br data-start=\"5180\" data-end=\"5183\" \/>Here, we would typically load parameters, initialize publishers or resources, and prepare the node for operation.<\/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-41dc26a elementor-widget elementor-widget-code-highlight\" data-id=\"41dc26a\" 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\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>CallbackReturn on_activate(const rclcpp_lifecycle::State &)\r\n{\r\n    RCLCPP_INFO(get_logger(), \"Activating...\");\r\n    return CallbackReturn::SUCCESS;\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-a962652 elementor-widget elementor-widget-text-editor\" data-id=\"a962652\" 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=\"1949\" data-end=\"2139\">The <code data-start=\"5466\" data-end=\"5481\">on_activate()<\/code> callback runs when the node becomes <em data-start=\"5518\" data-end=\"5526\">active<\/em>.<br data-start=\"5527\" data-end=\"5530\" \/>At this stage, publishers, subscribers, or timers are enabled \u2014 the node is now fully operational.<\/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-c2c1ba4 elementor-widget elementor-widget-code-highlight\" data-id=\"c2c1ba4\" 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\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>CallbackReturn on_deactivate(const rclcpp_lifecycle::State &)\r\n{\r\n    RCLCPP_INFO(get_logger(), \"Deactivating...\");\r\n    return CallbackReturn::SUCCESS;\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-b70a0c1 elementor-widget elementor-widget-text-editor\" data-id=\"b70a0c1\" 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=\"5802\" data-end=\"5819\">on_deactivate()<\/code> callback handles the transition from <em data-start=\"5857\" data-end=\"5865\">active<\/em> to <em data-start=\"5869\" data-end=\"5879\">inactive<\/em>.<br data-start=\"5880\" data-end=\"5883\" \/>It\u2019s used to pause activity while keeping resources available for reactivation.<\/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-6b53ddc elementor-widget elementor-widget-code-highlight\" data-id=\"6b53ddc\" 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\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>CallbackReturn on_cleanup(const rclcpp_lifecycle::State &)\r\n{\r\n    RCLCPP_INFO(get_logger(), \"Cleaning up...\");\r\n    return CallbackReturn::SUCCESS;\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-f590093 elementor-widget elementor-widget-text-editor\" data-id=\"f590093\" 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=\"6403\" data-end=\"6591\">The <code data-start=\"6132\" data-end=\"6146\">on_cleanup()<\/code> callback frees resources and resets parameters, returning the node to the <em data-start=\"6221\" data-end=\"6235\">unconfigured<\/em> state \u2014 ready for reconfiguration.<\/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-8759947 elementor-widget elementor-widget-code-highlight\" data-id=\"8759947\" 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\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>CallbackReturn on_shutdown(const rclcpp_lifecycle::State &)\r\n{\r\n    RCLCPP_INFO(get_logger(), \"Shutting down...\");\r\n    return CallbackReturn::SUCCESS;\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-acb53bd elementor-widget elementor-widget-text-editor\" data-id=\"acb53bd\" 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=\"6798\" data-end=\"6840\">The <code data-start=\"6443\" data-end=\"6458\">on_shutdown()<\/code> callback executes during final shutdown.<br data-start=\"6499\" data-end=\"6502\" \/>It\u2019s the ideal place to save data, close files, and release hardware safely.<\/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-4872011 elementor-widget elementor-widget-code-highlight\" data-id=\"4872011\" 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\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>int main(int argc, char * argv[])\r\n{\r\n    rclcpp::init(argc, argv);\r\n    auto lc_node = std::make_shared<MyLifecycleNode>(rclcpp::NodeOptions());\r\n    rclcpp::spin(lc_node->get_node_base_interface());\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-3c61bba elementor-widget elementor-widget-text-editor\" data-id=\"3c61bba\" 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=\"7843\" data-end=\"7858\">The <code data-start=\"6837\" data-end=\"6845\">main()<\/code> function initializes ROS 2, creates an instance of the node, spins it to keep it running, and then shuts down cleanly.<br data-start=\"6964\" data-end=\"6967\" \/>The <code data-start=\"6971\" data-end=\"6979\">spin()<\/code> call ensures the node stays active until an external shutdown signal is received.<\/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-6e30ba6 elementor-widget elementor-widget-text-editor\" data-id=\"6e30ba6\" 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=\"7068\" data-end=\"7107\"><strong>Managing Lifecycle Nodes via CLI<\/strong><\/h3>\n<p data-start=\"7109\" data-end=\"7314\">Once the node is running, you can control its state directly from the terminal using ROS 2\u2019s command-line interface.<br data-start=\"7225\" data-end=\"7228\" \/>This tool allows you to move the node between states \u2014 ideal for testing or debugging.<\/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-9e625c4 elementor-widget elementor-widget-code-highlight\" data-id=\"9e625c4\" 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 lifecycle set \/my_lifecycle_node configure\r\nros2 lifecycle set \/my_lifecycle_node activate\r\nros2 lifecycle set \/my_lifecycle_node deactivate\r\nros2 lifecycle set \/my_lifecycle_node cleanup\r\nros2 lifecycle set \/my_lifecycle_node 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-a76dd41 elementor-widget elementor-widget-text-editor\" data-id=\"a76dd41\" 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=\"7363\" data-end=\"7396\">Each command triggers the corresponding callback in the code.<br data-start=\"7627\" data-end=\"7630\" \/>To check the node\u2019s current state, simply run:<\/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-806e6b5 elementor-widget elementor-widget-code-highlight\" data-id=\"806e6b5\" 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 lifecycle get \/my_lifecycle_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-5e371d2 elementor-widget elementor-widget-text-editor\" data-id=\"5e371d2\" 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=\"7363\" data-end=\"7396\">This mechanism makes Lifecycle Nodes perfect for distributed robotics environments where multiple components must be activated and deactivated in a controlled order.<\/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-cebe6cb elementor-widget elementor-widget-text-editor\" data-id=\"cebe6cb\" 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=\"7901\" data-end=\"7943\"><strong>Why Lifecycle Nodes Matter in ROS 2<\/strong><\/h3>\n<p data-start=\"7945\" data-end=\"8134\">Lifecycle Nodes are one of the most significant advancements of ROS 2 compared to ROS 1.<br data-start=\"8033\" data-end=\"8036\" \/>They provide <strong data-start=\"8049\" data-end=\"8074\">deterministic control<\/strong>, promote <strong data-start=\"8084\" data-end=\"8098\">modularity<\/strong>, and ensure <strong data-start=\"8111\" data-end=\"8133\">system reliability<\/strong>.<\/p>\n<p data-start=\"8136\" data-end=\"8440\">In industrial and research applications, they are essential for ensuring that sensors activate only when the system is ready and that actuators deactivate safely.<br data-start=\"8298\" data-end=\"8301\" \/>They also make it possible to dynamically reconfigure systems without restarting the entire application \u2014 improving uptime and flexibility.<\/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-078e0ac elementor-widget elementor-widget-text-editor\" data-id=\"078e0ac\" 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=\"8212\" data-end=\"8228\"><strong>\ud83c\udfaf Conclusion<\/strong><\/h3>\n<p data-start=\"8465\" data-end=\"8776\">In this article, we explored how to create and manage a <strong data-start=\"8521\" data-end=\"8558\">Lifecycle Node in ROS 2 using C++<\/strong>, analyzing the full code and comparing it to the version described in <em data-start=\"8629\" data-end=\"8657\">\u201cLifecycle Node in Python\u201d<\/em>.<br data-start=\"8658\" data-end=\"8661\" \/>We learned how to define transition callbacks, monitor node states, and use the ROS 2 CLI for lifecycle management.<\/p>\n<p data-start=\"8873\" data-end=\"9285\">\u00a0<\/p>\n<p data-start=\"8873\" data-end=\"9285\">Scroll down to discover how to access the full course today and take your ROS 2 development to the next level.<\/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-e8bdddd 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=\"e8bdddd\" 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\/plan_navigation.webp);\" role=\"img\" aria-label=\"plan_navigation\"><\/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\tIf you want to learn how to design and build professional robotic systems leveraging the full power of ROS 2 Lifecycle Nodes, check out our \"Self Driving and ROS 2 - Learn by doing! Plan &amp; Navigation\" 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>\n\t\t\t\t<\/div>","protected":false},"excerpt":{"rendered":"<p>When developing complex robotic systems, managing the operational state of each node precisely is essential to ensure stability, safety, and predictability.ROS 2 introduces a key concept to meet this need: Lifecycle Nodes. \u00a0 Unlike standard nodes, which start operating as soon as they are launched, Lifecycle Nodes allow you to explicitly control their behavior through [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":4100,"comment_status":"closed","ping_status":"open","sticky":false,"template":"elementor_header_footer","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[45,43],"tags":[328,347,349,179,66,74,106,319,96,110,343,348,296,71,107,72,342,76,73],"class_list":["post-4323","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ros-2","category-tutorials","tag-antonio-brandi","tag-brandi","tag-costmaps","tag-lbd","tag-learn-by-doing","tag-linux","tag-mapping","tag-maps","tag-nav2","tag-navigation","tag-obstacle","tag-pc","tag-raspberry","tag-ros","tag-ros-2","tag-ros2","tag-static","tag-step-by-step","tag-ubuntu"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Creating and Managing a Lifecycle Node in ROS 2 with C++ - Learn by Doing!<\/title>\n<meta name=\"description\" content=\"Learn how to create and manage Lifecycle Nodes in ROS 2. Understand their states, transitions, and benefits with a step-by-step practical guide and examples.\" \/>\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\/creating-and-managing-a-lifecycle-node-in-ros-2-with-c\/\" \/>\n<meta property=\"og:locale\" content=\"es_ES\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Creating and Managing a Lifecycle Node in ROS 2 with C++\" \/>\n<meta property=\"og:description\" content=\"Learn by Doing!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/learnbydoing.dev\/es\/creating-and-managing-a-lifecycle-node-in-ros-2-with-c\/\" \/>\n<meta property=\"og:site_name\" content=\"Learn by Doing!\" \/>\n<meta property=\"article:published_time\" content=\"2025-10-31T14:04:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-01-10T21:53:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/4.png\" \/>\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\/png\" \/>\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\/creating-and-managing-a-lifecycle-node-in-ros-2-with-c\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/learnbydoing.dev\/creating-and-managing-a-lifecycle-node-in-ros-2-with-c\/\"},\"author\":{\"name\":\"\",\"@id\":\"\"},\"headline\":\"Creating and Managing a Lifecycle Node in ROS 2 with C++\",\"datePublished\":\"2025-10-31T14:04:37+00:00\",\"dateModified\":\"2026-01-10T21:53:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/learnbydoing.dev\/creating-and-managing-a-lifecycle-node-in-ros-2-with-c\/\"},\"wordCount\":789,\"publisher\":{\"@id\":\"https:\/\/learnbydoing.dev\/es\/#organization\"},\"image\":{\"@id\":\"https:\/\/learnbydoing.dev\/creating-and-managing-a-lifecycle-node-in-ros-2-with-c\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/4.png\",\"keywords\":[\"antonio brandi\",\"brandi\",\"costmaps\",\"lbd\",\"learn by doing\",\"Linux\",\"mapping\",\"Maps\",\"nav2\",\"navigation\",\"obstacle\",\"pc\",\"Raspberry\",\"ROS\",\"ROS 2\",\"ROS2\",\"static\",\"step by step\",\"Ubuntu\"],\"articleSection\":[\"ROS 2\",\"Tutorials\"],\"inLanguage\":\"es\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/learnbydoing.dev\/creating-and-managing-a-lifecycle-node-in-ros-2-with-c\/\",\"url\":\"https:\/\/learnbydoing.dev\/creating-and-managing-a-lifecycle-node-in-ros-2-with-c\/\",\"name\":\"Creating and Managing a Lifecycle Node in ROS 2 with C++ - Learn by Doing!\",\"isPartOf\":{\"@id\":\"https:\/\/learnbydoing.dev\/es\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/learnbydoing.dev\/creating-and-managing-a-lifecycle-node-in-ros-2-with-c\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/learnbydoing.dev\/creating-and-managing-a-lifecycle-node-in-ros-2-with-c\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/4.png\",\"datePublished\":\"2025-10-31T14:04:37+00:00\",\"dateModified\":\"2026-01-10T21:53:25+00:00\",\"description\":\"Learn how to create and manage Lifecycle Nodes in ROS 2. Understand their states, transitions, and benefits with a step-by-step practical guide and examples.\",\"breadcrumb\":{\"@id\":\"https:\/\/learnbydoing.dev\/creating-and-managing-a-lifecycle-node-in-ros-2-with-c\/#breadcrumb\"},\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/learnbydoing.dev\/creating-and-managing-a-lifecycle-node-in-ros-2-with-c\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\/\/learnbydoing.dev\/creating-and-managing-a-lifecycle-node-in-ros-2-with-c\/#primaryimage\",\"url\":\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/4.png\",\"contentUrl\":\"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/4.png\",\"width\":1920,\"height\":1080},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/learnbydoing.dev\/creating-and-managing-a-lifecycle-node-in-ros-2-with-c\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/learnbydoing.dev\/es\/learn-by-doing-es\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Creating and Managing a Lifecycle Node in ROS 2 with C++\"}]},{\"@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":"Creating and Managing a Lifecycle Node in ROS 2 with C++ - Learn by Doing!","description":"Learn how to create and manage Lifecycle Nodes in ROS 2. Understand their states, transitions, and benefits with a step-by-step practical guide and examples.","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\/creating-and-managing-a-lifecycle-node-in-ros-2-with-c\/","og_locale":"es_ES","og_type":"article","og_title":"Creating and Managing a Lifecycle Node in ROS 2 with C++","og_description":"Learn by Doing!","og_url":"https:\/\/learnbydoing.dev\/es\/creating-and-managing-a-lifecycle-node-in-ros-2-with-c\/","og_site_name":"Learn by Doing!","article_published_time":"2025-10-31T14:04:37+00:00","article_modified_time":"2026-01-10T21:53:25+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/4.png","type":"image\/png"}],"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\/creating-and-managing-a-lifecycle-node-in-ros-2-with-c\/#article","isPartOf":{"@id":"https:\/\/learnbydoing.dev\/creating-and-managing-a-lifecycle-node-in-ros-2-with-c\/"},"author":{"name":"","@id":""},"headline":"Creating and Managing a Lifecycle Node in ROS 2 with C++","datePublished":"2025-10-31T14:04:37+00:00","dateModified":"2026-01-10T21:53:25+00:00","mainEntityOfPage":{"@id":"https:\/\/learnbydoing.dev\/creating-and-managing-a-lifecycle-node-in-ros-2-with-c\/"},"wordCount":789,"publisher":{"@id":"https:\/\/learnbydoing.dev\/es\/#organization"},"image":{"@id":"https:\/\/learnbydoing.dev\/creating-and-managing-a-lifecycle-node-in-ros-2-with-c\/#primaryimage"},"thumbnailUrl":"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/4.png","keywords":["antonio brandi","brandi","costmaps","lbd","learn by doing","Linux","mapping","Maps","nav2","navigation","obstacle","pc","Raspberry","ROS","ROS 2","ROS2","static","step by step","Ubuntu"],"articleSection":["ROS 2","Tutorials"],"inLanguage":"es"},{"@type":"WebPage","@id":"https:\/\/learnbydoing.dev\/creating-and-managing-a-lifecycle-node-in-ros-2-with-c\/","url":"https:\/\/learnbydoing.dev\/creating-and-managing-a-lifecycle-node-in-ros-2-with-c\/","name":"Creating and Managing a Lifecycle Node in ROS 2 with C++ - Learn by Doing!","isPartOf":{"@id":"https:\/\/learnbydoing.dev\/es\/#website"},"primaryImageOfPage":{"@id":"https:\/\/learnbydoing.dev\/creating-and-managing-a-lifecycle-node-in-ros-2-with-c\/#primaryimage"},"image":{"@id":"https:\/\/learnbydoing.dev\/creating-and-managing-a-lifecycle-node-in-ros-2-with-c\/#primaryimage"},"thumbnailUrl":"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/4.png","datePublished":"2025-10-31T14:04:37+00:00","dateModified":"2026-01-10T21:53:25+00:00","description":"Learn how to create and manage Lifecycle Nodes in ROS 2. Understand their states, transitions, and benefits with a step-by-step practical guide and examples.","breadcrumb":{"@id":"https:\/\/learnbydoing.dev\/creating-and-managing-a-lifecycle-node-in-ros-2-with-c\/#breadcrumb"},"inLanguage":"es","potentialAction":[{"@type":"ReadAction","target":["https:\/\/learnbydoing.dev\/creating-and-managing-a-lifecycle-node-in-ros-2-with-c\/"]}]},{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/learnbydoing.dev\/creating-and-managing-a-lifecycle-node-in-ros-2-with-c\/#primaryimage","url":"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/4.png","contentUrl":"https:\/\/learnbydoing.dev\/wp-content\/uploads\/2025\/10\/4.png","width":1920,"height":1080},{"@type":"BreadcrumbList","@id":"https:\/\/learnbydoing.dev\/creating-and-managing-a-lifecycle-node-in-ros-2-with-c\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/learnbydoing.dev\/es\/learn-by-doing-es\/"},{"@type":"ListItem","position":2,"name":"Creating and Managing a Lifecycle Node in ROS 2 with C++"}]},{"@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\/4323","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\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/learnbydoing.dev\/es\/wp-json\/wp\/v2\/comments?post=4323"}],"version-history":[{"count":16,"href":"https:\/\/learnbydoing.dev\/es\/wp-json\/wp\/v2\/posts\/4323\/revisions"}],"predecessor-version":[{"id":5487,"href":"https:\/\/learnbydoing.dev\/es\/wp-json\/wp\/v2\/posts\/4323\/revisions\/5487"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/learnbydoing.dev\/es\/wp-json\/wp\/v2\/media\/4100"}],"wp:attachment":[{"href":"https:\/\/learnbydoing.dev\/es\/wp-json\/wp\/v2\/media?parent=4323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learnbydoing.dev\/es\/wp-json\/wp\/v2\/categories?post=4323"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learnbydoing.dev\/es\/wp-json\/wp\/v2\/tags?post=4323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}