概要
ROS 2でCLIコマンド(例:ros2 topic listやros2 node list)を実行した際に、結果が取得できないことがありました。本記事では、その際の対処方法について説明します。
現象
ros2 topic listを実行後、2〜3分待機すると、以下のような「Connection timed out」エラーが表示されました。
Traceback (most recent call last):
File "/opt/ros/humble/bin/ros2", line 33, in
sys.exit(load_entry_point('ros2cli==0.18.11', 'console_scripts', 'ros2')())
File "/opt/ros/humble/lib/python3.10/site-packages/ros2cli/cli.py", line 91, in main
rc = extension.main(parser=parser, args=args)
File "/opt/ros/humble/lib/python3.10/site-packages/ros2topic/command/topic.py", line 41, in main
return extension.main(args=args)
File "/opt/ros/humble/lib/python3.10/site-packages/ros2topic/verb/list.py", line 55, in main
with NodeStrategy(args) as node:
File "/opt/ros/humble/lib/python3.10/site-packages/ros2cli/node/strategy.py", line 27, in __init__
if use_daemon and is_daemon_running(args):
File "/opt/ros/humble/lib/python3.10/site-packages/ros2cli/node/daemon.py", line 75, in is_daemon_running
return node.connected
File "/opt/ros/humble/lib/python3.10/site-packages/ros2cli/node/daemon.py", line 46, in connected
for method in self._proxy.system.listMethods()
File "/usr/lib/python3.10/xmlrpc/client.py", line 1122, in __call__
return self.__send(self.__name, args)
File "/usr/lib/python3.10/xmlrpc/client.py", line 1464, in __request
response = self.__transport.request(
File "/usr/lib/python3.10/xmlrpc/client.py", line 1166, in request
return self.single_request(host, handler, request_body, verbose)
File "/usr/lib/python3.10/xmlrpc/client.py", line 1178, in single_request
http_conn = self.send_request(host, handler, request_body, verbose)
File "/usr/lib/python3.10/xmlrpc/client.py", line 1291, in send_request
self.send_content(connection, request_body)
File "/usr/lib/python3.10/xmlrpc/client.py", line 1321, in send_content
connection.endheaders(request_body)
File "/usr/lib/python3.10/http/client.py", line 1278, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.10/http/client.py", line 1038, in _send_output
self.send(msg)
File "/usr/lib/python3.10/http/client.py", line 976, in send
self.connect()
File "/usr/lib/python3.10/http/client.py", line 942, in connect
self.sock = self._create_connection(
File "/usr/lib/python3.10/socket.py", line 845, in create_connection
raise err
File "/usr/lib/python3.10/socket.py", line 833, in create_connection
sock.connect(sa)
TimeoutError: [Errno 110] Connection timed out
結論
以下のコマンドを実行します。
ros2 daemon start
説明
このエラーの原因は、ROS 2 CLI内で、XML-RPC(HTTPプロトコル上でリモートプロシージャコールを実現するためのプロトコル)を使用してROS 2デーモンと通信を行っているためです。しかし、ROS 2デーモンが起動していない場合、この通信が失敗し、エラーが発生します。
ROS 2デーモンは、ROS 1のマスターのように、ROS 2ネットワーク内で動作しているノード、トピック、サービスなどの情報をキャッシュする役割を持っています。デーモンが起動していないと、ros2 topic listなどのCLIコマンドが結果を表示できないことがあります。
なお、ROS 1のマスターとは異なり、ROS 2はデーモンがなくても分散処理が可能であり、システム自体の動作に影響はありません。しかし、CLIコマンドなどでデーモンが使用されている場合、その機能が動作しないことがあります。
参考
301 Moved Permanently


コメント