搭建ROS Kinetic,从Ubuntu虚拟机开始

零、前言

7月24日~7月25日配了两天ROS环境,遇到不少坑,中途电脑死机把虚拟机搞崩了,又重新搭建了一遍ROS环境,顺便把整个搭建的过程记录下来了,对网上的相关内容进行了总结和归纳。有不清楚的地方,大家可以去访问参考网站或者在评论区交流。

一、WMware下载及安装

https://zhuanlan.zhihu.com/p/616883406

1.1 访问wmware网站下载Workstation 17 Pro for Windows

https://www.vmware.com/products/workstation-pro/workstation-pro-evaluation.html

1.2 安装

1、双击运行VMware-workstation-full-{版本号}.exe

2、下一步

3、勾选我接受,下一步

4、勾选自动安装WHP,下一步

5、更改安装位置到自己喜欢的位置,勾选增强型键盘,将VW添加到PATH不变,下一步

6、取消勾选启动时检查更新,取消勾选加入体验计划,下一步

7、创建快捷方式不变,下一步

8、安装,等待进度条

9、进度条完成后,寻找合适的许可证许可证,进去,输入

https://appnee.com/vmware-workstation-pro-universal-license-keys-collection/

10、完成


二、Ubuntu安装

2.1 下载系统镜像

2.1.1 访问https://releases.ubuntu.com/16.04/

2.1.2 

(不推荐)直接下载ubuntu-16.04.7-desktop-amd64.iso

(推荐)或者找到并下载ubuntu-16.04.7-desktop-amd64.iso.torrent

使用迅雷打开ubuntu-16.04.7-desktop-amd64.iso.torrent文件进行下载

2.2 创建虚拟机

2.2.1打开WMware,新建虚拟机

2.2.1 选择典型,下一步

2.2.3 选择安装程序光盘映像文件,浏览,选择1.2下载好的系统镜像文件(*.iso),下一步

2.2.4 输入全名(随便取),用户名(简单点),密码(越简单越好),确认(和密码一样),下一步

2.2.5 虚拟机名称取好听点,位置放在自己喜欢的文件夹下一步

2.2.6 最大磁盘大小70GB-100GB,选择将虚拟磁盘拆分成多个文件,下一步

2.2.7 完成

2.2.8 启动虚拟机后,Ubuntu会初始化,有一个步骤可以skip,尽量skip,不然联网加载会耗时较久,然后进入系统


三、Ubuntu换源

3.1 系统设置换源

3.1.1 System Settings > Software & Updates

3.1.2 点开Download from右边的下拉列表,选择Other,向上拉选择China分类下mirrors.aliyun.com

3.1.3 确定,输入密码确定,点close,如果提示要更新,点更新即可

3.2 终端换源

https://developer.aliyun.com/mirror/ubuntu

3.2.1 由于系统设置换源中的源不一定好用,所以我们还可以进行终端换源

3.2.2 用gedit打开Ubuntu的网络源文件

sudo gedit /etc/apt/sources.list

3.2.3 复制以下内容粘贴(16.04)替换掉原来的内容:

deb https://mirrors.aliyun.com/ubuntu/ xenial main
deb-src https://mirrors.aliyun.com/ubuntu/ xenial main

deb https://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb-src https://mirrors.aliyun.com/ubuntu/ xenial-updates main

deb https://mirrors.aliyun.com/ubuntu/ xenial universe
deb-src https://mirrors.aliyun.com/ubuntu/ xenial universe
deb https://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb-src https://mirrors.aliyun.com/ubuntu/ xenial-updates universe

deb https://mirrors.aliyun.com/ubuntu/ xenial-security main
deb-src https://mirrors.aliyun.com/ubuntu/ xenial-security main
deb https://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb-src https://mirrors.aliyun.com/ubuntu/ xenial-security universe

3.2.4软件列表更新:

sudo apt update

3.3 设置中文界面

3.3.1 System Setting > Lauguage Support

3.3.2 一开始会提示语言支持不完全,Remind me later即可

3.3.3 点击Install/Remove Lauguage

3.3.4 勾选Chinese(Simplified),点击Apply

3.3.5 输入密码,等待加载完成

3.3.6 下拉Language for menus and windows这个列表,将汉语(中国)选中并拖到第一个(多试几次)

3.3.7 点击Apply System-Wide

3.3.8 将Keyboard input method system选为fcitx

3.3.9 注销(右上角设置图标 > Log Out… > 右边的Log Out),登录

3.3.10 重新登录之后会发现弹窗:“将标准文件夹更新到当前语言吗?”

        最好不要改,不然以后在终端中访问文件夹还要输入中文太麻烦了
        勾选不要再次询问我,单击保留旧的名称


四、ROS安装

https://developer.aliyun.com/mirror/ros
http://wiki.ros.org/cn/kinetic/Installation/Ubuntu

5.1 更换ROS源,运行

sudo gedit /etc/apt/sources.list.d/ros-latest.list

5.2 粘贴ROS阿里源,并保存关闭(阿里源来自https://developer.aliyun.com/mirror/ros)

deb https://mirrors.aliyun.com/ros/ubuntu/ xenial main

5.3 然后再输入如下命令,信任ROS的GPG Key,并更新索引

sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

sudo apt update

4、安装ROS桌面完整版,运行

sudo apt-get install ros-kinetic-desktop-full

(进入漫长的等待)
安装完成后进入下一章本地初始化

五、ROS本地初始化

ROS在初始化时需要访问GitHub上的资源,由于网络原因失败率很高,所以我们通过手动下载加修改文件的方式来进行本地化初始化

https://zhuanlan.zhihu.com/p/388629886
http://wiki.ros.org/cn/kinetic/Installation/Ubuntu


5.1 安装git

sudo apt install git

5.2 克隆仓库(可能因为网络环境原因失败,可以手动下载https://github.com/ros/rosdistro放入home)

git clone https://github.com/ros/rosdistro.git

5.3 本地新建对应目录

sudo mkdir -p /etc/ros/rosdep/sources.list.d

5.4 将克隆下来的 rosdistro 仓库中的 list 文件拷贝到上述目录

cd rosdistro

sudo cp rosdep/sources.list.d/20-default.list /etc/ros/rosdep/sources.list.d/

5.5 查找文件中的 https://raw.githubusercontent.com/ros/rosdistro/master 字段,
将其替换为本地 rosdistro 仓库的绝对路径,如用户名为cqx,file:///home/cqx/rosdistro

5.5.1 需要更改的文件有4个:

        /etc/ros/rosdep/sources.list.d/20-default.list
        /usr/lib/python2.7/dist-packages/rosdep2/gbpdistro_support.py
        /usr/lib/python2.7/dist-packages/rosdep2/rep3.py
        /usr/lib/python2.7/dist-packages/rosdistro/__init__.py

5.5.2 终端依次运行一下几行命令,手动修改,快捷键Ctrl+F进行查找然后替换。

sudo gedit /etc/ros/rosdep/sources.list.d/20-default.list
sudo gedit /usr/lib/python2.7/dist-packages/rosdep2/gbpdistro_support.py
sudo gedit /usr/lib/python2.7/dist-packages/rosdep2/rep3.py
sudo gedit /usr/lib/python2.7/dist-packages/rosdistro/__init__.py

5.5.3 例如用户名为cqx,rosdistro文件夹放在home下,修改后的20-default.list如下:

# os-specific listings first
yaml file:///home/cqx/rosdistro/rosdep/osx-homebrew.yaml osx

# generic
yaml file:///home/cqx/rosdistro/rosdep/base.yaml
yaml file:///home/cqx/rosdistro/rosdep/python.yaml
yaml file:///home/cqx/rosdistro/rosdep/ruby.yaml
gbpdistro file:///home/cqx/rosdistro/releases/fuerte.yaml fuerte

# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead

5.6 此时再进行初始化和更新

sudo rosdep init
rosdep update

5.7 ROS环境配置(如果每次打开一个新的终端时ROS环境变量都能够自动配置好(即添加到bash会话中),那将会方便很多)

sudo gedit ~/.bashrc

将以下内容加入到文件结尾:

# >>> ros start
source /opt/ros/kinetic/setup.bash
# <<< ros end

六、通过Anaconda创建Python虚拟环境

https://www.guyuehome.com/33763

6.1 下载并安装Anaconda

6.1.1 访问https://www.anaconda.com/download下载Anaconda3-{版本号}-Linux-x86_64.sh

将其拖入虚拟机放在home下即可

6.1.2 打开终端,运行

./Anaconda3-2023.07-1-Linux-x86_64.sh

(注意./后面为Anaconda3-{版本号}-Linux-x86_64.sh,确保和自己安装时安装包的名字一致)

6.1.3 出现 Please, press ENTER to continue

        在终端中按回车

6.1.4 出现 --更多--

        长按空格

6.1.5 出现 Do you accept the license terms? [yes|no]

        删掉多余的空格,输入yes,回车

6.1.6 出现
  - Press ENTER to confirm the location
  - Press CTRL-C to abort the installation
  - Or specify a different location below

        回车即可

6.1.7 出现by running conda init? [yes|no]

        输入yes回车

6.1.8 将conda改成每次不默认激活,否则会影响终端中原本的python环境(方法来自古月居)

sudo gedit ~/.bashrc

在文件末尾# <<< conda initialize <<<前面加上一行并粘贴

conda deactivate

6.2 更换anaconda源(来自https://developer.aliyun.com/mirror/anaconda)

6.2.1 运行

conda config --set show_channel_urls yes

sudo gedit ~/.condarc

6.2.2 用以下阿里源内容替换原本内容

channels:
  - defaults
show_channel_urls: true
default_channels:
  - http://mirrors.aliyun.com/anaconda/pkgs/main
  - http://mirrors.aliyun.com/anaconda/pkgs/r
  - http://mirrors.aliyun.com/anaconda/pkgs/msys2
custom_channels:
  conda-forge: http://mirrors.aliyun.com/anaconda/cloud
  msys2: http://mirrors.aliyun.com/anaconda/cloud
  bioconda: http://mirrors.aliyun.com/anaconda/cloud
  menpo: http://mirrors.aliyun.com/anaconda/cloud
  pytorch: http://mirrors.aliyun.com/anaconda/cloud
  simpleitk: http://mirrors.aliyun.com/anaconda/cloud

6.2.3 保存退出

6.3 创建python3.9环境
6.3.1 清理索引缓存

conda clean -i

6.3.2 创建环境(网络问题可能需要多试几次)

conda create -n py39 python=3.9

6.3.3 激活环境

conda activate py39

6.3.4 更换pypi源

6.3.4.1运行

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
sudo gedit .config/pip/pip.conf

6.3.4.2将以下阿里源(来自https://developer.aliyun.com/mirror/pypi)代替原本内容:

[global]
index-url = http://mirrors.aliyun.com/pypi/simple/

[install]
trusted-host=mirrors.aliyun.com

6.3.4.3 保存退出

6.4 安装python包(同样由于网络原因可能需要多试几次)

依次安装numpy pyyaml empy catkin_pkg rospkg

pip install numpy

pip install pyyaml

pip install empy

pip install catkin_pkg

pip install rospkg

全部安装完成后恭喜你,ROS Kinetic搭建已经OK了!

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

在C站取昵称真寄儿难

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

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

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

打赏作者

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

抵扣说明:

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

余额充值