在 ubuntu 18.04 环境下ROS 2 源码安装笔记

之前在Ubuntu 16.04虚拟机上通过二进制包的方式安装了ROS2 的 Ardent 版本,考虑到虚拟机在3D图形数据展示方面比较吃力,在笔记本上配置了Ubuntu18.04 、windows双系统,另外由于ROS 2还在快速发展中,所以决定通过源代码安装方式安装ROS 2目前最新版—— Bouncy版。

1、UTF-8 相关设置

sudo locale-gen en_US en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8

2、添加ROS 2 apt存储库

安装Debian软件包,需要将Debian存储库添加到apt源代码中。 首先需要使用以下方式授权gpg密钥,然后将存储库添加到源列表:

sudo apt update && sudo apt install curl

curl http://repo.ros2.org/repos.key | sudo apt-key add -

sudo sh -c 'echo "deb [arch=amd64,arm64] http://repo.ros2.org/ubuntu/main `lsb_release -cs` main" > /etc/apt/sources.list.d/ros2-latest.list'

3、安装开发工具和ROS工具

sudo apt update && sudo apt install -y \
  build-essential \
  git \
  python3-colcon-common-extensions \
  python3-pip \
  python-rosdep \
  python3-vcstool \
  wget
# install some pip packages needed for testing
sudo -H python3 -m pip install -U \
  argcomplete \
  flake8 \
  flake8-blind-except \
  flake8-builtins \
  flake8-class-newline \
  flake8-comprehensions \
  flake8-deprecated \
  flake8-docstrings \
  flake8-import-order \
  flake8-quotes \
  pytest-repeat \
  pytest-rerunfailures
# [Ubuntu 16.04] install extra packages not available or recent enough on Xenial
python3 -m pip install -U \
  pytest \
  pytest-cov \
  pytest-runner \
  setuptools
# install Fast-RTPS dependencies
sudo apt install --no-install-recommends -y \
  libasio-dev \
  libtinyxml2-dev

4、获取 ROS 2.0 代码

mkdir -p ~/ros2_ws/src
cd ~/ros2_ws
wget https://raw.githubusercontent.com/ros2/ros2/release-latest/ros2.repos
vcs import src < ros2.repos

由于在终端中使用了代理f a n qiang上网(参见https://mp.csdn.net/postedit/81323573   https://mp.csdn.net/postedit/81316399),这一步的源代码几分钟就下载完了,上一次没有用代理下载时断断续续,花了一天时间才下载完成。

5、使用rosdep安装依赖项

sudo rosdep init
rosdep update
rosdep install --from-paths src --ignore-src --rosdistro bouncy -y --skip-keys "console_bridge fastcdr fastrtps libopensplice67 rti-connext-dds-5.3.1 urdfdom_headers"

执行这一步 rosdep update 时一开始遇到一个奇怪的问题:

扫描二维码关注公众号,回复: 2563753 查看本文章
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
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml]:
	'' (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.yaml
Add distro "groovy"

ERROR: Rosdep experienced an error: while scanning a simple key
  in "<string>", line 4840, column 3:
      urdfdom
      ^
could not find expected ':'
  in "<string>", line 4840, column 10:
      urdfdom
             ^
Please go to the rosdep page [1] and file a bug report with the stack trace below.
[1] : http://www.ros.org/wiki/rosdep

rosdep version: 0.12.2

Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/rosdep2/main.py", line 140, in rosdep_main
    exit_code = _rosdep_main(args)
  File "/usr/lib/python2.7/dist-packages/rosdep2/main.py", line 386, in _rosdep_main
    return _no_args_handler(command, parser, options, args)
  File "/usr/lib/python2.7/dist-packages/rosdep2/main.py", line 395, in _no_args_handler
    return command_handlers[command](options)
  File "/usr/lib/python2.7/dist-packages/rosdep2/main.py", line 592, in command_update
    error_handler=update_error_handler)
  File "/usr/lib/python2.7/dist-packages/rosdep2/sources_list.py", line 490, in update_sources_list
    rosdep_data = get_gbprepo_as_rosdep_data(dist_name)
  File "/usr/lib/python2.7/dist-packages/rosdep2/gbpdistro_support.py", line 149, in get_gbprepo_as_rosdep_data
    distro_file = get_release_file(gbpdistro)
  File "/usr/lib/python2.7/dist-packages/rosdep2/rosdistrohelper.py", line 76, in get_release_file
    dist_file = rosdistro.get_distribution_file(get_index(), distro)
  File "/usr/lib/python2.7/dist-packages/rosdistro/__init__.py", line 116, in get_distribution_file
    data = _get_dist_file_data(index, dist_name, 'distribution')
  File "/usr/lib/python2.7/dist-packages/rosdistro/__init__.py", line 194, in _get_dist_file_data
    data.append(_load_yaml_data(u))
  File "/usr/lib/python2.7/dist-packages/rosdistro/__init__.py", line 187, in _load_yaml_data
    return yaml.load(yaml_str)
  File "/usr/lib/python2.7/dist-packages/yaml/__init__.py", line 71, in load
    return loader.get_single_data()
  File "/usr/lib/python2.7/dist-packages/yaml/constructor.py", line 37, in get_single_data
    node = self.get_single_node()
  File "/usr/lib/python2.7/dist-packages/yaml/composer.py", line 36, in get_single_node
    document = self.compose_document()
  File "/usr/lib/python2.7/dist-packages/yaml/composer.py", line 55, in compose_document
    node = self.compose_node(None, None)
  File "/usr/lib/python2.7/dist-packages/yaml/composer.py", line 84, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/usr/lib/python2.7/dist-packages/yaml/composer.py", line 133, in compose_mapping_node
    item_value = self.compose_node(node, item_key)
  File "/usr/lib/python2.7/dist-packages/yaml/composer.py", line 84, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/usr/lib/python2.7/dist-packages/yaml/composer.py", line 127, in compose_mapping_node
    while not self.check_event(MappingEndEvent):
  File "/usr/lib/python2.7/dist-packages/yaml/parser.py", line 98, in check_event
    self.current_event = self.state()
  File "/usr/lib/python2.7/dist-packages/yaml/parser.py", line 428, in parse_block_mapping_key
    if self.check_token(KeyToken):
  File "/usr/lib/python2.7/dist-packages/yaml/scanner.py", line 116, in check_token
    self.fetch_more_tokens()
  File "/usr/lib/python2.7/dist-packages/yaml/scanner.py", line 170, in fetch_more_tokens
    return self.fetch_stream_end()
  File "/usr/lib/python2.7/dist-packages/yaml/scanner.py", line 374, in fetch_stream_end
    self.remove_possible_simple_key()
  File "/usr/lib/python2.7/dist-packages/yaml/scanner.py", line 316, in remove_possible_simple_key
    "could not find expected ':'", self.get_mark())
ScannerError: while scanning a simple key
  in "<string>", line 4840, column 3:
      urdfdom
      ^
could not find expected ':'
  in "<string>", line 4840, column 10:
      urdfdom
             ^

这个问题网上同样有人遇到过(https://github.com/ros-infrastructure/rosdep/issues/576),跟帖没有人给出明确解决问题的答复,里面有人怀疑是网络的问题,并且有人提到多次执行rosdep update命令时报错的位置、内容不一样,我也验证了这一点,但是尝试了很多次都没有成功。

后来突然灵光一闪,是不是终端f a n  墙代理带来的问题?于是把终端代理上网取消掉,采用直连上网模式,居然真的成功了!真是成也萧何败萧何,正确执行完结果如下:

执行 rosdep install --from-paths src --ignore-src --rosdistro bouncy -y --skip-keys "console_bridge fastcdr fastrtps libopensplice67 rti-connext-dds-5.3.1 urdfdom_headers"遇到一个错误:

E: Failed to fetch http://mirrors.tuna.tsinghua.edu.cn/ubuntu/pool/universe/l/llvm-defaults/clang-format_6.0-41~exp5~ubuntu1_amd64.deb  Cannot initiate the connection to mirrors.tuna.tsinghua.edu.cn:80 (2402:f000:1:408:8100::1). - connect (101: Network is unreachable)
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
ERROR: the following rosdeps failed to install
  apt: command [sudo -H apt-get install -y clang-format] failed

解决方法是更换软件源,我这里是将清华的源替换成了阿里云的源:

然后执行sudo apt update,再次执行rosdep install --from-paths src --ignore-src --rosdistro bouncy -y --skip-keys "console_bridge fastcdr fastrtps libopensplice67 rti-connext-dds-5.3.1 urdfdom_headers",解决问题。

6、安装更多DDS实现(可选)

教程上有这一步,是可选上,为了避免节外生枝,我暂时没有安装,后面看情况再安装。

7、编译工作空间的代码

cd ~/ros2_ws/
colcon build --symlink-install

8、运行示例代码

打开两个终端,分别运行:

. ~/ros2_ws/install/local_setup.bash
ros2 run demo_nodes_cpp talker
. ~/ros2_ws/install/local_setup.bash
ros2 run demo_nodes_py listener

猜你喜欢

转载自blog.csdn.net/wsc820508/article/details/81349675