Kria Robotics Stack (環境設定)
はじめに
とうとうKV206評価ボードが手元に届きました。KV206はROS2対応のソフトウエアスタック(Kria Robotics Stack)というものがあり、以前から気になっていたのでこれから色々見ていければと思います。
Kria Robotics Stack(KRS)は、ROS2ベースのロボット開発用ライブラリ・ユーティリティの統合ツールで、XilinxのFPGAでROS2で開発がでるようになります。FPGA(実際はCPU、GPU、FPGAですが)を使う事で「低遅延」、「決定論」、「リアルタイム」、「セキュリティ」、「高スループット」といったロボット性能が実現できるのが特徴のようです。正式版のリリースはまだ先のようなので、今回はベータ版で環境を構築してみようと思います。
動作条件
以下がKRSベータ版の動作条件になります。
- Ubuntu 20.04 Focal Fossa オペレーティングシステム
- Vitis 2020.2.2スイート(Vitis、Vivado、Vitis HLS)
- ROS2 Rolling ディストリビューション
以降で順番にインストールをしていきたいと思います。
Ubuntu 20.04 Focal Fossa のインストール
以下のサイトからUbuntu 20.04 Focal Fossaをダウンロードします。
インストール方法については、以下で書いた内容と同じ手順になります。
Vitis 2021.2 のインストール
以下のサイトからVitis 2021.2をダウンロードします。
Vitisのインストール方法についても、こちらと同じ手順になります。
ROS Rolling のインストール
locale 設定
Ubunt20.04のlocaleを設定変更します。
locale
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
最終的なlocaleの結果は以下の通りとなります。
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8
APTリポジトリへのROS2パッケージ登録
Ubuntuユニバースリポジトリが有効になっていることを確認します
apt-cache policy | grep universe
# 以下のメッセージが表示されることを確認します
500 http://us.archive.ubuntu.com/ubuntu focal/universe amd64 Packages
release v=20.04,o=Ubuntu,a=focal,n=focal,l=Ubuntu,c=universe,b=amd64
続いて、ROS2パッケージのAPTリポジトリを追加します。
始めにGPGキーを承認します。
sudo apt update && sudo apt install curl gnupg lsb-release
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
リポジトリをソースリストに追加します。
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
ROS2パッケージのインストール
PythonのリンクをPython3に設定します。
sudo apt update
sudo apt install ros-rolling-desktop
sudo apt install ros-rolling-ros-base
ROS2の動作確認
ビルドが完了したら動作を確認してみます。Terminalを二つ起動してデモプログラムを実行します。
source /opt/ros/rolling/setup.bash
ros2 run demo_nodes_cpp talker
source /opt/ros/rolling/setup.bash
ros2 run demo_nodes_py listener
以下の画面の通り、TalkerとListenerノード間でメッセージ通信できていることが確認できます。
![]() |
|---|
XRTをインストールする
KRSベータ版の動作条件に記載はありませんが、KRSをインストールするためにXRT(Xilinx Run Time)をインストールする必要があります。
最初に以下からXRT_2021.2をダウンロードしてきます。
ダウンロードしたXRT-2021.2.zipを適当なディレクトリに展開します。
unzip XRT-2021.2.zip
XRTをビルドします。
sudo ./XRT-2021.2/src/runtime_src/tools/scripts/xrtdeps.sh
cd build
./build.sh
cd build/Release
make package
ビルドしたパッケージをインストールします。
cd ./XRT-2021.2/Build/Release
sudo apt install ./xrt_202120.2.12.0_20.04-amd64-xrt.deb
以上で/opt/xilinx/xrtにXRTがインストールされます。
KRS(Kria Robotics Stack)のインストール
依存関係のあるパッケージをインストールします。
sudo apt-get -y install curl build-essential libssl-dev git wget ocl-icd-* opencl-headers python3-vcstool python3-colcon-common-extensions python3-colcon-mixin kpartx u-boot-tools pv
ディレクトリを作成します。
mkdir -p ~/krs_ws/src
cd krs_ws/
krs_alpha.repoファイルを生成します。
cat << 'EOF' > krs_rolling.repos
#以下を書き込みます
repositories:
ros2/ament_lint:
type: git
url: https://github.com/ament/ament_lint
version: master
ros2/launch:
type: git
url: https://github.com/ros2/launch
version: master
perception/image_common:
type: git
url: https://github.com/ros-perception/image_common
version: 9729de81f7dff6156f644d6152b200f687360f1f
perception/image_pipeline:
type: git
url: https://github.com/ros-acceleration/image_pipeline
version: ros2
perception/vision_opencv:
type: git
url: https://github.com/ros-perception/vision_opencv
version: 7bbc5ecc232e8faf36b45efaa2b6bc979b04157f
tracing/ros2_tracing:
type: git
url: https://gitlab.com/ros-tracing/ros2_tracing.git
version: master
tracing/tracetools_acceleration:
type: git
url: https://github.com/ros-acceleration/tracetools_acceleration
version: main
acceleration/acceleration_firmware:
type: git
url: https://github.com/ros-acceleration/acceleration_firmware
version: main
acceleration/acceleration_firmware_kv260:
type: zip
url: https://github.com/ros-acceleration/acceleration_firmware_kv260/releases/download/v0.9.0/acceleration_firmware_kv260.zip
acceleration/adaptive_component:
type: git
url: https://github.com/ros-acceleration/adaptive_component
version: main
acceleration/ament_acceleration:
type: git
url: https://github.com/ros-acceleration/ament_acceleration
version: main
acceleration/ament_vitis:
type: git
url: https://github.com/ros-acceleration/ament_vitis
version: main
acceleration/colcon-acceleration:
type: git
url: https://github.com/ros-acceleration/colcon-acceleration
version: main
acceleration/ros2_kria:
type: git
url: https://github.com/ros-acceleration/ros2_kria
version: main
acceleration/ros2acceleration:
type: git
url: https://github.com/ros-acceleration/ros2acceleration
version: main
acceleration/vitis_common:
type: git
url: https://github.com/ros-acceleration/vitis_common
version: master
acceleration/acceleration_examples:
type: git
url: https://github.com/ros-acceleration/acceleration_examples
version: main
EOF
KRSベータリリースのリポジトリをインポートします。
vcs import src --recursive < krs_rolling.repos
Xilinxの環境とROS2の環境設定ファイルを読み込みます。
source /tools/Xilinx/Vitis/2021.2/settings64.sh
source /opt/ros/rolling/setup.bash
KRSをビルドします。
export PATH="/usr/bin":$PATH
colcon build --merge-install
ビルドすると以下のエラーが発生します。
CMakeのバージョンがあっていないようです。
・・・
--- stderr: image_geometry
CMake Error at CMakeLists.txt:1 (cmake_minimum_required):
CMake 3.5 or higher is required. You are running version 3.3.2
・・・
CMakeのパスを確認すると、確かにバージョン3.3.2になっています。
/tools/Xilinx/Vitis/2021.2/tps/lnx64/cmake-3.3.2/bin/cmake
/tools/Xilinx/Vitis/2021.2/tps/lnx64ディレクトを確認すると、cmake-3.21.0があるのでそちらに切り替えてみます。
cd /tools/Xilinx/Vitis/2021.2/tps/lnx64
ls
clangd-8.0.0 cmake-3.21.0 cmake-3.3.2 dfu-util-0.9 javafx-sdk-11.0.2 jre11.0.11_9 python-2.7.5 python-3.8.3
/tools/Xilinx/Vitis/2021.2ディレクトにある.settings64-Vitis.shでパスを設定している箇所があります。/tools/Xilinx/Vitis/2021.2/tps/lnx64/cmake-3.3.2/binから/tools/Xilinx/Vitis/2021.2/tps/lnx64/cmake-3.21.0/binに変更します。
再度Xilinxの環境設定ファイルを読み込みます。cmakeのパスが変更されていることが確認できました。
source /tools/Xilinx/Vitis/2021.2/settings64.sh
which cmake
/tools/Xilinx/Vitis/2021.2/tps/lnx64/cmake-3.21.0/bin/cmake
KRSをもう一度ビルドしてみます
cd ~/krs_ws
colcon build --merge-install
今度は、image_procのビルドでインクルードファイルが無いというエラーが発生します。
--- stderr: image_proc
In file included from /home/kino/krs_ws/src/perception/image_pipeline/image_proc/src/rectify_resize_fpga_integrated_xrt.cpp:35:
/home/kino/krs_ws/src/perception/image_pipeline/image_proc/include/image_proc/rectify_resize_fpga_integrated_xrt.hpp:37:10: fatal error: experimental/xrt_bo.h: No such file or directory
37 | #include "experimental/xrt_bo.h"
| ^~~~~~~~~~~~~~~~~~~~~~~
~/krs_ws/src/perception/image_pipeline/image_proc/CMakeLists.txtの
target_include_directories(rectify_resize_fpga_integrated_node PUBLIC ~target_include_directories(rectify_resize_fpga_streamlined_xrt PUBLIC ~
に以下の様にxrtヘッダのPATHを追加します。
target_include_directories(rectify_resize_fpga_xrt PUBLIC
・・・
/opt/xilinx/xrt/include
)
同様に、~/krs_ws/src/acceleration/acceleration_examples/nodes/image_pipeline_examples/CMakeLists.txtの
target_include_directories(rectify_resize_fpga_xrt PUBLIC ~target_include_directories(rectify_resize_fpga_streamlined_node PUBLIC ~
にもxrtヘッダのPATHを追加します。
この状態でKRSをリビルドしたら成功しました。
あの手この手で強引にインストールしたので正常動作するか微妙な所ですが、次回以降で動作確認も含めていろいろと試していきたいと思います。

Discussion