<<<<<<< HEAD

1 ROS2工程结构

1.1 colcon工作空间

colocn工作空间是创建、修改、编译软件包的目录。colcon的工作空间,直观的形容就是一个仓库,里面装载着ROS的各种项目工程,便于系统组织管理调用。

  • 创建工作空间
mkdir -p ~/colcon_ws/src  # 创建文件夹
cd ~/colcon_ws/        # 进入文件夹
colcon build               # 构建工作区中的代码。

注意: colcon 支持选项 --symlink-install 。这允许通过更改 source 空间中的文件(例如 Python 文件或其他未编译的资源)来更改已安装的文件,以加快迭代速度。避免每次修改 python 脚本时都需要重新编译。

1 ROS2 project structure

1.1 colcon workspace

The colocn workspace is the directory where software packages are created, modified, and compiled. Colcon's workspace can be intuitively described as a warehouse, which contains various ROS project projects to facilitate system organization, management and calling.

  • Create workspace:
mkdir -p ~/colcon_ws/src # Create folder
cd ~/colcon_ws/ # Enter the folder
colcon build # Build the code in the workspace.

Note: colcon supports option --symlink-install. This allows for faster iteration by changing installed files by changing files in the source space (such as Python files or other uncompiled resources). Avoid the need to recompile every time you modify your python script.

5673ade8eb00a28794557125b7d1c8cd332434a9

colcon build --symlink-install

<<<<<<< HEAD ROS2工作空间是一个具有特定结构的目录。通常有一个 src 子目录。在该子目录中是 ROS2 包的源代码所在的位置。通常,目录以其他方式为空开始。

colcon 会进行源代码构建。默认情况下,它将创建以下目录作为 src 目录的同级目录:

src/: ROS2的colcon软件包(源代码包)

build/: 存储中间文件的位置。对于每个包,将创建一个子文件夹,例如在其中调用 CMake。

install/: 每个包的安装位置。默认情况下,每个包都将安装到单独的子目录中。

log/: 包含有关每个 colcon 调用的各种日志记录信息。

一个ROS2工作空间目录结构如下所示:

WorkSpace --- 自定义的工作空间。
    |--- build:存储中间文件的目录,该目录下会为每一个功能包创建一个单独子目录。
    |--- install:安装目录,该目录下会为每一个功能包创建一个单独子目录。
    |--- log:日志目录,用于存储日志文件。
    |--- src:用于存储功能包源码的目录。
        |-- C++功能包
            |-- package.xml:包信息,比如:包名、版本、作者、依赖项。
            |-- CMakeLists.txt:配置编译规则,比如源文件、依赖项、目标文件。
            |-- src:C++源文件目录。
            |-- include:头文件目录。
            |-- msg:消息接口文件目录。
            |-- srv:服务接口文件目录。
            |-- action:动作接口文件目录。
        |-- Python功能包
            |-- package.xml:包信息,比如:包名、版本、作者、依赖项。
            |-- setup.py:与C++功能包的CMakeLists.txt类似。
            |-- setup.cfg:功能包基本配置文件。
            |-- resource:资源目录。
            |-- test:存储测试相关文件。
            |-- 功能包同名目录:Python源文件目录。

1.2 ROS2软件包

Package不仅是Linux上的软件包,也是colcon编译得基本单元,我们使用 colcon build 编译的对象就是每个ROS2的package。

创建自己的软件包:

  • 使用Python创建软件包的命令语法为:

======= A ROS workspace is a directory with a particular structure. Commonly there is a src subdirectory. Inside that subdirectory is where the source code of ROS packages will be located. Typically the directory starts otherwise empty.

colcon does out of source builds. By default it will create the following directories as peers of the src directory:

src/: colcon package for ROS2 (source code package)

build/: The location where intermediate files are stored. For each package, a subfolder is created in which CMake is called, for example.

install/: The installation location of each package. By default, each package will be installed into a separate subdirectory.

log/: Contains various logging information about each colcon call.

The directory structure of a ROS2 workspace is as follows:

WorkSpace --- Customized workspace.
     |--- build: The directory where intermediate files are stored. A separate subdirectory will be created for each function package in this directory.
     |--- install: Installation directory, a separate subdirectory will be created for each function package in this directory.
     |--- log: Log directory, used to store log files.
     |--- src: Directory used to store function package source code.
         |-- C++ function package
             |-- package.xml: package information, such as: package name, version, author, dependencies.
             |-- CMakeLists.txt: Configure compilation rules, such as source files, dependencies, and target files.
             |-- src: C++ source file directory.
             |-- include: header file directory.
             |-- msg: message interface file directory.
             |-- srv: Service interface file directory.
             |-- action: action interface file directory.
         |-- Python function package
             |-- package.xml: package information, such as: package name, version, author, dependencies.
             |-- setup.py: similar to CMakeLists.txt of C++ function package.
             |-- setup.cfg: Function package basic configuration file.
             |-- resource: resource directory.
             |-- test: stores test-related files.
             |-- Directory with the same name of the function package: Python source file directory.

1.2 ROS2 package

Package is not only a software package on Linux, but also the basic unit of colcon compilation. The object we use colcon build to compile is each ROS2 package.

Create your own package:

  • The command syntax for creating a software package using Python is:

5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 pkg create --build-type ament_python <package_name>

<<<<<<< HEAD

- 例如:

  • For example:

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 pkg create --build-type ament_python --node-name my_node my_package

<<<<<<< HEAD

2 基本工具命令

在本章中,您将了解ROS2的常用命令工具。

2.1 Topics

ROS 2 将复杂的系统分解为许多模块化节点。 Topics是 ROS 图的重要元素,充当节点交换消息的总线。 Topics是数据在节点之间移动的主要方式之一,因此在系统的不同部分之间移动。

具体参考: 官方教程

- topics 帮助

2 Basic tool commands

In this chapter, you will learn about the common command tools of ROS2.

2.1 Topics

ROS 2 breaks complex systems down into many modular nodes. Topics are a vital element of the ROS graph that act as a bus for nodes to exchange messages. Topics are one of the main ways in which data is moved between nodes and therefore between different parts of the system.

Specific reference: Official Tutorials

  • topics help

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 topics -h

<<<<<<< HEAD

- 启动turtlesim和键盘控制

  • Start turtlesim and keyboard control

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 run turtlesim turtlesim_node
ros2 run turtlesim turtle_teleop_key

<<<<<<< HEAD

- 节点关系图

  • Node Relationship Diagram

    5673ade8eb00a28794557125b7d1c8cd332434a9

rqt_graph

<<<<<<< HEAD

- 了解topics相关命令

  • Learn about topic-related commands

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 topics -h

<<<<<<< HEAD

  • 话题列表
ros2 topic list
ros2 topic list -t # 显示相应的消息类型

- 查看话题内容

  • topics list
ros2 topic list
ros2 topic list -t # Display the corresponding message type
  • View topic content

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 topic echo <topic_name>
ros2 topic echo /turtle1/cmd_vel

<<<<<<< HEAD

  • 显示话题相关信息,类型
ros2 topic info <topic_name>
# 输出 /turtle1/cmd_vel 话题接口相关信息
ros2 topic info /turtle1/cmd_vel
  • 显示接口相关信息
ros2 interface show <msg_type>
# 输出 geometry_msgs/msg/Twist接口相关信息
ros2 interface show geometry_msgs/msg/Twist
  • 发布命令
ros2 topic pub <topic_name> <msg_type> '<args>' 
# 发布速度命令
ros2 topic pub --once /turtle1/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.8}}"
# 按一定频率发布速度命令
ros2 topic pub --rate 1 /turtle1/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.8}}"
  • 查看话题发布的频率
ros2 topic hz <topic_name>
#输出/turtle1/cmd_vel发布频率
=======
- **Display topic-related information, type**

```bash
ros2 topic info <topic_name>
# Output /turtle1/cmd_vel topic related information
ros2 topic info /turtle1/cmd_vel
  • Display interface related information
ros2 interface show <msg_type>
# Output geometry_msgs/msg/Twist interface related information
ros2 interface show geometry_msgs/msg/Twist
  • Issue an order
ros2 topic pub <topic_name> <msg_type> '<args>' 
# Issue speed command
ros2 topic pub --once /turtle1/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.8}}"
# Issue speed commands at a certain frequency
ros2 topic pub --rate 1 /turtle1/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.8}}"
  • See how often topics are posted
ros2 topic hz <topic_name>
# Output /turtle1/cmd_vel publish frequency
>>>>>>> 5673ade8eb00a28794557125b7d1c8cd332434a9
ros2 topic pub --rate 1 /turtle1/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.8}}"

2.2 Nodes

<<<<<<< HEAD ROS 中的每个节点都应该负责一个单一的模块用途(例如,一个节点用于控制车轮电机,一个节点用于控制激光测距仪等)。 每个节点都可以通过主题、服务、操作或参数向其他节点发送和接收数据。 一个完整的机器人系统由许多协同工作的节点组成。 在 ROS 2 中,单个可执行文件(C++ 程序、Python 程序等)可以包含一个或多个节点。

具体参考: 官方教程

- nodes 帮助

Each node in ROS should be responsible for a single, module purpose (e.g. one node for controlling wheel motors, one node for controlling a laser range-finder, etc). Each node can send and receive data to other nodes via topics, services, actions, or parameters. A full robotic system is comprised of many nodes working in concert. In ROS 2, a single executable (C++ program, Python program, etc.) can contain one or more nodes.

Specific reference: Official Tutorials

  • nodes help

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 nodes -h

<<<<<<< HEAD

- 启动turtlesim和键盘控制

  • Start turtlesim and keyboard control

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 run turtlesim turtlesim_node
ros2 run turtlesim turtle_teleop_key

<<<<<<< HEAD

- 查看节点列表

  • View the node list

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 node list

<<<<<<< HEAD

- 查看节点关系图

  • View Node Relationship Diagram

    5673ade8eb00a28794557125b7d1c8cd332434a9

rqt_graph

<<<<<<< HEAD

- 重映射

  • Remapping

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 run turtlesim turtlesim_node --ros-args --remap __node:=my_turtle
ros2 node list

<<<<<<< HEAD

- 查看节点信息

  • View node information

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 node info <node_name>
ros2 node info /my_turtle

2.3 Services

<<<<<<< HEAD 服务是 ROS 图中节点的另一种通信方法。 服务基于调用和响应模型,而不是主题的发布者-订阅者模型。 虽然主题允许节点订阅数据流并获得持续更新,但服务仅在客户端专门调用时才提供数据。

具体参考: 官方教程

- services 帮助

Services are another method of communication for nodes in the ROS graph. Services are based on a call-and-response model, versus topics’ publisher-subscriber model. While topics allow nodes to subscribe to data streams and get continual updates, services only provide data when they are specifically called by a client.

Specific reference: Official Tutorials

  • services help

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 service -h

<<<<<<< HEAD

- 启动turtlesim和键盘控制

  • Start turtlesim and keyboard control

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 run turtlesim turtlesim_node
ros2 run turtlesim turtle_teleop_key

<<<<<<< HEAD

  • 查看服务列表
ros2 service list
# 显示服务列表及消息类型
ros2 service list -t

- 查看服务接收到的消息类型

  • View the service list
ros2 service list
# Display service list and message type
ros2 service list -t
  • View the message types received by the service

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 service type <service_name>
ros2 service type /clear

<<<<<<< HEAD

- 找到使用某类消息类型的服务

  • Find services that use a certain message type

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 service find <type_name>
ros2 service find std_srvs/srv/Empty

<<<<<<< HEAD

- 查看服务消息类型定义

  • View Service Message Type Definitions

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 interface show <type_name>.srv
ros2 interface show std_srvs/srv/Empty.srv

<<<<<<< HEAD

- 调用服务命令,清除行走轨迹

  • Call the service command to clear the walking track

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 service call <service_name> <service_type>
ros2 service call /clear std_srvs/srv/Empty

<<<<<<< HEAD

- 生成新乌龟

  • Spawn a new turtle

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 service call /spawn turtlesim/srv/Spawn "{x: 2, y: 2, theta: 0.2, name: 'turtle2'}"

2.4 Parameters

<<<<<<< HEAD 参数是节点的配置值。 您可以将参数视为节点设置。 节点可以将参数存储为整数、浮点数、布尔值、字符串和列表。 在 ROS 2 中,每个节点都维护自己的参数。 有关参数的更多背景信息,请参阅概念文档。

具体参考: 官方教程

- parameters 帮助

A parameter is a configuration value of a node. You can think of parameters as node settings. A node can store parameters as integers, floats, booleans, strings, and lists. In ROS 2, each node maintains its own parameters. For more background on parameters, please see the concept document.

Specific reference: Official Tutorials

  • parameters help

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 param -h

<<<<<<< HEAD

- 启动turtlesim和键盘控制

  • Start turtlesim and keyboard control

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 run turtlesim turtlesim_node
ros2 run turtlesim turtle_teleop_key

<<<<<<< HEAD

- 查看服务列表

  • View service list

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 param list

<<<<<<< HEAD

- 获取参数值

  • Get the parameter value

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 param get <node_name> <parameter_name>
ros2 param get /turtlesim background_g

<<<<<<< HEAD

- 设置参数值

  • Set parameter values

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 param set <node_name> <parameter_name> <value>
ros2 param set /turtlesim background_r 150

<<<<<<< HEAD

- 导出参数值

  • Export parameter values

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 param dump <node_name>
ros2 param dump /turtlesim

<<<<<<< HEAD

- 独立导入参数

  • Import parameters independently

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 param load <node_name> <parameter_file>
ros2 param load /turtlesim ./turtlesim.yaml

<<<<<<< HEAD

- 启动节点同时导入参数

  • Start the node and import parameters at the same time

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 run <package_name> <executable_name> --ros-args --params-file <file_name>
ros2 run turtlesim turtlesim_node --ros-args --params-file ./turtlesim.yaml

2.5 Actions

<<<<<<< HEAD 动作是 ROS 2 中的一种通信类型,用于长时间运行的任务。 它们由三部分组成:目标、反馈和结果。

操作基于主题和服务。 它们的功能类似于服务,除了操作是可抢占的(您可以在执行时取消它们)。 他们还提供稳定的反馈,而不是返回单一响应的服务。

操作使用客户端-服务器模型,类似于发布者-订阅者模型(在主题教程中描述)。 “动作客户端”节点将目标发送到“动作服务器”节点,该节点确认目标并返回反馈流和结果。

具体参考: 官方教程

- action 帮助

Actions are one of the communication types in ROS 2 and are intended for long running tasks. They consist of three parts: a goal, feedback, and a result.

Actions are built on topics and services. Their functionality is similar to services, except actions are preemptable (you can cancel them while executing). They also provide steady feedback, as opposed to services which return a single response.

Actions use a client-server model, similar to the publisher-subscriber model (described in the topics tutorial). An “action client” node sends a goal to an “action server” node that acknowledges the goal and returns a stream of feedback and a result.

Specific reference: Official Tutorials

  • action help

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 action -h

<<<<<<< HEAD

- 启动turtlesim和键盘控制

  • Start turtlesim and keyboard control

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 run turtlesim turtlesim_node
ros2 run turtlesim turtle_teleop_key

<<<<<<< HEAD 按G|B|V|C|D|E|R|T 实现旋转,按F键盘取消l

- 查看节点action的服务端和客户端

Press G|B|V|C|D|E|R|T to achieve rotation, press F to cancel

  • View the server and client of the node action

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 node info /turtlesim

<<<<<<< HEAD

  • 查看动作列表
ros2 action list
ros2 action list -t # 显示动作类型

- 查看动作信息

  • View action list
ros2 action list
ros2 action list -t # show action type
  • view action info

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 action info <action>
ros2 action info /turtle1/rotate_absolute

<<<<<<< HEAD

- 查看动作消息内容

  • View action message content

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 interface show turtlesim/action/RotateAbsolute

<<<<<<< HEAD

- 发送动作目标信息

  • Send action target information

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 action send_goal <action_name> <action_type>
ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "{theta: 1.57}"
<<<<<<< HEAD
# 带反馈信息
=======
# With feedback information
>>>>>>> 5673ade8eb00a28794557125b7d1c8cd332434a9
ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "{theta: 0}" --feedback

2.6 RQt

<<<<<<< HEAD RQt 是一个图形用户界面框架,它以插件的形式实现各种工具和界面。 可以将所有现有的 GUI 工具作为 RQt 中的可停靠窗口运行! 这些工具仍然可以以传统的独立方式运行,但 RQt 可以更轻松地在单个屏幕布局中管理所有不同的窗口。

具体参考: 官方教程

您可以通过以下方式轻松运行任何 RQt 工具/插件:

RQt is a graphical user interface framework that implements various tools and interfaces in the form of plugins. One can run all the existing GUI tools as dockable windows within RQt! The tools can still run in a traditional standalone method, but RQt makes it easier to manage all the various windows in a single screen layout.

Specific reference: Official Tutorials

You can run any RQt tools/plugins easily by:

5673ade8eb00a28794557125b7d1c8cd332434a9

rqt

<<<<<<< HEAD

- rqt 帮助

  • rqt help

    5673ade8eb00a28794557125b7d1c8cd332434a9

rqt -h

<<<<<<< HEAD

- 启动turtlesim和键盘控制

  • Start turtlesim and keyboard control

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 run turtlesim turtlesim_node
ros2 run turtlesim turtle_teleop_key

<<<<<<< HEAD

  • 动作浏览器: / Plugins -> Actions ->Action Type Browser

  • 参数重配置: / Plugins -> configuration ->Parameter Reconfigure

  • 节点图: /Node Graph

  • 控制转向: /Plugins -> Robot Tools -> Robot Steering

  • 服务调用: /Plugins -> Services -> Service Caller

  • 服务类型浏览器: Plugins -> Services -> Service Type Browser

  • 消息发布: Plugins -> Topics -> Message Publisher

  • 消息类型浏览器: Plugins -> Topics -> Message Type Browser

  • 话题列表: Plugins -> Topics -> Topic Monitor

  • 绘制曲线图: Plugins -> Visualization -> Plot

  • 查看日志: rqt_console

  • Action Type Browser: / Plugins -> Actions ->Action Type Browser

  • parameter reconfiguration: / Plugins -> configuration ->Parameter Reconfigure

  • Node grap: /Node Graph

  • control steering: /Plugins -> Robot Tools -> Robot Steering

  • service invocation: /Plugins -> Services -> Service Caller

  • Service Type Browser: Plugins -> Services -> Service Type Browser

  • message release: Plugins -> Topics -> Message Publisher

  • Message Type Browser: Plugins -> Topics -> Message Type Browser

  • topic list: Plugins -> Topics -> Topic Monitor

  • draw a graph: Plugins -> Visualization -> Plot

  • View logs: rqt_console

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 run rqt_console rqt_console
ros2 run turtlesim turtlesim_node
ros2 topic pub -r 1 /turtle1/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0,y: 0.0,z: 0.0}}"

2.7 TF2

<<<<<<< HEAD tf2 是变换库,它允许用户随着时间的推移跟踪多个坐标系。 tf2 以时间缓冲的树结构维护坐标系之间的关系,并让用户在任何需要的时间点在任意两个坐标系之间变换点、向量等。

具体参考: 官方教程

让我们从安装演示包及其依赖项开始。

tf2 is the transform library, which lets the user keep track of multiple coordinate frames over time. tf2 maintains the relationship between coordinate frames in a tree structure buffered in time and lets the user transform points, vectors, etc. between any two coordinate frames at any desired point in time.

Specific reference: Official Tutorials

Let’s start by installing the demo package and its dependencies.

5673ade8eb00a28794557125b7d1c8cd332434a9

sudo apt-get install ros-foxy-turtle-tf2-py ros-foxy-tf2-tools ros-foxy-tf-transformations

<<<<<<< HEAD

  • 跟随

  • launch启动2个小乌龟,第一个小乌龟自动跟随第二个

  • follow

  • launch starts 2 little turtles, the first little turtle automatically follows the second one

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 launch turtle_tf2_py turtle_tf2_demo.launch.py

<<<<<<< HEAD

- 通过键盘控制第一个小乌龟移动

  • Control the movement of the first little turtle through the keyboard

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 run turtlesim turtle_teleop_key

<<<<<<< HEAD

- 查看TF树

  • View TF tree

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 run tf2_tools view_frames.py
evince frames.pdf

<<<<<<< HEAD

- 查看两个坐标系之间的关系

  • View the relationship between two coordinate systems

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 run tf2_ros tf2_echo [reference_frame] [target_frame]
ros2 run tf2_ros tf2_echo turtle2 turtle1

<<<<<<< HEAD

- 在rviz上查看TF关系

  • View TF relationships on rviz

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 run rviz2 rviz2 -d $(ros2 pkg prefix --share turtle_tf2_py)/rviz/turtle_rviz.rviz

2.8 URDF

<<<<<<< HEAD URDF 是统一机器人描述格式,用于指定 ROS 中的机器人几何和组织。

具体参考: 官方教程

- 完整语法

URDF is the Unified Robot Description Format for specifying robot geometry and organization in ROS.

Specific reference: Official Tutorials

  • Complete syntax

    5673ade8eb00a28794557125b7d1c8cd332434a9

<robot>
    # describe:
    # Parameters: name=""
    #  Child node:
        <link>
            # Description:
            # Parameters:name=""
            # Child node:
                <visual>
                    # describe:
                    # Parameters:
                    # child nodes: 
                        <geometry>
                            # description
                            # parameters
                            # Child node: 
                                <cylinder />
                                    # Description:
                                    # Parameters:
                                        # length="0.6"
                                        # radius="0.2"
                                <box />
                                    # description
                                    # Parameters:size="0.6 0.1 0.2"
                                <mesh />
                                    #  Description
                                    #Parameters: filename="package://urdf_tutorial/meshes/l_finger_tip.dae"
                        <collision>
                            # Description: collision element, prioritized
                            # parameters
                            # child node 
                                <geometry>
                        <inertial>
                            # description
                            # parameters
                            # Child nodes: 
                                <mass />
                                    # description: mass
                                    # Parameters: value=10
                                <inertia />
                                    # Description: Inertia
                                    # Parameters: i+"Cartesian product of xyz" (9 in total)="0.4"
                        <origin />
                            # Description:
                            # Parameters:
                                # rpy="0 1.5 0"
                                # xyz="0 0 -0.3"
                        <material />
                            # Description
                            # Parameters:name="blue"
        <joint>
            # Description
            # Parameters:
                # name=""
                # type=""
                    # fixed
                    # prismatic
            # child node
                <parent />
                    # Description
                    # Parameters:link=""
                <child />
                    # Description:
                    # Parameters:link=""
                <origin />
                    # Description:
                    # Parameters:xyz="0 -0.2 0.25"
                <limit />
                    # Description
                    # Parameters:
                        # effort="1000.0"    maximum effort
                        # lower="-0.38"      Joint upper limit (radians)
                        # upper="0"          Joint lower limit (radians)
                        # velocity="0.5"     Maximum velocity 
                <axis />
                    # Description: Press ? axis rotation
                    # Parameters:xyz="0 0 1",along the Z axis
        <material>
            # Description:
            # Parameters:name="blue"
            # child node:
                <color />
                    # description:
                    # Parameters:rgba="0 0 0.8 1"

<<<<<<< HEAD

- 安装依赖库

  • Install dependent libraries

    5673ade8eb00a28794557125b7d1c8cd332434a9

sudo apt install ros-foxy-joint-state-publisher-gui ros-foxy-joint-state-publisher
sudo apt install ros-foxy-xacro

<<<<<<< HEAD

- 下载源代码

  • Download the source code

    5673ade8eb00a28794557125b7d1c8cd332434a9

cd ~/dev_ws  
git clone -b ros2 https://github.com/ros/urdf_tutorial.git src/urdf_tutorial

<<<<<<< HEAD

- 编译源代码

  • Compiling the source code

    5673ade8eb00a28794557125b7d1c8cd332434a9

colcon build --packages-select urdf_tutorial

<<<<<<< HEAD

- 运行示例

  • Running the example

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 launch urdf_tutorial display.launch.py model:=urdf/01-myfirst.urdf

2.9 Launch

<<<<<<< HEAD ROS 2 中的启动系统负责帮助用户描述他们系统的配置,然后按照描述执行。 系统的配置包括要运行的程序、运行它们的位置、传递给它们的参数,以及 ROS 特定的约定,这些约定通过为每个组件提供不同的配置,使得在整个系统中重用组件变得容易。 它还负责监视已启动流程的状态,并报告和/或响应这些流程状态的变化。

用 Python、XML 或 YAML 编写的launch文件可以启动和停止不同的节点,以及触发和处理各种事件。

具体参考: 官方教程

The launch system in ROS 2 is responsible for helping the user describe the configuration of their system and then execute it as described. The configuration of the system includes what programs to run, where to run them, what arguments to pass them, and ROS-specific conventions which make it easy to reuse components throughout the system by giving them each a different configuration. It is also responsible for monitoring the state of the processes launched, and reporting and/or reacting to changes in the state of those processes.

Launch files written in Python, XML, or YAML can start and stop different nodes as well as trigger and act on various events.

Specific reference: Official Tutorials

5673ade8eb00a28794557125b7d1c8cd332434a9

Setup

<<<<<<< HEAD

创建一个新目录来存储您的launch文件:

Create a new directory to store your launch files:

5673ade8eb00a28794557125b7d1c8cd332434a9

mkdir launch

<<<<<<< HEAD 编写启动文件

让我们使用 turtlesim 包及其可执行文件将 ROS 2 启动文件放在一起。 正如刚才提到的。

将完整代码复制并粘贴到 launch/turtlesim_mimic_launch.py 文件中:

Writer the launch file

Let’s put together a ROS 2 launch file using the turtlesim package and its executables. As mentioned above.

Copy and paste the complete code into the launch/turtlesim_mimic_launch.py file:

5673ade8eb00a28794557125b7d1c8cd332434a9

from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    return LaunchDescription([
        Node(
            package='turtlesim',
            namespace='turtlesim1',
            executable='turtlesim_node',
            name='sim'
        ),
        Node(
            package='turtlesim',
            namespace='turtlesim2',
            executable='turtlesim_node',
            name='sim'
        ),
        Node(
            package='turtlesim',
            executable='mimic',
            name='mimic',
            remappings=[
                ('/input/pose', '/turtlesim1/turtle1/pose'),
                ('/output/cmd_vel', '/turtlesim2/turtle1/cmd_vel'),
            ]
        )
    ])

<<<<<<< HEAD 运行ros2启动文件

要运行上面创建的launch文件,请进入您之前创建的目录并运行以下命令:

语法格式为:

Run the ros2 launch file

To run the launch file created above, enter into the directory you created earlier and run the following command:

The syntax format is:

5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 launch <package_name> <launch_file_name>
cd launch
ros2 launch turtlesim_mimic_launch.py

<<<<<<< HEAD

- launch 帮助

  • launch help

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 launch -h

<<<<<<< HEAD

- 运行节点

  • running node

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 launch turtlesim multisim.launch.py

<<<<<<< HEAD

- 查看launch文件有哪些参数

  • Check the parameters of the launc file

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 launch turtlebot3_fake_node turtlebot3_fake_node.launch.py -s
ros2 launch turtlebot3_fake_node turtlebot3_fake_node.launch.py --show-arguments
ros2 launch turtlebot3_bringup robot.launch.launch.py -s

<<<<<<< HEAD

- 运行launch文件带参数

  • Run the launch file with parameters

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 launch turtlebot3_bringup robot.launch.launch.py usb_port:=/dev/opencr

<<<<<<< HEAD

- 运行节点并调试

  • Run the node and debug

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 launch turtlesim turtlesim_node.launch.py -d

<<<<<<< HEAD

- 只输出节点描述

  • Only output node description

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 launch turtlesim turtlesim_node.launch.py -p

<<<<<<< HEAD

- 运行组件

  • running components

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 launch composition composition_demo.launch.py

2.10 Run

<<<<<<< HEAD run用于运行单个节点,组件程序。

- run 帮助

run is used to run a single node, component program

  • run help

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 run -h

<<<<<<< HEAD

- 运行节点

  • running node

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 run turtlesim turtlesim_node

<<<<<<< HEAD

- 运行节点带参数

  • Run node with parameters

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 run turtlesim turtlesim_node --ros-args -r __node:=turtle2 -r __ns:=/ns2

<<<<<<< HEAD

- 运行组件容器

  • Run component container

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 run rclcpp_components component_container

<<<<<<< HEAD

- 运行组件

  • running components

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 run composition manual_composition

2.11 Package

<<<<<<< HEAD 一个包可以被认为是你的 ROS 2 代码的容器。 如果您希望能够安装您的代码或与他人共享,那么您需要将其组织在一个包中。 借助软件包,您可以发布您的 ROS 2 作品并允许其他人轻松构建和使用它。

ROS 2 中的包创建使用 ament 作为其构建系统,并使用 colcon 作为其构建工具。 您可以使用官方支持的 CMake 或 Python 创建包,但确实存在其他构建类型。

具体参数: 官方教程

创建工作空间

为每个新工作区创建一个新目录。 名称并不重要,但它有助于表明工作区的用途。 让我们为“开发工作区”选择目录名称 ros2_ws:

A package can be considered a container for your ROS 2 code. If you want to be able to install your code or share it with others, then you’ll need it organized in a package. With packages, you can release your ROS 2 work and allow others to build and use it easily.

Package creation in ROS 2 uses ament as its build system and colcon as its build tool. You can create a package using either CMake or Python, which are officially supported, though other build types do exist.

Specific reference: Official Tutorials

Creating a workspace

Create a new directory for every new workspace. The name doesn’t matter, but it is helpful to have it indicate the purpose of the workspace. Let’s choose the directory name ros2_ws, for “development workspace”:

5673ade8eb00a28794557125b7d1c8cd332434a9

mkdir -p ~/ros2_ws/src
cd ~/ros2_ws/src

<<<<<<< HEAD

- pkg 帮助

  • pkg help

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 pkg -h

<<<<<<< HEAD

- 列出功能包

  • List Feature Packs

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 pkg executable turtlesim

<<<<<<< HEAD

- 输出某个功能包可执行程序

  • Output a function package executable program

    5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 pkg executable turtlesim

<<<<<<< HEAD

  • 创建Python功能包

在运行包创建命令之前,请确保您位于 src 文件夹中。

  • Create a Python package

Make sure you are in the src folder before running the package creation command.

5673ade8eb00a28794557125b7d1c8cd332434a9

cd ~/ros2_ws/src

<<<<<<< HEAD 在 ROS 2 中创建新包的命令语法是:

ros2 pkg create --build-type ament_python <package_name>
# 您将使用可选参数 --node-name 在包中创建一个简单的 Hello World 类型可执行文件。
ros2 pkg create --build-type ament_python --node-name my_node my_package
  • 构建package

将包放在工作区中特别有价值,因为您可以通过在工作区根目录中运行 colcon build 来一次构建许多包。 否则,您将不得不单独构建每个包。

# 返回到工作区目录:
cd ~/ros2_ws
# 现在你可以构建你的包:
colcon build
  • Source setup文件

要使用您的新包和可执行文件,首先打开一个新终端并获取您的主要 ROS 2 安装源。

然后,从 ros2_ws 目录中,运行以下命令来获取您的工作空间:

The command syntax for creating a new package in ROS 2 is:

ros2 pkg create --build-type ament_python <package_name>
# you will use the optional argument --node-name which creates a simple Hello World type executable in the package.
ros2 pkg create --build-type ament_python --node-name my_node my_package
  • Build a package

Putting packages in a workspace is especially valuable because you can build many packages at once by running colcon build in the workspace root. Otherwise, you would have to build each package individually.

# Return to the root of your workspace:
cd ~/ros2_ws
# Now you can build your packages:
colcon build
  • Source the setup file

To use your new package and executable, first open a new terminal and source your main ROS 2 installation.

Then, from inside the ros2_ws directory, run the following command to source your workspace:

5673ade8eb00a28794557125b7d1c8cd332434a9

source install/setup.bash

<<<<<<< HEAD 现在您的工作区已添加到您的路径中,您将能够使用新包的可执行文件。

  • 使用 package

要运行您在包创建期间使用 --node-name 参数创建的可执行文件,请输入以下命令:

Now that your workspace has been added to your path, you will be able to use your new package’s executables.

  • Use the package

To run the executable you created using the --node-name argument during package creation, enter the command:

5673ade8eb00a28794557125b7d1c8cd332434a9

ros2 run my_package my_node

<<<<<<< HEAD

← 上一页 | 下一页 →

← Previous Page | Next Page →

5673ade8eb00a28794557125b7d1c8cd332434a9

results matching ""

    No results matching ""