ros ros2

ubuntu20.04安装ros2

Posted on 2022-08-23,2 min read
封面图

本文简单介绍如何安装ros2(galactic版)。

设置镜像源

镜像源可设置国内的也可以设置官方的,可直接执行如下命令。

#官方源
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'
#清华源
sudo sh -c 'echo "deb [arch=$(dpkg --print-architecture)] http://mirror.tuna.tsinghua.edu.cn/ros2/ubuntu $(lsb_release -cs) main" > /etc/apt/sources.list.d/ros2.list'

安装ros的key

curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
或
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg

安装ros

设置源和key后,先更新一下,再搜索一下,看是否有我们需要的ros版本,然后再安装。

sudo apt update
sudo apt search ros-galactic-desktop
sudo apt install ros-galactic-desktop

配置环境变量

# 临时配置
source /opt/ros/galactic/setup.bash
# 设置配置文件
echo "source /opt/ros/galactic/setup.bash" >> ~/.bashrc

测试

使用ros2 run packname nodename可执行一个节点,以下命令可运行两个实例,talker发布,listener接收。

ros2 run demo_nodes_cpp talker
ros2 run demo_nodes_py listener

安装编译工具colcon

ros提供了一个编译工具colcon,安装命令如下

sudo apt install python3-colcon-common-extensions

如何卸载

sudo apt remove ros-galactic-* && sudo apt autoremove

参考

https://blog.csdn.net/qintianhaohao/article/details/111397957
https://mirror.tuna.tsinghua.edu.cn/help/ros2/
https://book.guyuehome.com/ROS2/1.%E7%B3%BB%E7%BB%9F%E6%9E%B6%E6%9E%84/1.3_ROS2%E5%AE%89%E8%A3%85%E6%96%B9%E6%B3%95/


下一篇: Ubuntu环境变量配置文件→

loading...