RoboCup-SSL / ssl-vision

Shared Vision System For The RoboCup Small Size League
GNU General Public License v3.0
88 stars 109 forks source link

Fix/basler oscillating timing #177

Closed rolfvdhulst closed 4 years ago

rolfvdhulst commented 4 years ago

This PR is related to fix issue #173.

The problem turned out to be two-fold. First of all, we were (accidentally) building in debug. This was not a problem by itself, but it was one of the causes for this issue.

Because in this case, the processing of an image took longer than the interval between two camera frames, ssl-vision would sometimes skip frames from the camera. This, combined with the 'take latest image' strategy and the timestamping being done in SSL-vision, would cause periodic timing errors on the order of ~10 ms.

Note other camera implementations might face the same issue if their capture rate is higher than the rate SSL-vision can process at and they use a process-latest-image strategy. (I would probably check if this is the case for camera's with large images, such as the ones used in competition).

Even though building in Release largely fixed the issue, we still wanted to use the timestamps provided by the camera itself. These were typically more reliable than the ones from ssl-vision. I implemented a moving average filter to measure the average delay between the camera time and the observation time by ssl-vision. Combining this with the time from the camera gives good accuracy on both a higher level (so that more than one camera can be used) and on a lower level (using the exact camera timing from the internal camera clock).

This PR also fixes various segfaults, bugs, exceptions and a deadlock in the basler module, and adds a framerate cap for the camera so that this issue can be prevented in the future.

rolfvdhulst commented 4 years ago

LGTM

Do know of any other team that uses Basler camera and who could test it? Otherwise, I'll merge it the next days.

As far as I am aware, RoboTeam Twente is the only team using the Basler Camera's. I asked in the discord roughly 2 months ago and no one replied.