#include <ros/ros.h>
#include <std_msgs/String.h>
#include <sstream>
int main(int argc, char **argv)
{
//初始化ros节点并设置其名称
ros::init(argc, argv, "hello_world_node");
//进程的处理句柄
ros::NodeHandle nh;
//将节点实例化成发布者,并讲所发布主题和类型的名称告诉节点管理器,第二个参数是缓冲区的大小
ros::Publisher chatter_pub = nh.advertise<std_msgs::String>("say_hello_world", 1000);
//发送数据的频率设置为10hz
ros::Rate loop_rate(1);
int count = 0;
while (ros::ok())
{
std_msgs::String msg;
std::stringstream ss;
ss << "Hello World !" << count;
msg.data = ss.str();
ROS_INFO("%s", msg.data.c_str());
chatter_pub.publish(msg);
ros::spinOnce();
loop_rate.sleep();
++count;
}
return 0;
}