ROS学习笔记九:用C++编写ROS发布与订阅
本节主要介绍如何用C++编写一个简单的ROS发布与订阅。
编写发布节点
在之前创建的例子beginner_tutorials软件包中,在其目录下的src目录中,创建talker.cpp文件:
#include "ros/ros.h" //ROS中最常用片段的头文件
#include "std_msgs/String.h" //由String.msg自动产生的头文件
#include <sstream> //stringstream头文件
/**
* This tutorial demonstrates simple sending of messages over the ROS system.
*/
int main(int argc, char **argv)
{
/**
* The ros::init() function needs to see argc and argv so that it can perform
* any ROS arguments and name remapping that were provided at the command line.
* For programmatic remappings you can use a different version of init() which takes
* remappings directly, but for most command-line programs, passing argc and argv is
* the easiest way to do it. The third argument to init() is the name of the node.
*
* You must call one of the versions of ros::init() before using any other
* part of the ROS system.
*/
ros::init(argc, argv, "talker"); //初始化ROS,在这里可以指定我们节点的名称,一个ROS系统中节点的名称必须是唯一的
/**
* NodeHandle is the main access point to communications with the ROS system.
* The first NodeHandle constructed