参考学习资料:B站赵虚左的ROS课程
节点关闭
C++
节点关闭api
ros::shutdown()
修改之前的pub.cpp
ros::Publisher pub = n.advertise<std_msgs::String>("chongfu",1000,true);
std_msgs::String msg;
ros::Rate rate(1);
int count = 0;
while (ros::ok())
{
count++;
std::stringstream ss;
ss << "hello -->" << count;
msg.data = ss.str();
if(count <= 10)
{
pub.publish(msg);
ROS_INFO("发布数据:%s", msg.data.c_str());
rate.sleep();
}
else
{
ros::shutdown();
}
// pub.publish(msg);
// ROS_INFO("发布数据:%s", msg.data.c_str());
// rate.sleep();
ros::spinOnce();
// ROS_INFO("