Configuring environment[译文 ROS humble]


You're reading the documentation for an older, but still supported, version of ROS 2. For information on the latest version, please have a look at Iron.
您正在阅读有关较旧但仍受支持的 ROS 2 版本的文档。有关最新版本的信息,请查看 Iron。

Configuring environment
配置环境 

Goal: This tutorial will show you how to prepare your ROS 2 environment.
目标:本教程将向您展示如何准备 ROS 2 环境。

Tutorial level: Beginner 教程级别:初级

Time: 5 minutes 时间:5分钟

Background 背景 

ROS 2 relies on the notion of combining workspaces using the shell environment. “Workspace” is a ROS term for the location on your system where you’re developing with ROS 2. The core ROS 2 workspace is called the underlay. Subsequent local workspaces are called overlays. When developing with ROS 2, you will typically have several workspaces active concurrently.
ROS 2 依赖于使用 shell 环境组合工作区的概念。“工作区”是一个 ROS 术语,用于表示您使用 ROS 2 进行开发的系统上的位置。核心 ROS 2 工作区称为底层。后续的本地工作区称为叠加层。使用 ROS 2 进行开发时,通常会同时激活多个工作区。

Combining workspaces makes developing against different versions of ROS 2, or against different sets of packages, easier. It also allows the installation of several ROS 2 distributions (or “distros”, e.g. Dashing and Eloquent) on the same computer and switching between them.
通过组合工作区,可以更轻松地针对不同版本的 ROS 2 或不同的软件包集进行开发。它还允许在同一台计算机上安装多个 ROS 2 发行版(或“发行版”,例如 Dashing 和 Eloquent)并在它们之间切换。

This is accomplished by sourcing setup files every time you open a new shell, or by adding the source command to your shell startup script once. Without sourcing the setup files, you won’t be able to access ROS 2 commands, or find or use ROS 2 packages. In other words, you won’t be able to use ROS 2.
这是通过在每次打开新 shell 时获取安装文件,或者将 source 命令添加到 shell 启动脚本一次来实现的。如果不获取安装文件,您将无法访问 ROS 2 命令,也无法查找或使用 ROS 2 软件包。换句话说,您将无法使用 ROS 2。

Prerequisites 先决条件 

Before starting these tutorials, install ROS 2 by following the instructions on the ROS 2 Installation page.
在开始这些教程之前,请按照 ROS 2 安装页面上的说明安装 ROS 2。

The commands used in this tutorial assume you followed the binary packages installation guide for your operating system (Debian packages for Linux). You can still follow along if you built from source, but the path to your setup files will likely be different. You also won’t be able to use the sudo apt install ros-<distro>-<package> command (used frequently in the beginner level tutorials) if you install from source.
本教程中使用的命令假定您遵循了操作系统的二进制软件包安装指南(适用于 Linux 的 Debian 软件包)。如果从源代码构建,您仍然可以继续操作,但安装文件的路径可能会有所不同。如果从源代码安装,则也无法使用该 sudo apt install ros-<distro>-<package> 命令(在初学者教程中经常使用)。

If you are using Linux or macOS, but are not already familiar with the shell, this tutorial will help.
如果您使用的是 Linux 或 macOS,但还不熟悉 shell,本教程将有所帮助。

Tasks 任务 

1 Source the setup files
1 获取安装文件 

You will need to run this command on every new shell you open to have access to the ROS 2 commands, like so:
您需要在打开的每个新 shell 上运行此命令才能访问 ROS 2 命令,如下所示:

LinuxmacOSWindows
# Replace ".bash" with your shell if you're not using bash
# Possible values are: setup.bash, setup.sh, setup.zsh
source /opt/ros/humble/setup.bash

Note 注意

The exact command depends on where you installed ROS 2. If you’re having problems, ensure the file path leads to your installation.
确切的命令取决于您安装 ROS 2 的位置。如果遇到问题,请确保文件路径指向您的安装。

2 Add sourcing to your shell startup script
2 将采购添加到您的 shell 启动脚本中 

If you don’t want to have to source the setup file every time you open a new shell (skipping task 1), then you can add the command to your shell startup script:
如果您不想在每次打开新 shell 时都获取安装文件(跳过任务 1),则可以将命令添加到 shell 启动脚本中:

LinuxmacOSWindows
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc

To undo this, locate your system’s shell startup script and remove the appended source command.
要撤消此操作,请找到系统的 shell 启动脚本并删除附加的 source 命令。

3 Check environment variables
3 检查环境变量 

Sourcing ROS 2 setup files will set several environment variables necessary for operating ROS 2. If you ever have problems finding or using your ROS 2 packages, make sure that your environment is properly set up using the following command:
获取 ROS 2 安装文件将设置操作 ROS 2 所需的几个环境变量。如果您在查找或使用 ROS 2 软件包时遇到问题,请确保使用以下命令正确设置您的环境:

LinuxmacOSWindows
printenv | grep -i ROS

Check that variables like ROS_DISTRO and ROS_VERSION are set.
检查变量 like ROS_DISTRO 和 ROS_VERSION 是否已设置。

ROS_VERSION=2
ROS_PYTHON_VERSION=3
ROS_DISTRO=humble

If the environment variables are not set correctly, return to the ROS 2 package installation section of the installation guide you followed. If you need more specific help (because environment setup files can come from different places), you can get answers from the community.
如果环境变量设置不正确,请返回您遵循的安装指南的 ROS 2 软件包安装部分。如果您需要更具体的帮助(因为环境设置文件可能来自不同的地方),您可以从社区获得答案。

3.1 The ROS_DOMAIN_ID variable
3.1 ROS_DOMAIN_ID 变量 

See the domain ID article for details on ROS domain IDs.
有关 ROS 域 ID 的详细信息,请参阅域 ID 一文。

Once you have determined a unique integer for your group of ROS 2 nodes, you can set the environment variable with the following command:
一旦为您的 ROS 2 节点组确定了一个唯一的整数,您可以使用以下命令设置环境变量:

LinuxmacOSWindows
export ROS_DOMAIN_ID=<your_domain_id>

To maintain this setting between shell sessions, you can add the command to your shell startup script:
若要在 shell 会话之间保持此设置,可以将命令添加到 shell 启动脚本中:

echo "export ROS_DOMAIN_ID=<your_domain_id>" >> ~/.bashrc
3.2 The ROS_LOCALHOST_ONLY variable
3.2 ROS_LOCALHOST_ONLY 变量 

By default, ROS 2 communication is not limited to localhost. ROS_LOCALHOST_ONLY environment variable allows you to limit ROS 2 communication to localhost only. This means your ROS 2 system, and its topics, services, and actions will not be visible to other computers on the local network. Using ROS_LOCALHOST_ONLY is helpful in certain settings, such as classrooms, where multiple robots may publish to the same topic causing strange behaviors. You can set the environment variable with the following command:
默认情况下,ROS 2 通信不限于 localhost。 ROS_LOCALHOST_ONLY 环境变量允许您将 ROS 2 通信限制为仅与 localhost 通信。这意味着您的 ROS 2 系统及其主题、服务和操作将对本地网络上的其他计算机不可见。在某些 ROS_LOCALHOST_ONLY 环境中使用是有帮助的,例如教室,在教室中,多个机器人可能会发布到同一主题,从而导致奇怪的行为。您可以使用以下命令设置环境变量:

LinuxmacOSWindows
export ROS_LOCALHOST_ONLY=1

To maintain this setting between shell sessions, you can add the command to your shell startup script:
若要在 shell 会话之间保持此设置,可以将命令添加到 shell 启动脚本中:

echo "export ROS_LOCALHOST_ONLY=1" >> ~/.bashrc

Summary 摘要 

The ROS 2 development environment needs to be correctly configured before use. This can be done in two ways: either sourcing the setup files in every new shell you open, or adding the source command to your startup script.
ROS 2 开发环境在使用前需要正确配置。这可以通过两种方式完成:在打开的每个新 shell 中获取安装文件,或将 source 命令添加到启动脚本中。

If you ever face any problems locating or using packages with ROS 2, the first thing you should do is check your environment variables and ensure they are set to the version and distro you intended.
如果您在查找或使用 ROS 2 软件包时遇到任何问题,您应该做的第一件事是检查您的环境变量并确保它们设置为您想要的版本和发行版。

Next steps 后续步骤 

Now that you have a working ROS 2 installation and you know how to source its setup files, you can start learning the ins and outs of ROS 2 with the turtlesim tool.
现在你已经有一个有效的 ROS 2 安装,并且你知道如何获取它的安装文件,你可以开始使用 turtlesim 工具学习 ROS 2 的来龙去脉。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值