ROS ROS study notes 4- to create a package

In this article comes from the official Wiki, http://wiki.ros.org/ROS/Tutorials/CreatingPackage

  1. What package contains a catkin
    1. It must contain package.xml file that describes the package information.
    2. CMakeLists.txt file must have a catkin use.
    3. Each package must have its own folder.
      A simple packet structure is as follows:
      my_package/
        CMakeLists.txt
        package.xml
      
  2. Package catkin workspace (Workspace) is
    recommended to work in catkin catkin packet workspace, although the package may also be constructed separately.
    A typical catkin workspace file structure is as follows:
    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
    

    Before continuing, take a look at how to create a catkin workspace.

  3. Creating catkin workspace.
    ROS can be installed after the installation using this command catkin,
    $ source /opt/ros/kinetic/setup.bash
    

    Catkin create a workspace using the following command name for catkin_ws:

    $ mkdir -p ~/catkin_ws/src
    $ cd ~/catkin_ws/
    $ catkin_make
    

     Use the ls command to view, it can be seen build, devel, src subdirectories have emerged.
    Then run:

    $ source devel/setup.bash
    $ echo $ROS_PACKAGE_PATH
    

     Returns the following:

    /home/spy/catkin_ws/src:/opt/ros/kinetic/share
    

    As can be seen, the environment variable already contains the workspace directory.

  4. Create a catkin package
    can be used catkin_create_pkg command to create a catkin package, the command syntax is as follows:
    # This is an example, do not try to run this
    # catkin_create_pkg <package_name> [depend1] [depend2] [depend3]
    

    For example, the following command:

    $ cd ~/catkin_ws/src
    $ catkin_create_pkg beginner_tutorials std_msgs rospy roscpp
    

     Creating a named beginner_tutorials package dependencies of std_msgs rospy roscpp and
    output as follows:

    Created file begginner_tutorials/CMakeLists.txt
    Created file begginner_tutorials/package.xml
    Created folder begginner_tutorials/include/begginner_tutorials
    Created folder begginner_tutorials/src
    Successfully created files in /home/shao/catkin_ws/src/begginner_tutorials. Please adjust the values in package.xml.
    

     As can be seen, the command automatically creates some files. Including CMakeLists.txt and package.xml these files.

  5. Catkin package compiled
    using the following command
    $ cd ~/catkin_ws
    $ catkin_make
    

    All packages will be automatically compiled, including beginner_tutorials package you just created.

    catkin_make command actually calls the cmake command, catkin_make more information, please refer catkin / commands / catkin_make

  6. Package dependencies
    1. A dependent
      can specify dependencies when creating a package using catkin_create_pkg command, you can view these dependencies rospack command:
      $ rospack depends1 begginner_tutorials 
      

      Returns:

      roscpp
      rospy
      std_msgs
      

       These depend on the information stored in package.xml, you can view package.xml.

    2. Indirectly dependent
      a dependency own dependencies may exist, these are called indirectly dependent, e.g., packet and there rospy their dependencies:
      Rospack depends1 rospy $ 
      genpy 
      roscpp 
      rosgraph 
      rosgraph_msgs 
      roslib 
      std_msgs
      
    3. All rely on
      the use of rospack depends command to view all the dependencies
      $ rospack depends begginner_tutorials 
      cpp_common
      rostime
      roscpp_traits
      roscpp_serialization
      catkin
      genmsg
      genpy
      message_runtime
      gencpp
      geneus
      gennodejs
      genlisp
      message_generation
      rosbuild
      rosconsole
      std_msgs
      rosgraph_msgs
      xmlrpcpp
      roscpp
      rosgraph
      ros_environment
      rospack
      roslib
      rospy
      
  7. Custom package information
    can be meta information through custom package.xml to customize the package, more detailed information, please refer package.xml
    the same time, CMakeLists.txt used to compile the package, the file can also be customized.

Guess you like

Origin www.cnblogs.com/spyplus/p/11479921.html