見出し画像

ROS入門 (61) - パッケージの依存関係

「catkin_create_pkg」「ros2 pkg create」によるパッケージ作成時に依存関係の引数を追加することで、「マニフェストファイル」「メイクファイル」にどのような情報が付加されるか調べてみました。

・Noetic
・Galactic

前回

1. ROS1のパッケージ作成時の依存関係の引数

以下の2つのパッケージ作成コマンドを比較してみます。

$ catkin_create_pkg hello rospy
$ catkin_create_pkg hello rospy std_msgs message_generation message_runtime

◎ マニフェストファイルの変更点
マニフェストファイル(package.xml)の変更点は、次のとおりです。

・依存関係タグの追加

  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>rospy</build_depend>
  <build_export_depend>rospy</build_export_depend>
  <exec_depend>rospy</exec_depend>
  ↓
  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>message_generation</build_depend>
  <build_depend>rospy</build_depend>
  <build_depend>std_msgs</build_depend>
  <build_export_depend>rospy</build_export_depend>
  <build_export_depend>std_msgs</build_export_depend>
  <exec_depend>message_runtime</exec_depend>
  <exec_depend>rospy</exec_depend>
  <exec_depend>std_msgs</exec_depend>

依存関係タグの意味は、次のとおりです。

・<buildtool_depend> : ビルドツール。基本的にcatkinのみ。
・<build_depend> : ビルド時に必要となるパッケージ。基本的にCMakeList.txtで指定するものは全て指定。
・<build_export_depend> : ヘッダーをインクルードする最に必要となるパッケージ。
・<exec_depend> : 実行時に必要となるパッケージ。Pythonノード。
・<depend> : <build_depend>/<build_export_depend>/<exec_depend>の3つを指定したのと同じ効果。
・<test_depend> : テスト実行時に必要となるパッケージ。
・<doc_depend> : ドキュメント作成時に必要となるパッケージ。doxygenなど。

依存関係タグを正しく記述することによって、ビルド前や実行前などに、必要なROSパッケージをインストールできるようになります。

◎ メイクファイルの変更点
メイクファイル(CMakeList.txt)の変更点は、次のとおりです。

・find_package()への依存関係の追加

find_package(catkin REQUIRED COMPONENTS
    rospy
)
   
find_package(catkin REQUIRED COMPONENTS
    message_generation
    message_runtime

    rospy
    std_msgs
)

・generate_messages()への依存関係の追加 (コメントアウト)

## Generate added messages and services with any dependencies listed here
# generate_messages(
    # DEPENDENCIES
    # std_msgs
# )
   
## Generate added messages and services with any dependencies listed here
# generate_messages(
    # DEPENDENCIES
    # std_msgs # Or other packages containing msgs
# )

・catkin_package()への依存関係の追加 (コメントアウト)

catkin_package(
    # INCLUDE_DIRS include
    # LIBRARIES hello
    # CATKIN_DEPENDS rospy
    # DEPENDS system_lib
)
   
catkin_package(
    # INCLUDE_DIRS include
    # LIBRARIES hello
    # CATKIN_DEPENDS  message_generation message_runtime rospy
std_msgs
    # DEPENDS system_lib
)

2. ROS2のパッケージ作成時の依存関係の引数

以下の2つのパッケージ作成コマンドを比較してみます。

$ ros2 pkg create --build-type ament_python my_custom_topic
$ ros2 pkg create --build-type ament_python my_custom_topic --dependencies rclpy my_custom_topic_msg

◎ マニフェストファイルの変更点
マニフェストファイル(package.xml)の変更点は、次のとおりです。

・依存関係タグの追加

<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
<test_depend>ament_pep257</test_depend>
<test_depend>python3-pytest</test_depend>

<depend>rclpy</depend>
<depend>my_custom_topic_msg</depend>

<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
<test_depend>ament_pep257</test_depend>
<test_depend>python3-pytest</test_depend>

3. パッケージの依存関係の確認

・ROS1
以下のコマンドでROS1の直接的な依存関係を確認することができます。

$ rospack depends1 <パッケージ名>
$ rospack depends1 turtlesim
geometry_msgs
message_runtime
rosconsole
roscpp
roscpp_serialization
roslib
rostime
std_msgs
std_srvs

以下のコマンドでROS1の直接的な依存関係が持つ依存関係を再帰的に取得できます。

$ rospack depends <パッケージ名>
$ rospack depends turtlesim
cpp_common
rostime
roscpp_traits
roscpp_serialization
catkin
genmsg
genpy
message_runtime
std_msgs
geometry_msgs
gencpp
geneus
gennodejs
genlisp
message_generation
rosbuild
rosconsole
rosgraph_msgs
xmlrpcpp
roscpp
ros_environment
rospack
roslib
std_srvs

・ROS2
ROS2には依存関係を確認するコマンドは用意されていません。代わりに「ament list_dependencies」を利用できるようです。

4. パッケージの依存関係のインストール

以下のコマンドで、ROSのパッケージの依存関係となるパッケージを全てインストールすることができます。

$ rosdep install -i --from-paths <パッケージのパス>


・ROS1

$ roscd turtlesim
$ rosdep install -i --from-paths .
#All required rosdeps installed successfully

・ROS2

$ cd `ros2 pkg prefix --share turtlesim`
$ rosdep install -i --from-paths .
#All required rosdeps installed successfully

【おまけ】 rosdepのヘルプ

◎ 使い方

$ rosdep [オプション] <コマンド> <引数>

◎ コマンド

・rosdep check <stacks-and-packages>...
パッケージの依存関係が満たされているかどうかを確認。

rosdep install <stacks-and-packages>...
特定の1つまたは複数のパッケージの依存関係をダウンロードしてインストール。

rosdep db
依存関係データベースを生成してコンソールに出力。

rosdep init
/etc/ros/rosdepのrosdepのソースを初期化。sudoが必要な場合がある。

rosdep keys <stacks-and-packages>...
パッケージが依存するrosdepキーを一覧表示。

rosdep resolve <rosdeps>
<rosdeps>をシステムの依存関係に解決。

rosdep update
rosdepソースに基づいてローカルrosdepデータベースを更新。

rosdep what-needs <rosdeps>...
<rosdeps>(の少なくとも1つ)にrosdepを宣言するパッケージのリストを出力。

rosdep where-defined <rosdeps>...
<rosdeps>(の少なくとも1つ)でrosdepを宣言するyamlファイルのリストを出力。

rosdep fix-permissions
ユーザーのrosホームディレクトリの権限を再帰的に変更。 sudoが必要な場合がある。誤ってsudoで「rosdepupdate」を呼び出した後に権限を修正するのに役立つ。

◎ オプション

・-h, --help
ヘルプ表示。

・--os=OS_NAME:OS_VERSION
OSの名前とバージョン(コロンで区切る)を上書き。
ex. ubuntu:lucid

・-c SOURCES_CACHE_DIR, --sources-cache-dir=SOURCES_CACHE_DIR
/home/ubuntu/.ros/rosdep/sources.cache をオーバーライド。

・-v, --verbose
詳細表示。

・--version
バージョン表示。

・--all-versions rosdep
バージョンとインストーラーのバージョンを表示。

・--reinstall
既にインストールされている場合でも、すべての依存関係を再インストール。

・-y, --default-yes
パッケージマネージャーに、デフォルトでyにするか、インストール時に失敗するように指示。

・-s, --simulate
インストールをシミュレート。

・-r
エラーが発生してもインストールを続行。

・-q
エラーを除いて出力を抑制。

-a, --all
全てパッケージを選択

-n
暗黙的/再帰的な依存関係を考慮しない。'keys'、'check'、および'install'コマンドでのみ有効。

・-i, --ignore-packages-from-source, --ignore-src
'check'、'install'、'keys'に影響。指定した場合、rosdepは、ROS_PACKAGE_PATH、AMENT_PREFIX_PATH、または--from-pathsオプションで指定されたディレクトリのいずれかでcatkinまたはamentパッケージであることが判明したキーを無視。

・--skip-keys=SKIP_KEYS
'check'および'install'に影響。指定されたrosdepキーは無視される。つまり、解決されず、インストールされない。オプションは複数回指定できる。 スペースで区切られたrosdepキーのリストを文字列として渡すこともできる。rosdepキーをローカルで無視するためのより永続的な解決策は、パッケージの空のリストを使用してローカルrosdepルールを作成すること。
(デフォルトの前に/etc/ros/rosdep/sources.list.d/に含める)。

・--filter-for-installers=FILTER_FOR_INSTALLERS
'db'に影響。指定されている場合、「db」コマンドの出力は、インストーラーが提供されたリストにあるパッケージのみをリストするようにフィルター処理される。オプションは複数回指定できる。スペースで区切られたインストーラーのリストを文字列として渡すこともできる。
ex. `--filter-for-installers "apt pip"`

・--from-paths
'check'、'keys'、'install'に影響。指定した場合、それらへの引数は検索対象のパスと見なされ、で見つかったすべての尾状花序パッケージに作用。

--rosdistro=ROS_DISTRO
使用するROSディストリビューションを明示的に設定し、ROS_DISTRO環境変数を使用してROSディストリビューションを検出する通常の方法をオーバーライド。'update'と一緒に使用すると、指定されたディストリビューションのみが更新される。

・--as-root=INSTALLER_KEY:<bool>
sudoが特定のインストーラーに使用されているかどうかをオーバーライド。複数回指定できる。
e.g. '--as-root pip:false' or '--as-root "pip:no homebrew:yes"'

・--include-eol-distros
'update'に影響。指定された場合、保守終了ディストリビューションもフェッチされる。

・-t DEPENDENCY_TYPES, --dependency-types=DEPENDENCY_TYPES
インストールする依存関係の種類は、複数回指定できる。
{'buildtool_export'、'exec'、'buildtool'、'test'、'build_export'、'build'、'doc'}から選択。
Default : all except doc。


この記事が気に入ったらサポートをしてみませんか?