Real-time head tracking or feedback

The scripts for launching real-time head tracking or real-time feedback have been modified on the MEG acquisition computer. This is to avoid issues with left-over processes and shared memory segments which would not only cause issues with further attempts at running real-time, but also made Acq unnecessarily copy its data even when real-time was not being used.

This also makes it a little easier to use, again on the acquisition computer side.

Usage info:

The HeadTracking.sh script launches a program that creates a shared memory segment for communicating with Acq. Acq looks for this segment each time it starts processing data: when entering preview, when localizing the head, and when going to preview again after localizing. This means that it is not necessary to start the script before launching Acq, but it should be started at the latest during the initial head localization for it to be connected for that run. If it is started after that, you can simply abort the run and start a new acquisition for Acq to connect to the shared memory (no need to close and reopen Acq).

For stopping, you can use Ctrl+C in the terminal that displays the stream of data packets, or it is now ok to simply close that terminal. The script will take care of fully cleaning the real-time process and mark the shared memory for deletion. This can be done even if Acq is still running. Only once Acq is fully closed will the shared memory be deleted.

Additional info (not needed for end users):

Acq does not detach when it stops streaming data to the shared memory. It only does so when Acq is closed. This means that many “attachments” will accumulate during an Acq session. It also means the shared memory segment cannot be deleted until Acq is closed.

Neither Acq nor ctf2ft_v3, the real-time program that we use (provided with Fieldtrip), delete the shared memory segment once it is created. ctf2ft_v3 would reconnect to the same segment if it already exists when it starts, otherwise it creates it. This means the segment was staying present from the moment any user started a real-time process, across all user sessions, until the system was shut down. Therefore Acq was always copying its data to this shared memory, adding an unnecessary load on the system during data acquisition. Our script now removes the segment when stopping.

Depending on how ctf2ft_v3 is launched and stopped, it could remain running in the background, even after logging off. This would happen for example if a Gnome launcher was set up as “application” instead of “application in terminal”. In the situation where multiple instances are running, it will not work, sometimes intermittently displaying messages like “waiting on (545)” because duplicate processes are then competing to retrieve data packets from Acq.