ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Just to elaborate further on Josh Whitley's answer: This is still true in ROS2 Galactic. You can write a node that inherits from rclcpp::LifecycleNode, implements the lifecycle states, and is launched as either a standalone Node or ComposableNode. However the mechanisms in ros_launch that automate the state transitions only work with LifecycleNode objects. This means that without them, lifecycle nodes will start in the "unconfigured" state, and won't automatically configure or activate themselves, much less shut down properly.

If you really need to run a lifecycle node inside a container, this leaves you with a couple of options (other users please feel free to chime in with any I've missed):

  1. Manually force the state changes with CLI commands, e.g. $ ros2 lifecycle set /<node_name> configure/activate/shutdown. I've tested this out and can confirm it works. Visit this lifecycle demo readme for more information.
  2. Create another node that is responsible for managing the state changes via service calls. This is what the Nav2 package does with its nav2_lifecycle_manager. If you have a look here you will see an example of a Nav2 package which launches quite a few lifecycle nodes as ComposableNodes. For more information on the service calls that can transition states, see the same lifecycle demo readme.
  3. You could try this cascade_lifecycle package which extends the lifecycle node interface and adds state transition self-calls that you can make from the source code. I haven't tried this myself yet so I can't confirm if it works.
  4. Wait until official support for lifecycle nodes in containers has been added. There is a large body of work underway to re-write how the underlying node execution process works, and part of this includes changing the lifecycle process so that it is just a trait that you can add to any node (composable or otherwise). You can read the discussion on the redesign here: #215, and track the corresponding PR here: #272