トラブルシューティング
このページでは、特に ROS を使用する際、より具体的には ROS でテストを作成する際に発生する可能性のある一般的な問題について説明します。
ROS
許可されていない終了コードによるテスト失敗 (ROS2 launch_testing)
すべてのノード、プロセスなどが正常にシャットダウンされたことをテストすることは比較的一般的です。以下の例は、launch_testing
を使用して特定のプロセス(この場合はコントローラー)に対してこれを行う方法を示しています。
launch_testing.asserts.assertExitCodes(
proc_info, [launch_testing.asserts.EXIT_OK], controller_process
)
プロセスが正常に終了しない場合、エラーコード -6
と terminate called without an active exception
. という行が表示されることがあります。このエラーコードは通常、未処理の例外や信号によってプロセスが終了したことを示します。
この問題は、(Python を使用している場合) rclpy
が正常にシャットダウンされるだけでなく、開始されたすべてのスレッドも確実に終了させることで解決できる場合があります。以下の例でこれを示します:
import rclpy
from threading import Thread
...
def main(args=None):
rclpy.init(args=args)
my_node = MyNode()
executor = rclpy.executors.MultiThreadedExecutor(4)
executor.add_node(my_node)
# Start the executor in a separate thread
executor_thread = Thread(target=executor.spin, daemon=True)
executor_thread.start()
try:
my_node.my_initiating_function()
except KeyboardInterrupt:
pass
finally:
# Shutdown the executor and wait for the thread to terminate
executor.shutdown()
executor_thread.join()
rclpy.shutdown()
if __name__ == '__main__':
main()
Summary
この例では:
- rclpy を初期化し、ノードを追加します。
- MultiThreadedExecutor を作成し、そこにノードを追加します。
- エグゼキューターを別のスレッドで開始します。
- finally ブロックで、エグゼキューターが確実にシャットダウンされ、エグゼキュータースレッドが終了するまで待機します。