ROS学习之订阅消息——Subscriber_代码分析

接上篇:ROS学习之发布消息——Publisher

//详解版本:
//本代码文件名为:subscriber.cpp

#include "ros/ros.h"
#include "std_msgs/String.h"
#include 

using namespace ros;
using namespace std;

//回调函数的形参为std_msgs::String 类型,也就是要处理_msgs::String类型的消息
void callBack(const std_msgs::String &msg){
    cout<<"I heard from topic_1: "<
//简洁版本:

#include "ros/ros.h"
#include "std_msgs/String.h"
#include 

using namespace ros;
using namespace std;

void callBack(const std_msgs::String &msg){
    cout<<"I heard from topic_m: "<

继上节ROS学习之发布消息——Publisher中的CMakeList.txt:

cmake_minimum_required(VERSION 2.8.3)

project(my_package)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
)

catkin_package(
  INCLUDE_DIRS include
  LIBRARIES my_package
  CATKIN_DEPENDS roscpp rospy std_msgs
  DEPENDS system_lib
)

include_directories(
#  include
  ${catkin_INCLUDE_DIRS}
)

# talker_Node在ros中是独一无二的,不能和其它节点名字重复
add_executable(publisher_Node src/publisher.cpp)
target_link_libraries(publisher_Node ${catkin_LIBRARIES})

add_executable(subscriber_Node src/subscriber.cpp)
target_link_libraries(subscriber_Node ${catkin_LIBRARIES})

你可能感兴趣的:(ROS,使用笔记)