ubuntu18.04安裝ROS Melodic(二)


ubuntu18.04安裝ROS Melodic

⒈ 添加ROS軟件源

國外的ROS軟件源:

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

國內的ROS軟件源,速度快:

1 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'

 

清華的軟件源:

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

 

選擇其中的一個軟件源即可,本教程選擇的第二個。輸入命令后,會提示輸入用戶密碼,輸入密碼即可。

 

2. 設置密鑰

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

 

會有以下輸出信息:

1 Executing: /tmp/apt-key-gpghome.mlvFNotKlF/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys F42ED6FBAB17C654
2 gpg: 密鑰 F42ED6FBAB17C654:“Open Robotics <info@osrfoundation.org>”未改變
3 gpg: 合計被處理的數量:1
4 gpg:              未改變:1
5 
6 密鑰是 F42ED6FBAB17C654

 

3.更新

1 sudo apt-get update

 

確保 apt-get 是最新版本的。如果需要更新apt,就用sudo apt update。兩條命令相似,但是sudo apt update 命令不僅更新存儲庫索引,還告知存儲庫中是否可用軟件以及有多少新版本可用。

apt-get和apt的命令對比:

APT-GET APT 功能
apt-get apt 安裝軟件包
apt-get remove apt remove 刪除軟件包
apt-get remove apt remove 更換所有包
apt-get purge aptpurge 移除軟件包及配置文件
apt-get upgrade apt upgrade 更新所有軟件包(自動處理依賴項)
apt-get autoremove apt autoremove 自動刪除不需要的包
apt-get dist-upgrade apt full-upgrade 在升級軟件包時自動處理依賴關系
apt-cache search apt search 搜索應用程序
apt-cache show apt show 顯示裝細節
新的APT命令 功能
apt list 列出包含條件的包(已安裝,可升級等)
apt edit-sources 編輯源列表

參考博客:https://www.eet-china.com/mp/a36246.html

 

3*安裝最新版cmake

首先,檢查cmake的版本:

1 cmake --version
 

然后,如果已經安裝了cmake並且版本較低,需要卸載:

1 sudo apt-get autoremove cmake
 

接下來,安裝最新版本cmake:

1 sudo apt install cmake
 

最后,通過cmake版本號檢查一下:

1 cmake --version
 

4. ROS-Melodic 桌面完整版安裝

1 sudo apt-get install ros-melodic-desktop-full
 

這條命令需要執行很久,可能需要3小時吧,我當時前前后后好像有3小時左右。

此時,我們需要學習如何掛起進程和解除掛起:

1 ctrl + z    #掛起進程
2 3 fg %1       #解除掛起
 

還需要把ubuntu設置為屏幕常量:

ubuntu18.04的中文版設置方式是:設置--電源--空白屏幕 ,隱私--自動鎖屏。

 

桌面完整版安裝成功后,順便安裝一下 rqt 工具:

1 sudo apt-get install ros-melodic-rqt*
 

5. rosdep初始化

先安裝 rosdep 命令,確保有 rosdep :

1 sudo apt install python-rosdep   
 

然后進行初始化:

1 sudo rosdep init
 

5* rosdep 更新

1 rosdep update
 

親測多次后,發現 終端有梯子后,以上這句命令直接一次性通過!!

 

以下這種方法,多次運行 rosdep update 我也成功過:

當出現time out 錯誤的時候,可以考慮用手機熱點連接運行以上這句命令,會出現以下錯誤:

ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml]:
<urlopen error [Errno 111] Connection refused> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml)
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml]:
<urlopen error [Errno 111] Connection refused> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml)
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml]:
<urlopen error [Errno 111] Connection refused> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml)
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml]:
<urlopen error [Errno 111] Connection refused> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml)
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml]:
Failed to download target platform data for gbpdistro:
<urlopen error [Errno 111] Connection refused>
Query rosdistro index https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml
ERROR: error loading sources list:
<urlopen error <urlopen error [Errno 111] Connection refused> (https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml)>

方法:可以修改resolv.conf文件的服務器信息,再更新 apt-get 和 rosdep 即可:

1 sudo gedit /etc/resolv.conf
 

將原有的nameserver這一行注釋,並添加 google 域名服務器:

1 nameserver 8.8.8.8 #google域名服務器
2 nameserver 8.8.4.4 #google域名服務器
 

保存文件並退出,執行更新命令,不報錯就成功了:

1 sudo apt-get update
2 rosdep update
 

參考博客:https://blog.csdn.net/mrh1714348719/article/details/103803110

 

6. 添加 ROS-Melodic 環境變量(跳過,后面再運行)

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

 

7.安裝rosinstall

為了管理我們自己的ROS-Melodic工作空間,需要安裝rosinstall:

1 sudo apt-get install python-rosinstall python-rosinstall-generator python-wstool build-essential

安裝成功后,再安裝一下ROS插件(包括3D包圍框):

1 sudo apt install ros-melodic-jsk-rviz-plugins
 

8. 小海龜實例

第一次啟動ROS之前,必須進行ROS-Melodic 環境變量的配置,執行如下命令:

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

在第一個終端里面運行:

1 roscore
 

在第二個終端(打開第二個終端的方法是點擊終端左上角 文件--新建標簽頁)里面運行,會出現一只靜止的小海龜:

1 rosrun turtlesim turtlesim_node
 

在第三個終端里面運行讓海龜可以移動:

1 rosrun turtlesim turtle_teleop_key
 

rosrun是運行單個節點,turtlesim是文件夾,里面含有turtle_teleop_key。

鍵盤上面的“上下左右” 小海龜移動情況
前進
后退
原地向左轉
原地向右轉

運行成功截圖如下:

 

 

卸載ROS-Melodic

1 sudo apt-get remove ros-melodic-*
 

沒必要就不用卸載了,安裝也挺費時間的。

 

 

參考博客:https://blog.csdn.net/qq_44830040/article/details/106049992

https://www.guyuehome.com/10082

https://blog.csdn.net/qq_41450811/article/details/99079041


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM