当前位置:网站首页>[introduction to ROS] - 03 ROS workspace and function pack

[introduction to ROS] - 03 ROS workspace and function pack

2022-06-11 01:01:00 Life is like Zhaoxu

 Insert picture description here

Just like other software learning ,ROS You also need to start with the project , about ROS Come on , At the beginning of the project, you need to create a workspace , Create a feature pack after compiling the build folder , Then continue through the command line , Or programming through code to achieve the goal function , This blog section mainly introduces the contents of the first part , It also briefly introduces the functions of the files in the workspace .

One 、 working space

1. Create a workspace

  • Create folder :mkdir -p ~/catkin_ws/src
    In the above order catkin_ws, Is the name of the workspace , This name will be covered in subsequent courses , So you can also use the appropriate name by yourself ,src Is the folder where the feature pack is placed , For storing source code .
  • Switch to src Folder :cd ~catkin_ws/src
  • Create a workspace :catkin_init_workspace

Command line output prompt :

Creating symlink "/home/zhaoxu/project/ROS/catkin_ws/src/CMakeLists.txt" pointing to "/opt/ros/noetic/share/catkin/cmake/toplevel.cmake"
  • Switch to working directory :cd ~/catkin_ws/
  • Compile workspace :catkin_make
    there catkin Note that it is independent of the workspace name , It belongs to fixed command , After compilation, the command line indicates as follows :
     Insert picture description here
  • Generate install Folder :catkin_make install
    The instructions here are only intended to be the first to create install file , Essentially meaningless .

2. Set the environment variable

  • General practice : You need to reload each time you open the terminal
source devel/setup.bash
  • Once and for all : stay .bashrc Add a fixed path to the file , There is no need to source
echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc
  • Query environment variables :echo $ROS_PACKAGE_PATH
    The results are as follows , It proves that the modification is successful
     Insert picture description here

3. Introduction to workspace

 Insert picture description here

  • src: Code space ,Source Space, Used to place feature packs ( Code 、 The configuration file 、launch file );
  • build: Compilation space ,Build Space, Used to place intermediate files 、 Binary files, etc ;
  • devel: Development space ,Development Space, Used to place the executable generated by compilation 、 Script 、 Kuo et al ;
  • install: Installation space ,Install Space, Used to place installed files ;

Two 、 Function pack

1. Create and compile feature packs

  • Switch to the specified directory :cd ~/catkin_ws/src
  • Create Feature Pack :catkin_create_pkg pkg_ts std_msgs rospy roscpp

Standard directive :catkin_create_pkg <package_name> [depend1] [depend2] …
That is to use catkin_create_pkg Instruction to create function pack , Depends on the above three dependencies

 Insert picture description here

  • Switch to the workspace Directory :cd ~catkin_ws
  • Compile function packs :catkin_make

Be careful : Under the same workspace , A feature pack with the same name is not allowed ; In different workspaces , Feature packs with the same name are allowed

2. Function package file parsing

 Insert picture description here

  • include: For placement The header file
  • src: For placement Source file
  • CMakelist.txt: Compile configuration file , Describe the Compilation Rules of the function package
  • package.xml: Feature Pack list file , contain name、version、 Description information 、author email、depend、license etc.

Here we focus on the latter two :

1)CMakelist.txt

  • The function of documents :CMakeList.txt File is CMake The input file of the compilation process of the compilation system . whatever CMake Compatible packages contain one or more CMakeLists.txt file , These documents describe How to compile the code and where to install it . take CMakeLists.txt File applies to a catkin Project time , It is a standard with some restrictions vanilla CMakeLists.txt file . Use CMake When compiling a program ,cmake Instruction basis CMakeLists.txt File generation makefiles file ,make The order is based on makefiles The file compilation link can generate Executable files

  • Supplementary knowledge :catkin_make, It's actually ROS Compiler system of take cmake and make Unified encapsulated instructions , Therefore, in essence, it is still the use of cmake and make The process of compiling .

  • Sequential structure analysis :

 Insert picture description here

  1. CMake edition :cmake_minimum_required(VERSION 3.0.2)
  2. Package name :project(pkg_ts)
  3. Declare dependency Library :find_package()

 Insert picture description here

  1. start-up python Module support :catkin_python_package()

 Insert picture description here

  1. news / service / operation (Message/Service/Action) generator : add_message_files(),add_service_files(),add_action_files()

 Insert picture description here

  1. Call message / service / Operation generation :generate_messages()

 Insert picture description here

  1. Dynamically reconfigure parameters :generate_dynamic_reconfigure_options() ,cfg The configuration file , Used to configure some rviz Format , Record some configuration parameters

 Insert picture description here

  1. Specify the export of package compilation information :catkin_package()

 Insert picture description here

  1. a key : Add libraries and executables to compile :add_library()/add_executable()/target_link_libraries()

 Insert picture description here

  1. Installation rules :install()

 Insert picture description here

  1. Test compilation [ To configure :catkin_add_gtest()

2)package.xml

The specific explanation here is mainly within the code , See the explanation below :

<?xml version="1.0"?> 
<!‐‐  At present xml edition  ‐‐> 
<package format="2"> 
<name>learning_cplus</name> 
<!‐‐  The Feature Pack name is learning_cplus,name, name  ‐‐> 
<version>0.0.0</version> 
<!‐‐  The current feature pack version is 0.0.0,version, edition ‐‐> 
<description>The learning_cplus package</description> 
<!‐‐  Introduction to the current feature pack ,description, detailed  ‐‐> 
<maintainer email="[email protected]">waveshare</maintainer> 
<!‐‐  Current maintainer information ( Mailbox and nickname )‐‐>
<!‐‐ BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3  >
<license>TODO</license> 
<!‐‐  Protocol version , Default TODO Can . You can learn by yourself if you are interested .‐‐> 
<!‐‐ <url type="website">http://wiki.ros.org/learning_cplus</url> ‐‐> 
<!‐‐  Shareable path , You can upload your package to ROS Community or github.‐‐> 
<author email="[email protected]">Jane Doe</author> 
<!‐‐  Current developer information ( Mailbox and nickname )‐‐> 
<!‐‐ The *depend tags are used to specify dependencies ‐‐> 
<!‐‐ Dependencies can be catkin packages or system dependencies ‐‐> 
<!‐‐ Examples: ‐‐> 
<!‐‐ Use depend as a shortcut for packages that are both build and exec dependencies ‐‐> 
<!‐‐ <depend>roscpp</depend> ‐‐> 
<!‐‐ Note that this is equivalent to the following: ‐‐> 
<!‐‐ <build_depend>roscpp</build_depend> ‐‐> 
<!‐‐ <exec_depend>roscpp</exec_depend> ‐‐> 
<!‐‐ Use build_depend for packages you need at compile time: ‐‐> 
<!‐‐ <build_depend>message_generation</build_depend> ‐‐>
<!‐‐ Use build_export_depend for packages you need in order to build ag ainst this package: ‐‐>
<!‐‐ <build_export_depend>message_generation</build_export_depend> ‐‐> 
<!‐‐ Use buildtool_depend for build tool packages: ‐‐> 
<!‐‐ <buildtool_depend>catkin</buildtool_depend> ‐‐> 
<!‐‐ Use exec_depend for packages you need at runtime: ‐‐> 
<!‐‐ <exec_depend>message_runtime</exec_depend> ‐‐> 
<!‐‐ Use test_depend for packages you need only for testing: ‐‐> 
<!‐‐ <test_depend>gtest</test_depend> ‐‐> 
<!‐‐ Use doc_depend for packages you need only for building documentati on: ‐‐> 
<!‐‐ <doc_depend>doxygen</doc_depend> ‐‐> 
<buildtool_depend>catkin</buildtool_depend> 
<!‐‐ The compiler tool is catkin ‐‐> 
<build_depend>roscpp</build_depend> 
<!‐‐ Compile dependencies roscpp ‐‐> 
<build_depend>rospy</build_depend> 
<!‐‐ Compile dependencies rospy ‐‐> 
<build_depend>std_msgs</build_depend> 
<!‐‐ Compile dependencies std_msgs ‐‐>
<build_export_depend>roscpp</build_export_depend> 
<!‐‐ Compile output dependencies roscpp ‐‐>
<build_export_depend>rospy</build_export_depend> 
<!‐‐ Compile output dependencies rospy ‐‐> 
<build_export_depend>std_msgs</build_export_depend> 
<!‐‐ Compile output dependencies std_msgs ‐‐> 
<exec_depend>roscpp</exec_depend> 
<!‐‐ Operational dependency roscpp ‐‐> 
<exec_depend>rospy</exec_depend> 
<!‐‐ Operational dependency rospy ‐‐> 
<exec_depend>std_msgs</exec_depend>
<!‐‐ Operational dependency std_msgs ‐‐> 
<!‐‐ The export tag contains other, unspecified, tags ‐‐> 
<export> 
<!‐‐ Other tools can request additional information be placed here ‐‐>

<!‐‐  Output  ‐‐> 
</export> 
</package>

summary

This article mainly introduces the workspace 、 The basic content of the function pack , And the process of creating and compiling them ; And in-depth analysis of CMakelist.txt And package.xml Specific content of , The blog content refers to Gu Yueju's ROS introduction 21 Talk to the light snow class ROS Basic series of tutorials , The next blog will mainly introduce how to use the turtle test to analyze the actual effect of each instruction , And simply test the use of programming code , Coming soon .

 Insert picture description here

原网站

版权声明
本文为[Life is like Zhaoxu]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206102352123143.html