ubuntu20.04上編譯ros2

https://index.ros.org/doc/ros2/Installation/Foxy/Linux-Development-Setup/

系統要求¶
Foxy Fitzroy的目標平臺是(請參閱REP 2000):

第1層:Ubuntu Linux-Focal Fossa(20.04)64位

第3層平臺(未經過積極測試或支持)包括:

Debian Linux-剋星(10)

Fedora 32,請參閱替代說明

Arch Linux,請參閱替代說明

OpenEmbedded / webOS OSE,請參閱替代說明

系統設置¶
設置語言環境
確保設置支持UTF-8的語言環境。 如果您在最小的環境(例如Docker容器)中,則語言環境可能設置爲最小的東西,例如POSIX。

以下是設置語言環境的示例。 不過,如果您使用的是其他受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

添加ROS 2 apt存儲庫¶
您將需要將ROS 2 apt存儲庫添加到系統中。 爲此,請首先使用如下所示的apt授權我們的GPG密鑰:

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'

 安裝開發工具和ROS工具

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

獲取ROS 2代碼
創建一個工作區並克隆所有存儲庫:

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

Install dependencies using rosdep

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"

安裝其他DDS實現(可選)¶
如果您想使用默認eProsima的Fast RTPS以外的其他DDS或RTPS供應商,則可以在此處找到說明。

在工作空間中構建代碼
注意:要構建ROS 1橋,請閱讀ros1_bridge指令。

在本教程中可以找到有關使用ROS工作空間的更多信息。

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

注意:如果您在編譯所有示例時遇到麻煩,並且這妨礙了您成功完成構建,則可以以與CATKIN_IGNORE相同的方式使用AMENT_IGNORE來忽略子樹或從工作空間中刪除文件夾。 例如:您希望避免安裝大型OpenCV庫。 好吧,只需在cam2image演示目錄中$ $觸摸AMENT_IGNORE即可將其排除在構建過程之外。

(可選)將所有軟件包安裝到組合目錄中(而不是將每個軟件包安裝在單獨的子目錄中)。 在Windows上,由於環境變量長度的限制,在構建包含多個(〜>> 100個軟件包)的工作區時,應使用此選項。

另外,如果您已經從Debian安裝了ROS 2,請確保在全新環境中運行build命令。 您可能要確保.bashrc中沒有源/opt/ros/${ROS_DISTRO}/setup.bash。

colcon build --symlink-install --merge-install

 

Environment setup

Source the setup script

Set up your environment by sourcing the following file.

. ~/ros2_foxy/install/setup.bash

Install argcomplete (optional)

ROS 2 command line tools use argcomplete to autocompletion. So if you want autocompletion, installing argcomplete is necessary.

sudo apt install python3-argcomplete

Try some examples

In one terminal, source the setup file and then run a C++ talker:

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

In another terminal source the setup file and then run a Python listener:

. ~/ros2_foxy/install/local_setup.bash
ros2 run demo_nodes_py listener

您應該看到說話者說這是發佈消息,而聽者說我聽到了這些消息。 這可以驗證C ++和Python API是否正常工作。 萬歲!

請參閱教程和演示以嘗試其他方法。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章