6
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ROS2のコンポーネントの利用

6
Last updated at Posted at 2021-09-04

【ROS2関係トップページへ】
【前:ROS2におけるコンポーネントの作成】

ROS2におけるコンポーネントの作成などで使用したコンポーネントの利用方法について.

コンポーネントの使い方

詳しくは公式tutorialのComposing multiple nodes in a single processのRun the demosを参考のこと.

共有ライブラリのように使用

main関数のあるターゲットを作成し,普通の共有ライブラリと同じように使用する.

簡単なコマンド一覧

ros2 component -h や ros2 component load -h などで詳しい情報を見ることが出来る.

システムが見えているコンポーネント一覧を表示

$ ros2 component types

コンポーネントをスタンドアロンで実行

$ ros2 component standalone [パッケージ名] [名前空間::クラス名]

例では以下の通り.

$ ros2 component standalone minimal_comp minimal_comp::MinimalCompNode1

rclcpp_componentsによる実行

コンポーネントマネージャをterminal1で実行.terminal2でloadすることでterminal1で次々ロード・実行される.single threadなコンポーネントマネージャの実行の仕方は以下の通り.

terminal1
$ ros2 run rclcpp_components component_container

multi threadなコンポーネントマネージャを実行したい場合は以下のようにする.
詳しくはgithubのrclcpp_componentsのソースを見ると分かりやすい.

terminal1
$ ros2 run rclcpp_components component_container_mt

terminal2でコンポーネントマネージャを確認してみる.

terminal2
$ ros2 component list
/ComponentManager

コンポーネントマネージャにnodeを追加する場合は以下のようにする.

terminal2
$ ros2 component load [コンテナノード名] [パッケージ名] [名前空間::クラス名]

例では以下の通り.

$ ros2 component load /ComponentManager minimal_comp minimal_comp::MinimalCompNode1

実行するとコンポーネントマネージャを実行したterminal1に実行結果が出てくる.

コンテナノードのノード名・名前空間の変更

コンテナは普通のノードなのでノード名・名前空間を変えることができる.その場合コンポーネントのロードにも影響がある.
詳しくは公式tutorialのComposing multiple nodes in a single processのRemapping container name and namespaceを参考のこと.

YAMLファイルの読み込み

ROS2 launchの使用でlaunchファイルを作ってその中でyamlを読み込んで実行.

2020/7/24現在.模索中の話.

最初に.以下は出来ません.現在模索中の話.

ros2 component standalone や ros2 component load でyamlの設定ファイルを読み込む方法.-r __params:=[yamlファイルの指定] かな?(参考)

./yaml/test.yaml を読み込む場合,例えば以下の通り.

$ ros2 component load /ComponentManager minimal_comp minimal_comp::MinimalCompNode1 -r ./yaml/test.yaml

rclcpp_components_register_nodes詳細

公式githubの関係ページでは使用方法が以下のようになっている.

# usage: rclcpp_components_register_node(
#        <target> PLUGIN <component> EXECUTABLE <node>)
#
# :param target: the shared library target
# :type target: string
# :param PLUGIN: the plugin name
# :type PLUGIN: string
# :param EXECUTABLE: the node's executable name
# :type EXECUTABLE: string
# :param RESOURCE_INDEX: the ament resource index to register the components
# :type RESOURCE_INDEX: string

つまり,以下の書き方が正しいかもしれない.ちなみに,PLUGIN書いても書かなくても同じように動いた.

rclcpp_components_register_nodes([target名]
  PLUGIN "namespace::クラス名"
)

なお,デフォルトでついてくるジョイスティックを動かす用のjoyパッケージでは以下のようになっている.

rclcpp_components_register_node(joy
  PLUGIN "joy::Joy"
  EXECUTABLE joy_node)

このようにEXECUTABLEを指定することで実行するための名前を付けられるようである.
実際,以下のコマンドで起動できる.

$ ros2 run joy joy_node

ただ,EXECUTABLEについては自分のところでは出来ていない(2020/07/23).

6
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?