コード例 #1
0
def initDisplays(initFlag=vizconnect.INIT_INDEPENDENT, initList=None):
    #VC: place any general initialization code here
    rawDisplay = vizconnect.getRawDisplayDict()

    #VC: initialize a new display
    _name = 'dk2'
    if vizconnect.isPendingInit('display', _name, initFlag, initList):
        #VC: init the raw object
        if initFlag & vizconnect.INIT_RAW:
            #VC: set the window for the display
            _window = viz.MainWindow

            #VC: set some parameters
            autoDetectMonitor = True

            #VC: create the raw object
            import oculus
            try:
                display = oculus.Rift(window=_window,
                                      autoDetectMonitor=autoDetectMonitor)
                _window.displayNode = display
            except AttributeError:
                _window.displayNode = None
            rawDisplay[_name] = _window

        #VC: init the wrapper (DO NOT EDIT)
        if initFlag & vizconnect.INIT_WRAPPERS:
            vizconnect.addDisplay(rawDisplay[_name],
                                  _name,
                                  make='Oculus VR',
                                  model='DK2')

    #VC: return values can be modified here
    return None
コード例 #2
0
ファイル: vrlabConfig.py プロジェクト: bmj8778/CatchB
    def __init__(self, cfg, enabled=1, displayList=None):

        type = cfg['type']
        offset = cfg['offset']
        overlap = cfg['overlap']
        fov = cfg['fov']
        #self.hmdstats = self.HMDStats(offset, overlap)
        self.enabled = enabled

        if enabled:

            if 'nvis' == type:

                import nvis
                self.hmd = nvis.nvisorSX111()

                #vizconfig.register(self.hmd)
                print "HMD type: NVIS SX111"

                print '*** Offset:' + str(viz.MainWindow.getViewOffset())

            elif 'oculus' == type:

                import oculus
                self.hmd = oculus.Rift()
                print "HMD type: Oculus Rift"
                #vizconfig.register(self.hmd)
                #self.updateOverlap(self.hmdstats.overlap-self.hmd._overlap)

            elif 'DK2' == type:

                self.setupOculusMon(displayList)
                self.hmd = vizconnect.getTracker('rift')

            else:
                print "Unsupported HMD type when starting HMD"
                sys.exit(1)

#			import vizconfig
#			vizconfig.register(self.hmd)

            if (overlap > -1):
                self.updateOverlap(self.hmdstats.overlap - self.hmd._overlap)
            else:
                defaultOverlap = 100
                self.hmdstats = self.HMDStats(viz.MainWindow.getViewOffset,
                                              defaultOverlap)

            #print 'After: ' + str(viz.MainWindow.getViewOffset()) + str(viz.MainWindow.stereoOverlap())
            #self.hmdstats = self.HMDStats(viz.MainWindow.getViewOffset, viz.MainWindow.stereoOverlap)

        else:
            self.hmd = None
            print "HMD disabled"
コード例 #3
0
ファイル: hardware.py プロジェクト: RothkopfLab/catchingballs
def setup(conf):
    """
    Set up all the hardware used in the ball catching experiment
    :param conf: config['hardware'] entry of full config dict
    :return: None
    """
    global config
    global hmd
    global head_tracker
    global eye_tracker
    global link

    config = conf

    print '\nSetting up hardware modules...'

    # configure Oculus Rift
    if config['use_hmd']:
        hmd = oculus.Rift()
        hmd.setMonoMirror(True)
        hmd.getSensor().reset()

        # setup position tracking (WorldViz PPTX)
        if config['use_ppt']:
            head_tracker = ppt.add_tracker(0)

            link = ppt.link(tracker=head_tracker, ori=hmd.getSensor(), target=viz.MainView,
                            pre_trans=[-0.05, -0.05, 0.02])

            head_tracker = head_tracker
        # no ppt
        else:

            link = viz.link(hmd.getSensor(), viz.MainView, mask=viz.LINK_ORI)
            link.setOffset([0, 1.8, 0])
            viz.MainView.setPosition([0, 1.8, -3])

        # setup eye tracker
        if config['eye_tracking']:
            eye_tracker = EyeTracker()

    # configure screen setup
    else:
        viz.MainView.setPosition(0, 0, -4, viz.REL_LOCAL)
        viz.setOption('viz.fullscreen.monitor', 2)
        keyboard_cam = vizcam.KeyboardCamera()

    link = link

    # keys for hardware control
    viz.callback(viz.KEYDOWN_EVENT, on_key_down)
コード例 #4
0
ファイル: configOculus.py プロジェクト: dgo721/averno
def initDisplays(initFlag=vizconnect.INIT_INDEPENDENT, initList=None):
	#VC: place any general initialization code here
	rawDisplay = vizconnect.getRawDisplayDict()

	#VC: initialize a new display
	_name = 'main_display'
	if vizconnect.isPendingInit('display', _name, initFlag, initList):
		#VC: init the raw object
		if initFlag&vizconnect.INIT_RAW:
			#VC: set the window for the display
			_window = viz.MainWindow
			
			#VC: set some parameters
			autoDetectMonitor = True
			timeWarpEnabled = True
			
			#VC: create the raw object
			import oculus
			try:
				display = oculus.Rift(window=_window, autoDetectMonitor=autoDetectMonitor)
				display.setTimeWarp(timeWarpEnabled)
				_window.displayNode = display
				viz.window.setFullscreen(True)
			except AttributeError:
				_window.displayNode = None
			rawDisplay[_name] = _window
	
		#VC: init the wrapper (DO NOT EDIT)
		if initFlag&vizconnect.INIT_WRAPPERS:
			vizconnect.addDisplay(rawDisplay[_name], _name, make='Oculus VR', model='DK2')
	
		#VC: set the parent of the node
		if initFlag&vizconnect.INIT_PARENTS:
			vizconnect.getDisplay(_name).setParent(vizconnect.getAvatar('main_avatar').getAttachmentPoint('head'))

	#VC: return values can be modified here
	return None
    def __init__(self):

        self.hmd = oculus.Rift()
        self.link = viz.link(self.hmd.getSensor(), viz.MainView)
        self.sky = ""
        self.env = ""
        self.video = ""

        self.mainSurvey = []
        self.warmupSurvey = []
        self.config = self.readconfig()

        self.stimuli = self.config["stimuli"].strip(" ").split(",")
        self.warmup = self.config["warmup"].strip(" ").split(",")
        self.survey = self.config["survey"]
        print self.survey
        self.splitSurvey = self.config["splitSurvey"]
        self.delay = self.config["delay"]
        self.PIDdigits = int(self.config["digits"])
        # recess and message
        self.recessList = self.config["recess"].strip(" ").strip("\n").split(
            ",")
        self.recessMessage = self.config["recessMessage"]
        # Finale and message
        self.finale = self.config["finale"]
        self.finaleMessage = self.config["finaleMessage"]

        self.group = "A"
        #self.group = self.participant()[0]
        self.designOutput = self.expDesign()

        self.stimuliList = self.designOutput[0][self.group]
        self.warmupList = self.designOutput[1]
        self.groupNumber = len(self.designOutput[1].keys())
        #print self.groupNumber
        viz.go()
コード例 #6
0
monoWindow = viz.addWindow(size=(1, 1), pos=(0, 1), scene=viz.addScene())
monoQuad = viz.addTexQuad(parent=viz.ORTHO, scene=monoWindow)
monoQuad.setBoxTransform(viz.BOX_ENABLED)
monoQuad.setTexQuadDisplayMode(viz.TEXQUAD_FILL)
texture = vizfx.postprocess.getEffectManager().getColorTexture()


def UpdateTexture():
    monoQuad.texture(texture)


vizact.onupdate(0, UpdateTexture)

global hmd
view = viz.addView
hmd = oculus.Rift()
hmd.getSensor()
#profile = hmd.getProfile()
#hmd.setIPD(profile.ipd)

OF1 = viz.addChild('OpticFlowBox5.osgb', scale=[3, 3, 3])
OF1.disable(viz.LIGHTING)
OF2 = viz.addChild('OpticFlowBox5.osgb', scale=[3, 3, 3])
OF2.disable(viz.LIGHTING)
OF2.setPosition(0, 0, 1.27 * 3)
OF3 = viz.addChild('OpticFlowBox5.osgb', scale=[3, 3, 3])
OF3.disable(viz.LIGHTING)
OF3.setPosition(0, 0, 1.27 * 6)

viz.MainView.setPosition(0, 0.15, -1.27 * 3 / 2 + 0.002)
viz.MainView.setEuler(0, 0, 0)
コード例 #7
0
ファイル: Experiment_VR.py プロジェクト: dlcen/VizardCode
folder = path.split('\\')
folder = folder[-1]
folder = folder.split('_')

# Read condition information from the folder name
id = folder[0]
Exp_Sequence = folder[4]
Room_Sequence = folder[5]
Room_OffsetOrder = folder[6]
Distance_Sequence = folder[7]
Distance_OffsetOrder = folder[8]

sub_ipd = ipd / 1000

# Setup Oculus Rift HMD
hmd = oculus.Rift()  #renderMode=oculus.RENDER_CLIENT)

if hmd.getSensor().getDisplayMode() == oculus.DISPLAY_DESKTOP:
    viz.window.setFullscreen(True)

hmd.setIPD(sub_ipd)

# Network Setup
VRPNserver = 'SimonR-PC'
serverName = 'srushton-PC'
myNetwork = viz.addNetwork(serverName)

# Set up Tracking
vrpn = viz.add('vrpn7.dle')
ori_marker = vrpn.addTracker('Tracker0@' + VRPNserver, 9)
ori_marker.swapPos([1, 2, -3])
コード例 #8
0
init = False
# add intersense tracker
isense = viz.add('intersense.dle')
while not init:
	ISTracker = isense.addTracker(port=5001,station=0)
	if ISTracker.getPosition()[0] != 0:
		init = True
ISTracker.setEnhancement(2) 
ISTracker.setSensitivity(4)
ISTracker.setShockSuppression(2)
ISTracker.setAccelSensitivity(4)


# add Oculus tracker
OVRTracker = oculus.Rift().getSensor()

# add the virtual tracker, link it to the MainView and set an offset to get the eye position
virtual = viz.addGroup()
link = viz.link(virtual, viz.MainView)
# setting position offset
link.preTrans([0, -0.055, -0.073])

viz.go()


# variables for recording
DATA_COLLECT = True
dataBuffer = ''
time = 0
MODEL_DIR = 'Models/'
コード例 #9
0
ファイル: setupDK2Cluster.py プロジェクト: EvanKrueger/CatchB
def initDisplays(initFlag=vizconnect.INIT_INDEPENDENT, initList=None):
	#VC: place any general initialization code here
	rawDisplay = vizconnect.getRawDisplayDict()

	#VC: initialize a new display
	_name = 'exp_display'
	if vizconnect.isPendingInit('display', _name, initFlag, initList):
		#VC: init the raw object
		if initFlag&vizconnect.INIT_RAW:
			#VC: set the window for the display
			_window = viz.addWindow()
			_window.setView(viz.addView())
			
			#VC: set placement with alignment: free
			_window.setPosition(0, 1, mode=viz.WINDOW_NORMALIZED)
			_window.setSize(1, 1, mode=viz.WINDOW_NORMALIZED)
			
			#VC: make the window visible only for certain clients
			_clusterMask = viz.CLIENT1
			with viz.cluster.MaskedContext(viz.ALLCLIENTS&~_clusterMask):# hide
				_window.visible(False)
			with viz.cluster.MaskedContext(_clusterMask):# show
				_window.visible(True)
			
			#VC: set the fullscreen monitor
			with viz.cluster.MaskedContext(viz.CLIENT1):# only for clients with this display
				viz.window.setFullscreenMonitor(3)
				viz.window.setFullscreen(True)
			
			#VC: set some parameters
			VFOV = 60
			aspect = viz.AUTO_COMPUTE
			stereo = viz.OFF
			
			#VC: create the raw object
			_window.fov(VFOV,aspect)
			_window.stereo(stereo)
			rawDisplay[_name] = _window
	
		#VC: init the wrapper (DO NOT EDIT)
		if initFlag&vizconnect.INIT_WRAPPERS:
			vizconnect.addDisplay(rawDisplay[_name], _name, make='Generic', model='Custom Window')
	
		#VC: set the parent of the node
		if initFlag&vizconnect.INIT_PARENTS:
			vizconnect.getDisplay(_name).setParent(vizconnect.getTracker('head_tracker'))

	#VC: initialize a new display
	_name = 'rift_display'
	if vizconnect.isPendingInit('display', _name, initFlag, initList):
		#VC: init the raw object
		if initFlag&vizconnect.INIT_RAW:
			
			#VC: set the window for the display
			_window = viz.MainWindow
			
			#VC: set some parameters
			autoDetectMonitor = True
			timeWarpEnabled = True
			
			#VC: create the raw object
			import oculus
			try:
				display = oculus.Rift(window=_window, autoDetectMonitor=autoDetectMonitor)
				_window.displayNode = display
				viz.window.setFullscreen(True)
			except AttributeError:
				_window.displayNode = None
			rawDisplay[_name] = _window
	
		#VC: init the wrapper (DO NOT EDIT)
		if initFlag&vizconnect.INIT_WRAPPERS:
			vizconnect.addDisplay(rawDisplay[_name], _name, make='Oculus VR', model='DK2')
	
		#VC: set the parent of the node
		if initFlag&vizconnect.INIT_PARENTS:
			vizconnect.getDisplay(_name).setParent(vizconnect.getTracker('head_tracker'))

	#VC: return values can be modified here
	return None
コード例 #10
0
ファイル: init.py プロジェクト: EvanKrueger/Anatomy-Puzzle
	def cameraInput(self):
		"""
		Initialize the camera movement controls
	
		Mode selection:
			0 - Arrow keys circular movement
			1 - Spacemouse (WARNING: potential conflict with pointer mode 1)
			2 - Wiimote (Not implemented)
		"""
		if self.camMode == 0:
			# Use the arrow keys to move
			self.camcenter = viz.addChild('ball.wrl')
			self.camcenter.setPosition(0,1.4,0)
			self.pointer.setParent(self.camcenter)
			self.camcenter.disable(viz.RENDERING)
		
	#		#occulus Rift enabled
			if(self.displayMode == 2):
				self.hmd = oculus.Rift()
				navigationNode = viz.addGroup()
				viewlink = viz.link(navigationNode, viz.MainView)
				viewlink.preMultLinkable(self.hmd.getSensor())
				camlink = viz.link(self.camcenter,navigationNode)
				
				#set initial positions
				camlink.preEuler([0,0,0])
				camlink.preTrans([0,0,-3.25])
				

			#2D display
			else:
				camlink = viz.link(self.camcenter,viz.MainView)
			
#				#set initial positions
				camlink.preEuler([0,30,0])
#				camlink.preTrans([0,0,0])
				
				self.camcenter.setPosition(0,3.2,-3.5)
				

			
			#instantiate control class
			controlScheme = CameraKeyboardControl()
			
			#schedule the control loop to be called
#			viztask.schedule(controlScheme.performKeyMovements(self.camcenter, camlink))
#			viztask.schedule(controlScheme.cameraFocus(self.camcenter, camlink))		
			
			#backup control functions:
			vizact.whilekeydown(viz.KEY_RIGHT,self.camcenter.setEuler,[vizact.elapsed(90),0,0],viz.REL_GLOBAL)
			vizact.whilekeydown(viz.KEY_LEFT,self.camcenter.setEuler,[vizact.elapsed(-90),0,0],viz.REL_GLOBAL)
			vizact.whilekeydown(viz.KEY_UP,self.camcenter.setEuler,[0,vizact.elapsed(-90),0],viz.REL_LOCAL)
			vizact.whilekeydown(viz.KEY_DOWN,self.camcenter.setEuler,[0,vizact.elapsed(90),0],viz.REL_LOCAL)
			vizact.whilekeydown( 't' , self.camcenter.setPosition,[0,0,vizact.elapsed(4)],viz.REL_LOCAL)
			vizact.whilekeydown( 'g' ,  self.camcenter.setPosition,[0,0,vizact.elapsed(-4)],viz.REL_LOCAL)
		
		
			default = self.camcenter.getPosition()


		elif self.camMode == 1:
			# Use the SpaceMouse to move camera
			MOVE_SCALE = 0.5
			ROTATE_SCALE = 5.0
			
			def UpdateMovement():
				elapsed = viz.getFrameElapsed()
				trans = device.getRawTranslation()
				rx,ry,rz = device.getRawRotation()
				viz.MainView.setAxisAngle([0,1,0,ry*elapsed*ROTATE_SCALE], viz.HEAD_ORI, viz.REL_LOCAL)
				viz.MainView.move(viz.Vector(trans)*elapsed*MOVE_SCALE)
			
			vizact.onupdate(0, UpdateMovement)

	#	elif mode == 2:
	#		# wiimote
	#		pass

		else:
			raise ValueError('Invaid control mode selection')
コード例 #11
0
    if (hmdconnected):
        global navigationNode
        global viewLink
        navigationNode.addAction(
            vizact.move(-4, 0, 0, 60)
        )  # Move player on the X axis for 60 seconds, at the same speed as the train -- Rather than updating the position relitive to the train every frame, which resulted in jittery movement.
        viewLink = viz.link(navigationNode, viz.MainView)
        viewLink.preMultLinkable(hmd.getSensor())
    else:
        viz.MainView.addAction(vizact.move(-4, 0, 0, 60))


global hmdConnected
hmdconnected = False

hmd = oculus.Rift(
)  # First Look for Oculus Rift -- Return error if not detected

if not hmd.getSensor():
    print 'Oculus Rift not detected'
else:
    hmdconnected = True

    navigationNode = viz.addGroup()
    viewLink = viz.link(navigationNode, viz.MainView)
    viewLink.preMultLinkable(hmd.getSensor())

    # Apply user profile eye height to view
    profile = hmd.getProfile()
    if profile:
        viewLink.setOffset(
            [0, profile.eyeHeight,
コード例 #12
0
    def use_control(self, control_style):
        """
        Enable the control modality depending on the provided input modality.

        Different experimental setup make use of different ways to exert control over the experimental world.
        Use this function to define and setup the necessary things depending on the control modality to be used.

        Args:
            control_style: interaction possibilities between subject and VR world. Currently supports:
            'mouse and keyboard', 'joystick', 'wiimote with dk2 head', 'dk2 head only', 'dk2 head hands'

        """

        # control type for test purposes
        if control_style == 'mouse and keyboard': # control type for test purposes

            viz.mouse(viz.ON)
            vizact.onmousedown(viz.MOUSEBUTTON_LEFT, self.on_button_press, 'A')
            vizact.onmousedown(viz.MOUSEBUTTON_RIGHT, self.on_button_press, 'B')

            self.sphere_radius = 0.02
            self.right_hand_sphere = vizshape.addSphere(radius=self.sphere_radius)
            self.right_hand_sphere.color(viz.GREEN)
            self.right_hand_target = self.right_hand_sphere.collideSphere()
            self.right_hand_sphere.disable(viz.DYNAMICS)

            self.right_hand_sphere.alpha(1)

            self.head_sphere = vizshape.addSphere(radius=self.sphere_radius)
            self.head_sphere.color(viz.YELLOW)
            self.head_target = self.head_sphere.collideSphere()
            self.head_sphere.disable(viz.DYNAMICS)

            MOVE_SPEED = 0.025

            def move_hand():
                if viz.key.isDown(viz.KEY_UP):
                    self.right_hand_sphere.setPosition([self.right_hand_sphere.getPosition()[0], 1.6, self.right_hand_sphere.getPosition()[2]+MOVE_SPEED])
                elif viz.key.isDown(viz.KEY_DOWN):
                    self.right_hand_sphere.setPosition([self.right_hand_sphere.getPosition()[0], 1.6, self.right_hand_sphere.getPosition()[2]-MOVE_SPEED])
                elif viz.key.isDown(viz.KEY_LEFT):
                    self.right_hand_sphere.setPosition(self.right_hand_sphere.getPosition()[0]-MOVE_SPEED, 1.6, self.right_hand_sphere.getPosition()[2])
                elif viz.key.isDown(viz.KEY_RIGHT):
                    self.right_hand_sphere.setPosition(self.right_hand_sphere.getPosition()[0]+MOVE_SPEED, 1.6, self.right_hand_sphere.getPosition()[2])

            def move_head():
                if viz.key.isDown('w'):
                    self.head_sphere.setPosition([self.head_sphere.getPosition()[0], 1.6, self.head_sphere.getPosition()[2]+MOVE_SPEED])
                elif viz.key.isDown('s'):
                    self.head_sphere.setPosition([self.head_sphere.getPosition()[0], 1.6, self.head_sphere.getPosition()[2]-MOVE_SPEED])
                elif viz.key.isDown('a'):
                    self.head_sphere.setPosition(self.head_sphere.getPosition()[0]-MOVE_SPEED, 1.6, self.head_sphere.getPosition()[2])
                elif viz.key.isDown('d'):
                    self.head_sphere.setPosition(self.head_sphere.getPosition()[0]+MOVE_SPEED, 1.6, self.head_sphere.getPosition()[2])

            vizact.ontimer(0, move_hand)
            vizact.ontimer(0, move_head)

        elif control_style == 'joystick':

            # first load the oculus rift plugin and link sensor to viewpoint
            import oculus
            hmd = oculus.Rift()

            # loads the DirectInput plug-in and adds first available joystick
            dinput = viz.add('DirectInput.dle')
            self.joy = dinput.addJoystick()

            # Set dead zone threshold so small movements of joystick are ignored
            self.joy.setDeadZone(0.2)

            # add viewpoint at subject height
            eye_height = float(self._height) - 0.05

            joystick_node = viz.addGroup(pos=(0, eye_height, 0))
            viz.link(joystick_node, viz.MainView)

            # joystick control class with lsl streams of pos and ori as in the dk2 tracker class
            # stream pos and ori in joystick movement function which gets called with ontimer / onupdate
            # set lsl stream parameters
            lsl_streamName = 'vizard_hmd6dof_stateLog_joystick'
            lsl_streamType = 'sixFloat'  # no official lsl type (not recognized by eeglab or mobilab)
            lsl_numChannels = 6
            lsl_regularSPS = 75  # regular rate, one sample per DK2 frame
            lsl_dataType = 'float32'
            lsl_streamUuid = socket.gethostname()  # PC name as uuid

            # create stream
            lsl_hmd6dofStreamInfo = StreamInfo(lsl_streamName, lsl_streamType, lsl_numChannels, lsl_regularSPS,
                                                    lsl_dataType, lsl_streamUuid)
            lsl_hmd6dofStreamInfo.desc().append_child('synchronization').append_child_value('can_drop_samples',
                                                                                                 'true')
            lsl_hmd6dofOutlet = StreamOutlet(lsl_hmd6dofStreamInfo)

            viz.callback(viz.SENSOR_DOWN_EVENT, self.on_button_press)
            vizact.onupdate(0, self.update_joystick_movement, self.joy, joystick_node, 5, 90, lsl_hmd6dofOutlet)

        else:
            self.start_dk2_head_tracker(control_style)