본문 바로가기

ROS

[ROS2] Install (Ubuntu 20.04, foxy)

환경

  • Ubuntu 20.04
  • ros2 foxy

공식 홈페이지

https://docs.ros.org/en/foxy/Installation.html

 

Installation — ROS 2 Documentation: Foxy documentation

You're reading the documentation for an older, but still supported, version of ROS 2. For information on the latest version, please have a look at Galactic. Installation Options for installing ROS 2 Foxy Fitzroy: Which install should you choose? Installing

docs.ros.org

위 링크에 설치법을 따라하면 된다.

locale  # check for 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  # verify settings

GPG key 발급

sudo apt update && sudo apt install curl gnupg2 lsb-release
sudo curl -sSL <https://raw.githubusercontent.com/ros/rosdistro/master/ros.key>  -o /usr/share/keyrings/ros-archive-keyring.gpg

apt에 등록

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] <http://packages.ros.org/ros2/ubuntu> $(source /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null

설치

sudo apt update
sudo apt install ros-foxy-desktop

여기까지 하면 기본적인 ros2 foxy는 설치가 완료 되지만 build에 사용되는 colcon 같은 package는 포함되어 있지 않으므로 다음을 추가로 설치해 준다.

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

이 상태에선 terminal창에 ros2 명령어가 나오진 않는다. 다음과 같이 source를 가져와야 환경세팅이 된다.

source /opt/ros/foxy/setup.bash

!!!!! 만약 ros1과 같이 사용하고 있다면 ~/.bashrc에 위 구문을 바로 넣지 않는다!!! 충돌이 날수도 있다.

따라서 다음과 같이 ~/.bashrc에 추가해 주고 그때 그때 터미널 환경 세팅을 해주자.

  • ~/.bashrc
......
....
..
## bash pre setting..

function ros1_setup {
    source /opt/ros/noetic/setup.bash
    alias cs='cd ~/{ROS_NOETIC_WS}/src'
    alias cw='cd ~/{ROS_NOETIC_WS}/'
		alias cm='cw && catkin_make'
}

function ros2_setup {
    source /opt/ros/foxy/setup.bash
    alias cs='cd ~/{ROS_FOXY_WS}/src'
    alias cw='cd ~/{ROS_FOXY_WS}/'
		alias cm='cw && colcon build'
}
  • ros1 setup
ros1_setup ##ros1 setup
  • ros2 setup
ros2_setup