Skip to content

How to apply time synchronization properly #127

@ChadChen68

Description

@ChadChen68

I am currently setting up an LSL (Lab Streaming Layer) connection between my Meta Quest Pro and my host PC. However, I am still facing issues with time synchronization in the inlet stream.
I have tried using processing_flags=pylsl.proc_ALL, but the problem persists. My implementation is based on the ReceiveAndPlot.py example.
I have read the LSL time synchronization documentation, which mentions that a main clock is required to synchronize timestamps. I think I already applied my host PC clock.

I also tried using time_correction from the GetTimeCorrection.py example, but I don't fully understand this part:
Returns the current time correction estimate. This is the number that needs to be added to a time stamp that was remotely generated via local_clock() to map it into the local clock domain of this machine.
Should I simply use local_clock() + timeout?

Here is my build-up:

  • Host PC: Receives data and event streams (running in Python).
  • Data stream: A homemade EEG headset (running in Python), sending data to the host PC.
  • Event stream: Meta Quest Pro sends event data to the host PC (task running in Unity).
  • All three devices are on the same LAN (without wifi).

My current code below

import pylsl
from typing import List
class Inlet:
    def __init__(self, info: pylsl.StreamInfo):
        self.inlet = pylsl.StreamInlet(info, processing_flags=pylsl.proc_ALL)
        self.name = info.name()
        self.channel_count = info.channel_count()
    def pull_and_plot(self):
        pass
class MarkerInlet(Inlet):
    def __init__(self, info: pylsl.StreamInfo):
        super().__init__(info)
    def pull_and_plot(self):
        markers, timestamps = self.inlet.pull_chunk(0)
        if markers and timestamps:
            for marker, timestamp in zip(markers, timestamps):
                print(f"Marker:{marker}, Timestamp: {timestamp}") 
class DataInlet(Inlet):
    def __init__(self, info: pylsl.StreamInfo):
        super().__init__(info)
    def pull_and_plot(self):
        data, timestamps = self.inlet.pull_chunk(timeout = 0.0)
def main():
    inlets: List[Inlet] = []
    print("Looking for streams")
    streams = pylsl.resolve_streams()
    for info in streams:
                if info.type() == 'Markers':
                    if info.nominal_srate() != pylsl.IRREGULAR_RATE \
                            or info.channel_format() != pylsl.cf_string:
                        print('Invalid marker stream ' + info.name())
                    print('Adding marker inlet: ' + info.name())
                    inlets.append(MarkerInlet(info))
                elif info.nominal_srate() != pylsl.IRREGULAR_RATE \
                        and info.channel_format() != pylsl.cf_string:
                    print('Adding data inlet: ' + info.name())
                    inlets.append(DataInlet(info))
                else:
                    print('Don\'t know what to do with stream ' + info.name())
    while True:
            for inlet in inlets:
                inlet.pull_and_plot()
if __name__ == '__main__':
    main()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions