[ros-users] [Discourse.ros.org] How to shutdown and reinitia…

Forside
Vedhæftede filer:
Indlæg som e-mail
+ (text/plain)
Slet denne besked
Besvar denne besked
Skribent: Akash via ros-users
Dato:  
Til: ros-users
CC: Akash
Emne: [ros-users] [Discourse.ros.org] How to shutdown and reinitialize a publisher node in ROS 2


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.


If you do not want to receive messages from ros-users please use the unsubscribe link below. If you use the one above, you will stop all of ros-users from receiving updates.
______________________________________________________________________________
ros-users mailing list

http://lists.ros.org/mailman/listinfo/ros-users
Unsubscribe: <http://lists.ros.org/mailman//options/ros-users>