Beispiel #1
0
def init(qHaveSimultaneous):
    if qHaveSimultaneous:
        vizconnect.go('vizconnectSetups/vive_ppt_intersense.py')
    else:
        vizconnect.go('vizconnectSetups/viveLighthouse.py')
    piazza = viz.add('piazza.osgb')
    piazza2 = viz.add('piazza_animations.osgb')

    vive = vizconnect.getRawTracker('head_tracker')
    if qHaveSimultaneous:
        optHead = vizconnect.getRawTracker('optical_heading')
        PPT1 = vizconnect.getRawTracker('ppt_1')
        PPT2 = vizconnect.getRawTracker('ppt_2')
        PPT3 = vizconnect.getRawTracker('ppt_3')
        PPT4 = vizconnect.getRawTracker('ppt_4')
        inertiacube = vizconnect.getRawTracker('inertiacube')

    # check controller is on
    steamvr.getControllerList()[0].isButtonDown(2)

    def getTrackInfo():
        if 1:
            if qHaveSimultaneous:
                return {
                    'vive': vive.getPosition() + vive.getEuler(),
                    'optical_heading':
                    optHead.getPosition() + optHead.getEuler(),
                    'PPT1': PPT1.getPosition(),
                    'PPT2': PPT2.getPosition(),
                    'PPT3': PPT3.getPosition(),
                    'PPT4': PPT4.getPosition(),
                    'inertiacube': inertiacube.getEuler()
                }
            else:
                return {'vive': vive.getPosition() + vive.getEuler()}
        else:
            return {
                'viveController':
                steamvr.getControllerList()[0].getPosition() +
                steamvr.getControllerList()[0].getEuler()
            }

    trialStartSound = viz.addAudio('sounds/quack.wav', play=0, volume=2.)
    trialCompletedSound = viz.addAudio('sounds/pop.wav', play=0, volume=2.)
    alarmSound = viz.addAudio('alarm.wav', play=0, volume=2.)

    # make return values
    Sounds = namedtuple('Sounds', 'trialStart trialCompleted alarm')
    InitReturn = namedtuple('initReturn', 'visuals sounds trackerDataFun')
    return InitReturn(visuals=[piazza, piazza2],
                      sounds=Sounds(trialStart=trialStartSound,
                                    trialCompleted=trialCompletedSound,
                                    alarm=alarmSound),
                      trackerDataFun=getTrackInfo)
    def steamvr_setup_vm2(self, right_hand_object, head_object):

        hmd = steamvr.HMD()
        if not hmd.getSensor():
            sys.exit('SteamVR HMD not detected')
        viz.link(hmd.getSensor(), viz.MainView)

        # create LSL stream for MoBIlab pos and ori analysis --> ori should be in quaternions
        hmd_stream = self.create_non_phasespace_rigid_body_stream(
            'headRigid', 0)
        # stream 6dof of HMD as pos (x,y,z) and ori(x,y,z,w) --> quaternion
        vizact.onupdate(18, self.update_and_push_rigid_body, viz.MainView,
                        head_object, hmd_stream)

        #  connecting present controllers
        trackers = steamvr.getTrackerList()
        self.controller = steamvr.getControllerList()[0]
        tracker_names = ['handRigid', 'torsoRigid']

        for i in range(len(trackers)):
            # create LSL stream for MoBIlab pos and ori analysis --> ori should be in quaternions
            tracker_stream = self.create_non_phasespace_rigid_body_stream(
                tracker_names[i], 0)
            # stream 6dof as pos (x,y,z) and ori(x,y,z,w) --> quaternion

            print(trackers[i].getData())
            print(trackers[i].getPosition())

            if i == 0:
                vizact.onupdate(19, self.update_and_push_rigid_body,
                                trackers[i], right_hand_object, tracker_stream)
            else:
                vizact.onupdate(19, self.update_and_push_rigid_body,
                                trackers[i], None, tracker_stream)
    def start_vr(self):
        hmd = steamvr.HMD()
        if not hmd.getSensor():
            sys.exit('SteamVR HMD not detected')
        viz.link(hmd.getSensor(), viz.MainView)

        # create LSL stream for MoBIlab pos and ori analysis --> ori should be in quaternions
        hmd_stream = self.subject.create_non_phasespace_rigid_body_stream('headRigid', 0)
        # stream 6dof of HMD as pos (x,y,z) and ori(x,y,z,w) --> quaternion
        vizact.onupdate(0, self.subject.update_and_push_rigid_body, viz.MainView, self.subject.head_sphere, hmd_stream)

        #  connecting present controllers
        trackers = steamvr.getTrackerList()
        self.controller = steamvr.getControllerList()[0]
        print self.controller
        tracker_names = ['handRigid', 'armRigid', 'torsoRigid']

        find_out_tracker = vizact.onupdate(0, self.assign_trackers, trackers)
        yield viztask.waitTime(5) # wait two seconds to figure out which tracker is more to the front in z direction = hand tracker
        find_out_tracker.remove()
        
        # create LSL stream for MoBIlab pos and ori analysis --> ori should be in quaternions
        # stream 6dof as pos (x,y,z) and ori(x,y,z,w) --> quaternion
        hand_stream = self.subject.create_non_phasespace_rigid_body_stream(tracker_names[self.hand_tracker_id], 0)
        vizact.onupdate(0, self.subject.update_and_push_rigid_body, trackers[self.hand_tracker_id], self.subject.right_hand_sphere, hand_stream)
        
        # create LSL stream for MoBIlab pos and ori analysis --> ori should be in quaternions
        arm_stream = self.subject.create_non_phasespace_rigid_body_stream(tracker_names[self.arm_tracker_id], 0)
        vizact.onupdate(0, self.subject.update_and_push_rigid_body, trackers[self.arm_tracker_id], None, arm_stream)

        # create LSL stream for MoBIlab pos and ori analysis --> ori should be in quaternions
        torso_stream = self.subject.create_non_phasespace_rigid_body_stream(tracker_names[self.torso_tracker_id], 0)
        vizact.onupdate(0, self.subject.update_and_push_rigid_body, trackers[self.torso_tracker_id], None, torso_stream)
def CheckForMarkers():
	global Tracking, Controllers
	Trackers = steamvr.getTrackerList()
	ControllerLocal = steamvr.getControllerList()
	Tracking = []
	Controllers = []
	print("Trackers: ")
	print(Tracking)
	print("Controllers: ")
	print(Controllers)
	i = 0
	for x in Trackers:
		Tracking.append(x)
		if DebugFlag == True:
			viz.link(Tracking[i], Tracking[i].addModel())
		i += 1
	i = 0
	for x in ControllerLocal:
		Controllers.append(x)
		if DebugFlag == True:
			viz.link(Controllers[i], Controllers[i].addModel())
		i += 1
	print("Trackers: ")
	print(Tracking)
	print("Controllers: ")
	print(Controllers)
Beispiel #5
0
 def getTrackInfo():
     if 1:
         if qHaveSimultaneous:
             return {
                 'vive': vive.getPosition() + vive.getEuler(),
                 'optical_heading':
                 optHead.getPosition() + optHead.getEuler(),
                 'PPT1': PPT1.getPosition(),
                 'PPT2': PPT2.getPosition(),
                 'PPT3': PPT3.getPosition(),
                 'PPT4': PPT4.getPosition(),
                 'inertiacube': inertiacube.getEuler()
             }
         else:
             return {'vive': vive.getPosition() + vive.getEuler()}
     else:
         return {
             'viveController':
             steamvr.getControllerList()[0].getPosition() +
             steamvr.getControllerList()[0].getEuler()
         }
Beispiel #6
0
def setControl(selectedControlSchema, isLeftHanded = 0):
	global isCube1, isCube2
	# EXTENSION: Add rotational tracking of the two hands via intersense cube
	isense = viz.add('intersense.dle')
	if isLeftHanded == 0:
		#user right-handed; in unimanual setting, moves right hand
#		isCube1 = isense.addTracker(port=6)
		isCube1 = steamvr.getControllerList()[1]	#pptextensionDK2.lhPPTmarker #isense.addTracker(port=some_global_variables.isensePort1)
#		isCube2 = isense.addTracker(port=7)
		isCube2 = steamvr.getControllerList()[0]  #pptextensionDK2.rhPPTmarker #isense.addTracker(port=some_global_variables.isensePort2)
	else:
		#user left-handed; in unimanual setting, moves left hand
		isCube1 = steamvr.getControllerList()[0]	#pptextensionDK2.lhPPTmarker #isense.addTracker(port=some_global_variables.isensePort1)
#		isCube2 = isense.addTracker(port=7)
		isCube2 = steamvr.getControllerList()[1]  #pptextensionDK2.rhPPTmarker #isense.addTracker(port=some_global_variables.isensePort2)		
		
#		isCube1 = isense.addTracker(port=7)
		#isCube1 = pptextensionDK2.rhPPTmarker #isense.addTracker(port=some_global_variables.isensePort2)
#		isCube2 = isense.addTracker(port=6)
		#isCube2 = pptextensionDK2.lhPPTmarker #isense.addTracker(port=some_global_variables.isensePort1)

	
	# Link 
	pptextensionDK2.isCube1 = isCube1
	pptextensionDK2.isCube2 = isCube2

	global functionPointerForBimanualControl, functionPointerForUnimanualControl, functionPointerForHeadControl
	#Control schema switch
#	if (selectedControlSchema == 0):
#		functionPointerForBimanualControl = vizact.onupdate(0, controlWithBimanualWristRotation)
#	elif (selectedControlSchema == 1):
#		functionPointerForUnimanualControl = vizact.onupdate(0, controlWithUnimanualWristRotation)
#	elif (selectedControlSchema == 2):
#		functionPointerForHeadControl = vizact.onupdate(0, controlWithHeadRotation)
	functionPointerForBimanualControl = vizact.onupdate(0, controlWithBimanualWristRotation)
	functionPointerForUnimanualControl = vizact.onupdate(0, controlWithUnimanualWristRotation)
	functionPointerForHeadControl = vizact.onupdate(0, controlWithHeadRotation)
	global controlSchemaCounter
	controlSchemaCounter = selectedControlSchema
	setControlSchema()
Beispiel #7
0
def setUpHMD():
	global lhTracker, rhTracker, flyingLink, headTracker
	viz.window.setSize(1520,1205)
	viz.go(viz.TRACKER)

	
	view = viz.MainView
#	isense = viz.add('intersense.dle')
#	headTracker = isense.addTracker(port=1)
#	vizact.onkeydown('r',headTracker.resetHeading)
	#vrpn = viz.add('vrpn7.dle')
	#Tracker_HOSTNAME = '171.64.33.43'
	
	from vizconnect.util.virtual_trackers import OpticalHeading
	
	import steamvr
	# vive view will take the Main View (viz.MainView)
	hmd = steamvr.HMD()


		
### Trackers ###

	ORI_TRACKER = hmd.getSensor()
	offsetMarkerNode = viz.addGroup()
	headTracker = viz.link(ORI_TRACKER, offsetMarkerNode)

	lhTracker = steamvr.getControllerList()[0]
	rhTracker = steamvr.getControllerList()[1]
	
	viveViewLink = viz.link(headTracker, viz.MainView)

	
	if FLYING_F:
		flyingLink = viveViewLink
		flyingLink.postTrans(START_POSITION_BASE)
def main():
    # Initialize window
    viz.setMultiSample(8)
    viz.go()

    # Setup SteamVR HMD
    hmd = steamvr.HMD()
    if not hmd.getSensor():
        sys.exit('SteamVR HMD not detected')

    # Setup navigation node and link to main view
    navigationNode = viz.addGroup()
    viewLink = viz.link(navigationNode, viz.MainView)
    viewLink.preMultLinkable(hmd.getSensor())

    # Load environment
    gallery = vizfx.addChild('gallery.osgb')
    gallery.hint(viz.OPTIMIZE_INTERSECT_HINT)
    gallery.disable(viz.SHADOW_CASTING)

    #Create skylight
    viz.MainView.getHeadLight().disable()
    sky_light = viz.addDirectionalLight(euler=(0,90,0), color=viz.WHITE)
    sky_light.setShadowMode(viz.SHADOW_DEPTH_MAP)
    
    #Start the Leap Motion!
    handGenerator = LeapListener()
    handGenerator.startLeap(hmd.getSensor())
    
    # Add controllers
    for controller in steamvr.getControllerList():

        # Create model for controller
        controller.model = controller.addModel(parent=navigationNode)
        controller.model.disable(viz.INTERSECTION)
        viz.link(controller, controller.model)
def initInputs(initFlag=vizconnect.INIT_INDEPENDENT, initList=None):
    #VC: place any general initialization code here
    rawInput = vizconnect.getRawInputDict()

    #VC: initialize a new input
    _name = 'keyboard'
    if vizconnect.isPendingInit('input', _name, initFlag, initList):
        #VC: init the raw object
        if initFlag & vizconnect.INIT_RAW:
            #VC: set some parameters
            index = 0

            #VC: create the raw object
            d = viz.add('directinput.dle')
            device = d.getKeyboardDevices()[index]
            rawInput[_name] = d.addKeyboard(device)

        #VC: init the wrapper (DO NOT EDIT)
        if initFlag & vizconnect.INIT_WRAPPERS:
            vizconnect.addInput(rawInput[_name],
                                _name,
                                make='Generic',
                                model='Keyboard')

    #VC: initialize a new input
    _name = 'r_hand_input'
    if vizconnect.isPendingInit('input', _name, initFlag, initList):
        #VC: init the raw object
        if initFlag & vizconnect.INIT_RAW:
            #VC: set some parameters
            index = 0

            #VC: create the raw object
            import steamvr
            try:
                input = steamvr.getControllerList()[index]
                input._isValid = True
            except IndexError:
                viz.logWarn(
                    "** WARNING: Not able to connect to a controller at index {0}. It's likely that not enough controllers are connected."
                    .format(index))
                input = viz.VizExtensionSensor(-1)
                input.isButtonDown = lambda e: False
                input.getTrackpad = lambda: [0, 0]
                input._isValid = False
            rawInput[_name] = input

        #VC: init the wrapper (DO NOT EDIT)
        if initFlag & vizconnect.INIT_WRAPPERS:
            vizconnect.addInput(rawInput[_name],
                                _name,
                                make='HTC',
                                model='Vive Controller')

        #VC: init the mappings for the wrapper
        if initFlag & vizconnect.INIT_WRAPPER_MAPPINGS:
            #VC: per frame mappings
            if initFlag & vizconnect.INIT_MAPPINGS_PER_FRAME:
                #VC: get the raw input dict so we have access to signals
                import vizact
                rawInput = vizconnect.getConfiguration().getRawDict('input')

                #VC: set the update function which checks for input signals
                def update(input):
                    if rawInput['r_hand_input'].isButtonDown(
                            2
                    ):  # make=HTC, model=Vive Controller, name=r_hand_input, signal=Button Trigger
                        input.setQuasimode()

                vizconnect.getInput(_name).setUpdateFunction(update)

    #VC: initialize a new input
    _name = 'l_hand_input'
    if vizconnect.isPendingInit('input', _name, initFlag, initList):
        #VC: init the raw object
        if initFlag & vizconnect.INIT_RAW:
            #VC: set some parameters
            index = 1

            #VC: create the raw object
            import steamvr
            try:
                input = steamvr.getControllerList()[index]
                input._isValid = True
            except IndexError:
                viz.logWarn(
                    "** WARNING: Not able to connect to a controller at index {0}. It's likely that not enough controllers are connected."
                    .format(index))
                input = viz.VizExtensionSensor(-1)
                input.isButtonDown = lambda e: False
                input.getTrackpad = lambda: [0, 0]
                input._isValid = False
            rawInput[_name] = input

        #VC: init the wrapper (DO NOT EDIT)
        if initFlag & vizconnect.INIT_WRAPPERS:
            vizconnect.addInput(rawInput[_name],
                                _name,
                                make='HTC',
                                model='Vive Controller')

    #VC: set the name of the default
    vizconnect.setDefault('input', 'r_hand_input')

    #VC: return values can be modified here
    return None
def initTrackers(initFlag=vizconnect.INIT_INDEPENDENT, initList=None):
    #VC: place any general initialization code here
    rawTracker = vizconnect.getRawTrackerDict()

    #VC: initialize a new tracker
    _name = 'head_tracker'
    if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
        #VC: init the raw object
        if initFlag & vizconnect.INIT_RAW:
            #VC: set some parameters
            index = 0

            #VC: create the raw object
            import steamvr
            try:
                tracker = steamvr.getExtension().getHMDList()[index]
            except IndexError:
                viz.logWarn(
                    "** WARNING: Not able to connect to tracker at index {0}. It's likely that not enough trackers are connected."
                    .format(index))
                tracker = viz.addGroup()
                tracker.invalidTracker = True
            rawTracker[_name] = tracker

        #VC: init the wrapper (DO NOT EDIT)
        if initFlag & vizconnect.INIT_WRAPPERS:
            vizconnect.addTracker(rawTracker[_name],
                                  _name,
                                  make='Valve',
                                  model='SteamVR HMD Tracker')

    #VC: initialize a new tracker
    _name = 'r_hand_tracker'
    if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
        #VC: init the raw object
        if initFlag & vizconnect.INIT_RAW:
            #VC: set some parameters
            index = 0

            #VC: create the raw object
            import steamvr
            try:
                tracker = steamvr.getControllerList()[index]
            except IndexError:
                viz.logWarn(
                    "** WARNING: Not able to connect to tracker at index {0}. It's likely that not enough trackers are connected."
                    .format(index))
                tracker = viz.addGroup()
                tracker.invalidTracker = True
            rawTracker[_name] = tracker

        #VC: init the wrapper (DO NOT EDIT)
        if initFlag & vizconnect.INIT_WRAPPERS:
            vizconnect.addTracker(rawTracker[_name],
                                  _name,
                                  make='Valve',
                                  model='SteamVR Controller Tracker')

    #VC: initialize a new tracker
    _name = 'l_hand_tracker'
    if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
        #VC: init the raw object
        if initFlag & vizconnect.INIT_RAW:
            #VC: set some parameters
            index = 1

            #VC: create the raw object
            import steamvr
            try:
                tracker = steamvr.getControllerList()[index]
            except IndexError:
                viz.logWarn(
                    "** WARNING: Not able to connect to tracker at index {0}. It's likely that not enough trackers are connected."
                    .format(index))
                tracker = viz.addGroup()
                tracker.invalidTracker = True
            rawTracker[_name] = tracker

        #VC: init the wrapper (DO NOT EDIT)
        if initFlag & vizconnect.INIT_WRAPPERS:
            vizconnect.addTracker(rawTracker[_name],
                                  _name,
                                  make='Valve',
                                  model='SteamVR Controller Tracker')

    #VC: set the name of the default
    vizconnect.setDefault('tracker', 'head_tracker')

    #VC: return values can be modified here
    return None
PHYSICS_ENABLED = True #if false, then you can pick up snails; if true can pick up soccerball w/ physics

viz.setMultiSample(4)
viz.fov(60)
viz.go()

if PHYSICS_ENABLED:
    viz.phys.enable()
    viz.phys.setGravity(0,-1,0) 

if VIVE:
    hmd = steamvr.HMD()
    if not hmd.getSensor():
        print "ERROR: HTC Vive not detected"
    viz.link(hmd.getSensor(), viz.MainView)
    viveHandControllerList = steamvr.getControllerList()
    if viveHandControllerList:
        hand = viveHandControllerList[0]
        handModel = hand.addModel()
        link = viz.link(hand, handModel)
    else:
        print "ERROR: No controllers detected"
else:
    keyCam = vizcam.KeyboardCamera()
    # keyboard navigation, see vizcam documentation for keypresses
        
#set up collision with ocean floor
zone1 = vizfx.addChild(FILE_PATH_TO_ZONE1)
zone1.setPosition(0,1.5,0)

terrain = zone1.getChild('Terrain_Zone01')
Beispiel #12
0
    def findDevices(self):
        """ Enumerate SteamVR devices and set up models """

        # HMD
        hmd = steamvr.HMD()
        self.hmd['sensor'] = hmd.getSensor()

        hmd_ui = viz.addText('N/A')
        self._ui.addItem(viz.addText('Headset'))        
        self._ui.addLabelItem('0', hmd_ui)
        self._ui.addSeparator()
        self.hmd['ui'] = hmd_ui

        hud = viz.addText3D('X: 0.00 (123.0°)', scale=(self.VALUE_SCALE * 2.5,) * 3, color=viz.GRAY)
        hud_link = viz.link(viz.MainView, hud)
        hud_link.preTrans(self.HUD_POS, viz.REL_LOCAL)
        self.hmd['hud'] = hud
        self._obj.append(hud)

        # Lighthouses
        for lidx, lighthouse in enumerate(steamvr.getCameraList()):
            lighthouse.model = lighthouse.addModel(parent=self._root)
            if not lighthouse.model:
                lighthouse.model = viz.addGroup()
            lighthouse.model.setCompositeAlpha(self.DEBUG_ALPHA)
            lighthouse.model.disable(viz.INTERSECTION)
            viz.link(lighthouse, lighthouse.model)
            
            l_text = viz.addText3D(str(lidx), scale=(self.LABEL_SCALE,) * 3, color=viz.YELLOW,
                                parent=lighthouse.model, pos=(0.1, 0, 0))
            l_text.setEuler(180, 0, 0)
            
            # Lighthouse normal vector
            l_normal = addRayPrimitive(origin=[0,0,0], direction=[0,0,1], color=viz.YELLOW, parent=lighthouse.model)
            l_normal.visible(False)

            self.lighthouses[lidx] = {'model': lighthouse.model,
                                      'normal': l_normal,
                                      'text': l_text}
            self._obj.append(lighthouse.model)
            print('* Found Lighthouse: {:d}'.format(lidx))

        # Controllers
        if steamvr.getControllerList():
            self._ui.addItem(viz.addText('Controllers'))

            for cidx, controller in enumerate(steamvr.getControllerList()):
                
                controller.model = controller.addModel(parent=self._root)
                if not controller.model:
                    controller.model = viz.addGroup(parent=self._root)
                controller.model.setCompositeAlpha(self.DEBUG_ALPHA)
                controller.model.disable(viz.INTERSECTION)
                viz.link(controller, controller.model)
                
                c_axes = vizshape.addAxes(scale=(0.1, 0.1, 0.1))
                viz.link(controller, c_axes)

                markers = {'axes': c_axes}
                for m in self._markers:
                    markers[m] = self._markers[m].copy()
                    markers[m].visible(False)
                    viz.link(controller, markers[m])

                c_text = viz.addText3D(str(cidx), scale=(self.LABEL_SCALE,) * 3, 
                                    parent=controller.model, pos=(-0.05, 0, 0))
                val_x = viz.addText3D('X: 0.00 (123.0°)', scale=(self.VALUE_SCALE,) * 3, 
                                    parent=controller.model, pos=(-0.18, 0.04, 0), color=viz.RED)
                val_y = viz.addText3D('Y: 0.00 (123.0°)', scale=(self.VALUE_SCALE,) * 3, 
                                    parent=controller.model, pos=(-0.18, 0.02, 0), color=viz.GREEN)
                val_z = viz.addText3D('Z: 0.00 (123.0°)', scale=(self.VALUE_SCALE,) * 3, 
                                    parent=controller.model, pos=(-0.18, 0, 0), color=viz.BLUE)
                
                self.controllers[cidx] = {'model': controller.model,
                                          'axes': c_axes,
                                          'text': c_text,
                                          'values': [val_x, val_y, val_z],
                                          'ui': viz.addText('N/A'),
                                          'markers': markers,
                                          'active_marker': 'axes'}

                self._ui.addLabelItem(str(cidx), self.controllers[cidx]['ui'])
                self._obj.extend([controller.model, c_axes, val_x, val_y, val_z])
                print('* Found Controller: {:d}'.format(cidx))

                self._callbacks.append(vizact.onsensordown(controller, steamvr.BUTTON_TRIGGER, self._storePoint, controller, cidx))
                self._callbacks.append(vizact.onsensordown(controller, steamvr.BUTTON_TRACKPAD, self._switchMarker, cidx))
                self._callbacks.append(vizact.onsensordown(controller, 1, self.savePoints))
                self._callbacks.append(vizact.onsensordown(controller, 0, self.saveScreenshot))
        else:
            print('* No controllers detected.')

        # Trackers
        if steamvr.getTrackerList():
            self._ui.addSeparator()
            self._ui.addItem(viz.addText('Trackers'))

            for tidx, tracker in enumerate(steamvr.getTrackerList()):
                
                tracker.model = tracker.addModel(parent=self._root)
                if not tracker.model:
                    tracker.model = viz.addGroup(parent=self._root)
                tracker.model.setCompositeAlpha(self.DEBUG_ALPHA)
                tracker.model.disable(viz.INTERSECTION)
                viz.link(tracker, tracker.model)

                t_axes = vizshape.addAxes(scale=(0.1, 0.1, 0.1))
                viz.link(tracker, t_axes)

                t_text = viz.addText3D(str(tidx), scale=(0.05, 0.05, 0.05), color=viz.BLUE,
                                    parent=tracker.model, pos=(-0.1, 0, 0))
                val_x = viz.addText3D('X: 0.00 (123.0°)', scale=(self.VALUE_SCALE,) * 3, 
                                    parent=tracker.model, pos=(0.18, 0.04, 0), color=viz.RED)
                val_x.setEuler([180, 0, 0], mode=viz.REL_LOCAL)
                val_y = viz.addText3D('Y: 0.00 (123.0°)', scale=(self.VALUE_SCALE,) * 3, 
                                    parent=tracker.model, pos=(0.18, 0.02, 0), color=viz.GREEN)
                val_y.setEuler([180, 0, 0], mode=viz.REL_LOCAL)
                val_z = viz.addText3D('Z: 0.00 (123.0°)', scale=(self.VALUE_SCALE,) * 3, 
                                    parent=tracker.model, pos=(0.18, 0, 0), color=viz.BLUE)
                val_z.setEuler([180, 0, 0], mode=viz.REL_LOCAL)

                self.trackers[tidx] = {'model': tracker.model,
                                       'axes': t_axes,
                                       'text': t_text,
                                       'values': [val_x, val_y, val_z],
                                       'ui': viz.addText('N/A')}
                self._ui.addLabelItem(str(tidx), self.trackers[tidx]['ui'])
                self._obj.extend([tracker.model, t_axes, val_x, val_y, val_z])
                print('* Found Vive tracker: {:d}'.format(tidx))
        else:
            print('* No trackers detected.')
			background2.visible(viz.OFF)
		if info.name == "basketball":
			if(test_num == 2):
				consent = True;
				canvas.visible(False)
				background.visible(viz.OFF)
				background2.visible(viz.OFF)
			else:
				
				test_num = test_num + 1
				panel.setText(test_text[test_num])
				if(test_num == 2):
					background2.visible(viz.ON)

# Add controllers
for controller in steamvr.getControllerList():

	# Create model for controller
	controller.model = controller.addModel(parent=navigationNode)
	controller.model.disable(viz.INTERSECTION)
	viz.link(controller, controller.model)

	# Create pointer line for controller
	viz.startLayer(viz.LINES)
	viz.vertexColor(viz.WHITE)
	viz.vertex([0,0,0])
	viz.vertex([0,0,100])
	controller.line = viz.endLayer(parent=controller.model)
	controller.line.disable([viz.INTERSECTION, viz.SHADOW_CASTING])
	controller.line.visible(True)
Beispiel #14
0
def TrackTask():
    prevPos = None
    tracking = False
    allData = []
    tCount = -1
    # run until number of trials finished, or forever
    while True:
        # wait for trigger press
        while not (steamvr.getControllerList()[0].isButtonDown(2)
                   or viz.key.isDown('c', immediate=True)):
            pos = setup.trackerDataFun()
            if prevPos is not None and pos['vive'] == prevPos['vive']:
                # position didn't change at all, not tracking
                if tracking:
                    print 'track lost'
                    setup.sounds.trialStart.play()
                tracking = False
            else:
                if not tracking:
                    print 'track regained'
                tracking = True
            prevPos = pos

            # store data upon keypress, or upon requested number of trials reached
            if (viz.key.isDown(viz.KEY_CONTROL_L, immediate=True)
                    and viz.key.isDown('s', immediate=True)
                    and len(allData) > 0) or (nTrial is not None
                                              and tCount == nTrial):
                # make filename
                time = datetime.datetime.now()
                fname = ''.join(
                    (str(time.year) + str(time.month).zfill(2) +
                     str(time.day).zfill(2) + str(time.hour).zfill(2) +
                     str(time.minute).zfill(2) + str(time.second).zfill(2)))

                saveData = {}
                saveData['data'] = allData
                scio.savemat('data/' + fname,
                             saveData,
                             long_field_names=True,
                             do_compression=True,
                             oned_as='column')

                # done, either quit or notify and clear data store
                if nTrial is not None:
                    viz.quit()
                else:
                    setup.sounds.trialStart.play()
                    allData = []

            # limit to update rate
            d = yield viztask.waitDraw()

        # report position
        print 'capturing track data'
        tCount += 1
        count = 0
        data = []
        while count < trackRate * nSec:
            ti = setup.trackerDataFun()
            ti['timeStamp'] = d.time
            data.append(ti)
            count += 1

            d = yield viztask.waitDraw()

        # store for later
        allData.append(data)
        setup.sounds.trialCompleted.play()

        # Wait for trigger to release if still down
        if steamvr.getControllerList()[0].isButtonDown(2):
            yield viztask.waitSensorUp(steamvr.getControllerList()[0],
                                       steamvr.BUTTON_TRIGGER)
Beispiel #15
0
def setup(isLeftHanded):
	global lhPPT, rhPPT, lfPPT, rfPPT, headPPT, headLink, headPPTmarker, rhPPTlink, lhPPTlink, offsetTimerEvent
	global lhSphere, rhSphere
	global riftLink
	
	#nvis.nvisorSX111();
	#nvis.nvisorSX60();
	
	viz.mouse.setVisible(False)
	#viz.cursor(viz.OFF);
	view = viz.MainView
	#isense = viz.add('intersense.dle')
	#headTracker = isense.addTracker(port=1)
	
	vrpn = viz.add('vrpn7.dle');
	PPT_HOSTNAME = '171.64.33.43';
	
	#ading the headPPT marker
#	headPPTmarker = vrpn.addTracker('PPT0@' + PPT_HOSTNAME, 0);
	headPPTmarker = vrpn.addTracker('PPT0@' + PPT_HOSTNAME, some_global_variables.headPPTmarkerVirtualID - 1);
	headMarkerNode = viz.addGroup()
	headMarker = viz.link(headPPTmarker, headMarkerNode)
#	headMarker.preTrans(list(EYE_VECTOR))
#	headMarker.setOffset(some_global_variables.pptMarkerWeirdOffset)
	
	#now add the PPT hands tracker
	if isLeftHanded == 0:
		#user right-handed
#		rhPPT = vrpn.addTracker('PPT0@' + PPT_HOSTNAME, 1)
#		rhPPT = vrpn.addTracker('PPT0@' + PPT_HOSTNAME, some_global_variables.rhPPTmarkerVirtualID - 1)
		lhPPTmarker = steamvr.getControllerList()[1]		
		rhPPTmarker = steamvr.getControllerList()[0]
		#Replacing this line of code for vive version
#		rhPPTmarker = vrpn.addTracker('PPT0@' + PPT_HOSTNAME, some_global_variables.rhPPTmarkerVirtualID - 1)
#		lhPPT = vrpn.addTracker('PPT0@' + PPT_HOSTNAME, 2)
#		lhPPTmarker = vrpn.addTracker('PPT0@' + PPT_HOSTNAME, some_global_variables.lhPPTmarkerVirtualID - 1)
	else:
		#user left-handed		
		rhPPTmarker = steamvr.getControllerList()[0]
		lhPPTmarker = steamvr.getControllerList()[1]		
#		rhPPT = vrpn.addTracker('PPT0@' + PPT_HOSTNAME, 2)
#Replacing this line of code for vive version
#		rhPPTmarker = vrpn.addTracker('PPT0@' + PPT_HOSTNAME, some_global_variables.rhPPTmarkerVirtualID)
#		lhPPT = vrpn.addTracker('PPT0@' + PPT_HOSTNAME, 1)
#		lhPPTmarker = vrpn.addTracker('PPT0@' + PPT_HOSTNAME, some_global_variables.lhPPTmarkerVirtualID)
	if USE_LEG:
		rfPPT = vrpn.addTracker('PPT0@' + PPT_HOSTNAME, 3)
		lfPPT = vrpn.addTracker('PPT0@' + PPT_HOSTNAME, 4)

	headPPT = None
	headTracker = None
	#loading rift
#	rift = oculus.Rift()
#	headTracker = rift.getSensor()
	if headTracker is None:
		#DK2 not found, trying the vive now
		hmd = steamvr.HMD()
		headTracker = hmd.getSensor()
		headPPT = headTracker
		#activating a timer to adjust the PPT-Vive offset at runtime
		if some_global_variables.ADJUST_PPT_VIVE_OFFSET_AT_RUNTIME:
			offsetTimerEvent = vizact.ontimer(0, offsetTimer)
	else:
		vizact.onkeydown('r',headTracker.reset)
		headPPT = viz.mergeLinkable(headMarker,headTracker)
	
	#if rift is not available
	
	#Merge two links together
	#headPPT = viz.mergeLinkable(headPPTmarker,headTracker)
	headLink = viz.link(headPPT, viz.MainView);
	#headLink.postTrans([EYE_VECTOR[0], EYE_VECTOR[1], EYE_VECTOR[2]]);
	riftLink = headLink
	#riftLink.preTrans(EYE_VECTOR)
	#view.preTrans(EYE_VECTOR)
	#headPPT.preTrans([0,10,0]);
	
	rhPPT = viz.addGroup()
	rhPPTlink = viz.link(rhPPTmarker, rhPPT)
#	rhPPTlink.setOffset(some_global_variables.pptMarkerWeirdOffset)

	lhPPT = viz.addGroup()
	lhPPTlink = viz.link(lhPPTmarker, lhPPT)
#	lhPPTlink.setOffset(some_global_variables.pptMarkerWeirdOffset)

	
	grid = vizshape.addGrid();
	grid.color([0.5] * 3);
	
	viz.callback(viz.KEYDOWN_EVENT, onKeyDown);
	
	if(DEBUG_MODE):
		print "adding spheres";
		rhSphere = vizshape.addSphere(radius = 0.1, color = viz.WHITE);
		lhSphere = vizshape.addSphere(radius = 0.1, color = viz.WHITE);
		rfSphere = vizshape.addSphere(radius = 0.1, color = viz.WHITE);
		lfSphere = vizshape.addSphere(radius = 0.1, color = viz.WHITE);
		

	
	return;
Beispiel #16
0
def setup():
	global leftWristPPT, rightWristPPT, lfPPT, rfPPT, headPPT, viewLink, navigationNode
	global lhSphere, rhSphere
	global hmdLink
	#add more trackers for trying things out
	global rightFingersPPT, leftFingersPPT, leftForeArmPPT, rightForeArmPPT, rightHandViveController, leftHandViveController
	
	#nvis.nvisorSX111();
	#nvis.nvisorSX60();
	#try the oculus rift
	hmd = None
	headOriTracker = None
	
	if some_global_variables.PPT1:
		vrpn = viz.add('vrpn7.dle')

	#trying to connect the vive now
	if not some_global_variables.DONT_USE_VIVE:
		hmd = steamvr.HMD()
		headOriTracker = hmd.getSensor()
	headPosTracker = None
	headPosLink = None

	if headOriTracker is None:
		print "HTC Vive is not connected. Trying Oculus Rift now"
		hmd = oculus.Rift()
		headOriTracker = hmd.getSensor()
		if headOriTracker is None:
			print "Rift is also not connected!"
		else:
			print "Connected to Rift!"
			vizact.onkeydown('r',headOriTracker.reset)
			if some_global_variables.PPT1:
				headPosTracker = vrpn.addTracker('PPT0@' + some_global_variables.PPT_HOSTNAME, some_global_variables.PPT_HEAD_VIRTUAL_ID - 1)
				headPosTrackerNode = viz.addGroup()
				headPosLink = viz.link(headPosTracker, headPosTrackerNode)
				headPosLink.preTrans(list(EYE_VECTOR))
	else:
		print "Connected to Vive!"

	#Merge position and orientation links for the head tracker, if needed
	if headPosLink is not None:
		#using DK2 in PPT1 with a PPT marker for head tracking
		headPPT = viz.mergeLinkable(headPosLink,headOriTracker)
	else:
		#like using vive, or DK2 outside PPT1
		headPPT = headOriTracker

	if headOriTracker is not None:
		some_global_variables.headTrackingActive = True

	viz.mouse.setVisible(False)
	#viz.cursor(viz.OFF);
	view = viz.MainView

	viewLink = None
	navigationNode = viz.addGroup()
	viewLink = viz.link(navigationNode, viz.MainView)
	if headPPT is not None:
		viewLink.preMultLinkable(headPPT)
		
	if not some_global_variables.PPT1:
		viewLink.setOffset([0,1.4,0])
#		viewLink = viz.link(headPPT, viz.MainView)
	#viewLink.postTrans([EYE_VECTOR[0], EYE_VECTOR[1], EYE_VECTOR[2]])
	#hmdLink.preTrans(EYE_VECTOR)
	#view.preTrans(EYE_VECTOR)
	#headPPT.preTrans([0,10,0]);
	
	#now add the PPT hands tracker
	if some_global_variables.PPT1:
		rightForeArmPPT = vrpn.addTracker('PPT0@' + some_global_variables.PPT_HOSTNAME, some_global_variables.PPT_RIGHT_FOREARM_VIRTUAL_ID-1)
		if rightForeArmPPT is not None: print "right forearm tracker is active with virtual PPT ID = " + str(some_global_variables.PPT_RIGHT_FOREARM_VIRTUAL_ID)

		leftForeArmPPT = vrpn.addTracker('PPT0@' + some_global_variables.PPT_HOSTNAME, some_global_variables.PPT_LEFT_FOREARM_VIRTUAL_ID-1)
		if leftForeArmPPT is not None: print "left forearm tracker is active with virtual PPT ID = " + str(some_global_variables.PPT_LEFT_FOREARM_VIRTUAL_ID)
		
		appendageControlWithVive = vizinput.choose('Using Vive controllers or a bunch of PPT markers?', ['Vive','4 extra PPT marker!'])
		
		if appendageControlWithVive == 0: #using vive hand controllers
			some_global_variables.usingViveHandControllers = True
			viveHandControllerList = steamvr.getControllerList()
			controllerCount = 0
			for controller in steamvr.getControllerList():
				controllerCount += 1
				#Right Hand Controller Setup
				if controllerCount == 1:
				  rightHandViveController = viveHandControllerList[0]
				#Left Hand Controller Setup
				elif controllerCount == 2:
				  leftHandViveController = viveHandControllerList[1]
		else: #using four extra PPT markers - could be noisy due to interference
			rightFingersPPT = vrpn.addTracker('PPT0@' + some_global_variables.PPT_HOSTNAME, some_global_variables.PPT_RIGHT_FINGERS_VIRTUAL_ID-1)
			if rightFingersPPT is not None: print "right fingers tracker is active with virtual PPT ID = " + str(some_global_variables.PPT_RIGHT_FINGERS_VIRTUAL_ID)

			leftFingersPPT = vrpn.addTracker('PPT0@' + some_global_variables.PPT_HOSTNAME, some_global_variables.PPT_LEFT_FINGERS_VIRTUAL_ID-1)
			if leftFingersPPT is not None: print "left fingers tracker is active with virtual PPT ID = " + str(some_global_variables.PPT_LEFT_FINGERS_VIRTUAL_ID)

			rightWristPPT = vrpn.addTracker('PPT0@' + some_global_variables.PPT_HOSTNAME, some_global_variables.PPT_RIGHT_WRIST_VIRTUAL_ID-1)
			if rightWristPPT is not None: print "right wrist tracker is active with virtual PPT ID = " + str(some_global_variables.PPT_RIGHT_WRIST_VIRTUAL_ID)

			leftWristPPT = vrpn.addTracker('PPT0@' + some_global_variables.PPT_HOSTNAME, some_global_variables.PPT_LEFT_WRIST_VIRTUAL_ID-1)
			if leftWristPPT is not None: print "left wrist tracker is active with virtual PPT ID = " + str(some_global_variables.PPT_LEFT_WRIST_VIRTUAL_ID)

			
	
	grid = vizshape.addGrid()
	grid.color([0.5] * 3)
	
	viz.callback(viz.KEYDOWN_EVENT, onKeyDown)
	
	if(DEBUG_MODE):
		print "adding spheres";
		rhSphere = vizshape.addSphere(radius = 0.1, color = viz.WHITE);
		lhSphere = vizshape.addSphere(radius = 0.1, color = viz.WHITE);
		rfSphere = vizshape.addSphere(radius = 0.1, color = viz.WHITE);
		lfSphere = vizshape.addSphere(radius = 0.1, color = viz.WHITE);
		

	
	return
def TrackTask():
    prevPos = None
    allData = []
    tRegained = 0
    stage = 0  # 0: wait for track loss, 1: wait for track regained, 2: wait for trigger pull, 3: trigger pulled. check optical heading position ok, 4: trigger released, ready for next trigger pull that will start actual data collection
    t = 0.
    opticalHeadScrewed = False
    tCount = -1
    while True:
        # wait for track regained
        stage = 0
        while True:
            pos = setup.trackerDataFun()
            if prevPos is not None and pos['vive'] == prevPos['vive']:
                # position didn't change at all, not tracking
                if stage is not 1:
                    setup.sounds.trialStart.play()
                    print 'track lost'
                    stage = 1
            else:
                # get here only once vive position/orientation starts changing again
                if stage == 1:
                    setup.sounds.trialCompleted.play()
                    print 'track regained'
                    tRegained = t
                    stage = 2 if qCheckOptHeading else 4  # if not qCheckOptHeading, skip the check

                if stage == 2 and t - tRegained > nSecWait and (
                        steamvr.getControllerList()[0].isButtonDown(2)
                        or viz.key.isDown('c', immediate=True)):
                    # first press, check if optical heading position is ok
                    stage = 3

                if stage == 3 and not (
                        steamvr.getControllerList()[0].isButtonDown(2)
                        or viz.key.isDown('c', immediate=True)):
                    # button/trigger released
                    stage = 4

                if stage == 4 and (
                        steamvr.getControllerList()[0].isButtonDown(2)
                        or viz.key.isDown('c', immediate=True)):
                    # second press: time to record some data
                    tCount += 1
                    break
            prevPos = pos

            # check position of optical heading markers is within expected range. Otherwise markers probably switched
            if qCheckOptHeading and stage in [3, 4] and any([
                    abs(p - m) > l for p, m, l in zip(
                        pos['optical_heading'][:3], optHeadingPos, optHeadLims)
            ]):
                # optical markers screwed, notify
                if not opticalHeadScrewed:
                    print 'optical heading error. current pose: ' + str(
                        pos['optical_heading'])
                    setup.sounds.alarm.play()
                    opticalHeadScrewed = True
            else:
                opticalHeadScrewed = False

            # limit to update rate
            d = yield viztask.waitDraw()
            t = d.time

        # report position
        print 'capturing track data'
        setup.sounds.trialStart.play()
        count = 0
        data = []
        while count < trackRate * nSec:
            ti = setup.trackerDataFun()
            ti['timeStamp'] = d.time
            data.append(ti)
            count += 1

            d = yield viztask.waitDraw()

        # store for later
        allData.append(data)
        setup.sounds.trialCompleted.play()

        # make filename
        if tCount + 1 == nTrial:
            time = datetime.datetime.now()
            fname = ''.join(
                (str(time.year) + str(time.month).zfill(2) +
                 str(time.day).zfill(2) + str(time.hour).zfill(2) +
                 str(time.minute).zfill(2) + str(time.second).zfill(2)))

            saveData = {}
            saveData['data'] = allData
            scio.savemat('data/' + fname,
                         saveData,
                         long_field_names=True,
                         do_compression=True,
                         oned_as='column')

            # done
            viz.quit()
def initTrackers(initFlag=vizconnect.INIT_INDEPENDENT, initList=None):
	#VC: place any general initialization code here
	rawTracker = vizconnect.getRawTrackerDict()

	#VC: initialize a new tracker
	_name = 'steamvr_controller_tracker'
	if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
		#VC: init the raw object
		if initFlag&vizconnect.INIT_RAW:
			#VC: set some parameters
			index = 1
			
			#VC: create the raw object
			import steamvr
			try:
				tracker = steamvr.getControllerList()[index]
			except IndexError:
				viz.logWarn("** WARNING: Not able to connect to tracker at index {0}. It's likely that not enough trackers are connected.".format(index))
				tracker = viz.addGroup()
				tracker.invalidTracker = True
			rawTracker[_name] = tracker
	
		#VC: init the wrapper (DO NOT EDIT)
		if initFlag&vizconnect.INIT_WRAPPERS:
			vizconnect.addTracker(rawTracker[_name], _name, make='Valve', model='SteamVR Controller Tracker')

	#VC: initialize a new tracker
	_name = 'steamvr_controller_tracker2'
	if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
		#VC: init the raw object
		if initFlag&vizconnect.INIT_RAW:
			#VC: set some parameters
			index = 0
			
			#VC: create the raw object
			import steamvr
			try:
				tracker = steamvr.getControllerList()[index]
			except IndexError:
				viz.logWarn("** WARNING: Not able to connect to tracker at index {0}. It's likely that not enough trackers are connected.".format(index))
				tracker = viz.addGroup()
				tracker.invalidTracker = True
			rawTracker[_name] = tracker
	
		#VC: init the wrapper (DO NOT EDIT)
		if initFlag&vizconnect.INIT_WRAPPERS:
			vizconnect.addTracker(rawTracker[_name], _name, make='Valve', model='SteamVR Controller Tracker')

	#VC: initialize a new tracker
	_name = 'steamvr_hmd_tracker'
	if vizconnect.isPendingInit('tracker', _name, initFlag, initList):
		#VC: init the raw object
		if initFlag&vizconnect.INIT_RAW:
			#VC: set some parameters
			index = 0
			
			#VC: create the raw object
			import steamvr
			try:
				tracker = steamvr.getExtension().getHMDList()[index]
			except IndexError:
				viz.logWarn("** WARNING: Not able to connect to tracker at index {0}. It's likely that not enough trackers are connected.".format(index))
				tracker = viz.addGroup()
				tracker.invalidTracker = True
			rawTracker[_name] = tracker
	
		#VC: init the wrapper (DO NOT EDIT)
		if initFlag&vizconnect.INIT_WRAPPERS:
			vizconnect.addTracker(rawTracker[_name], _name, make='Valve', model='SteamVR HMD Tracker')
	
		#VC: init the offsets
		if initFlag&vizconnect.INIT_OFFSETS:
			_link = vizconnect.getTracker(_name).getLink()
			#VC: clear link offsets
			_link.reset(viz.RESET_OPERATORS)

	#VC: return values can be modified here
	return None
def TrackTask():
    prevPos = None
    tracking = True
    allData = []
    tRegained = 0.
    waitingForTrack = True
    t = 0.
    while True:
        # wait for trigger press
        while not (steamvr.getControllerList()[0].isButtonDown(2)
                   or viz.key.isDown('c', immediate=True)):
            # limit to update rate
            d = yield viztask.waitDraw()

        # record n seconds of data
        tRegained = d.time
        while True:
            pos = setup.trackerDataFun()
            if prevPos is not None and pos['vive'] == prevPos['vive']:
                # position didn't change at all, not tracking
                if tracking:
                    print 'track lost'
                    allData = []
                    waitingForTrack = True
                tracking = False
            else:
                # get here only once vive position/orientation starts changing again
                if not tracking:
                    print 'track regained'
                    tRegained = t
                tracking = True
                if waitingForTrack and t - tRegained > nSecWait:
                    # time to record some data
                    waitingForTrack = False
                    break

            pos['timeStamp'] = d.time
            prevPos = pos
            allData.append(pos)

            # limit to update rate
            d = yield viztask.waitDraw()
            t = d.time

        # calculate mean and SD for each variable of Vive
        means = [0.] * 6
        SDs = [0.] * 6
        for dat in allData:
            for i, e in enumerate(dat['vive']):
                means[i] += e
        N = len(allData)
        means = [x / N for x in means]
        # now SD
        for dat in allData:
            for i, e in enumerate(dat['vive']):
                SDs[i] += (e - means[i])**2
        SDs = [math.sqrt(x) / (N - 1) for x in SDs]

        # NB: for analysis of simulataneous data, can just do it qualitative. plot position/orientation over time for both vive and
        # other source. see offset in time between curves, that gives you differential latency.

        # wait for threshold exceeded, until controller trigger pulled that stops things
        setup.sounds.trialStart.play()
        exceeded = []
        d = yield viztask.waitDraw()
        visible = True
        while not (steamvr.getControllerList()[0].isButtonDown(2)
                   or viz.key.isDown('c', immediate=True)):
            pos = setup.trackerDataFun()
            pos['timeStamp'] = d.time
            allData.append(pos)

            # check threshold
            qThresh = [
                abs(x - m) > s * multiplier
                for x, m, s in zip(pos['vive'], means, SDs)
            ]
            if any(qThresh) and visible:
                for v in setup.visuals:
                    v.visible(viz.OFF)
                visible = False
                exceeded.append(
                    len(allData))  # store at which sample this happened

            # limit to screen update rate
            d = yield viztask.waitDraw()

        # save data and exit
        setup.sounds.trialCompleted.play()

        time = datetime.datetime.now()
        fname = ''.join(
            (str(time.year) + str(time.month).zfill(2) +
             str(time.day).zfill(2) + str(time.hour).zfill(2) +
             str(time.minute).zfill(2) + str(time.second).zfill(2)))

        saveData = {}
        saveData['data'] = allData
        saveData['means'] = means
        saveData['SDs'] = SDs
        saveData['multiplier'] = multiplier
        saveData['exceeded'] = exceeded
        scio.savemat('data/' + fname,
                     saveData,
                     long_field_names=True,
                     do_compression=True,
                     oned_as='column')

        # done
        viz.quit()