简化了教程中的示例(主要是CMakeLists.txt)
- 首先,中文教程里有一处翻译错误:
http://wiki.ros.org/cn/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29
http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29
示例
- 建立工作空间,创建软件包
pi@raspberrypi:~ $ mkdir -p catkin_ws/src
pi@raspberrypi:~ $ cd catkin_ws/src/
pi@raspberrypi:~/catkin_ws/src $ catkin_init_workspace
pi@raspberrypi:~/catkin_ws/src $ catkin_create_pkg hello roscpp
pi@raspberrypi:~/catkin_ws/src $ cd hello/
pi@raspberrypi:~/catkin_ws/src/hello $ ls
CMakeLists.txt include package.xml src
- 将talker.cpp、 listener.cpp 放入src目录(可从官网复制)
pi@raspberrypi:~/catkin_ws/src/hello/src $ ls
listener.cpp talker.cpp
- 修改CMakeLists.txt
cmake_minimum_required(VERSION 2.8.3)
project(hello)
find_package(catkin REQUIRED COMPONENTS roscpp)
catkin_package()
include_directories( ${catkin_INCLUDE_DIRS})
add_executable(talker src/talker.cpp)
target_link_libraries(talker ${catkin_LIBRARIES})
add_executable(listener src/listener.cpp)
target_link_libraries(listener ${catkin_LIBRARIES})
- 返回catkin_ws目录进行编译
pi@raspberrypi:~/catkin_ws $ catkin_make
- 运行程序
[1] 首先运行roscore节点
[2] 打开新终端,运行talker
[3] 打开新终端,运行listener