当前位置:网站首页>ROS2系列知识(3):环境配置
ROS2系列知识(3):环境配置
2022-07-31 00:47:00 【无水先生】
一、背景知识
1.1 关于工作区
ROS 2 依赖于使用 shell 环境组合工作空间的概念。 “工作区”是一个 ROS 术语,表示您使用 ROS 2 进行开发的系统上的位置。核心 ROS 2 工作区称为底层。随后的本地工作空间称为覆盖。使用 ROS 2 进行开发时,您通常会同时使用多个工作区。
结合工作空间可以更轻松地针对不同版本的 ROS 2 或针对不同的包集进行开发。它还允许在同一台计算机上安装多个 ROS 2 发行版(或“发行版”,例如 Dashing 和 Eloquent)并在它们之间切换。
1.2 每次开终端后的source指令
这是通过每次打开新 shell 时获取设置文件来完成的,或者通过将 source 命令添加到 shell 启动脚本一次来完成。如果不获取设置文件,您将无法访问 ROS 2 命令,或查找或使用 ROS 2 包。换句话说,您将无法使用 ROS 2。
二、先决条件
2.1 保证已经完成的阶段
1)安装已经完成
在开始这些教程之前,请按照 ROS 2 安装页面上的说明安装 ROS 2。参见本文的相关博文:
( ubuntu参见 ros2知识:Ubuntu20.4上ROS2- Rolling版安装 )(windows10参见:win10上安装ROS2)
本教程中使用的命令假定您遵循了适用于您的操作系统的二进制包安装指南(适用于 Linux 的 Debian 包)。如果您是从源代码构建的,您仍然可以继续使用,但安装文件的路径可能会有所不同。如果您从源代码安装,您也将无法使用 sudo apt install ros-<distro>-<package> 命令(在初级教程中经常使用)。
2)保证熟悉linux的shell
如果您使用的是 Linux 或 macOS,但还不熟悉 shell,那么shell指令速成法_本教程将有所帮助。
2.2 进入安装环境
您需要在打开的每个新 shell 上运行此命令才能访问 ROS 2 命令,如下所示:
Ubuntu命令 | source /opt/ros/humble/setup.bash |
windows命令 | call C:\dev\ros2\local_setup.bat |
确切的命令取决于您安装 ROS 2 的位置。如果您遇到问题,请确保文件路径指向您的安装。
2.3 将source添加到您的 shell 启动脚本
如果您不想每次打开新 shell(跳过任务 1)时都必须获取设置文件,那么您可以将命令添加到 shell 启动脚本中:
ubuntu操作 | echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc |
windows操作 | Only for PowerShell users, create a folder in ‘My Documents’ called ‘WindowsPowerShell’. Within ‘WindowsPowerShell’, create file ‘Microsoft.PowerShell_profile.ps1’. Inside the file, paste: C:\dev\ros2_humble\local_setup.ps1 PowerShell will request permission to run this script everytime a new shell is opened. To avoid that issue you can run: Unblock-File C:\dev\ros2_humble\local_setup.ps1 To undo this, remove the new ‘Microsoft.PowerShell_profile.ps1’ file. |
2.4 检查环境变量
获取 ROS 2 设置文件将设置运行 ROS 2 所需的几个环境变量。如果您在查找或使用 ROS 2 包时遇到问题,请确保使用以下命令正确设置您的环境:
Ubuntu指令 | printenv | grep -i ROS |
windows指令 | set | findstr -i ROS |
检查是否设置了 ROS_DISTRO 和 ROS_VERSION 等变量。
ROS_VERSION=2 ROS_PYTHON_VERSION=3 ROS_DISTRO=humble
如果环境变量设置不正确,请返回您遵循的安装指南的 ROS 2 包安装部分。如果您需要更具体的帮助(因为环境设置文件可能来自不同的地方),您可以从社区获得答案。
2.5 ROS_DOMAIN_ID 变量
有关 ROS 域 ID 的详细信息,请参阅域 ID 文章。 一旦您确定了您的 ROS 2 代理组的唯一整数,您可以使用以下命令设置环境变量:
ubuntu指令 | export ROS_DOMAIN_ID=<your_domain_id> To maintain this setting between shell sessions, you can add the command to your shell startup script: echo "export ROS_DOMAIN_ID=<your_domain_id>" >> ~/.bashrc |
windows指令 | set ROS_DOMAIN_ID=<your_domain_id> If you want to make this permanent between shell sessions, also run: setx ROS_DOMAIN_ID <your_domain_id> |
3 总结
使用前需要正确配置ROS 2开发环境。这可以通过两种方式完成:在您打开的每个新 shell 中获取设置文件,或者将 source 命令添加到您的启动脚本中。
如果您在定位或使用 ROS 2 软件包时遇到任何问题,您应该做的第一件事是检查您的环境变量并确保它们设置为您想要的版本和发行版。
后续步骤
现在您已经安装了有效的 ROS 2 并且您知道如何获取其设置文件,您可以开始使用 turtlesim 工具学习 ROS 2 的来龙去脉。
边栏推荐
- 【愚公系列】2022年07月 Go教学课程 019-循环结构之for
- [Yugong Series] July 2022 Go Teaching Course 016-Logical Operators and Other Operators of Operators
- MySQL table design for message queue to store message data
- Image processing tool design
- 图像处理工具设计
- Xss target drone training [success when pop-up window is realized]
- Regular expression password policy and regular backtracking mechanism bypass
- 深度学习可以求解特定函数的参数么?
- typescript12 - union types
- SereTOD2022 Track2代码剖析-面向半监督和强化学习的任务型对话系统挑战赛
猜你喜欢
binglog log tracking: data backup and backup tracking
Oracle has a weird temporary table space shortage problem
ShardingSphere之垂直分库分表实战(五)
What is Promise?What is the principle of Promise?How to use Promises?
MySQL数据库进阶篇
typescript17 - function optional parameters
MySQL database advanced articles
typescript14-(单独指定参数和返回值的类型)
mysql主从复制及读写分离脚本-亲测可用
unity2D横版游戏教程4-物品收集以及物理材质
随机推荐
Regular expression password policy and regular backtracking mechanism bypass
Optimization of aggregate mentioned at DATA AI Summit 2022
GO GOPROXY代理设置
MySQL triggers
MySQL笔记下
Summary of MySQL database interview questions (2022 latest version)
A complete guide to avoiding pitfalls for the time-date type "yyyy-MM-dd HHmmss" in ES
MySQL系列一:账号管理与引擎
MySQL database advanced articles
typescript10-常用基础类型
Error in go mode tidy go warning “all” matched no packages
Adding, deleting, modifying and checking the foundation of MySQL
深度学习可以求解特定函数的参数么?
Oracle has a weird temporary table space shortage problem
[Tang Yudi Deep Learning-3D Point Cloud Combat Series] Study Notes
[In-depth and easy-to-follow FPGA learning 15---------- Timing analysis basics]
【愚公系列】2022年07月 Go教学课程 015-运算符之赋值运算符和关系运算符
The difference between substring and substr in MySQL
typescript9 - common base types
typescript14-(单独指定参数和返回值的类型)