「catkin_create_pkg」「ros2 pkg create」によるパッケージ作成時に依存関係の引数を追加することで、「マニフェストファイル」「メイクファイル」にどのような情報が付加されるか調べてみました。
前回
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>
依存関係タグの意味は、次のとおりです。
依存関係タグを正しく記述することによって、ビルド前や実行前などに、必要なROSパッケージをインストールできるようになります。
◎ メイクファイルの変更点
メイクファイル(CMakeList.txt)の変更点は、次のとおりです。
・find_package()への依存関係の追加
・generate_messages()への依存関係の追加 (コメントアウト)
・catkin_package()への依存関係の追加 (コメントアウト)
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)の変更点は、次のとおりです。
・依存関係タグの追加
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 .
・ROS2
$ cd `ros2 pkg prefix --share turtlesim`
$ rosdep install -i --from-paths .
【おまけ】 rosdepのヘルプ
◎ 使い方
◎ コマンド
◎ オプション