Skip to content

Commit

Permalink
Merge pull request #48 from pupil-labs/python3-examples
Browse files Browse the repository at this point in the history
Update Python scripts
  • Loading branch information
mkassner authored Jun 4, 2018
2 parents 10c101b + 4d0a2f7 commit 24307b3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dev_Refactor-and-demos/Library/
dev_Refactor-and-demos/Temp/
*.pyc
2 changes: 1 addition & 1 deletion python_reference_client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This guide shows how to calibrate using the HMD_Calibration plugin in Pupil Capt
The calibration plugin samples pupil positions and receives reference positions (positions of a stimulus on the left and right hmd screen) from the client app. The reference positions are determined by the client and sent in normalised screen coordinates with timestamp and id.

```python
ref_data = [{'norm_pos':pos,'timestamp':t,'id':0},...]
ref_data = [{'norm_pos': pos,'timestamp': t, 'id': 0},...]
```

The right side is denoted as id 0 , the left side as id 1. The timestamp giving clock needs to be in sync with the Pupil Capture / Service.
Expand Down
7 changes: 5 additions & 2 deletions python_reference_client/gaze_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
print('connected')

while True:
topic,g = monitor.recv()
print(g)
try:
topic,g = monitor.recv()
print(g)
except KeyboardInterrupt:
break
23 changes: 12 additions & 11 deletions python_reference_client/hmd_calibration_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,29 @@
#convenience functions
def send_recv_notification(n):
# REQ REP requirese lock step communication with multipart msg (topic,msgpack_encoded dict)
req.send_multipart(('notify.%s'%n['subject'], msgpack.dumps(n)))
return req.recv()
req.send_string('notify.%s'%n['subject'], flags=zmq.SNDMORE)
req.send(msgpack.dumps(n, use_bin_type=True))
return req.recv_string()

def get_pupil_timestamp():
req.send('t') #see Pupil Remote Plugin for details
return float(req.recv())
req.send_string('t') #see Pupil Remote Plugin for details
return float(req.recv_string())

# set start eye windows
n = {'subject':'eye_process.should_start.0','eye_id':0, 'args':{}}
print send_recv_notification(n)
print(send_recv_notification(n))
n = {'subject':'eye_process.should_start.1','eye_id':1, 'args':{}}
print send_recv_notification(n)
print(send_recv_notification(n))
time.sleep(2)


# set calibration method to hmd calibration
n = {'subject':'start_plugin','name':'HMD_Calibration', 'args':{}}
print send_recv_notification(n)
print(send_recv_notification(n))

# start caliration routine with params. This will make pupil start sampeling pupil data.
n = {'subject':'calibration.should_start', 'hmd_video_frame_size':(1000,1000), 'outlier_threshold':35}
print send_recv_notification(n)
print(send_recv_notification(n))


# Mockup logic for sample movement:
Expand All @@ -45,7 +46,7 @@ def get_pupil_timestamp():

ref_data = []
for pos in ((0.5,0.5),(0,0),(0,0.5),(0,1),(0.5,1),(1,1),(1,0.5),(1,0),(.5,0)):
print 'subject now looks at position:',pos
print('subject now looks at position:', pos)
for s in range(60):
# you direct screen animation instructions here

Expand All @@ -65,13 +66,13 @@ def get_pupil_timestamp():
# This notification can be sent once at the end or multiple times.
# During one calibraiton all new data will be appended.
n = {'subject':'calibration.add_ref_data','ref_data':ref_data}
print send_recv_notification(n)
print(send_recv_notification(n))

# stop calibration
# Pupil will correlate pupil and ref data based on timestamps,
# compute the gaze mapping params, and start a new gaze mapper.
n = {'subject':'calibration.should_stop'}
print send_recv_notification(n)
print(send_recv_notification(n))

time.sleep(2)

Expand Down
9 changes: 6 additions & 3 deletions python_reference_client/notification_monitor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from zmq_tools import *
import zmq
from zmq_tools import Msg_Receiver


ctx = zmq.Context()
Expand All @@ -10,6 +11,8 @@
monitor = Msg_Receiver(ctx,'tcp://localhost:%s'%ipc_sub_port,topics=('notify.',))

while True:
print(monitor.recv())

try:
print(monitor.recv())
except KeyboardInterrupt:
break

0 comments on commit 24307b3

Please sign in to comment.