ROS | iron版本安装和简单运行

本文详细指导如何在Ubuntu系统中设置支持UTF-8的locale,添加ROS2apt仓库,安装turtlesim和rqt工具,以及进行环境配置和后续操作,包括启动、控制、服务调用和模拟器关闭等。

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

System setup

ubuntu(Debian packages)

set locale

Make sure you have a locale which supports UTF-8.

locale  #check for UTF-8

sudo apt update && sudo apt install locales
sudo locale-gen en_US en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8


locale # verify setting

Enable required repositories

need to add the ROS2 apt repository to your system
ensure that the ubuntu universe repository is enabled

sudo apt install software-properties-common
sudo add-apt-repository universe

Now add the ROS2 GPG key with apt

sudo apt update && sudo apt install curl -y
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] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null

if you can’t download it, please alter hosts document: sudo gedit /etc/hosts
to write: XX.XX.XX raw.githubusercontent.com
you must to confirm the IP address of this domain name

install ROS2

Update your apt repository caches after setting up the repositories.

sudo apt update

can install desktop
sudo apt install ros-iron-desktop

Setup environment

source /opt/ros/iron/setup.bash

Next steps

Use the ROS1 bridge(optional)

Uninstall

uninstall ROS2

sudo apt remove ~nros-iron-* && sudo apt autoremove

you may also want to remove the repository

sudo rm /etc/apt/sources.list.d/ros2.list
sudo apt update
sudo apt autoremove
# Consider upgrading for packages previously shadowed.
sudo apt upgrade

使用turtlesim、ros2、rqt

task

1. install turtlesim

sudo apt update
sudo apt install ros-iron-turtlesim

you also check the package is installed:
ros2 pkg executables turtlesim

The above command should return a list of turtlesim’s executables:

turtlesim draw_square
turtlesim mimic
turtlesim turtle_teleop_key
turtlesim turtlesim_node

2. Start turtlesim

To start turtlesim, enter the following command in your terminal:

ros2 run turtlesim turtlesim_node

3. Use turtlesim

Open a new terminal and source ROS2 again.

Now run a new node to control the turtle in the first node.
ros2 run turtlesim turtle_teleop_key

At this point you should have three windows open: a terminal running turtlesim_node, a terminal running turtle_teleop_key and the turtlesim window. Arrange these windows so that you can see the turtlesim window, but also have the terminal running turtle_teleop_key active so that you can control the turtle in turtlesim.
Use the arrow keys on your keyboard to control the turtle. It will move around the screen, using its attached “pen” to draw the path it followed so far.

4. Install rqt

sudo apt update

sudo apt install ~nros-iron-rqt*

run it.

rqt

5. Use rqt

When running rqt for the first time, the window will be blank. No worries; just select Plugins > Services > Service Caller from the menu bar at the top.

5.1 try the spawn service

Let’s use rqt to call the /spawn service. You can guess from its name that /spawn will create another turtle in the turtlesim window.

Give the new turtle a unique name, like turtle2, by double-clicking between the empty single quotes in the Expression column. You can see that this expression corresponds to the value of name and is of type string.

Next enter some valid coordinates at which to spawn the new turtle, like x = 1.0 and y = 1.0.

To spawn turtle2, you then need to call the service by clicking the Call button on the upper right side of the rqt window.

If the service call was successful, you should see a new turtle (again with a random design) spawn at the coordinates you input for x and y.

If you refresh the service list in rqt, you will also see that now there are services related to the new turtle, /turtle2/…, in addition to /turtle1/…

5.2 Try the set_pen service

Now let’s give turtle1 a unique pen using the /set_pen service:

The values for r, g and b, which are between 0 and 255, set the color of the pen turtle1 draws with, and width sets the thickness of the line.

To have turtle1 draw with a distinct red line, change the value of r to 255, and the value of width to 5. Don’t forget to call the service after updating the values.

If you return to the terminal where turtle_teleop_key is running and press the arrow keys, you will see turtle1’s pen has changed.
You’ve probably also noticed that there’s no way to move turtle2. That’s because there is no teleop node for turtle2.

6 close turtlesim

To stop the simulation, you can enter Ctrl + C in the turtlesim_node terminal, and q in the turtle_teleop_key terminals.

<think>好的,用户现在想了解如何安装ROS 2。之前我已经介绍了ROS 2的基本信息,现在需要提供一个安装教程。首先,我要确定用户的操作系统环境,因为ROS 2支持不同的平台,但最常见的还是Ubuntu。所以可能默认以Ubuntu为例,同时考虑是否需要提到其他系统如Windows或macOS。 用户可能对Linux系统有一定了解,但不一定熟悉具体命令,所以步骤要详细。需要检查他们使用的Ubuntu版本,因为不同ROS 2发行版对应不同的Ubuntu版本。例如,Humble Hawksbill支持Ubuntu 22.04,而最新的Iron Irwini可能对应更新的系统。需要列出常见的版本对应关系,方便用户确认。 接下来,安装步骤通常包括设置软件源、安装ROS 2包、配置环境变量等。要注意是否需要安装桌面版或基础版,用户可能更倾向于桌面版,因为它包含更多工具。然后要确保用户知道如何启用ROS 2的环境,比如通过source命令。 另外,用户可能会遇到依赖问题或网络问题,所以需要提醒他们更新系统安装必要的依赖,比如Python库。测试安装是否成功的部分也很重要,例如运行示例的发布者订阅者节点,这能帮助用户验证安装是否正确。 还要考虑用户可能的错误情况,例如密钥问题、软件源无法访问等,可能需要提供备选方案或解决方案。同时,是否需要指导他们安装额外的工具,比如colcon构建工具或Gazebo仿真环境,这取决于用户的具体需求,但可以先保持教程简洁,后续再根据需求扩展。 最后,要确保语言清晰,步骤分点明确,代码块正确展示命令,避免用户混淆。可能还需要给出官方文档链接,供用户进一步参考。整个过程要考虑到用户的技能水平,尽量详细但不过于复杂,确保他们能一步步顺利完成安装。</think>以下是ROS 2的详细安装教程(以**Ubuntu系统**为例,其他系统可参考官方文档调整): --- ### 一、环境准备 1. **确认Ubuntu版本** ROS 2不同发行版需对应特定Ubuntu版本。例如: - **Humble Hawksbill** → Ubuntu 22.04 (Jammy) - **Foxy Fitzroy** → Ubuntu 20.04 (Focal) - **Iron Irwini** → Ubuntu 22.04 (Jammy) (推荐使用长期支持版LTS,本文以**Humble**为例) 2. **更新系统** 打开终端执行: ```bash sudo apt update && sudo apt upgrade -y ``` --- ### 二、安装ROS 2 #### 步骤1:设置软件源 1. 添加ROS 2 GPG密钥: ```bash sudo apt install curl gnupg lsb-release curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add - ``` 2. 添加ROS 2仓库: ```bash sudo sh -c 'echo "deb [arch=$(dpkg --print-architecture)] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" > /etc/apt/sources.list.d/ros2.list' ``` #### 步骤2:安装核心包 1. 更新仓库并安装ROS 2基础包: ```bash sudo apt update sudo apt install ros-humble-desktop # 桌面版(含GUI工具) # 或选择轻量版:sudo apt install ros-humble-ros-base ``` #### 步骤3:配置环境变量 1. 将ROS 2命令添加到终端: ```bash echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc source ~/.bashrc ``` --- ### 三、验证安装 1. **测试通信** 打开两个终端窗口,分别运行: ```bash # 终端1:发布消息 ros2 run demo_nodes_cpp talker # 终端2:订阅消息 ros2 run demo_nodes_cpp listener ``` **若看到`"Hello World"`输出,则安装成功。** 2. **查看版本** ```bash ros2 --version # 应显示humble或其他已安装版本 ``` --- ### 四、可选工具安装 1. **编译工具** 安装`colcon`构建系统: ```bash sudo apt install python3-colcon-common-extensions ``` 2. **开发依赖** 安装常用工具: ```bash sudo apt install python3-rosdep sudo rosdep init rosdep update ``` --- ### 五、常见问题解决 1. **密钥错误** 若报错`NO_PUBKEY`,手动添加密钥: ```bash sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys <缺失的密钥ID> ``` 2. **网络问题** 可尝试切换镜像源(如清华源)或使用代理。 3. **Windows/macOS安装** - **Windows**:通过Chocolatey或二进制包安装(需WSL2支持) - **macOS**:使用Homebrew或源码编译(兼容性较差) --- ### 六、官方资源 - **文档**:[ROS 2 Humble Documentation](https://docs.ros.org/en/humble/) - **教程**:[ROS 2 Tutorials](https://docs.ros.org/en/humble/Tutorials.html) - **社区支持**:[ROS Answers](https://answers.ros.org/) --- 通过以上步骤,您已成功安装ROS 2!下一步建议从**创建第一个工作空间****编写简单节点**开始实践。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

suiuko

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值