• class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="2">
  • class="hljs-ln-code"> class="hljs-ln-line">Distributor ID: Ubuntu
  • class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="3"> class="hljs-ln-code"> class="hljs-ln-line">Description: Ubuntu 24.04.2 LTS
  • class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="4"> class="hljs-ln-code"> class="hljs-ln-line">Release: 24.04
  • class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="5"> class="hljs-ln-code"> class="hljs-ln-line">Codename: noble
  • class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}" onclick="hljs.signin(event)">

    2.选择与操作系统对应的ROS2版本

    进入ROS Documentation ROS2官网页面

    选择对应的ROS2版本,具体版本区别见ROS官网描述信息

    3.安装

    参考官网的安装步骤Ubuntu (Debian packages) — ROS 2 Documentation: Rolling documentation

    设置语言环境

    请确保您有一个支持 UTF-8 .如果您处于最小环境(例如 docker 容器)中,则区域设置可能是最小值,例如 POSIX .我们使用以下设置进行测试。但是,如果您使用的是不同的 UTF-8 支持的区域设置,这应该没问题。

    1. class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1"> class="hljs-ln-code"> class="hljs-ln-line">locale # check for UTF-8
    2. class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="2"> class="hljs-ln-code"> class="hljs-ln-line">
    3. class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="3"> class="hljs-ln-code"> class="hljs-ln-line">sudo apt update && sudo apt install locales
    4. class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="4"> class="hljs-ln-code"> class="hljs-ln-line">sudo locale-gen en_US en_US.UTF-8
    5. class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="5"> class="hljs-ln-code"> class="hljs-ln-line">sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
    6. class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="6"> class="hljs-ln-code"> class="hljs-ln-line">export LANG=en_US.UTF-8
    7. class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="7"> class="hljs-ln-code"> class="hljs-ln-line">
    8. class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="8"> class="hljs-ln-code"> class="hljs-ln-line">locale # verify settings
    class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}" onclick="hljs.signin(event)">

    启用所需的存储库

    您需要将 ROS 2 apt 存储库添加到您的系统中。

    首先,确保已启用 Ubuntu Universe 存储库。

    1. class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1"> class="hljs-ln-code"> class="hljs-ln-line">sudo apt install software-properties-common
    2. class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="2"> class="hljs-ln-code"> class="hljs-ln-line">sudo add-apt-repository universe
    class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}" onclick="hljs.signin(event)">

    现在使用 apt 添加 ROS 2 GPG 密钥。

    1. class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1"> class="hljs-ln-code"> class="hljs-ln-line">sudo apt update && sudo apt install curl -y
    2. class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="2"> class="hljs-ln-code"> class="hljs-ln-line">sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
    class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}" onclick="hljs.signin(event)">

    注:raw.githubusercontent.com 添加密钥事时可能出现超时情况,打开网站https://www.ipaddress.com/输入raw.githubusercontent.com进行查询

    进入Ubuntu命令行 添加本地路由表

    sudo vim /etc/hosts

    添加后再次运行第二条指令

    然后将存储库添加到源列表。

    echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}" onclick="hljs.signin(event)">

    安装开发工具(可选)

    如果你要构建ROS包或以其他方式进行开发,你也可以安装开发工具。

    sudo apt update && sudo apt install ros-dev-tools class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}" onclick="hljs.signin(event)">

    安装 ROS 2

    设置仓库后,更新 apt 仓库缓存。

    sudo apt update class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}" onclick="hljs.signin(event)">

    ROS 2 软件包建立在经常更新的 Ubuntu 系统上。始终建议您在安装新软件包之前确保您的系统是最新的。

    sudo apt upgrade class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}" onclick="hljs.signin(event)">

    1.桌面安装(推荐):ROS、RViz、演示、教程。

    sudo apt install ros-rolling-desktop class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}" onclick="hljs.signin(event)">

    2.ROS-Base Install(裸):通信库、消息包、命令行工具。没有 GUI 工具。

    sudo apt install ros-rolling-ros-base class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}" onclick="hljs.signin(event)">
    安装其他 RMW 实现(可选)

    The default middleware that ROS 2 uses is Fast DDS, but the middleware (RMW) can be replaced at runtime. See the guide on how to work with multiple RMWs.
    ROS 2 默认使用的中间件是 Fast DDS ,但中间件 (RMW) 可以在运行时替换。请参阅有关如何使用多个 RMW 的指南。

    设置环境

    通过获取以下文件来设置您的环境。

    1. class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1"> class="hljs-ln-code"> class="hljs-ln-line"># Replace ".bash" with your shell if you're not using bash
    2. class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="2"> class="hljs-ln-code"> class="hljs-ln-line"># Possible values are: setup.bash, setup.sh, setup.zsh
    3. class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="3"> class="hljs-ln-code"> class="hljs-ln-line">source /opt/ros/rolling/setup.bash
    class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}" onclick="hljs.signin(event)">

    尝试一些例子

    如果您安装了 ros-rolling-desktop 上面,您可以尝试一些示例。

    在一个终端中,获取设置文件,然后运行 C++ talker

    1. class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1"> class="hljs-ln-code"> class="hljs-ln-line">source /opt/ros/rolling/setup.bash
    2. class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="2"> class="hljs-ln-code"> class="hljs-ln-line">ros2 run demo_nodes_cpp talker
    class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}" onclick="hljs.signin(event)">

    在另一个终端源中,设置文件,然后运行 Python listener

    1. class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1"> class="hljs-ln-code"> class="hljs-ln-line">source /opt/ros/rolling/setup.bash
    2. class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="2"> class="hljs-ln-code"> class="hljs-ln-line">ros2 run demo_nodes_py listener
    class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}" onclick="hljs.signin(event)">

    你应该看到“这是 Publishing 消息”这句话 talkerlistener 以及说 I heard 那些消息的说法。这将验证 C++ 和 Python API 是否正常工作。万岁!

    卸载

    如果您需要卸载 ROS 2 或在已从二进制文件安装后切换到基于源代码的安装,请运行以下命令:

    sudo apt remove ~nros-rolling-* && sudo apt autoremove class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}" onclick="hljs.signin(event)">

    您可能还需要删除存储库:

    1. class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1"> class="hljs-ln-code"> class="hljs-ln-line">sudo rm /etc/apt/sources.list.d/ros2.list
    2. class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="2"> class="hljs-ln-code"> class="hljs-ln-line">sudo apt update
    3. class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="3"> class="hljs-ln-code"> class="hljs-ln-line">sudo apt autoremove
    4. class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="4"> class="hljs-ln-code"> class="hljs-ln-line"># Consider upgrading for packages previously shadowed.
    5. class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="5"> class="hljs-ln-code"> class="hljs-ln-line">sudo apt upgrade
    class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}" onclick="hljs.signin(event)">
    data-report-view="{"mod":"1585297308_001","spm":"1001.2101.3001.6548","dest":"https://blog.csdn.net/qq_29795941/article/details/140713156","extend1":"pc","ab":"new"}">>
    注:本文转载自blog.csdn.net的白水鉴心丶的文章"https://blog.csdn.net/qq_29795941/article/details/140713156"。版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。如有侵权,请联系我们删除。
    复制链接

    评论记录:

    未查询到任何数据!