Introduction to Ros Create and compile feature packs for Catkin and Rosmake _ros

Source: Internet
Author: User

The beginning of the design of Ros robot, from the creation of workspace to compile the running node, because Linux is also a beginner, all kinds of burn, the most basic things first summed up, for future viewing. This is the first time to write a blog, if there are many mistakes in the place, I hope you understand and point out. When writing this article, most of them refer to the following posts:

http://blog.csdn.net/baidu_18189515/article/details/52401329

Http://blog.csdn.net/baidu_18189515/article/details/52332754#comments

http://blog.csdn.net/robogreen/article/details/50488215

1. Create work space under Ros:

Mkdir-p catkin_ws/src  

cd src  

catkin_init_workspace  

CD.  

Catkin_make  

2. Create feature Packs
Method One: Use Catkin to create package

CD ~/catkin_ws/src
catkin_create_pkg beginner_tutorials std_msgs rospy roscpp

The general format for creating packages is catkin_create_pkg, which includes the feature package name and dependencies, and in the example above, dependencies include Std_msg, Rospy, and Roscpp.
After running the above command, a folder with the same name as the feature Pack name is generated under the SRC folder with the following files (folders)

workspace_folder/
                 src/
                      package_name/   
                                include--                   folder
                                src                       --folder       
                                CMakeLists.txt
                                

Method Two: Using Roscreate to create package

CD ~/catkin_ws/src
roscreate-pkg beginner_tutorials std_msgs rospy roscpp

Similarly, the format for creating packages using Rosmake is roscreate-pkg, and the format of this command also includes the feature package name and dependencies.
After running the above command, a folder with the same name as the feature Pack name is generated under the SRC folder with the following files (folders)

workspace_folder/
                 src/
                      package_name/   
                                include--                   folder
                                src                       --folder       
                                CMakeLists.txt
                                Manifest.xml 
                                mainpage.dox
                                Makefile

3. Compile function Package
Method one: Compile with Catkin
Compiled with Catkin is the first of these package created using Catkin, first modify the Cmakelists.test file that was generated when the feature pack was created, and open the file with Gedit.
⑴ Add the following statement to find the added dependency pack

Find_package (catkin REQUIRED components
    sensor_msgs cv_bridge image_transport
    )
find_package ( OpenCV 2 REQUIRED)
find_package (PLC REQUIRED)

⑵ Add the following statement to add a node program that participates in compilation

Add_executable (node name Src/node program) #添加可执行节点
target_link_libraries (node name ${catkin_libraries}) #链接库
add_dependencies (node name package name_generator_messages_cpp) #为可执行文件添加对生成的消息文件的依赖 because Catkin compiles all package in parallel , so if you want to use other package messages in other Catkin workspaces, you also need to add dependencies on the message files they generate, which is a process of importing header files first.

In addition to adding system-supplied dependencies when creating a Feature Pack (catkin_create_pkg beginner_tutorials std_msgs rospy roscpp), You can also modify the package.xml file that was generated when the feature Pack was created, taking the packages needed in the image processing as an example, adding the following instructions to illustrate the added dependency pack later

<run_depend>sensor_msgs</run_depend> 
<run_depend>image_transport</run_depend> 

The method of compiling using Catkin is:

#under workspace
Catkin_make [make_targets] [-dcmake_variables= ...]

Method two: Compile with Rosmake
Compiled with Rosmake is the second of the above package created using Roscreate, and, before compiling, You need to modify the CMakeLists.txt file and the Manifest.xml file, where you need to add the following statement when you modify the CMakeLists.txt file, adding the node program that participates in the compilation:

Rosbuild_add_executable (Node_name src/node_name.cpp)

Attention:
Ros no longer use OPENCV as a system-dependent package from the Indigo, but as a third-party package, if used directly in the Rosmake compile phase of the error, no exist package "OPENCV2", You only need to add Find_package (OpenCV 2 REQUIRED) to CMakeLists.txt, and then you cannot add a dependency pack in Manifest.xml, which is added here as a system-dependent package.
The method of compiling using Rosmkae is:

#under Workspace
Rosmake package_name

After you run the above command, if the compilation is not wrong, you can see the resulting executable file in the Bin folder and run the node directly./node_name.
3, run the completion of the compilation of the node (do not launch, do not understand)

Rosrun package_name Node_name

Attention:
1 Create the feature package is in the SRC directory, and the compilation function package is in the workspace directory.
2 before compiling, make sure that you add the path to the current workspace, and see how:

Echo $ROS _package_path

Add method is source Setup.bash file

#under the Path:workspace
source./devel/setup.bash

3 to run the node before the Roscore

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.