ROS 环境变量-----简介

本文详细介绍了ROS(Robot Operating System)中各种环境变量的作用与配置方法,包括ROS必须的环境变量如ROS_ROOT、ROS_MASTER_URI等,以及与路径、构建系统、节点相关的环境变量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


1 ROS必须的环境变量

   执行命令: source /opt/ros/ROSDISTRO/setup.bash (Replace ROSDISTRO with the desired ROS distribution, e.g. indigo.)可以完成设置。

   当然通常是添加该命令到~/.bashrc,系统启动自动设置这些必须的环境变量。

注意:1)如果执行source /opt/ros/<distro>/setup.bash,它会撤销已有设置的改变(换句话如果先source自己工作空间的setup.bash,再source  opt安装的setup.bash, 自己工作空间的一些设置,比如ROS_PACKAGE_PATH就会被撤销);

       2)如果再执行catkin_init_workspace , catkin_make后会有source /home/<user>/catkin_ws/devel/setup.bash执行,之前的设置(opt那边的ROS setup)会自动追加到home下的setup里。

1.1 ROS_ROOT

ROS_ROOT sets the location where the ROS core packages are installed.

export ROS_ROOT=/home/user/ros/ros
export PATH=$ROS_ROOT/bin:$PATH

注意:该包给出ROS 核心通讯组件的路径


1.2 ROS_MASTER_URI

ROS_MASTER_URI is a required setting that tells nodes where they can locate the master. It should be set to the XML-RPC URI of the master. Great care should be taken when usinglocalhost, as that can lead to unintended behaviors with remotely launched nodes.

export ROS_MASTER_URI=http://mia:11311/

注意:它给出ROS MASTER的URI,一般是本机上,11311端口。

1.3 PYTHONPATH

ROS requires that your PYTHONPATH be updated,even if you don't program in Python! Many ROS infrastructure tools rely on Python and need access to the roslib package for bootstrapping.

export PYTHONPATH=$PYTHONPATH:$ROS_ROOT/core/roslib/src

注意:这个是python寻找package时的路径,如果有误的话,import ROS相关的包就会找不到


2 PATH相关环境变量

2.1 ROS_PACKAGE_PATH

ROS_PACKAGE_PATH is an optional, but very common environment variable that allows you to add more ROS packages from source to your environment.ROS_PACKAGE_PATH can be composed of one or more paths separated by your standard OS path separator (e.g. ':' on Unix-like systems). Theseordered paths tell the ROS system where to search for more ROS packages. If there are multiple packages of the same name, ROS will choose the one that appears onROS_PACKAGE_PATH first.

export ROS_PACKAGE_PATH=/home/user/ros/ros-pkg:/another/path

Note that each entry in ROS_PACKAGE_PATH is searched recursively--all ROS packages below the named path will be found.

With the introduction of catkin, ROS_PACKAGE_PATH becomes obsolete, and will be kept only for backwards compatibility with rosbuild packages.

注意:这个环境变量主要影响ROS文件系统工具查找ros package,对于自建的catkin_ws如果 不把它的路径加入到该环境变量的话,无法通过ROS命令行工具以及roslaunch 来运行或者调用catkin_ws里面的包。

2.2 PATH

这个是通用Linux系统命令行中执行命令查找路径使用。但是对于ROS来讲,如果PATH 中没有你ROS相关的目录的话,也没有没办法使用ROS命令行工具。可以作为check考虑点

3 ROS系统生成数据相关环境变量

3.1 ROS_HOME

By default, ROS writes data to ~/.ros. This location can be changed by settingROS_HOME. You can also change the location of certain individual directories in~/.ros (e.g. ROS_TEST_RESULTS_DIR,ROS_LOG_DIR).

3.2 ROS_LOG_DIR

By default, ROS writes internal log files to ROS_HOME/log. If this location is not writable to ROS, or if you wish for log files to be written elsewhere, set ROS_LOG_DIR to that path.

3.3 ROS_TEST_RESULTS_DIR

Directory that test results should be written to.

4 ROS Bash相关环境变量

4.1 ROS_LOCATIONS

ROS_LOCATIONS is an optional environment variable that provides keyed names for useful locations. It is a: separated list of key-location pairs. Each key-location pair is separated by an=. For example:

export ROS_LOCATIONS="rospkg=/path/to/rospkg:stairpkg=/path/to/stairpkg"

These keys can then be used in tools such as roscd.

4.2 ROS_WORKSPACE

ROS_WORKSPACE is introduced by the rosinstall / rosws tools, it is set by setup.sh that is generated by these tools when creating a workspace. It points to the folder of the workspace and is used by the rosws command as a default target of the command.

The roscd tool in fuerte was also changed to use that variable when called without arguments. Previously it had defaulted to change toROS_ROOT.

5 ROS Node环境变量

5.1 ROS_IP/ROS_HOSTNAME

ROS_IP and ROS_HOSTNAME are optional environment variable that sets the declared network address of a ROSNode or tool. The options are mutually exclusive, if both are set ROS_HOSTNAME will take precedence. Use ROS_IP if you are specifying an IP address, and ROS_HOSTNAME if you are specifying a host name. When a ROS component reports a URI to the master or other components, this value will be used. This setting is only needed in situations where you have multiple addresses for a computer and need to force ROS to a particular one.

With the exception of 'localhost', it does not affect the actual bound address as ROS components bind to all available network interfaces. If the value is set to localhost, the ROS component will bind only to the loopback interface. This will prevent remote components from being able to talk to your local component.

注意:常用于多机通讯中表明自己所在网咯位置,ROS_IPROS_HOSTNAME设置好一个即可。

5.2 ROS_NAMESPACE

ROS_NAMESPACE lets you push down a Node into a namespace. All of the names in the Node will be resolved relative to this value, including remapped names.

注意:表示本机的namespace,本机node中的name都会有这个namespace前缀。

5.3 ROSCONSOLE_CONFIG_FILE

This is a roscpp-specific environment variable. rosconsole lets you define your own configuration file that will be used by log4cxx, defined by the ROSCONSOLE_CONFIG_FILE environment variable. Anything defined in this config file will override the default config file.

See http://ros.org/doc/api/rosconsole/html/index.html for more information.

5.4 Console Output Formatting

rosconsole allows you to specify how you'd like its output to show up in the console output through theROSCONSOLE_FORMAT environment variable. The default is equivalent to:

export ROSCONSOLE_FORMAT='[${severity}] [${time}]: ${message}'

See http://ros.org/doc/api/rosconsole/html/index.html for more information on this package in general. You can see the list of parsed format stringsin the source code.

.5 .5 ROS_PYTHON_LOG_CONFIG_FILE

This is specific to rospy, rosmaster,roslaunch, and rostest. For these tools, you can define your own Python logging configuration file to use instead of the default config file, which is stored in$ROS_ROOT/config/python_logging.conf.

For more information, see the Python logging documentation:

http://docs.python.org/library/logging.html

6 Build系统环境变量

In order to understand these environment variables better, please see the section on theROS Build System.

6.1 ROS_BOOST_ROOT

ROS_BOOST_ROOT is an optional environment variable that lets you override where to search for boost. IfROS_BOOST_ROOT is not set it defaults to using ROS_BINDEPS_PATH

6.2 ROS_PARALLEL_JOBS

The value of this variable, if set, is passed to make when building packages. The idea is to let you exploit a multi-processor machine. For example, if you have 8 processors / cores and want to run as many parallel jobs as possible, as long as the system load is less than 8, by limiting the jobs to 8 you prevent overshoot at startup time:

export ROS_PARALLEL_JOBS='-j8 -l8'

Alternatively, you could use the -j flag with an argument to run up to 8 jobs in parallel, independent of system load:

export ROS_PARALLEL_JOBS=-j8

We strongly recommend using the -l flag to set a system load-dependent limit on parallelism. Excessive parallelism in a large build can exhaust system memory.

What system load is acceptable to you depends on how many cores you have:http://blog.scoutapp.com/articles/2009/07/31/understanding-load-averages

So 8 might be suitable for a machine with 8 cores.

6.3 ROS_LANG_DISABLE

A colon-separated list of package names for message generators / client libraries that should be disabled. Message-generation will not happen for languages in this list.

For packages build with catkin you need to list the names of the message generators which should be ignored, e.g.:

export ROS_LANG_DISABLE=genlisp

For packages build with rosbuild you need to list the names of the message generatorsas well as the client libraries which should be ignored, e.g.:

export ROS_LANG_DISABLE=genlisp:roslisp

When ignoring message generators with rosbuild the CMake configure step will show a warning that the client library (e.g.roslisp) is not a known message generator. This warning can safely be ignored.

Note that before disabling a language, you should first be very sure that none of the code you're using requires that language's bindings.

6.4 ROS_OS_OVERRIDE

Format: "OS_NAME:OS_VERSION_STRING" This will force it to detect Ubuntu Lucid:

export ROS_OS_OVERRIDE=ubuntu:10.04

If defined, this will override the autodetection of an OS. This can be useful when debugging rosdep dependencies on alien platforms, when platforms are actually very similar and might need be forced, or of course if the autodetection is failing.


6.5

6.5 Other Build envs

$CPATH  $CMAKE_PREFIX_PATH  $LD_LIBRARY_PATH  $PKG_CONFIG_PATH


<think>好的,我需要帮助用户查找关于ROS Foxy Desktop的安装、配置和使用教程的信息。首先,根据用户提供的引用内容,我应该整理出相关的步骤和资源。 首先,安装部分。引用[1]提到可以通过sudo apt install ros-foxy-desktop来安装桌面版,这会包括ROS、RViz和其他工具。这是推荐的方法,所以需要放在最前面。然后引用[2]补充了安装前的准备工作,比如设置Ubuntu版本和添加源,这部分需要详细说明,包括更新系统和设置locale的步骤。用户可能不知道如何添加源,所以需要给出具体的命令,比如使用清华镜像源。 接下来是验证安装是否成功,引用[3]提到运行ros2 --help来检查,这一步很重要,应该放在安装后的步骤里。然后,用户可能想用Docker安装,引用[3]和[4]提到了Docker的安装方法,但需要解释Docker的优势和基本步骤,比如拉取镜像和运行容器。不过用户的问题主要是关于Desktop版,所以Docker部分可以简要提及。 配置方面,引用[4]提到安装不同的DDS实现,比如rmw-connext-cpp,这对高级用户可能有帮助,需要说明如何切换DDS。使用教程部分,引用[1]和[2]都提到了官方文档和古月居的教程,应该推荐这些资源,并建议用户运行示例demo。 需要确保所有命令正确无误,比如安装桌面版的命令是否正确,源是否正确。同时,注意用户可能遇到的问题,比如依赖项缺失或环境变量设置,应该在注意事项里提醒。引用中提到的清华镜像源可能加快下载速度,这点对国内用户很重要,需要强调。 最后,生成相关问题时要围绕安装、配置、使用和常见问题,比如性能优化、DDS选择、Docker使用和与其他版本的区别。确保问题覆盖用户可能感兴趣的方面,帮助他们进一步探索。 总结步骤:安装准备、桌面安装、验证、Docker安装(可选)、DDS配置、教程资源。每个部分引用对应的来源,并在末尾添加引用标识。确保语言简洁,步骤清晰,用户能一步步跟随操作。</think>### ROS Foxy Desktop 安装与配置教程 #### 一、安装准备 1. **系统要求** ROS 2 Foxy Fitzroy 支持 Ubuntu 20.04(需已安装 `wget` 和 `curl` 工具)[^2]。 2. **设置 Locale** 运行以下命令确保系统语言支持 UTF-8: ```bash sudo apt update && sudo apt install locales sudo locale-gen en_US en_US.UTF-8 export LANG=en_US.UTF-8 ``` #### 二、安装 ROS Foxy Desktop 1. **添加 ROS 2 软件源** 使用清华大学开源镜像加速下载: ```bash sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] https://mirrors.tuna.tsinghua.edu.cn/ros2/ubuntu $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null ``` 2. **安装桌面完整版** 包括 ROS、RViz、演示程序及核心工具: ```bash sudo apt update sudo apt install ros-foxy-desktop python3-argcomplete ``` 安装完成后,运行 `ros2 --help` 验证是否成功[^3]。 #### 三、可选配置 1. **Docker 安装方式(适用于隔离环境)** - 安装 Docker: ```bash sudo apt install docker.io sudo systemctl enable --now docker ``` - 拉取 ROS Foxy 镜像并运行: ```bash docker pull osrf/ros:foxy-desktop docker run -it osrf/ros:foxy-desktop ``` 2. **配置 DDS 实现** ROS Foxy 默认使用 Fast RTPS,如需切换为 Cyclone DDS 或 RTI Connext: ```bash sudo apt install ros-foxy-rmw-connext-cpp # RTI Connext export RMW_IMPLEMENTATION=rmw_connext_cpp # 切换 DDS ``` #### 四、使用教程 1. **官方资源** - [ROS 2 Foxy 官方文档](https://docs.ros.org/en/foxy/):涵盖基础概念、节点通信等。 - 古月居教程:中文社区教程,适合快速入门。 2. **运行示例** - 启动 Talker-Listener Demo: ```bash source /opt/ros/foxy/setup.bash ros2 run demo_nodes_cpp talker # 终端1 ros2 run demo_nodes_py listener # 终端2 ``` #### 五、注意事项 - 若安装后无法找到命令,检查环境变量是否生效(`source /opt/ros/foxy/setup.bash`)。 - 使用 Docker 时需映射端口或挂载目录以实现 GUI 工具(如 RViz)[^3]。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值