For ROS experienced user, You can just skip to the Constuction about ROS Package usage:
For Quick Reference(C++): http://blog.csdn.net/sonictl/article/details/46764855#t5
For Quick Reference(Python): http://blog.csdn.net/sonictl/article/details/46764855#t15
=== 在上一篇的基础上,Create并Customize了Package之后,要Build Package ===
来源:http://wiki.ros.org/ROS/Tutorials/BuildingPackages
$ source /opt/ros/hydro/setup.bash
使用方法:
# In a catkin workspace $ catkin_make [make_targets] [-DCMAKE_VARIABLES=...]这里catkin_make使用了CMake 的workflow来操作,科普一下这个workflow:
因为要涉及到对CMakeLists.txt的写法,需要先了解这个文章:http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29
具体关于CMakeLists.txt文件,请看http://wiki.ros.org/catkin/CMakeLists.txt
The build folder is the default location of thebuild space and is wherecmake andmake are called to configure and build your packages.
The devel folder is the default location of thedevel space, which is where your executables and libraries go before you install your packages.
catkin_make命令执行情况如下:
exbot@ubuntu:~/catkin_ws$ ls build devel src exbot@ubuntu:~/catkin_ws$ catkin_make Base path: /home/exbot/catkin_ws Source space: /home/exbot/catkin_ws/src Build space: /home/exbot/catkin_ws/build Devel space: /home/exbot/catkin_ws/devel Install space: /home/exbot/catkin_ws/install #### #### Running command: "make cmake_check_build_system" in "/home/exbot/catkin_ws/build" #### -- Using CATKIN_DEVEL_PREFIX: /home/exbot/catkin_ws/devel -- Using CMAKE_PREFIX_PATH: /opt/ros/hydro -- This workspace overlays: /opt/ros/hydro -- Using PYTHON_EXECUTABLE: /usr/bin/python -- Python version: 2.7 -- Using Debian Python package layout -- Using CATKIN_ENABLE_TESTING: ON -- Call enable_testing() -- Using CATKIN_TEST_RESULTS_DIR: /home/exbot/catkin_ws/build/test_results -- Found gtest sources under '/usr/src/gtest': gtests will be built -- catkin 0.5.86 -- BUILD_SHARED_LIBS is on -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- ~~ traversing 7 packages in topological order: -- ~~ - beginner_tutorials -- ~~ - exbotxi_bringup -- ~~ - exbotxi_description -- ~~ - exbotxi_example -- ~~ - exbotxi_nav -- ~~ - exbotxi_rviz -- ~~ - exbotxi_teleop -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- +++ processing catkin package: 'beginner_tutorials' -- ==> add_subdirectory(beginner_tutorials) -- +++ processing catkin package: 'exbotxi_bringup' -- ==> add_subdirectory(exbot_xi/exbotxi_bringup) -- +++ processing catkin package: 'exbotxi_description' -- ==> add_subdirectory(exbot_xi/exbotxi_description) -- +++ processing catkin package: 'exbotxi_example' -- ==> add_subdirectory(exbot_xi/exbotxi_example) -- +++ processing catkin package: 'exbotxi_nav' -- ==> add_subdirectory(exbot_xi/exbotxi_nav) -- +++ processing catkin package: 'exbotxi_rviz' -- ==> add_subdirectory(exbot_xi/exbotxi_rviz) -- +++ processing catkin package: 'exbotxi_teleop' -- ==> add_subdirectory(exbot_xi/exbotxi_teleop) -- Configuring done -- Generating done -- Build files have been written to: /home/exbot/catkin_ws/build #### #### Running command: "make -j1 -l1" in "/home/exbot/catkin_ws/build" #### [100%] Built target move exbot@ubuntu:~/catkin_ws$
1. create a catkin workspace
$ mkdir -p ~/catkin_ws/src $ cd ~/catkin_ws/src $ catkin_init_workspace
2. Make
Even though the workspace is empty (there are no packages in the 'src' folder, just a single CMakeLists.txt link) you can still "build" the workspace:
$ cd ~/catkin_ws/ $ catkin_make
3. Source
$ source devel/setup.bash
4. Check:
$ echo $ROS_PACKAGE_PATH
/home/youruser/catkin_ws/src:/opt/ros/indigo/share:/opt/ros/indigo/stacks
1. 确认你的catkin Workspace:~/catkin_ws/
2. $ cd ~/catkin_ws/src
3. 创建package
$ catkin_create_pkg <package_name> [depend1] [depend2] [depend3] ... [dependn]
# for example :
$ catkin_create_pkg beginner_tutorials std_msgs rospy roscpp
$ cd ~/catkin_ws $ catkin_make5. Source the generated setup file:
$ . ~/catkin_ws/devel/setup.bash
1. Edit the code in ~/catkin_ws/src/<package_name>/src/
Add source code file: SouceCode.cpp or SourceCode.py etc.
2. Modify the CMakeFile.txt , (refer the details about CMakeLists.txt : link )
Modify the CMakeList.txt file:
$ cd ~/catkin_ws/src/<package_name>
$ gedit CMakeList.txt
add/modify these lines as below:
find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs ) include_directories( ${catkin_INCLUDE_DIRS} ) add_executable(<package_name> src/<soucefile_name>.cpp) add_dependencies(<package_name> ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) target_link_libraries(<package_name> ${catkin_LIBRARIES} )
ref page: link
1. Source env setup file: (Optional)
$ source /opt/ros/%YOUR_ROS_DISTRO%/setup.bash2. Catkin_make
$ cd ~/catkin_ws $ catkin_make -DCMAKE_BUILD_TYPE=Release
For more advanced uses of catkin_make see the documentation: catkin/commands/catkin_make
To add the workspace to your ROS environment you need to source the generated setup file:
$ . ~/catkin_ws/devel/setup.bash
3. Rebuilding a Single catkin Package
If you update a single package in your catkin workspace and want to re-build just that package, use the following variation of catkin_make:
$ cd ~/catkin_ws $ catkin_make --pkg <package_name>
Here we also offere a simple launch file that interfaces to two microcontrollers using two serial connections, put the code into
"~/catkin_ws/src/<package_name>/launch/<launchfile_name>.launch" file:
<launch> <node pkg="r2SerialDriver" type="r2SerialDriver" name="r2Serial0" args="0 /dev/ttyUSB0 9600" output="screen" > <remap from="ucCommand" to="uc0Command" /> <remap from="ucResponse" to="uc0Response" /> </node> <node pkg="r2SerialDriver" type="r2SerialDriver" name="r2Serial1" args="1 /dev/ttyUSB1 9600" output="screen" > <remap from="ucCommand" to="uc1Command" /> <remap from="ucResponse" to="uc1Response" /> </node> </launch>
Usage:
$ rosrun <package_name> <node_name> arg1 arg2 arg3 ...
or
$ roslaunch <package_name> <launchfile_name>.launch
$ rosmake --target=cleanin a top level stack or package directory to remove all build objects. Unfortunately, this feature does not exist when using catkin. The only way to start with a clean slate, is to remove all build objects from all your catkin packages using the following commands:
$ cd ~/catkin_ws $ \rm -rf devel build installYou would then remake any packages as usual:
$ cd ~/catkin_ws $ catkin_make $ source devel/setup.bash
CMakeLists.txt package.xml
refer: http://wiki.ros.org/rospy_tutorials
1. create a catkin workspace
$ mkdir -p ~/catkin_ws/src $ cd ~/catkin_ws/src $ catkin_init_workspace
2. Make
Even though the workspace is empty (there are no packages in the 'src' folder, just a single CMakeLists.txt link) you can still "build" the workspace:
$ cd ~/catkin_ws/ $ catkin_make
3. Source
$ source devel/setup.bash
4. Check:
$ echo $ROS_PACKAGE_PATH
/home/youruser/catkin_ws/src:/opt/ros/indigo/share:/opt/ros/indigo/stacks
1. 确认你的catkin Workspace:~/catkin_ws/
$ cd ~/catkin_ws/src
2. 创建package
$ catkin_create_pkg <package_name> [depend1] [depend2] [depend3] ... [dependn]
# for example :
$ catkin_create_pkg beginner_tutorials std_msgs rospy roscpp
$ cd ~/catkin_ws $ catkin_make5. Source the generated setup file:
$ . ~/catkin_ws/devel/setup.bash
1. Edit the code in ~/catkin_ws/src/<package_name>/src/
Add source code file: SouceCode.cpp or SourceCode.py etc.
2. Modify the CMakeFile.txt , (refer the details about CMakeLists.txt for Python:Writing a ROS Python Makefile )
Modify the CMakeList.txt file:
$ cd ~/catkin_ws/src/<package_name>
$ gedit CMakeList.txt
add/modify these lines as below:
ref page: link
1. Source env setup file: (Optional)
$ source /opt/ros/%YOUR_ROS_DISTRO%/setup.bash2. Catkin_make
$ cd ~/catkin_ws $ catkin_make -DCMAKE_BUILD_TYPE=Release
For more advanced uses of catkin_make see the documentation: catkin/commands/catkin_make
To add the workspace to your ROS environment you need to source the generated setup file:
$ . ~/catkin_ws/devel/setup.bash
3. Rebuilding a Single catkin Package
If you update a single package in your catkin workspace and want to re-build just that package, use the following variation of catkin_make:
$ cd ~/catkin_ws $ catkin_make --pkg <package_name>
Here we also offere a simple launch file that interfaces to two microcontrollers using two serial connections, put the code into
"~/catkin_ws/src/<package_name>/launch/<launchfile_name>.launch" file:
<launch> <node pkg="r2SerialDriver" type="r2SerialDriver" name="r2Serial0" args="0 /dev/ttyUSB0 9600" output="screen" > <remap from="ucCommand" to="uc0Command" /> <remap from="ucResponse" to="uc0Response" /> </node> <node pkg="r2SerialDriver" type="r2SerialDriver" name="r2Serial1" args="1 /dev/ttyUSB1 9600" output="screen" > <remap from="ucCommand" to="uc1Command" /> <remap from="ucResponse" to="uc1Response" /> </node> </launch>
Usage:
$ rosrun <package_name> <node_name> arg1 arg2 arg3 ...
or
$ roslaunch <package_name> <launchfile_name>.launch
$ rosmake --target=cleanin a top level stack or package directory to remove all build objects. Unfortunately, this feature does not exist when using catkin. The only way to start with a clean slate, is to remove all build objects from all your catkin packages using the following commands:
$ cd ~/catkin_ws $ \rm -rf devel build installYou would then remake any packages as usual:
$ cd ~/catkin_ws $ catkin_make $ source devel/setup.bash