Search code examples
pythonfreezerosubuntu-20.04

ROS Python main loop hanging for few seconds


I have a problem in ROS 1 Noetic and Python in Ubuntu 20 on Raspberry Pi. I am running a few other nodes and the main node. In the main node it often happens that the code randomly hangs. This happens in a callback which receives information from another node. But it also happens if I only run the main loop. For simplicity purpose, I am attaching image of how that happens in the main loop. The first image shows the code and the second image shows the output.

As seen from the second picture, the main loop randomly hanged for whole 2.5 seconds.

If you need some more information, I would be happy to provide it.


Solution

  • Finally I have found the problem. It wasn't with the code, but with the SD card. When I switched to another SD card, the problem was gone.

    This is the SD card which had the problem: https://www.amazon.com/Kingston-Digital-32GB-microSDHC-SDCA3/dp/B00RVNGGT8?th=1

    And this is the one which didn't: https://www.amazon.com/Sandisk-Ultra-Micro-UHS-I-Adapter/dp/B073K14CVB?th=1

    The one which didn't have the problem has significantly greater read speed. I guess this is the difference that caused the problem. Or maybe the card I used before was faulty in some other way.

    What do you think? Could the read speed have such an impact?