ROS1(一):Ubuntu安装ROS1
目录:
Ubuntu安装ROS1
准备环境
添加ros源:
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'
设置密钥:
sudo apt install curl
curl -sSL 'http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xC1CF6E31E6BADE8868B172B4F42ED6FBAB17C654' | sudo apt-key add -
安装ROS
安装ros:
sudo apt update
sudo apt install ros-melodic-desktop-full
配置环境:
echo "source /opt/ros/melodic/setup.bash" >>~/.bashrc
source ~/.bashrc
安装构建包所需依赖:
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
rosdep
初始化 rosdep:
sudo rosdep init
由于域名污染,这一步往往会报下面的错误:
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.
为解决该问题,首先,克隆 rosdistro 仓库:
git clone https://github.com/ros/rosdistro.git
然后,本地新建对应目录:
sudo mkdir -p /etc/ros/rosdep/sources.list.d
最后,将克隆下来的 rosdistro 仓库中的 list 文件拷贝到上述目录:
cd rosdistro
sudo cp rosdep/sources.list.d/20-default.list /etc/ros/rosdep/sources.list.d/
更新本地 rosdep 数据库
rosdep update
同样是由于域名污染,这一步往往会报下面的错误:
reading in sources list data from /etc/ros/rosdep/sources.list.d
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)>
假设已经解决上面步骤中 rosdep init 遇到的问题,现在需要编辑以下四个文件(做好备份):
/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
搜索文件中的 https://raw.githubusercontent.com/ros/rosdistro/master
字段,将其替换为本地 rosdistro 仓库的绝对地址,例如本示例中为 file:///home/oliver/rosdistro
编辑后的 list 文件如下所示:
# os-specific listings first
yaml file:///home/oliver/rosdistro/rosdep/osx-homebrew.yaml osx
# generic
yaml file:///home/oliver/rosdistro/rosdep/base.yaml
yaml file:///home/oliver/rosdistro/rosdep/python.yaml
yaml file:///home/oliver/rosdistro/rosdep/ruby.yaml
gbpdistro file:///home/oliver/rosdistro/releases/fuerte.yaml fuerte
# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead
然后重新执行 rosdep update 命令即可:
reading in sources list data from /etc/ros/rosdep/sources.list.d
Hit file:///home/oliver/rosdistro/rosdep/osx-homebrew.yaml
Hit file:///home/oliver/rosdistro/rosdep/base.yaml
Hit file:///home/oliver/rosdistro/rosdep/python.yaml
Hit file:///home/oliver/rosdistro/rosdep/ruby.yaml
Hit file:///home/oliver/rosdistro/releases/fuerte.yaml
Query rosdistro index file:///home/oliver/rosdistro/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/oliver/.ros/rosdep/sources.cache
运行小海龟示例
打开终端,执行:
roscore
另开新的终端,执行:
rosrun turtlesim turtlesim_node
弹出小海龟界面:
另开新的终端,执行:
rosrun turtlesim turtle_teleop_key
保持该终端中的光标处于激活状态,通过方向键即可控制小海龟的移动。