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

You need to give the node some processing time. Because you are creating a node here:

auto node = std::make_shared<MyturtleSpawner>();

And then immediately calling rclcpp::shutdown() on the next line, by the time the thread gets a chance to run and create the client, the ROS context has been cleaned up.

You need to create an executor and spin the node after creating it and before calling rclcpp::shutdown(). See this tutorial, and look at the main() function. It has a call to rclcpp::spin() after creating the node.