[ROS 튜토리얼] ROS 파일 시스템 및 인프라


1. 작업공간 디렉토리

여기에 이미지 설명을 삽입하세요.

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 패키지.xml

  • 고정 형식
​<?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. 노드 시작 방법

2.1 한 번에 하나씩 시작

rosrun <the name of package> <the name of executable file>
  • 실행 파일: C 언어의 경우 CMakeLists.txt의 add_executable에 의해 생성된 실행 파일이고, Python의 경우 CMakeLists.txt의 catkin_install_python이 가리키는 파일입니다.

해당 구문:

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 한 번에 여러 개 시작

한 번에 패키지의 여러 노드를 시작하려면 rosrun 명령을 한 줄씩 입력하는 대신...

  • 실행 파일이 필요합니다. 고정 형식은 다음과 같습니다.
<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>
  • 노드: 포함된 노드
  • pkg: 기능 패키지
  • 유형: 실행 중인 노드 파일
  • name: 노드 이름을 지정합니다.
  • 출력: 로그의 출력 대상을 설정합니다.

그런 다음 터미널에 다음을 입력하십시오.

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

3. ROS 공통 명령어

3.1 증가

새로운 ROS 함수 패키지를 생성합니다:

catkin_create_pkg 自定义包名 依赖包

3.2 확인

모든 기능 패키지를 나열합니다.

rospack list

특정 기능 패키지가 있는지 확인하고 존재하는 경우 설치 경로를 반환합니다.

rospack find 包名

3.3 실행

3.3.1 환경변수 로드

먼저 작업 디렉터리를 입력한 후 다음을 수행합니다.

source ./devel/setup.bash

3.3.2 노드 실행

roscore: ROS 노드가 통신하기 위해 roscore를 실행해야 하는 ROS용 시스템 전제 조건 노드 및 프로그램 모음입니다. 새 터미널을 열고 다음을 입력하세요 .

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

roscore가 시작됩니다:

  • 로스 마스터
  • ros 매개변수 서버
  • rosout 로그 노드

3.4 계산 그래프 보기

노드가 실행 중인 상태에서 터미널에 다음을 입력합니다.

rosrun rqt_graph rqt_graph

여기에 이미지 설명을 삽입하세요.

4. 기능 패키지 생성

4.1 작업 디렉터리 선택

먼저 작업 디렉터리로 경로를 선택합니다. 여기서는 작업 디렉터리로 다음 경로를 선택했습니다.
여기에 이미지 설명을 삽입하세요.

4.2 함수 패키지 디렉터리 생성

mkdir src

그런 다음 작업 공간 디렉터리에서 다음을 수행합니다 .

catkin_make

src 디렉터리에 잠긴 CMakeLists.txt 파일이 추가로 있을 것이므로 걱정하지 마세요.

4.3 함수 패키지 생성

먼저 src 디렉토리로 들어가세요

cd src

그런 다음 ROS에서 제공하는 지침을 사용하여 함수 패키지를 직접 생성합니다.

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

roscpp, rospy, std_msgs 및 message_generatio는 필요한 종속성이며 원하는 종속성을 자유롭게 결정할 수 있습니다.

추천

출처blog.csdn.net/qq_50791664/article/details/129940748