1. 程式人生 > >【ROS】建立Publisher和Subscriber過程中遇到的問題和解決方案

【ROS】建立Publisher和Subscriber過程中遇到的問題和解決方案

Tutorial連結:http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29

 

1. 寫好並儲存好了talker.cpp和listener.cpp卻無法建立

  • 檢查~/catkin_ws/src/beginner_tutorials裡面的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)

2. 成功建立後新視窗執行rosrun beginner_tutorials talker卻發現以下提示錯誤:[rosrun]Couldn't find executable named talker below /home/<username>/catkin_ws/src/beginner_tutorials

  • 原因在於catkin_make編譯出來的可執行檔案在~/catkin_ws/devel/lib/beginner_tutorials裡面,所以要在新開啟的視窗內執行以下命令讓ros找到你想執行的檔案 (注意!每次開啟新視窗都要先執行“source”那一行
cd ~/catkin_ws
source ./devel/setup.bash
rosrun beginner_tutorials talker