how to integrate Pupil with matlab-ran experiments

1,385 views
Skip to first unread message

amir...@gmail.com

unread,
Apr 26, 2016, 10:08:32 AM4/26/16
to pupil-discuss
Hi everybody,

I was wondering if anyone has experience with using Pupil in experiments ran on matlab, specifically Psychtoolbox.
I want to use Pupil for subject eye-tracking during my experiments, but could not find a good way so far to link the two. Is there one? At least a way to place markers on Pupil timeline when matlab stimuli is presented or something like that?
So far the timestamps given by both are quite different, and aligning them one to the other is not straightforward.

Thank you very much,

Amir

Rafael Picanço

unread,
Apr 26, 2016, 5:23:32 PM4/26/16
to pupil-discuss, amir...@gmail.com
Hi, I know nothing about matlab, but there is a discussion on this topic (matlab and psychtoolbox) here: https://github.com/pupil-labs/pupil/issues/352

The timestamps are used to synchronize all the asynchronous events; eye frames, word frames, notes, and so on. Your task is to timestamp the desired events of your matlab experiment using Pupil. For that you can use Pupil Server or Pupil Sync to send timestamps from (python) Pupil "server" to your matlab "client". Pupil Server uses ZeroMQ req-sub, so you need to write a ZeroMQ "subscriber" for matlab.

There is no alternative more straightforward than that as far as I know. However, you could try to enter in contact with people already using matlab to get some prompts (or even some code?).

Pupil have a python use-case, example here: https://github.com/pupil-labs/pupil-helpers. Take a look at the zmq_filter example.

Note: you may want to use Pupil Sync if dealing with time critical events.

Some design alternatives:

1) Receive only the first timestamp from pupil in matlab at the start of an experiment and deduce the rest. This results in two types of timestamps.
2) Wait (inside a thread) for timestamp requests from matlab; then receive a timestamp for each matlab request. Gives you only one standard Pupil like timestamp set.
3) Wait (inside a thread) for Pupil and Matlab events; a more abstract way that would allow receive and send stuff.

Hope this helps,
Rafael

Pupil Labs Info

unread,
May 14, 2016, 12:50:45 PM5/14/16
to pupil-...@googlegroups.com, Amir Tal
Hi,

I would recommend something along the lines of what Rafael talks about.

Use the Matlab ZMQ client to talk to pupil server and pupil remote. With this you can synchronize time, get pupil and gaze data and start/stop recording and calibration.

Best,

Moritz



--
You received this message because you are subscribed to the Google Groups "pupil-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pupil-discus...@googlegroups.com.
To post to this group, send email to pupil-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pupil-discuss/ff193c23-b23d-4036-aac3-1203e296a4e9%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Pupil Labs
research + development + design

vaibha...@gmail.com

unread,
Jun 6, 2017, 2:04:33 PM6/6/17
to pupil-discuss, amir...@gmail.com
Hi Amir,

Was going through internet forums to figure out the same thing - interface matlab with pupil labs to get raw eye coordinates. Were you ever able to achieve this, could you share some info regarding this.

Thanks
Vaibhav

elodie rigal

unread,
Jun 7, 2017, 10:26:16 AM6/7/17
to pupil-discuss, amir...@gmail.com, vaibha...@gmail.com
Hello peeps, 

I am looking for something relatively similar. I'd like to be able to send signals from psychopy (works with python language) to pupil labs. 
There are some codes int he pupil helpers but I am not competent enough to figure out where to put this code and how the pupil server gets involved. Do I have to place the code into the server library or should I just run the code from python (or psychopy) - any help would be appreciated. 

Thank you

Elodie

car...@stolaf.edu

unread,
Jun 7, 2017, 11:31:05 AM6/7/17
to pupil-discuss, amir...@gmail.com, vaibha...@gmail.com
Hello all,

Joining events from my lab's cognitive battery has been a major headache with other eye tracking systems that I have used in the past. In Pupil, my thought was to join a Surface marker with each stimulus, then Pupil can get a timestamp from the surface and I can concatenate the Eye camera data with each event. Right now, the the timestamp and frames exported in the surface_events file does not line up perfectly with the timestanmps and frames available in the pupil_positions file.

Any advice?

Regards,
Brock Carlson

amir...@gmail.com

unread,
Jun 11, 2017, 10:58:34 AM6/11/17
to pupil-discuss, amir...@gmail.com, vaibha...@gmail.com, car...@stolaf.edu
Hi all,

Sorry for the delay in replying.
I didn't succeed in implementing any of the more sophisticated and correct solutions offered to me here and elsewhere. What I eventually did was simply record with matlab the point in time in which the 'R' button was hit - beginning recording on Pupil, and used that to align the data from the two parallel running programs.
This is far from ideal but turned out to be at least precise enough for my needs.

rob.fal...@freenet.de

unread,
Jul 26, 2017, 11:23:11 AM7/26/17
to pupil-discuss, amir...@gmail.com
Dear Amir,

I am having the same problem as you had back then. I think about implementing the KbWait function into the beginning of my psychtoolbox code (I know about the random delay between 0-5ms) but I don't know how to specify this function to pushing the R button. How did you solve this issue?

Best regards,
Rob

Matiar Jafari

unread,
Jul 27, 2017, 11:15:34 AM7/27/17
to pupil-discuss
I've committed code about 1-2 months ago that allows for integration with matlab

amir...@gmail.com

unread,
Jul 28, 2017, 10:47:58 AM7/28/17
to pupil-discuss, amir...@gmail.com, rob.fal...@freenet.de

Hi Rob,

This is the bit of code I used:

done = 0;
while ~done
[keyIsDown, secs, keyCode, ~] = KbCheck();
if keyIsDown & find(keyCode)==KbName('r')
done = 1;
end
end

Hope it helps,

Amir

twbu...@googlemail.com

unread,
Oct 31, 2017, 9:26:48 PM10/31/17
to pupil-discuss
On Thursday, July 27, 2017 at 8:15:34 AM UTC-7, Matiar Jafari wrote:
> I've committed code about 1-2 months ago that allows for integration with matlab

Hi Matiar

Our lab recently purchased a Pupil Mobile headset and I'm trying to get it to integrate with MATLAB and the Psychtoolbox. I'm running MATLAB 2017b on a mac with OS X SIerra. I downloaded your code from github and I think I'm close to getting it to work. However, I'm having some issues and have some questions...I hope you can help me?

First, is it possible to run everything on one machine (i.e. Pupil Capture, python server, matlab), or is this code designed to be run on two machines (one for Pupil capture and one for matlab)?

Second, if this is possible, what should the socket addresses be set to? I've tried setting the addresses/ports on lines 21,28,30 of pythonPupil.py to the local address displayed in the Pupil Capture software menu, but I get the error below.

If you have any suggestions I'd really appreciate it!

Thanks

Tom Bullock

Postdoc, UCSB Attention Lab

-------------------------------------------------------

>> matlabPython3
Timesync successful.
timeout... 1
timeout... 2
.........................................HARD TIMEOUT.........................................
timeout... 1
timeout... 2
Traceback (most recent call last):
File "/~/Pupil_Labs/pythonPupil.py", line 107, in <module>
my_socket.send(uMsg)
ConnectionRefusedError: [Errno 61] Connection refused

ans =

1

Warning: Unsuccessful read: The specified amount of data was not returned within the Timeout
period.
Reference to non-existent field 'isConnected'.

Error in pupilRead (line 12)
if ~eyeProperties.isConnected,return;end

Error in PupilNetwork2 (line 19)
[pupil_vals] = pupilRead(hUDP, eyeProperties);

Error in matlabPython3 (line 13)
PupilNetwork2

Reply all
Reply to author
Forward
0 new messages