하루에 한 걸음

[ROS2] ROS2 Eloquent 설치 - Ubuntu 18.04에서 빌드하기 본문

ROS

[ROS2] ROS2 Eloquent 설치 - Ubuntu 18.04에서 빌드하기

유파랑 2021. 9. 1. 03:22

드론 자율주행을 연구하면서 ROS를 열심히 썼던 기억이 있는데, 어느새 ROS는 지원이 중단되었고 ROS2가 나왔다길래 사용해보려고 한다.

목차

0. ROS란

1. 준비

2. 설치

0. ROS란

ROS는 Robot Operating System의 약자로 이름은 운영체제이지만 사실은 운영체제 위에서 돌아가는 조금 특이한 녀석이다. 라이다, IMU 카메라 등 수많은 센서의 측정값과 터틀봇 같은 로봇 사이를 rostopic이라는 포맷을 통해서 간편하게 통신할 수 있다. 각 장치는 Node를 가지고 있다. Node는 rostopic을 발행하는 Publisher와 받아보는 Subscriber로 구분할 수 있다. 한 장치(센서, 로봇 등)는 publisher node, subscriber node 중 하나만 혹은 둘 다 가질 수 있다. 예를 들면 터틀봇은 publisher node에서 자신의 가속도 rostopic을 발행함과 동시에 subscriber node에서 라이다가 발행한 rostopic을 받아볼 수 있는 것이다.

1. 준비

본인의 현재 OS는 Ubuntu 18.04이다.

바이너리를 설치해도 되지만 나중에 귀찮아졌던 기억이 있으므로 그냥 소스코드 빌드식으로 설치한다.

무엇이든지 공식문서가 최고다.

https://docs.ros.org/en/eloquent/Installation/Ubuntu-Development-Setup.html

[

Building ROS 2 on Ubuntu Linux — ROS 2 Documentation: Foxy documentation

If you have already installed ROS 2 another way (either via Debians or the binary distribution), make sure that you run the below commands in a fresh environment that does not have those other installations sourced. Also ensure that you do not have source

docs.ros.org

](https://docs.ros.org/en/foxy/Installation/Ubuntu-Development-Setup.html)

2. 설치

1. 환경 확인

현재 우분투 환경이 UTF-8을 지원하는지 확인한다.

설치시 영어로 했으면 별 문제 없을 것이다.

현재 지원 언어는

locale

명령어로 확인할 수 있다. 결과에서 UTF-8이 보이면 된다.
혹시 보이지 않는다면,

sudo apt update && sudo apt install locales
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

차례대로 실행하고 다시한번 locale 명령어로 확인해준다.

2. ROS2 apt 리포지토리 추가

ROS2 소스코드를 받기 위해서 apt 리포지토리를 추가해준다

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'

3. ROS2 사전 설치

ROS2를 빌드하는데 필요한 의존성 툴을 설치해준다.

sudo apt update && sudo apt install -y \
  build-essential \
  cmake \
  git \
  python3-colcon-common-extensions \
  python3-pip \
  python-rosdep \
  python3-vcstool \
  wget

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 \
  pytest \
  pytest-cov \
  pytest-runner \
  setuptools

sudo apt install --no-install-recommends -y \
  libasio-dev \
  libtinyxml2-dev

sudo apt install --no-install-recommends -y \
  libcunit1-dev

4. ROS2 소스코드 받기

홈에 디렉토리를 하나 생성하고 소스코드를 받아온다.

mkdir -p ~/ros2_eloquent/src
cd ~/ros2_eloquent
wget https://raw.githubusercontent.com/ros2/ros2/eloquent/ros2.repos
vcs import src < ros2.repos

5. rosdep으로 사전 설치

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

시간이 좀 걸린다...

6. 빌드하기

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

시간이 꽤 많이 걸린다... 컴퓨터 사양마다 다르지만 본인은 40분 정도 소요되었다.

7. 테스트

터미널 창을 하나 열고

. ~/ros2_eloquent/install/local_setup.bash
ros2 run demo_nodes_cpp talker

실행하면 publisher node가 하나 생성되면서 숫자를 던지기 시작한다.
터미널 창 하나를 더 열고

. ~/ros2_eloquent/install/local_setup.bash
ros2 run demo_nodes_cpp listener

실행하면 subscriber node가 생성되면서 다른 터미널에서 던지고 있는 숫자를 받아온다.

 

위 테스트가 정상 작동한다면
ROS2 설치 성공!!