goodrobots / vision_landing

Precision landing using visual targets
GNU General Public License v3.0
202 stars 71 forks source link

Take timestamp as close to shutter as possible #106

Closed fnoop closed 6 years ago

fnoop commented 6 years ago

The landing_target synchronised timestamp should be taken from as close to the shutter time as possible, before any image processing and pattern detection takes place. This is to more accurately correlate the inertial movement and attitude correction to the target image.

fnoop commented 6 years ago

c++ track_targets uses clock_gettime(CLOCK_MONOTONIC). python (2.7) vision_landing doesn't have inherent access to monotonic clock. Here's one way to do it: https://stackoverflow.com/a/1205762

fnoop commented 6 years ago

Python vision_landing uses:

    def current_timestamp(self):
        return int((datetime.utcnow() - datetime(1970, 1, 1)).total_seconds() * 1000000000);

This probably uses gettimeofday() to microsecond accuracy on Linux, although is CLOCK_REALTIME and thus subject to adjustments.

fnoop commented 6 years ago

So currently we can take the timestamp at great accuracy (clock_gettime monotonic) as soon as possible after the sensor frame is grabbed and before processing. This is output by track_targets and read by python, which will have to calculate where in the synced (with autopilot) clock object to insert this. As long as we get <1ms accuracy/correlation, this should be OK.

fnoop commented 6 years ago

Updated python code to use monotonic clock_gettime() clock and read new timestamp measure close to sensor grab. https://github.com/goodrobots/vision_landing/commit/cef02bd42b1ecf05706bbbecaf20bf4aec8ce12e