Ubuntu18.04下安裝ROS Melodic

本文主要針對在Ubuntu18.04下安裝ROS Melodic版本時所做的一些記錄,並給出一些問題的解決方案。

安裝時間:2019-11-06

之前在Ubuntu16.04下安裝ROS Kinetic時怎麼安裝怎麼順,沒想到在Ubuntu18.04下安裝ROS Melodic時卻折騰了我好久。因此本文則詳細記錄我安裝過程中的一些操作,並給出一些問題解決方案。

詳細安裝流程在很多博客上都有呈現,此處就不詳細摘抄了,只是簡單走一下完整的流程。這些流程都是在我電腦上成功的操作。

同步Ubuntu和Windows系統時間

如果你是Windows和Ubuntu雙系統,有必要首先執行該步驟。雖然不確定該步驟對於最終成功安裝ROS有沒有用,但是最好還是同步一下,因爲有資料看到說雙系統時間不同步確實也是安裝ROS不成功的一個原因。

sudo apt-get install ntpdate
sudo nptdate time.windows.com

然後將本地時間更新到硬件上:

sudo hwclock --localtime --systohc

添加軟件源

該步驟的目的是允許你的電腦能夠接受ROS相關軟件的安裝和更新。
國外源:

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

推薦國內源:

sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.ustc.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'

設置密鑰

注意密鑰好像有變化,我使用的最新的密鑰如下:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F42ED6FBAB17C654

安裝ROS

sudo apt-get update
sudo apt-get install ros-melodic-desktop-full
安裝其他必要庫:
sudo apt-get install python-rosdep
sudo apt-get install python-rosinstall

這個安裝過程時間比較長,我裝了將近半個小時,需要有耐心和一個好的Wifi!

初始化rosdep

sudo rosdep init
rosdep update

添加ROS環境變量

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

常見錯誤

1、sudo rosdep init或rosdep update報錯

ERROR: cannot download default sources list from:
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
Website may be down.

在這裏插入圖片描述
這個錯誤參考了很多的資料,有各種解決方案,最終總結起來不外乎以下幾種:
(1)

sudo apt-get install ca-certificates
sudo c_rehash /etc/ssl/certs
sudo -E rosdep init
rosdep update

然而對我來說這個方案並不起作用。
(2)我成功的解決方案
前提條件:

  • 需要一個好網,網絡不好其實也會一直失敗;
  • 更換軟件下載服務器,最好使用國內的服務器

然後進入到網站(需要科學上網才能打開,或者直接複製我下面的內容):https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list,會有以下內容:

# os-specific listings first
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml osx

# generic
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
gbpdistro https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml fuerte

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

然後執行以下命令:

sudo mkidr -p /etc/ros/rosdep/sources.list.d
cd /etc/ros/rosdep/sources.list.d
sudo gedit 20-default.list

然後把上述網站中的內容複製到20-default.list文件中,以上所有操作就等同於執行sudo rosdep init。然後直接執行:

rosdep update

如果不出意外的話就能成功(關鍵是要網好,多試幾次): 在這裏插入圖片描述
網不好的話,會出現如下的錯誤: 在這裏插入圖片描述
注意:以上第(2)條解決方案其實是參考本文最後的參考文章4中的方案,但我並沒有把20-default.list中的raw.githubusercontent.com替換成raw.githuhub.com

【參考】:
1、Ubuntu18.04下安裝ROS
2、ubuntu18.04安裝ROS Melodic(最詳細配置)
3、ubuntu 18.04 LTS 安裝ROS系統
4、sudo rosdep init ERROR: cannot download default sources list from

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章