[ros-users] [Discourse.ros.org] How to shutdown and reinitialize a publisher node in ROS 2

Akash ros.discourse at gmail.com
Fri Mar 2 12:49:22 UTC 2018



I have a use case of shutting down and reinitializing the publisher in ROS 2,

i have included my init function inside the while loop when i execute the publisher i get this error
"""terminate called after throwing an instance of 'rclcpp::exceptions::RCLError'
  what():  failed to create interrupt guard condition: rcl_init() has not been called, at /home/administrator/ros2_ws/src/ros2/rcl/rcl/src/rcl/guard_condition.c:61
Aborted (core dumped)"""

my code::
int main(int argc, char * argv[] )
{
auto node = rclcpp::Node::make_shared("talker1");
auto Pub = node->create_publisher<std_msgs::msg::String>("chatter1",rmw_qos_profile_default);
rclcpp::WallRate loop_rate(1);
size_t count = 1;
auto msg = std::make_shared<std_msgs::msg::String>();

while(1)
    {
    	   rclcpp::init(argc, argv);
		

		msg->data = "Hello World" + to_string(count++);
            
    		std::cout << msg->data << ":msg_no:" << count << std::endl;
    		Pub->publish(msg); 
loop_rate.sleep();
	
    }

  rclcpp::shutdown();
  return 0;
}

Can anyone help me with this





---
[Visit Topic](https://discourse.ros.org/t/how-to-shutdown-and-reinitialize-a-publisher-node-in-ros-2/4090/1) or reply to this email to respond.




More information about the ros-users mailing list