WSL2+ubuntu-22+ROS2(humble)安装

前提:WSL设置好代理:export ALL_PROXY="http://172.29.32.1:9999"

1)下载ros安全key

sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg

2)设置apt源

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(source /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null

3)更新源

sudo apt update

4)安装humble桌面

sudo apt install ros-humble-desktop

此处大概安装2.8G内容,需要10分钟左右

5)把ros2环境设置脚本放到.bashrc,每次打开console时自动设置

echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc source ~/.bashrc

6)验证安装

$ cd /opt/ros/humble/lib/demo_nodes_cpp/

$ ros2 run demo_nodes_cpp talker

如果能看到:

[INFO] [1731684725.255266976] [talker]: Publishing: 'Hello World: 1'
[INFO] [1731684735.006586720] [talker]: Publishing: 'Hello World: 2'
[INFO] [1731684727.233476009] [talker]: Publishing: 'Hello World: 3'
[INFO] [1731684728.233519208] [talker]: Publishing: 'Hello World: 4'
[INFO] [1731684729.233587407] [talker]: Publishing: 'Hello World: 5'
[INFO] [1731684730.233339296] [talker]: Publishing: 'Hello World: 6'
[INFO] [1731684740.006937224] [talker]: Publishing: 'Hello World: 7'
[INFO] [1731684732.267169557] [talker]: Publishing: 'Hello World: 8'
[INFO] [1731684733.267418962] [talker]: Publishing: 'Hello World: 9'
[INFO] [1731684734.267358958] [talker]: Publishing: 'Hello World: 10'

那就是成功了。

7)GUI显示小海龟

开一个console,运行:

$ ros2 run turtlesim turtlesim_node

此时应该能看到一个小海龟窗口出现。

再开一个console,运行:

$ ros2 run turtlesim turtle_teleop_key

Reading from keyboard
---------------------------
Use arrow keys to move the turtle.
Use G|B|V|C|D|E|R|T keys to rotate to absolute orientations. 'F' to cancel a rotation.
'Q' to quit.

可以通过不同按键控制小海龟。

 

 


欢迎转载,本文地址: https://blog.prodrich.com/detail/88/

带着使命来到世上的你,给他人提供价值,才有价值