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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

suiuko

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

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

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

打赏作者

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

抵扣说明:

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

余额充值