From 4d0a2f7c19003c8d6961eb563eb17d446f782808 Mon Sep 17 00:00:00 2001 From: Pablo Prietz Date: Fri, 1 Jun 2018 10:24:45 +0200 Subject: [PATCH] Update Python scripts --- .gitignore | 1 + python_reference_client/README.md | 2 +- python_reference_client/gaze_monitor.py | 7 ++++-- .../hmd_calibration_client.py | 23 ++++++++++--------- .../notification_monitor.py | 9 +++++--- 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index a9360398..644d8823 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ dev_Refactor-and-demos/Library/ dev_Refactor-and-demos/Temp/ +*.pyc diff --git a/python_reference_client/README.md b/python_reference_client/README.md index 6538d743..e924eb74 100644 --- a/python_reference_client/README.md +++ b/python_reference_client/README.md @@ -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. diff --git a/python_reference_client/gaze_monitor.py b/python_reference_client/gaze_monitor.py index f5155723..319b3c78 100644 --- a/python_reference_client/gaze_monitor.py +++ b/python_reference_client/gaze_monitor.py @@ -10,5 +10,8 @@ print('connected') while True: - topic,g = monitor.recv() - print(g) + try: + topic,g = monitor.recv() + print(g) + except KeyboardInterrupt: + break diff --git a/python_reference_client/hmd_calibration_client.py b/python_reference_client/hmd_calibration_client.py index b328eaf2..6b91dee2 100644 --- a/python_reference_client/hmd_calibration_client.py +++ b/python_reference_client/hmd_calibration_client.py @@ -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: @@ -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 @@ -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) diff --git a/python_reference_client/notification_monitor.py b/python_reference_client/notification_monitor.py index 1b41e4c2..2e3dd2ca 100644 --- a/python_reference_client/notification_monitor.py +++ b/python_reference_client/notification_monitor.py @@ -1,4 +1,5 @@ -from zmq_tools import * +import zmq +from zmq_tools import Msg_Receiver ctx = zmq.Context() @@ -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