根据 官网,可找到已安装好的Ubuntu20.04适合的 版本和安装步骤,所以我的工作主要是记录我干了什么。
〇、确定系统,选定版本(版本选择指导)
(理由:“Installing from Debian packages is the recommended method. It’s more convenient because it installs its necessary dependencies automatically. It also updates alongside regular system updates.”)
一、根据安装步骤,首先确定自己电脑是否支持UTF-8编码
fan@fan-HP-ProBook-440-G2:~$ echo $LANG
en_US.UTF-8
OK 跳过这个 Set locale 步骤
二、添加ROS 2 仓库
需要将ROS 2 apt存储库添加到系统中。
1、首先授权密钥(authorize our GPG key with apt like this:)
fan@fan-HP-ProBook-440-G2:~$ sudo apt update && sudo apt install curl gnupg2 lsb-release
稍加等待,下载和安装完成
fan@fan-HP-ProBook-440-G2:~$ curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
OK
在实现的时候遇到 gpg:no valid openpgp data found 的问题,发现链接被墙啦;
解决方法:
rosdep init 或者rosdep update 连接错误的解决办法
问题1:ERROR: unable to process source https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc 之类的错误,可能是因为raw.githubusercontent.com网站被墙了。
解决方法:修改hosts文件,添加这个网站的ip地址。
#打开hosts文件
sudo gedit /etc/hosts
#在文件末尾添加
151.101.84.133 raw.githubusercontent.com
2、然后把这个仓库添加到自己的源列表中
fan@fan-HP-ProBook-440-G2:~$ 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-latest.list'
三、 安装 ROS 2 包
1、Update your apt repository caches after setting up the repositories.
fan@fan-HP-ProBook-440-G2:~/ros2_foxy$ sudo apt update
为什么会出现这个奇怪的路径呢,因为我看错教程了……执行到了 源代码安装的 vcs import src < ros2.repos 这个命令,执行了一半,不知道之后会不会出问题。可能需要执行一下源代码安装教程的最后一部——卸载……
2、Desktop Install (Recommended): ROS, RViz, demos, tutorials.
fan@fan-HP-ProBook-440-G2:~/ros2_foxy$ sudo apt install ros-foxy-desktop
3、ROS-Base Install (Bare Bones): Communication libraries, message packages, command line tools. No GUI tools.
fan@fan-HP-ProBook-440-G2:~$ sudo apt install ros-foxy-ros-base
我在这一步之前执行了那个卸载步骤 (fan@fan-HP-ProBook-440-G2:~$ rm -rf ~/ros2_foxy)
四、环境配置
1、让启动脚本生效(在使用ROS的每个bash终端中获取此脚本的源代码)
Set up your environment by sourcing the following file.
fan@fan-HP-ProBook-440-G2:~$ source /opt/ros/foxy/setup.bash
2、安装argcomplete(可选)
(ROS 2 command line tools use argcomplete to autocompletion. So if you want autocompletion, installing argcomplete is necessary.)
fan@fan-HP-ProBook-440-G2:~$ sudo apt install python3-argcomplete
五、尝试一些例子
例一:
结果:
![发送和接收](https://img-blog.csdnimg.cn/2020072714512836.png)
例子二:
![小海龟画矩形的例子](https://img-blog.csdnimg.cn/20200727150743701.png)
![](https://img-blog.csdnimg.cn/20200727151255134.png)
成功!
ps:可以配置一下环境变量,在~/.bashrc 文件中加入 source /opt/ros/foxy/setup.bash 。这样就可以不需要每次打开新的终端都执行source命令了
方法一:
vim ~/.bashrc , 加入 source /opt/ros/foxy/setup.bash
方法二:
echo "source /opt/ros/foxy/setup.bash" >> ~/.bashrc
source ~/.bashrc