目录
一、ROS2版本与ubuntu版本之间的对应关系
二、安装与配置
1.备份并替换中科大源:
2、安装源设定
3、安装ros2
4、环境配置
5、ros2命令的自动补全
6、通信测试
三、编译工作空间
1、按着古月居21讲步骤安装依赖
2、创建编译工作空间
3、设置环境变量
ROS2版本 | 发布时间 | 维护截止时间 | Ubuntu版本 |
---|---|---|---|
Ardent Apalone | 2017.12 | 2018.12 | Ubuntu 16.04(Xenial Xerus) |
Bouncy Bolson | 2018.7 | 2019.7 | Ubuntu 16.04(Xenial Xerus)、Ubuntu 18.04 (Bionic Beaver) |
Crystal Clemmys | 2018.12 | 2019.12 | Ubuntu 18.04 (Bionic Beaver) |
Dashing Diademata | 2019.5 | 2021.5 | Ubuntu 18.04 (Bionic Beaver) |
Eloquent Elusor | 2019.11 | 2020.11 | Ubuntu 18.04 (Bionic Beaver) |
Foxy Fitzroy | 2020.6 | 2023.5 | Ubuntu 20.04 (Focal Fossa) |
Galactic Geochelone | 2021.5 | 2022.11 | Ubuntu 20.04 (Focal Fossa) |
Humble Hawksbill | 2022.5 | 2027.5 | Ubuntu 22.04 (Jammy Jellyfish) |
sudo cp /etc/apt/sources.list /etc/apt/sources.list.back
sudo gedit /etc/apt/sources.list
ubuntu 18.04 :
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
ubuntu 20.04:
deb https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
## Pre-released source, not recommended.
# deb https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
1)添加密钥
ubuntu 18.04
sudo apt update && sudo apt install curl gnupg2 lsb-release
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
ubuntu20.04
sudo apt update && sudo apt install curl gnupg2 lsb-release
curl -s https://gitee.com/ohhuo/rosdistro/raw/master/ros.asc | sudo apt-key add -
2)安装源添加
sudo sh -c 'echo "deb [arch=amd64,arm64] http://packages.ros.org/ros2/ubuntu `lsb_release -cs` main" > /etc/apt/sources.list.d/ros2-latest.list'
sudo apt update
sudo apt install ros-eloquent-desktop #ubuntu18.04
(或者使用基础版:sudo apt install ros-eloquent-ros-base)
sudo apt install ros-foxy-desktop # ubuntu 20.04
sudo apt install ros-galactic-desktop # ubuntu 20.04
sudo apt remove ros-foxy-* && sudo apt autoremove
echo "source /opt/ros/eloquent/setup.bash" >> ~/.bashrc
echo "source /opt/ros/foxy/setup.bash" >> ~/.bashrc
echo "source /opt/ros/galactic/setup.bash" >> ~/.bashrc
sudo apt install python3-argcomplete
开一个终端:ros2 run demo_nodes_cpp talker
再开一个终端:ros2 run demo_nodes_py listene
sudo apt install -y python3-pip
sudo pip3 install rosdepc #选择热点
sudo rosdepc init
rosdepc update
cd ..
rosdepc install -i --from-path src --rosdistro eloquent -y
依赖安装完成后,就可以使用如下命令编译工作空间啦,如果有缺少的依赖,或者代码有错误,编译过程中会有报错,否则编译过程应该不会出现任何错误:
sudo apt install python3-colcon-ros
mkdir -p ~/dev_ws/src
cd ~/dev_ws/src
git clone https://gitee.com/guyuehome/ros2_21_tutorials.git
cd ..
colcon build
编译成功后,为了让系统能够找到我们的功能包和可执行文件,还需要设置环境变量:
source install/local_setup.sh # 仅在当前终端生效
echo " source ~/dev_ws/install/local_setup.sh" >> ~/.bashrc # 所有终端均生效
至此,我们就完成了工作空间的创建、编译和配置。