本文主要是介绍用C++编写一个简单的Publisher和Subscriber,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.创建Publisher Node
roscd beginner_tutorials
创建src/talker.cpp文件,内容如下(可从https://raw.github.com/ros/ros_tutorials/kinetic-devel/roscpp_tutorials/talker/talker.cpp获取源码):
#include "ros/ros.h"
#include "std_msgs/String.h"
#include <sstream>
int main(int argc, char **argv)
{
ros::init(argc, argv,"talker");
ros::NodeHandle n;
ros::Publisher chatter_pub =n.advertise("chatter", 1000);
ros::Rate loop_rate(10);
int count = 0;
while(ros::ok())
{
std_msgs::String msg;
std::stringst
这篇关于用C++编写一个简单的Publisher和Subscriber的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!