码迷,mamicode.com
首页 > 其他好文 > 详细

ROS消息, 服务, 主题, 订阅 4

时间:2017-05-17 12:05:58      阅读:325      评论:0      收藏:0      [点我收藏+]

标签:nts   class   lis   packages   pen   sts   directory   运行   message   

发布者跟订阅者都ok了, 现在要建立节点:

cmake_minimum_required(VERSION 2.8.3)
project(beginner_tutorials)

## Find catkin and any catkin packages
find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs genmsg)

## Declare ROS messages and services
add_message_files(DIRECTORY msg FILES Num.msg)
add_service_files(DIRECTORY srv FILES AddTwoInts.srv)

## Generate added messages and services
generate_messages(DEPENDENCIES std_msgs)

## Declare a catkin package
catkin_package()

 修改CMakeLists.txt

尾部增加这个:

add_executable(talker src/talker.cpp)
target_link_libraries(talker ${catkin_LIBRARIES})
add_dependencies(talker beginner_tutorials_generate_messages_cpp)

add_executable(listener src/listener.cpp)
target_link_libraries(listener ${catkin_LIBRARIES})
add_dependencies(listener beginner_tutorials_generate_messages_cpp)

 

catkin_make一下吧.

 

开始运行吧:

$ cd ~/catkin_ws
$ source ./devel/setup.bash

首先talker:

$ rosrun beginner_tutorials talker 

 然后另一个窗口

$ rosrun beginner_tutorials listener 

 

通过rosrun rqt_graph rqt_graph看看topic的中转吧:

技术分享

 

ROS消息, 服务, 主题, 订阅 4

标签:nts   class   lis   packages   pen   sts   directory   运行   message   

原文地址:http://www.cnblogs.com/Montauk/p/6866413.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!