Ubuntu18.04安装ROS详细步骤

ROS安装目录

1. 添加ROS软件源
2. 添加秘钥
3. 安装ROS
4. 初始化rosdep
5. 设置环境变量
6. 安装rosiinstall
7. 运行小海龟示例

1. 添加ROS软件源

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

2. 添加秘钥

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

3. 安装ROS

执行下面两条命令
sudo apt update
sudo apt install ros-melodic-desktop-full

如果出现无法定位软件包,则执行

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'

4. 初始化rosdep

执行下面两条命令
sudo rosdep init
rosdep update

rosdep update 命令执行成功的结果如下:

reading in sources list data from /etc/ros/rosdep/sources.list.d
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml
Query rosdistro index https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml
Skip end-of-life distro "ardent"
Skip end-of-life distro "bouncy"
Skip end-of-life distro "crystal"
Skip end-of-life distro "dashing"
Skip end-of-life distro "eloquent"
Add distro "foxy"
Add distro "galactic"
Skip end-of-life distro "groovy"
Skip end-of-life distro "hydro"
Skip end-of-life distro "indigo"
Skip end-of-life distro "jade"
Skip end-of-life distro "kinetic"
Skip end-of-life distro "lunar"
Add distro "melodic"
Add distro "noetic"
Add distro "rolling"
updated cache in /home/hc/.ros/rosdep/sources.cache

如果显示找不到rosdep命令,则执行

sudo apt-get install python-rosdep

如果失败:打开hosts文件

sudo gedit /etc/hosts

然后在文件末尾添加 151.101.84.133 raw.githubusercontent.com

151.101.84.133 raw.githubusercontent.com

如果提示形如这样的错误:

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.

则按照这个来解决,百分百解决问题
https://blog.csdn.net/HuangChen666/article/details/120801041?spm=1001.2014.3001.5502

保存后退出再尝试,然后断开无线网,改成连接手机热点
如果总是出现 time out,可以用以下办法:
1.将 /usr/lib/python2.7/dist-packages/rosdep2/下的三个文件sources_list.py、gbpdistro_support.py、rep3.py中的DOWNLOAD_TIMEOUT = 15.0值,改成500。
也可以用 ping raw.githubusercontent.com 命令查看超时时间,把 DOWNLOAD_TIMEOUT 改成大于超时时间的数即可
2.超时的话说明手机的热点不给力,可以换个信号好的地方多尝试几次,或者用别人的手机热点试几次

sudo gedit /usr/lib/python2.7/dist-packages/rosdep2/gbpdistro_support.py
sudo gedit /usr/lib/python2.7/dist-packages/rosdep2/sources_list.py
sudo gedit /usr/lib/python2.7/dist-packages/rosdep2/rep3.py

5. 设置环境变量

执行下面两条命令
echo "source /opt/ros/melodic/setup.bash">>~/.bashrc
source ~/.bashrc

6.安装rosiinstall

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

7.运行小海龟示例

rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key

你可能感兴趣的:(ROS,ubuntu)