raspberrypi / picamera2

New libcamera based python library
BSD 2-Clause "Simplified" License
887 stars 186 forks source link

[HOW-TO] Camera gets stuck when requesting frame #962

Closed feoranis26 closed 8 months ago

feoranis26 commented 8 months ago

I'm using an official Pi camera v2.1 onboard a robot for AprilTag recognition. As the robot is rather large and there wasn't enough space to put the Pi close to where the camera is, I had to use a 1 meter cable between the Pi and the camera. It works most of the time, but after a few minutes of running at about 5 fps, the code locks up while trying to capture an image. I assume the long cable is the problem as I didn't have an issue like this while testing with a shorter cable. It gets fixed when the program is restarted.

As this is for competitive robotics, it has to be reliable and be able to reset itself within a reasonable amount of time. Is it possible to add a timeout using the library itself, or do I need to add a watchdog thread that resets the camera if this happens?

The code is available here: https://github.com/CosmosRobotW0rks/CRW-7742-AprilTag-Coprocessor/blob/main/aruco_detect_udp.py (I'm not sure if this is the proper way to mention code, should I have attached it as a file, or pasted it here?)

davidplowman commented 8 months ago

Hi, thanks for the report. With all bugs, it's really helpful to post the most minimal example that you can that demonstrates the problem, preferably no more than a dozen lines if that's possible. That makes it much easier for us to reproduce problems and fix them.

In your case, I'm quite nervous about the 1m cable between the Pi and camera. The ribbon cable is simply not designed for lengths such as that, and I would expect it to be very prone to transmission errors. I simply would not recommend it. I presume you have tested a regular short (30cm or less) cable to confirm that the unreliability is related to the long cable?

I don't really have a solution for that. You could try asking on the Camera Forum. I know there are folks who have experimented with different kinds of extension cables, but it's not something that I know about, nor something that we "officially" support. Obviously you could experiment with restarting the camera after a timeout - but I couldn't say how best to do that, nor how well it would work - I guess you'd just have to try it. Sorry not to be more help.

feoranis26 commented 8 months ago

I'll try to find a spot for the Pi closer to the camera then. Thanks for taking the time to reply.