当前位置:网站首页>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 的来龙去脉。
边栏推荐
- unity2D横版游戏教程4-物品收集以及物理材质
- MySQL database advanced articles
- Optimization of aggregate mentioned at DATA AI Summit 2022
- typescript10-commonly used basic types
- Mini Program - Global Data Sharing
- Regular expression password policy and regular backtracking mechanism bypass
- ABC 261 F - Sorting Color Balls (reverse pair)
- 【愚公系列】2022年07月 Go教学课程 015-运算符之赋值运算符和关系运算符
- Responsive layout vs px/em/rem
- 解决:Parameter 0 of method ribbonServerList in com.alibaba.cloud.nacos.ribbon.NacosRibbonClientConfigu
猜你喜欢
Niuke.com question brushing training (4)
Detailed explanation of 9 common reasons for MySQL index failure
Huawei's "genius boy" Zhihui Jun has made a new work, creating a "customized" smart keyboard from scratch
typescript12-联合类型
不用Swagger,那我用啥?
Jmeter parameter transfer method (token transfer, interface association, etc.)
ShardingSphere read-write separation (8)
【952. 按公因数计算最大组件大小】
Meeting OA project pending meeting, all meeting functions
[In-depth and easy-to-follow FPGA learning 14----------Test case design 2]
随机推荐
Can deep learning solve the parameters of a specific function?
Jmeter parameter transfer method (token transfer, interface association, etc.)
IOT cross-platform component design scheme
MySql数据恢复方法个人总结
人工智能与云安全
Bypass of xss
GO GOPROXY proxy Settings
【Yugong Series】July 2022 Go Teaching Course 019-For Circular Structure
Go study notes (84) - Go project directory structure
【Yugong Series】July 2022 Go Teaching Course 013-Constants, Pointers
Artificial Intelligence and Cloud Security
MySQL数据库(基础)
Adding, deleting, modifying and checking the foundation of MySQL
程序员工作三年攒多少钱合适?
BOM系列之history对象
Why use high-defense CDN when financial, government and enterprises are attacked?
mysql索引失效的常见9种原因详解
MySQL master-slave replication and read-write separation script - pro test available
ShardingSphere之公共表实战(七)
typescript11-数据类型