< >
Home » ROS2入门教程 » ROS2入门教程-在ubuntu20.04源码安装ros2的foxy版本

ROS2入门教程-在ubuntu20.04源码安装ros2的foxy版本

ROS2入门教程-在ubuntu20.04源码安装ros2的foxy版本

说明:

  • 介绍如何在ubuntu20.04源码安装ros2的foxy版本

步骤:

  • 设置UTF8
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
  • 增加ros2源
sudo apt update && sudo apt install curl gnupg2 lsb-release
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
sudo sh -c 'echo "deb [arch=$(dpkg --print-architecture)] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" > /etc/apt/sources.list.d/ros2-latest.list'
  • 安装系统依赖
sudo apt update && sudo apt install -y \
  build-essential \
  cmake \
  git \
  libbullet-dev \
  python3-colcon-common-extensions \
  python3-flake8 \
  python3-pip \
  python3-pytest-cov \
  python3-rosdep \
  python3-setuptools \
  python3-vcstool \
  wget
# install some pip packages needed for testing
python3 -m pip install -U \
  argcomplete \
  flake8-blind-except \
  flake8-builtins \
  flake8-class-newline \
  flake8-comprehensions \
  flake8-deprecated \
  flake8-docstrings \
  flake8-import-order \
  flake8-quotes \
  pytest-repeat \
  pytest-rerunfailures \
  pytest
# install Fast-RTPS dependencies
sudo apt install --no-install-recommends -y \
  libasio-dev \
  libtinyxml2-dev
# install Cyclone DDS dependencies
sudo apt install --no-install-recommends -y \
  libcunit1-dev
  • 编译ros2
mkdir -p ~/ros2_foxy/src
cd ~/ros2_foxy
wget https://raw.githubusercontent.com/ros2/ros2/foxy/ros2.repos
vcs import src < ros2.repos
  • 安装ros2依赖
sudo rosdep init
rosdep update
rosdep install --from-paths src --ignore-src --rosdistro foxy -y --skip-keys "console_bridge fastcdr fastrtps rti-connext-dds-5.3.1 urdfdom_headers"
  • 全新编译
cd ~/ros2_foxy/
colcon build --symlink-install
  • 或者,已经安装了apt版本的ros2, 在安装源码版本。
  • 全新打开终端,确保不能先加载source /opt/ros/foxy/setup.bash
cd ~/ros2_foxy/
colcon build --symlink-install --merge-install
  • 安装命令自动提示
sudo apt install python3-argcomplete
  • 加载环境
. ~/ros2_foxy/install/setup.bash
  • 如果是已经apt版本,加载环境
. ~/ros2_foxy/install/local_setup.bash

测试:

  • 新开终端执行发布话题:
. ~/ros2_foxy/install/local_setup.bash
ros2 run demo_nodes_cpp talker
  • 效果如下:
ubuntu@AiROS2-NUC:~/ros2$ ros2 run demo_nodes_cpp talker
[INFO] [1594797644.290559499] [talker]: Publishing: 'Hello World: 1'
[INFO] [1594797645.289723573] [talker]: Publishing: 'Hello World: 2'
[INFO] [1594797646.289719347] [talker]: Publishing: 'Hello World: 3'
[INFO] [1594797647.289761742] [talker]: Publishing: 'Hello World: 4'
[INFO] [1594797648.289772975] [talker]: Publishing: 'Hello World: 5'
[INFO] [1594797649.289780796] [talker]: Publishing: 'Hello World: 6'
[INFO] [1594797650.289786173] [talker]: Publishing: 'Hello World: 7'
[INFO] [1594797651.289801926] [talker]: Publishing: 'Hello World: 8'
[INFO] [1594797652.289828138] [talker]: Publishing: 'Hello World: 9'
[INFO] [1594797653.289842107] [talker]: Publishing: 'Hello World: 10'
[INFO] [1594797654.289833311] [talker]: Publishing: 'Hello World: 11'
[INFO] [1594797655.289883915] [talker]: Publishing: 'Hello World: 12'
[INFO] [1594797656.289652896] [talker]: Publishing: 'Hello World: 13'
[INFO] [1594797657.289887309] [talker]: Publishing: 'Hello World: 14'
[INFO] [1594797658.289663278] [talker]: Publishing: 'Hello World: 15'
[INFO] [1594797659.289676276] [talker]: Publishing: 'Hello World: 16'
[INFO] [1594797660.289695999] [talker]: Publishing: 'Hello World: 17'
  • 新开终端执行订阅话题:
. ~/ros2_foxy/install/local_setup.bash
ros2 run demo_nodes_py listener
  • 效果如下:
ubuntu@AiROS2-NUC:~$ ros2 run demo_nodes_py listener
[INFO] [1594797675.306879843] [listener]: I heard: [Hello World: 32]
[INFO] [1594797676.291847879] [listener]: I heard: [Hello World: 33]
[INFO] [1594797677.292016853] [listener]: I heard: [Hello World: 34]
[INFO] [1594797678.292367939] [listener]: I heard: [Hello World: 35]
[INFO] [1594797679.292045184] [listener]: I heard: [Hello World: 36]
[INFO] [1594797680.292037706] [listener]: I heard: [Hello World: 37]
[INFO] [1594797681.292416698] [listener]: I heard: [Hello World: 38]
[INFO] [1594797682.292375981] [listener]: I heard: [Hello World: 39]
[INFO] [1594797683.292102894] [listener]: I heard: [Hello World: 40]
[INFO] [1594797684.292094574] [listener]: I heard: [Hello World: 41]
[INFO] [1594797685.292414997] [listener]: I heard: [Hello World: 42]
[INFO] [1594797686.292248540] [listener]: I heard: [Hello World: 43]
[INFO] [1594797687.292437264] [listener]: I heard: [Hello World: 44]

纠错,疑问,交流: 请进入讨论区点击加入Q群

获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号


标签: ros2入门教程