Amovlab-matnav compute offset
import datetime
import time
import depthai as dai
def main():
# 1. Capture "monotonic now" (time since host PC boot, unaffected by system clock changes)
monotonic_ref = dai.Clock.now() # Returns datetime.timedelta
# 2. Capture "UTC now" at the same instant
utc_ref = datetime.datetime.utcnow() # A naive datetime in UTC
# 3. Compute offset: (UTC time) - (monotonic time)
offset = utc_ref - monotonic_ref
print("Reference measure:")
print(f" Host monotonic: {monotonic_ref}")
print(f" UTC now: {utc_ref}")
print(f" => offset = {offset}")
# Example usage: convert future monotonic timestamps to UTC
print("\nWaiting 3 seconds to demonstrate future readings...\n")
time.sleep(3)
# Suppose we get a new monotonic timestamp
monotonic_now = dai.Clock.now()
# Convert monotonic -> UTC by adding offset
utc_now = monotonic_now + offset
print(f"Monotonic now: {monotonic_now}")
print(f"Approx UTC time: {utc_now}")
if __name__ == "__main__":
main()