1. 安装ros系统
- 创建工作空间
mkdir -p ~/catkin_ws/src // 创建对应目录
cd ~/catkin_ws/ // 进入对应地址
catkin_make // 编译对应工作环境
source devel/setup.bash // 讲当前工作空间设置为ros工作环境的最顶层 source一下设置工作环境
创建好的空间大概是这样:
workspace_folder/ -- WORKSPACE
src/ -- SOURCE SPACE
CMakeLists.txt -- 'Toplevel' CMake file, provided by catkin
package_1/
CMakeLists.txt -- CMakeLists.txt file for package_1
package.xml -- Package manifest for package_1
...
package_n/
CMakeLists.txt -- CMakeLists.txt file for package_n
package.xml -- Package manifest for package_n
- 创建catkin程序包
cd ~/catkin_ws/src // 进入对应环境
catkin_create_pkg beginner_tutorial std_msgs rospy roscpp // 后面是对应的依赖包
- 在上一步中catkin_create_pkg,在当下程序包中生成两个文件,分别是Cmakelists.txt和package.xml
5. vim打开对应的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)
6.在work space下,运行catkin_make
catkin_make
- 打开新的三个终端,分别运行如下:
roscore // 第一个终端保证运行
source devel/setup.bash // 添加source源 第二个第三个终端都要添加
rosrun beginner_tutorials talker (C++) // 第二个终端
rosrun beginner_tutorials listener (C++) // 第三个终端
8. end!!!
网友评论