5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【ROS】複数PCでの通信:rostopic echoが表示されない

Posted at

はじめに

リモートPC、ラズベリーパイの2つのPC間でROSの通信をしようとしてうまくいかなかったので同じ事象にあった方の助けになればうれしいです。
あくまで自分の環境の話なので参考にならないこともあるかと思いますがご容赦ください。

環境

リモートPC、ラズベリーパイともに以下の環境です。

項目 バージョン
Ubuntu 16.04
ROS Kinetic

結論

2つのPCの環境変数のROS_MASTER_URIROS_HOSTNAMEを正しくセットする。
ROS_IPを使わなかったらうまくいった

ROS_MASTER_URIは、リモートPCのアドレス(http://アドレス:11311)(**共通**)
ROS_HOSTNAMEは、追加する方のPCのIPアドレス(PCごとに違う)

具体例

ここで、リモートPCのIPアドレスは192.168.100.100
ラズベリーパイのIPアドレスは192.168.100.101とします。

~/.bashrcに以下を追記します。

リモートPC

export ROS_MASTER_URI=http://192.168.100.100:11311
export ROS_HOSTNAME=192.168.100.100

ラズベリーパイ

export ROS_MASTER_URI=http://192.168.100.100:11311
export ROS_HOSTNAME=192.168.100.101

起きた事象

解決策は違いましたが、この記事や、
ROS 複数台での通信時の問題点:rostopic list 見えるが rostopic echo 見えない

英語ですが、このエラーにも遭遇しました。
External ROS node can't communicate with simulink

Communication error between two nodes on two distributed machines
上記記事内の、

"ERROR: Communication with node[http:192.168.122.1:40426/] failed!"

このエラーです。

事象の具体例

ラズベリーパイ内でcmd_velトピックにpublishするraspi_velノードがあったとします。
まず最初に、以下の設定で、リモートPCでroscoreを立ち上げ、ラズベリーパイでraspi_velノードを立ち上げます。

リモートPC

export ROS_MASTER_URI=http://192.168.100.100:11311
export ROS_IP=192.168.100.100

ラズベリーパイ

export ROS_MASTER_URI=http://192.168.100.100:11311
export ROS_IP=192.168.100.101

その後、リモートPCのターミナルで、以下のコマンドを実行したところ、何も出ませんでした。

rostopic echo /cmd_vel

しかし、以下のコマンドを実行すると、cmd_velは表示されます。

rostopic list

また、以下のコマンドを実行しても。raspi_velノードは表示されます。

rosnode list

しかし、以下のコマンドを実行すると、この記事にあるようなエラーが出ました。

rosnode info raspi_vel
実行結果
Node [/raspi_vel]
Publications: 
 * /rosout [rosgraph_msgs/Log]
 * /cmd_vel

Subscriptions: 
 * /topic

Services: 
 * /raspi_vel/get_loggers
 * /raspi_vel/set_logger_level


contacting node http://IPアドレス:43126/ ...
ERROR: Communication with node[http://IPアドレス:43126/] failed!

※ちなみに、ラズベリーパイのターミナルでrostopic echo /cmd_velを実行すると表示されました。

おわりに

ややこしかったので、
ROS_IPROS_HOSTNAMEについて何かわかったら追記します!

5
3
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
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?