ROSにおけるパッケージ管理ツールであるvcstoolとrosdepの紹介とその使い方

ROSのチュートリアルを進めていると、vcsrosdepコマンドを使うことがあると思います。今回はこれらのパッケージ管理ツールとその使い方について紹介します。

この記事はROS 2 Advent Calendar 2023の12/5の記事として投稿しています。

すごくざっくり書くと、vcsコマンドを提供するvcstoolはソースからビルドするパッケージを管理するツール、rosdepコマンドを提供するrosdepはバイナリインストールするパッケージを管理するツールです。両方使えるととても便利です。

目次

vcstool

vcstoolは元Open Roboticsの@drik-thomasさんが開発したパッケージ管理ツールです。GitやMercurialなどでバージョン管理をしている複数のリポジトリを便利に管理するために開発されたようです。

GitHub
GitHub - dirk-thomas/vcstool: Vcstool is a command line tool designed to make working with multiple ... Vcstool is a command line tool designed to make working with multiple repositories easier - dirk-thomas/vcstool

vcstoolはROS 2から標準のパッケージ管理ツールになりました。ROS 1ではwstoolという別のツール[1]wstool updatewstool mergeコマンドなどで馴染みがあるかもしれません。が標準で使われていましたが、今はもう非推奨になっています[2] recommend / use vcstool instead of wstool · Issue #25432 · ros/rosdistro · GitHub
https://github.com/ros/rosdistro/issues/25432
。vcstoolはこのwstool用のファイルである.rosinstall形式(REP-126にて定義されています)にも対応しています。コマンドの読み替えが必要にはなりますが、vcstoolはwstoolの代わりになると言えそうです。

今回はwstoolとvcstoolの違いについては省略しますが、過去の記事で少し触れているので、興味のある方はぜひご確認ください。

あわせて読みたい
ROSパッケージ管理に使うバージョン管理ツールの違いとその使い方 ROS/ROS2のパッケージ管理のためにバージョン管理について調べていると、vcstools, wstool, rosinstall, vcstoolなど様々なバージョン管理ツールやバージョン管理のため...

vcstoolを使うために必要なこと

vcstoolを使うためには、

  1. vcstool自体のインストール
  2. vcstoolに読み込ませるためのパッケージリスト

が必要です。

vcstoolはROS 2がインストールされている環境であれば、sudo apt install python3-vcstoolでインストールすることができます。その他のインストール方法は公式ページを参照してください。

GitHub
GitHub - dirk-thomas/vcstool: Vcstool is a command line tool designed to make working with multiple ... Vcstool is a command line tool designed to make working with multiple repositories easier - dirk-thomas/vcstool

vcstoolでパッケージをまとめてダウンロードできるようにするためには、下記のようにvcstoolに読み込ませるためのパッケージリストを用意する必要があります。下記のようにROSパッケージ内で一緒に管理するケースがよく見る例です。

https://github.com/rt-net/raspimouse_slam_navigation_ros2/blob/main/.ci.rosinstall

https://github.com/ROBOTIS-GIT/turtlebot3/blob/ros2/turtlebot3.repos

https://github.com/OUXT-Polaris/dynamixel_hardware_interface/blob/master/dependency.repos

vcstoolの使い方

私がよく使っているvcstoolのコマンドをいくつか紹介します。vcstoolとrosdepをあわせて便利に使う方法は最後に紹介します。

パッケージをまとめてダウンロードしてくるとき

mypackage.reposファイルに各種パッケージが記載されている場合に、srcディレクトリにダウンロードしてくるとき

vcs import src < mypackage.repos

https://example.com/mypackage.repos に公開されているファイルに各種パッケージが記載されている場合に、srcディレクトリにダウンロードしてくるとき

vcs import src --input https://example.com/mypackage.repos

パッケージをリスト化するとき

srcディレクトリに各種パッケージがある場合に、mypackage.reposファイルに書き出すとき

vcs export src > mypackage.repos

パッケージをまとめて更新するとき

srcディレクトリに各種パッケージがある場合に、まとめて更新(git pull)するとき

vcs pull src

rosdep

rosdepはOpen Roboticsが中心となってメンテナンスをしている、依存パッケージをまとめてインストールするためのパッケージ管理ツールです。

GitHub
GitHub - ros-infrastructure/rosdep: rosdep multi-package manager system dependency tool rosdep multi-package manager system dependency tool - ros-infrastructure/rosdep

下記の”rosdistro”という名前のリポジトリに数多くのソフトウェア・ライブラリが登録されており、rosdepコマンドを実行するとこのリストを参照してシステムにマッチした依存パッケージをダウンロード・インストールします。例えばですが、Pythonの数値計算ライブラリとして有名なnumpyも、rosdepを使ってインストールすることができます。

GitHub
GitHub - ros/rosdistro: This repo maintains a lists of repositories for each ROS distribution This repo maintains a lists of repositories for each ROS distribution - ros/rosdistro

rosdepを使うために必要なこと

rosdepを使うためには、

  1. rosdep自体のインストール
  2. rosdepが参照する”rosdistro”リポジトリに目的とするソフトウェア・ライブラリがリストされていること
  3. ROSパッケージのpackage.xmlに依存パッケージが定義されていること

が必要です。

rosdepはROS 2がインストールされている環境であれば、sudo apt install python3-rosdepでインストールすることができます。

“rosdistro”リポジトリへの追加方法とpackage.xmlの記載方法は今回は割愛します。

“rosdistro”リポジトリについては、CONTRIBUTING.mdに記載があります。

https://github.com/ros/rosdistro/blob/master/CONTRIBUTING.md

package.xmlの記載については、@srsさんのQiitaの記事が詳しいです。

Qiita
ROS講座97 CMakeList.txtとpackage.xmlの書き方 - Qiita 環境この記事は以下の環境で動いています。インストールについてはROS講座02 インストールを参照してください。またこの記事のプログラムはgithubにアップロードされていま...

rosdepの使い方

私がよく使っているrosdepのコマンドを紹介します。vcstoolとrosdepをあわせて便利に使う方法は最後に紹介します。

srcディレクトリに各種パッケージがある場合に、それらの依存パッケージをまとめてインストールするとき

rosdep install -riy --from-paths src

-rはエラーが出ても無視するオプション、-iはすでにソースコードがダウンロードしてあるパッケージはスキップするオプション、-yは全部に対してyesとするオプションです。

-yについてだけ補足します。今回紹介するか少し迷ったのですが、実際には使っている人も多いだろうということで紹介します。Ubuntuで実行する場合、rosdep install (中略)と実行すると、裏でsudo apt-get install (中略)が実行されます。これに対してすべてyesと回答する設定が-yオプションです。package.xmlの中身をよくチェックしてないまま実行すると、最悪の場合は意図してないパッケージがインストールされて環境が壊れたりすることも想定されますので、ご注意ください。-yのオプションを指定しない場合は、sudo apt-get installで「インストールしますか?はい・いいえ」のプロンプトで止まりますので、都度回答する必要があります。

その他のオプションはあまり使っていませんが、rosdep install --helpと実行すると多数出てきます。他にも「このオプション便利だよ!」などありましたらSNSやコメント等で教えていただけると嬉しいです!

rosdep install –help
$ rosdep install --help
Usage: rosdep [options]  

Commands:

rosdep check ...
  check if the dependencies of package(s) have been met.

rosdep install ...
  download and install the dependencies of a given package or packages.

rosdep db
  generate the dependency database and print it to the console.

rosdep init
  initialize rosdep sources in /etc/ros/rosdep.  May require sudo.

rosdep keys ...
  list the rosdep keys that the packages depend on.

rosdep resolve 
  resolve  to system dependencies

rosdep update
  update the local rosdep database based on the rosdep sources.

rosdep what-needs ...
  print a list of packages that declare a rosdep on (at least
  one of) 

rosdep where-defined ...
  print a list of yaml files that declare a rosdep on (at least
  one of) 

rosdep fix-permissions
  Recursively change the permissions of the user's ros home directory.
  May require sudo.  Can be useful to fix permissions after calling
  "rosdep update" with sudo accidentally.


Options:
  -h, --help            show this help message and exit
  --os=OS_NAME:OS_VERSION
                        Override OS name and version (colon-separated), e.g.
                        ubuntu:lucid
  -c SOURCES_CACHE_DIR, --sources-cache-dir=SOURCES_CACHE_DIR
                        Override /home/ubuntu/.ros/rosdep/sources.cache
  -v, --verbose         verbose display
  --version             print just the rosdep version, then exit
  --all-versions        print rosdep version and version of installers, then
                        exit
  --reinstall           (re)install all dependencies, even if already
                        installed
  -y, --default-yes     Tell the package manager to default to y or fail when
                        installing
  -s, --simulate        Simulate install
  -r                    Continue installing despite errors.
  -q                    Quiet. Suppress output except for errors.
  -a, --all             select all packages
  -n                    Do not consider implicit/recursive dependencies.  Only
                        valid with 'keys', 'check', and 'install' commands.
  -i, --ignore-packages-from-source, --ignore-src
                        Affects the 'check', 'install', and 'keys' verbs. If
                        specified then rosdep will ignore keys that are found
                        to be catkin or ament packages anywhere in the
                        ROS_PACKAGE_PATH, AMENT_PREFIX_PATH or in any of the
                        directories given by the --from-paths option.
  --skip-keys=SKIP_KEYS
                        Affects the 'check' and 'install' verbs. The specified
                        rosdep keys will be ignored, i.e. not resolved and not
                        installed. The option can be supplied multiple times.
                        A space separated list of rosdep keys can also be
                        passed as a string. A more permanent solution to
                        locally ignore a rosdep key is creating a local rosdep
                        rule with an empty list of packages (include it in
                        /etc/ros/rosdep/sources.list.d/ before the defaults).
  --filter-for-installers=FILTER_FOR_INSTALLERS
                        Affects the 'db' verb. If supplied, the output of the
                        'db' command is filtered to only list packages whose
                        installer is in the provided list. The option can be
                        supplied multiple times. A space separated list of
                        installers can also be passed as a string. Example:
                        `--filter-for-installers "apt pip"`
  --from-paths          Affects the 'check', 'keys', and 'install' verbs. If
                        specified the arguments to those verbs will be
                        considered paths to be searched, acting on all catkin
                        packages found there in.
  --rosdistro=ROS_DISTRO
                        Explicitly sets the ROS distro to use, overriding the
                        normal method of detecting the ROS distro using the
                        ROS_DISTRO environment variable. When used with the
                        'update' verb, only the specified distro will be
                        updated.
  --as-root=INSTALLER_KEY:
                        Override whether sudo is used for a specific
                        installer, e.g. '--as-root pip:false' or '--as-root
                        "pip:no homebrew:yes"'. Can be specified multiple
                        times.
  --include-eol-distros
                        Affects the 'update' verb. If specified end-of-life
                        distros are being fetched too.
  -t DEPENDENCY_TYPES, --dependency-types=DEPENDENCY_TYPES
                        Dependency types to install, can be given multiple
                        times. Choose from {'buildtool', 'doc', 'build',
                        'exec', 'build_export', 'buildtool_export', 'test'}.
                        Default: all except doc.

vcstoolとrosdepをあわせた使い方

vcstoolとrosdepをあわせた使い方として、ここでは具体的にTurtlebot3のシミュレーション用パッケージとその依存パッケージをまとめてインストールする場合の手順を紹介します。ROS 2 Humbleを想定します。

まず、ROSのワークスペースに移動して、vcsコマンドでTurtlebot3の関連パッケージをまとめてダウンロードしてきます。

cd ~/ros2_ws
vcs import src --input https://raw.githubusercontent.com/ROBOTIS-GIT/turtlebot3/ros2/turtlebot3.repos

次にrosdepコマンドで依存パッケージをまとめてダウンロードしてきます。

rosdep install -riy --from-paths src

最後にビルドが通れば完了です。

colcon build --symlink-install

メンテナンスが途中だったり、依存パッケージの更新があったりするとビルドが通らなかったりすることもありますが、基本的にはこのやり方でソースコードをダウンロードし、その依存パッケージをまとめてインストールすることができます。

CIの設定やDockerfileでこれらを活用すれば、「それぞれのツールが参照する先のリストや設定ファイルさえ整えておけばよい」という状態でメンテナンスすることができ、とても便利です。
(そうじゃないと、パッケージ更新のたびにインストールスクリプトを更新するというような事態になりかねません……そうなったらメンテナンス大変です……)

まとめ

ROSにおけるパッケージ管理ツールであるvcstoolとrosdepの紹介とその使い方を、よく使っているコマンドと一緒に紹介しました。それぞれのツールが参照する先のリストや設定ファイルが整っていれば、1つずつインストールする場合と比較して少ないコマンドで必要なパッケージをまとめてインストールすることができます。

vcstoolとrosdepを使いやすくするためにも、ROSパッケージには.reposファイルを置き、package.xmlとあわせて定期的にメンテナンスしていきましょう!この記事がvcstoolとrosdepを活用していくきっかけになれば幸いです。

参考・関連リンク

あわせて読みたい
ROSパッケージ管理に使うバージョン管理ツールの違いとその使い方 ROS/ROS2のパッケージ管理のためにバージョン管理について調べていると、vcstools, wstool, rosinstall, vcstoolなど様々なバージョン管理ツールやバージョン管理のため...
Qiita
rosdep使おうよ - Qiita rosdepROSユーザの皆様、rosdep— strv (@strv) December 10, 2019 みんな使おうよ、rosdepを!!※rosdepについては公式のチュートリアルや日本…
GitHub
recommend / use vcstool instead of wstool · Issue #25432 · ros/rosdistro wstool as well as its dependency vcstools are not actively being maintained for quite some time (see the list of pending issues and pull requests). With the mov...
GitHub
proposal to archive this repository · Issue #153 · vcstools/wstool While this project is not strictly related to ROS it was developed in the context of ROS and is mostly used in its ecosystem. Since ROS has moved to a different...

References
1 wstool updatewstool mergeコマンドなどで馴染みがあるかもしれません。
2 recommend / use vcstool instead of wstool · Issue #25432 · ros/rosdistro · GitHub
https://github.com/ros/rosdistro/issues/25432

この記事が気に入ったら
フォローしてね!

よかったらシェアしていただけると励みになります!
  • URLをコピーしました!
  • URLをコピーしました!

この記事を書いた人

Memotekiの管理人です。このブログには学んだことや共有しておきたいことをマイペースにメモしていきます。2020年からは日記も書き始めました。

コメント

コメントする


The reCAPTCHA verification period has expired. Please reload the page.

目次