Grab Events

See ExampleScripts Grab_Events to see how to trigger an event when you grab an object or release it.  This example will save a flag to the trial_data file with the name of the object and when it was grabbed or released along with the timestamp and the rest of the trial_data. If you have BIOPAC enabled, it will also send a synchronized event to Acqknowledge. 

To set objects as grabbable can click the checkbox in the GUI for grabbable (see creating a new scene) or add to the sceneObjects Dictionairy with code: 

basketball = env.getChild('basketball')

sightlab.addSceneObject('basketball',basketball,gaze = True, grab = True)

import sightlab_utils.sightlab as sl

from sightlab_utils.settings import *

from tools import grabber


sightlab = sl.SightLab()


# Constants

TRIAL_DATA_COLUMN = "grabbed item"


grabber_tool = vizconnect.getRawTool('grabber')

if not sightlab.getConfig() in ['Desktop']:

grabber_tool2 = vizconnect.getRawTool('grabber2')


def onGrab(event):

# Dynamically get the names of the objects during the event

scene_objects = sightlab.sceneObjects[GAZE_OBJECTS]

for name in scene_objects.keys():

if event.grabbed == scene_objects[name]:

sightlab.setCustomTrialData(f'Grabbed {name.capitalize()}', TRIAL_DATA_COLUMN)

print(f'grabbed {name}')

if sightlab.biopacFlag == True:

sightlab.acqServer.insertGlobalEvent(f'Grabbed {name}', 'stim', '')


def onRelease(event):

# Dynamically get the names of the objects during the event

scene_objects = sightlab.sceneObjects[GAZE_OBJECTS]

for name in scene_objects.keys():

if event.released == scene_objects[name]:

sightlab.setCustomTrialData(f'Released {name.capitalize()}', TRIAL_DATA_COLUMN)

print(f'released {name}')

if sightlab.biopacFlag == True:

sightlab.acqServer.insertGlobalEvent(f'Released {name}', 'stim', '')


def runExperiment():

while True:

yield viztask.waitKeyDown(' ')

print("Starting trial")

yield sightlab.startTrial()


viz.callback(grabber.GRAB_EVENT, onGrab)

viz.callback(grabber.RELEASE_EVENT, onRelease)


yield viztask.waitKeyDown(' ')

print("Ending trial")

yield sightlab.endTrial()


# Schedule tasks

viztask.schedule(sightlab.runExperiment)

viztask.schedule(runExperiment)

viz.callback(viz.getEventID('ResetPosition'), sightlab.resetViewPoint)