打开一个终端,进入到beginner_tutorials包下面:
编辑文件 src/listener.cpp:
将下面的代码复制到文件中:
cd ~/catkin_ws/src/beginner_tutorials
编辑文件 src/listener.cpp:
vim src/listener.cpp
将下面的代码复制到文件中:
#include "ros/ros.h"
#include "std_msgs/String.h"
/**
* This tutorial demonstrates simple receipt of messages over the ROS system.
*/
void chatterCallback(const std_msgs::String::ConstPtr& msg)
{
ROS_INFO("I heard: [%s]", msg->data.c_str());
}
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