[ROS Tutorial] ROS file system and infrastructure


1. Workspace directory

Insert image description here

WorkSpace --- 自定义的工作空间

    |--- build:编译空间,用于存放CMake和catkin的缓存信息、配置信息和其他中间文件。

    |--- devel:开发空间,用于存放编译后生成的目标文件,包括头文件、动态&静态链接库、可执行文件等。

    |--- src:源码

        |-- package:功能包(ROS基本单元)包含多个节点、库与配置文件,包名所有字母小写,只能由字母、数字与下划线组成

            |-- CMakeLists.txt:配置编译规则,比如源文件、依赖项、目标文件

            |-- package.xml:包信息,比如:包名、版本、作者、依赖项...(以前版本是 manifest.xml)

            |-- scripts:存储python文件

            |-- src:存储C++源文件

            |-- include:头文件

            |-- msg:消息通信格式文件

            |-- srv:服务通信格式文件

            |-- action:动作格式文件

            |-- launch:可一次性运行多个节点 

            |-- config:配置信息

            |-- CMakeLists.txt:编译的基本配置

1.1 package.xml

  • fixed format
​<?xml version="1.0"?>
<!-- 格式: 以前是 1,推荐使用格式 2 -->
<package format="2">
  <!-- 包名 -->
  <name><the name of package></name>
  <!-- 版本 -->
  <version>0.0.0</version>
  <!-- 描述信息 -->
  <description>The <the name of package> package</description>

  <!-- One maintainer tag required, multiple allowed, one person per tag -->
  <!-- Example:  -->
  <!-- <maintainer email="[email protected]">Jane Doe</maintainer> -->
  <!-- 维护人员 -->
  <maintainer email="*">XXX</maintainer>


  <!-- One license tag required, multiple allowed, one license per tag -->
  <!-- Commonly used license strings: -->
  <!--   BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
  <!-- 许可证信息,ROS核心组件默认 BSD -->
  <license>TODO</license>


  <!-- Url tags are optional, but multiple are allowed, one per tag -->
  <!-- Optional attribute type can be: website, bugtracker, or repository -->
  <!-- Example: -->
  <!-- <url type="website">http://wiki.ros.org/demo01_hello_vscode</url> -->


  <!-- Author tags are optional, multiple are allowed, one per tag -->
  <!-- Authors do not have to be maintainers, but could be -->
  <!-- Example: -->
  <!-- <author email="[email protected]">Jane Doe</author> -->


  <!-- 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 against 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 documentation: -->
  <!--   <doc_depend>doxygen</doc_depend> -->
  <!-- 依赖的构建工具,这是必须的 -->
  <buildtool_depend>catkin</buildtool_depend>

  <!-- 指定构建此软件包所需的软件包 -->
  <build_depend>roscpp</build_depend>
  <build_depend>rospy</build_depend>
  <build_depend>std_msgs</build_depend>

  <!-- 指定根据这个包构建库所需要的包 -->
  <build_export_depend>roscpp</build_export_depend>
  <build_export_depend>rospy</build_export_depend>
  <build_export_depend>std_msgs</build_export_depend>

  <!-- 运行该程序包中的代码所需的程序包 -->  
  <exec_depend>roscpp</exec_depend>
  <exec_depend>rospy</exec_depend>
  <exec_depend>std_msgs</exec_depend>


  <!-- The export tag contains other, unspecified, tags -->
  <export>
    <!-- Other tools can request additional information be placed here -->

  </export>
</package>

2. How to start the node

2.1 Start one at a time

rosrun <the name of package> <the name of executable file>
  • Executable file: For C language, this file is the executable file generated by add_executable in CMakeLists.txt; for python, this file is the file pointed by catkin_install_python in CMakeLists.txt.

Corresponding syntax:

add_executable(<the name of executable file>
               src/<the name of the source>.cpp
              )
catkin_install_python(PROGRAMS scripts/<the name of the source>.py
                      DESTINATION ${
    
    CATKIN_PACKAGE_BIN_DESTINATION}
                     )

2.2 Start multiple at one time

If you want to start multiple nodes in a package at once, instead of typing rosrun commands line by line...

  • We need a launch file, its fixed format is like this:
<launch>
    <node pkg="helloworld" type="demo_hello" name="hello" output="screen" />
    <node pkg="turtlesim" type="turtlesim_node" name="t1"/>
    <node pkg="turtlesim" type="turtle_teleop_key" name="key1" />
</launch>
  • node: a node included
  • pkg: function package
  • type: the node file being run
  • name: Name the node
  • output: Set the output target of the log

Then, enter in the terminal:

roslaunch <the name of package> <the name of launch file>

3. ROS common commands

3.1 increase

Create a new ROS function package:

catkin_create_pkg 自定义包名 依赖包

3.2 check

List all feature packages:

rospack list

Find out whether a feature package exists, and return the installation path if it exists:

rospack find 包名

3.3 Execution

3.3.1 Load environment variables

First enter the working directory, then:

source ./devel/setup.bash

3.3.2 Running Nodes

roscore: A collection of ROS system prerequisite nodes and programs, roscore must be running to enable ROS nodes to communicate. Open a new terminal and enter :

roscore #用法一
roscore -p xxxx #用法二,指定端口号

roscore will start:

  • ros master
  • ros parameter server
  • rosout log node

3.4 View the calculation graph

With the node running , type in the terminal:

rosrun rqt_graph rqt_graph

Insert image description here

4. Create a feature package

4.1 Select working directory

First, choose a path as the working directory. Here I chose the following path as the working directory
Insert image description here

4.2 Create function package directory

mkdir src

Then, in the workspace directory :

catkin_make

There will be an extra locked CMakeLists.txt file in the src directory, don't worry about it.

4.3 Create a function package

First enter the src directory

cd src

Then use the instructions provided by ROS to directly create the function package:

catkin_create_pkg <the name of your package> roscpp rospy std_msgs message_generatio

roscpp, rospy, std_msgs, message_generatio are the dependencies you need, you can freely decide which dependencies you want

Guess you like

Origin blog.csdn.net/qq_50791664/article/details/129940748