本文主要部分来源于ROS官网的Tutorials.
Creating a ROS Package by catkin_create_pkg
cd ~/catkin_ws/src
# catkin_create_pkg <package_name> [depend1] [depend2] [depend3]
catkin_create_pkg beginner_tutorials std_msgs rospy roscpp # create a new package called 'beginner_tutorials' which depends on std_msgs, roscpp, and rospy # build the packages in the catkin workspace cd ~/catkin_ws catkin_make # To add the workspace to your ROS environment you need to source the generated setup file . ~/catkin_ws/devel/setup.bash rospack depends1 beginner_tutorials # First-order dependencies roscd beginner_tutorials cat package.xml # These dependencies for a package are stored in the package.xml file rospack depends beginner_tutorials # Indirect dependencies, rospack can recursively determine all nested dependencies
Building a ROS Package
cd ~/catkin_ws/
ls src
catkin_make # build all catkin projects found in the src folder.
catkin_make install # (optionally) ls
Creating a ROS Package by Hand
cd ~/catkin_ws mkdir -p src/foobar cd src/foobar gedit package.xml # The very first thing we'll do is add our manifest file
pakage.xml中输入以下内容:
<package> <name>foobar</name> <version>1.2.4</version> <description> This package provides foo capability. </description> <maintainer email="foobar@foo.bar.willowgarage.com">PR-foobar</maintainer> <license>BSD</license> <buildtool_depend>catkin</buildtool_depend> <build_depend>roscpp</build_depend> <build_depend>std_msgs</build_depend> <run_depend>roscpp</run_depend> <run_depend>std_msgs</run_depend> </package>
Now that your package has a manifest, Test it:
rospack find foobar
创建CMakeLists.txt:
cd ~/catkin_ws cd src/foobar gedit CMakeLists.txt
在CmakeLists.txt中输入:
cmake_minimum_required(VERSION 2.8.3) project(foobar) find_package(catkin REQUIRED roscpp std_msgs) catkin_package()