sccn / labstreaminglayer

LabStreamingLayer super repository comprising submodules for LSL and associated apps.
Other
544 stars 161 forks source link

Time synchronization between multiple OS #78

Closed katerina-ds closed 2 years ago

katerina-ds commented 3 years ago

Hi,

Sorry if there was a question like this, I could not find any clear info. Have anyone had an experience of running LSL on a multiple devices with different OS?

Let's say we have a biofeedback system where: 1) EEG software runs on Windows (Acquisition machine), 2) the processing of the stream is done on the other machine that operates on Linux / Mac (Server). 3) The Server then controls what a person sees by sending commands to the third machine, also Linux / Mac (Display).

And surely, we wan't to minimize latency as much as possible.

How will the timing be managed in such system? Will Windows stream data with Windows-format timestamps? If so, can they be efficiently converted to unix timestamps (on which part?), so that the data streams from all machines are aligned?

Please, share your experience and feeling about the setup. Many thanks!

tstenner commented 3 years ago

Hi,

some parts of your question are answered indirectly in the FAQ and here, but hopefully I can clear things up quicker with a short history of time.

The central point is that each outlet (and also inlet) has its own, independent clock. It's possible that some outlets / inlets share the same clock, but even on the same PC two outlets with different liblsl versions might use different clocks, e.g. on clock records the time since 1970-01-01 00:00 and the other clock records the time since the last reboot. So, don't depend on two outlets sharing the same clock, use time synchronization to convert timestamps.

It follows that it doesn't matter if you have multiple PCs (because you use time synchronization) or which OSes these PCs run (because clocks might differ on the same PC anyway).

And surely, we wan't to minimize latency as much as possible.

In order of importance:

  1. Reduce the latency between the EEG and the PC (e.g. with the chunk size in BrainAmps)
  2. Avoid wireless networks, prefer cables
  3. Avoid liblsl versions before 1.14 on the inlets
  4. Check if your timing is good enough
  5. Adjust chunk sizes
  6. Run outlets and inlets on the same PC

If so, can they be efficiently converted to unix timestamps (on which part?), so that the data streams from all machines are aligned?

@cboulay is more up to date with the state of the documentation and if there's a perfect example for time synchronization.

For aligning the timestamps, you can either query the time offset manually or set the proc_clocksync flag when creating the inlet.

Please, share your experience and feeling about the setup.

Your setup looks good to me, depending on the complexity of your processing and the machine specs it might make sense to run processing on the presentation PC, but for most labs I'd recommend against it.

cboulay commented 3 years ago

@katerina-dandelion , if your control signal or feedback modality follows dynamical rules then you can predict the state at X msec into the future and use that to drive your feedback. I attached a few slides that kind of outline the concept. BCI_design.pdf

katerina-ds commented 3 years ago

Thank you so much for your help @tstenner and @cboulay. I'll try to figure out the setup and report how it went :)

cboulay commented 2 years ago

Closing as stale. We'd still love to hear your feedback when you get the chance!