ROS 2コマンドラインインタフェース
ROS 2 Beta 2からはコマンドラインインタフェース一式が導入されます。
本日は、以下の記事を和訳、増補追記して取り上げます。
https://github.com/ros2/ros2/wiki/Introspection-with-command-line-tools
使い方
コマンドラインインタフェースのエントリポイントはros2
です。 ros2
はさまざまなサブコマンドを持ち、ノード、トピック、サービスなどの動作検証(訳注:introspectの意)ができます。
$ ros2 --help
usage: ros2 [-h] Call `ros2 <command> -h` for more detailed usage. ...
ros2 is an extensible command-line tool for ROS 2.
optional arguments:
-h, --help show this help message and exit
Commands:
daemon Various daemon related sub-commands
msg Various msg related sub-commands
node Various node related sub-commands
pkg Various package related sub-commands
run Run a package specific executable
security Various security related sub-commands
service Various service related sub-commands
srv Various srv related sub-commands
topic Various topic related sub-commands
Call `ros2 <command> -h` for more detailed usage.
サブコマンドごとにエントリポイントros2cli
のプラグインとして実装されており、容易にコマンドの追加、拡張ができます。
https://github.com/ros2/ros2cli
sros2
のコマンドも同様に、security
というサブコマンド名でプラグインが用意されているようです。
https://github.com/ros2/sros2/tree/master/sros2/command
実行例
典型的なTalker/Listenerの例をコマンドラインインタフェースだけを使って再現できます。 メッセージのPublishにはtopic pub
、メッセージの標準出力にはtopic echo
を使います。
$ ros2 topic pub /chatter std_msgs/String "data: Hello world"
publisher: beginning loop
publishing std_msgs.msg.String(data='Hello world')
publishing std_msgs.msg.String(data='Hello world')
$ ros2 topic echo /chatter
data: Hello world
data: Hello world
簡単なメッセージやり取りのテストがコマンドラインインタフェースだけで完結するのは、やはりデバッグの面で楽でいいですね。 以前から使っていたlistener
でも同じトピック名を使っているので、同様にSubscribeして標準出力できます。
$ ros2 run demo_nodes_cpp listener
I heard: [Hello world]
I heard: [Hello world]
ノード発見デーモン
ROS 2は互いのノードを分散処理で発見(訳注:discoverの意)します。 これはROS 1のROSマスターのような中央集権的な発見機構を必要とさせないためです。 しかし、中央集権ではない分、ROSグラフに参加する全てのノードを発見するには時間がかかってしまいます。
そこで、ノード名のリストを取得する、などのROSグラフ関連のクエリにより早く応答するため、専用のデーモンをバックグラウンドで起動することができます。
ros2 daemon --help
usage: ros2 daemon [-h]
Call `ros2 daemon <command> -h` for more detailed usage.
...
Various daemon related sub-commands
optional arguments:
-h, --help show this help message and exit
Commands:
start Start the daemon if it isn't running
status Output the status of the daemon
stop Stop the daemon if it is running
Call `ros2 daemon <command> -h` for more detailed usage.
このデーモンはros2 daemon start
が呼ばれるとバックグラウンド実行されます。
これは技術(中央集権の撤廃)と現実(高速化)の結構いい落とし所ですね。 このデーモンがなければノードを分散発見し、あれば参照して高速に発見できるようになるようです。 ROSグラフが大きく複雑になる大規模なロボットシステムでは、実際問題として、こういった機能が必要になってくるものと思われます。
Comments powered by Disqus.