ROS_Kinetic_10 ROS程序基础Eclipse_C++(一)

时间:2023-11-21 20:13:20

ROS_Kinetic_10 ROS程序基础Eclipse_C++(一)

编写简单的消息发布器和订阅器 (C++)

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

这里简单用Eclipse实现一下。

首相将talker.cpp和listener.cpp复制到hello_kinetic/src目录下;

ROS_Kinetic_10 ROS程序基础Eclipse_C++(一)

然后修改CMakeLists.txt;加入下列代码:

## Build talker and listener
include_directories(include ${catkin_INCLUDE_DIRS})

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

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

注意,可执行的节点不能重名,这里为kinetic_talker和kinetic_listener。

ROS_Kinetic_10 ROS程序基础Eclipse_C++(一)

然后,就可以编译了,编译完成后。

ROS_Kinetic_10 ROS程序基础Eclipse_C++(一)

开启终端,启动roscore:

ROS_Kinetic_10 ROS程序基础Eclipse_C++(一)

-End-