ROS學習筆記--消息發佈器和訂閱器

簡化了教程中的示例(主要是CMakeLists.txt)

示例

  • 建立工作空間,創建軟件包
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
    這裏寫圖片描述
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章