ROS(六)简单的ros代码-hello word

版权声明:微信 kobesdu https://blog.csdn.net/kobesdu/article/details/85011608

#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;

//将节点实例化成发布者,并讲所发布主题和类型的名称告诉节点管理器,第二个参数是缓冲区的大小

扫描二维码关注公众号,回复: 4804545 查看本文章

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;

}

猜你喜欢

转载自blog.csdn.net/kobesdu/article/details/85011608