def ontimer(): #Get data from sensors rightData = RightSensor.getPosition()+RightSensor.getEuler() leftData = LeftSensor.getPosition()+LeftSensor.getEuler() #Save current drumstick position for calculating speed PrevRightTipPos = RightStickTip.get(viz.POSITION,viz.ABSOLUTE_WORLD) PrevLeftTipPos = LeftStickTip.get(viz.POSITION,viz.ABSOLUTE_WORLD) #Apply sensor data to drum sticks RightStick.translate(rightData[0],rightData[1],rightData[2]) RightStick.setEuler([rightData[3],rightData[4],rightData[5]]) LeftStick.translate(leftData[0],leftData[1],leftData[2]) LeftStick.setEuler([leftData[3],leftData[4],leftData[5]]) #Get position of drumstick tips RightTipPos = RightStickTip.get(viz.POSITION,viz.ABSOLUTE_WORLD) LeftTipPos = LeftStickTip .get(viz.POSITION,viz.ABSOLUTE_WORLD) #Calculate speed of drumsticks RightTipSpeed = (viz.Vector(RightTipPos) - PrevRightTipPos).length() / viz.elapsed() LeftTipSpeed = (viz.Vector(LeftTipPos) - PrevLeftTipPos).length() / viz.elapsed() #Update each drum for drum in DrumList: drum.checkHit(0,RightTipPos,RightTipSpeed) drum.checkHit(1,LeftTipPos,LeftTipSpeed)
def updateView(): if Navigation.walk == Move.FORWARD: viz.MainView.move(0, 0, Navigation.translation_speed * viz.elapsed(), viz.BODY_ORI) elif Navigation.walk == Move.BACK: viz.MainView.move(0, 0, -Navigation.translation_speed * viz.elapsed(), viz.BODY_ORI) if Navigation.yaw == Rotate.CW: # right viz.MainView.setEuler([Navigation.rotation_speed * viz.elapsed() * 2.0, 0, 0], viz.BODY_ORI, viz.REL_PARENT) elif Navigation.yaw == Rotate.CCW: # left viz.MainView.setEuler([-Navigation.rotation_speed * viz.elapsed() * 2.0, 0, 0], viz.BODY_ORI, viz.REL_PARENT) if Navigation.pitch == Rotate.CW: # down viz.MainView.setEuler([0, Navigation.rotation_speed * viz.elapsed(), 0], viz.HEAD_ORI, viz.REL_LOCAL) elif Navigation.pitch == Rotate.CCW: # up viz.MainView.setEuler([0, -Navigation.rotation_speed * viz.elapsed(), 0], viz.HEAD_ORI, viz.REL_LOCAL) if Navigation.roll == Rotate.CW: # right viz.MainView.setEuler([0, 0, Navigation.rotation_speed * viz.elapsed()], viz.HEAD_ORI, viz.REL_LOCAL) elif Navigation.roll == Rotate.CCW: # left viz.MainView.setEuler([0, 0, -Navigation.rotation_speed * viz.elapsed()], viz.HEAD_ORI, viz.REL_LOCAL) if Navigation.fly == Move.UP: viz.MainView.move(0, Navigation.TRANSLATION_SPEED / 2 * viz.elapsed(), 0, viz.BODY_ORI) elif Navigation.fly == Move.DOWN: viz.MainView.move(0, -Navigation.TRANSLATION_SPEED / 2 * viz.elapsed(), 0, viz.BODY_ORI)
def UpdateMovement(): pos = joy.getPosition() twist = joy.getTwist() viz.MainView.setAxisAngle(0, 1, 0, twist * viz.elapsed() * 35, viz.BODY_ORI, viz.REL_PARENT) viz.MainView.move( [pos[0] * viz.elapsed() * 5, 0, -pos[1] * viz.elapsed() * 5])
def updateView(): if viz.key.isDown(viz.KEY_UP): viz.MainView.move([0, 0, MOVE_SPEED * viz.elapsed()], viz.BODY_ORI) elif viz.key.isDown(viz.KEY_DOWN): viz.MainView.move([0, 0, -MOVE_SPEED * viz.elapsed()], viz.BODY_ORI) elif viz.key.isDown(viz.KEY_LEFT): viz.MainView.move([-MOVE_SPEED * viz.elapsed(), 0, 0], viz.BODY_ORI) elif viz.key.isDown(viz.KEY_RIGHT): viz.MainView.move([MOVE_SPEED * viz.elapsed(), 0, 0], viz.BODY_ORI)
def updateView(): if viz.key.isDown('W'): view.move([0,0,MOVE_SPEED*viz.elapsed()],viz.BODY_ORI) elif viz.key.isDown('S'): view.move([0,0,-MOVE_SPEED*viz.elapsed()],viz.BODY_ORI) elif viz.key.isDown('D'): view.setEuler([TURN_SPEED*viz.elapsed(),0,0],viz.BODY_ORI,viz.REL_PARENT) elif viz.key.isDown('A'): view.setEuler([-TURN_SPEED*viz.elapsed(),0,0],viz.BODY_ORI,viz.REL_PARENT)
def updatecar(): if viz.key.isDown(viz.KEY_UP): view.move([0,0,MOVE_SPEED*viz.elapsed()],viz.BODY_ORI) elif viz.key.isDown(viz.KEY_DOWN): view.move([0,0,-MOVE_SPEED*viz.elapsed()],viz.BODY_ORI) elif viz.key.isDown(viz.KEY_RIGHT): view.setEuler([TURN_SPEED*viz.elapsed(),0,0],viz.BODY_ORI,viz.REL_PARENT) elif viz.key.isDown(viz.KEY_LEFT): view.setEuler([-TURN_SPEED*viz.elapsed(),0,0],viz.BODY_ORI,viz.REL_PARENT) #Hier wurde das auto an den Viewpoint getakert car.setPosition(view.getPosition()) car.setEuler(view.getEuler(viz.BODY_ORI)) car.setPosition([0.35,-1.2,0.2],viz.REL_LOCAL)
def ontimer(self,num): self.yaw += self.yawspeed * viz.elapsed() self.yawspeed *= 0.99 self.pitch += viz.elapsed() * 360 if self.pitch > 360: self.magnitude *= 0.7 self.pitch -= 360 pitch = math.sin(viz.radians(self.pitch)) * self.magnitude self.model.setEuler([self.yaw,pitch,0])
def updatecar(): if viz.key.isDown(viz.KEY_UP): view.move([0, 0, MOVE_SPEED * viz.elapsed()], viz.BODY_ORI) elif viz.key.isDown(viz.KEY_DOWN): view.move([0, 0, -MOVE_SPEED * viz.elapsed()], viz.BODY_ORI) elif viz.key.isDown(viz.KEY_RIGHT): view.setEuler([TURN_SPEED * viz.elapsed(), 0, 0], viz.BODY_ORI, viz.REL_PARENT) elif viz.key.isDown(viz.KEY_LEFT): view.setEuler([-TURN_SPEED * viz.elapsed(), 0, 0], viz.BODY_ORI, viz.REL_PARENT) car.setPosition(view.getPosition()) car.setEuler(view.getEuler(viz.BODY_ORI)) car.setPosition([0.35, -1.2, 0.2], viz.REL_LOCAL)
def UpdateMovement(): elapsed = viz.elapsed() # Get the joystick position x, y, z = environment3D.joy.getPosition() # Get the twist of the joystick twist = environment3D.joy.getTwist() # Move the point based on xy-axis value move_amount = 10 * elapsed position = environment3D.point.getPosition() position = [ position[0] + x * move_amount, position[1], position[2] + y * move_amount ] # compute size direction and position of arrow environment3D.point.setPosition(position) if (training == True): environment3D.arrow.setPosition(position[0] + 2, 21, position[2] + 2) environment3D.arrow.setAxisAngle( [0, 1, 0, windSpeed.computeWindDirection(position)]) environment3D.arrow.setScale([ windSpeed.computeWindSpeed(position) * 5, 1, windSpeed.computeWindSpeed(position) * 5 ])
def joyhat(self, e): # e.hat - new hat value # e.oldHat - old hat value if e.joy != self.joystick: return if not isinstance(self.toolActive, int): self.moveCursor = True if e.hat >= 0: deg = e.hat x = y = 0 if deg > 180: deg = deg - 360 #check y move if abs(deg) < 90: y = 1 elif abs(deg) > 90: y = -1 #check x move if deg < 0: x = -1 elif 180 > deg > 0: x = 1 speed = viz.elapsed() * CURSOR_SPEED self.moveCursor = [speed * x, speed * y, 0] else: self.moveCursor = False
def UpdateMovement(): global tracker global node global yaw_ringbuffer, pitch_ringbuffer, roll_ringbuffer, ringbuffer_idx global ringbuffer_len global elapsed_sum, elapsed_N elapsed_sum = elapsed_sum + viz.elapsed() elapsed_N = elapsed_N + 1 if ( elapsed_N == 50 ): #print 'upp latency:',(elapsed_sum/elapsed_N)*12*1000,' ms' #print 'med latency:',(elapsed_sum/elapsed_N)*6*1000,' ms' #print 'low latency:',(elapsed_sum/elapsed_N)*1*1000,' ms' elapsed_sum = 0 elapsed_N = 0 yaw = yaw_ringbuffer[ringbuffer_idx] pitch = pitch_ringbuffer[ringbuffer_idx] roll = roll_ringbuffer[ringbuffer_idx] node.setPosition( viz.MainView.getPosition() ) node.setEuler( viz.MainView.getEuler() ) #node.setEuler( yaw,pitch,roll ) #Get tracker euler rotation yaw,pitch,roll = tracker.getEuler() viz.MainView.setEuler([yaw,pitch,roll]) #yaw,pitch,roll = viz.MainView.getEuler() yaw_ringbuffer[ringbuffer_idx] = yaw pitch_ringbuffer[ringbuffer_idx] = pitch roll_ringbuffer[ringbuffer_idx] = roll ringbuffer_idx = (ringbuffer_idx + 1)%ringbuffer_len
def update_joystick_movement(joystick, view_node, move_speed, turn_speed, lsl_stream): """ Updates the viewpoint depending on joystick movements. Sends 6dof of viz.MainView via lsl. Args: joystick: joystick loaded with either vizconnect or directly as in 'use_control' function above view_node: Viewpoint node move_speed: move speed translated from joystick movement to viewpoint updating. Default value is 5. turn_speed: turn speed elicited by joystick twist in VR. Default value is 90. lsl_stream: stream to push 6dof sample """ elapsed = viz.elapsed() # Get the joystick position x, y, z = joystick.getPosition() # Move the viewpoint based on xy-axis value view_node.setPosition([0, 0, y * move_speed * viz.getFrameElapsed()], viz.REL_LOCAL) # Turn the viewpoint left/right based on twist value view_node.setEuler([x * turn_speed * elapsed, 0, 0], viz.REL_LOCAL) # stream the HMD 6DOF pos = viz.MainView.getPosition() ori = viz.MainView.getEuler() lsl_stream.push_sample([pos[0], pos[1], pos[2], ori[0], ori[1], ori[2]])
def updatecar(): #move view forward and backward if viz.key.isDown(viz.KEY_UP): view.move([0,0,MOVE_SPEED*viz.elapsed()],viz.BODY_ORI) elif viz.key.isDown(viz.KEY_DOWN): view.move([0,0,-MOVE_SPEED*viz.elapsed()],viz.BODY_ORI) #rotate body of view left and right if viz.key.isDown(viz.KEY_RIGHT): view.setEuler([TURN_SPEED*viz.elapsed(),0,0],viz.BODY_ORI,viz.REL_PARENT) elif viz.key.isDown(viz.KEY_LEFT): view.setEuler([-TURN_SPEED*viz.elapsed(),0,0],viz.BODY_ORI,viz.REL_PARENT) #set the car to view position and body orientation car.setPosition(view.getPosition()) car.setEuler(view.getEuler(viz.BODY_ORI)) car.setPosition([3.02,-5.50,5.04],viz.REL_LOCAL)
def animateTexture(): #Increment texture position tex.pos += ANIMATE_SPEED * viz.elapsed() #Create transform for texture mat = viz.Transform() mat.setTrans(tex.pos,0,0) #Apply transform to texture quad.texmat(mat)
def UpdateMovement(): global positionList elapsed = viz.elapsed() # Get the joystick position x, y, z = environment.joy.getPosition() # Get the twist of the joystick twist = environment.joy.getTwist() # Move the point based on xy-axis value move_amount = parameters.joySpeed * elapsed position = environment.point.getPosition() if parameters.joystick: if ((position[0] + x * move_amount) > parameters.fieldsizeX): position[0] = parameters.fieldsizeX elif ((position[0] + x * move_amount) < -parameters.fieldsizeX): position[0] = -parameters.fieldsizeX else: position[0] += x * move_amount if ((position[2] + y * move_amount) > parameters.fieldsizeZ): position[2] = parameters.fieldsizeZ elif ((position[2] + y * move_amount) < -parameters.fieldsizeZ): position[2] = -parameters.fieldsizeZ else: position[2] += y * move_amount else: position = [ position[0] + x * move_amount, position[1], position[2] + y * move_amount ] environment.point.setPosition(position) # compute size direction and position of arrow if parameters.dreiDEnvironment: environment.shadow.setPosition(position[0], parameters.shadow_height, position[2]) if (parameters.intro or parameters.training): if parameters.dreiDEnvironment: #environment.arrow.setPosition(position[0], parameters.arrow_height3D, position[2]) environment.arrow.setPosition(0, parameters.arrow_height3D, 0) else: environment.arrow.setPosition(position[0], parameters.arrow_height2D, position[2]) environment.arrow.setAxisAngle( [0, 1, 0, windSpeed.computeWindDirection(position)]) environment.arrow.setScale([ windSpeed.computeWindSpeed(position) * parameters.arrow_size + parameters.arroa_min_size, windSpeed.computeWindSpeed(position) * parameters.arrow_size + parameters.arroa_min_size, windSpeed.computeWindSpeed(position) * parameters.arrow_size + parameters.arroa_min_size ]) positionList.append(position)
def onTimer(num): #Use the time ids to identify the timer. move_speed = 5 if viz.MainWindow.isCulled(gplane1): print "gplane1 culled" gplane1.setPosition(0, 0, texture_z_size * 2, viz.REL_GLOBAL) #bring to driver pos if viz.MainWindow.isCulled(gplane2): print "gplane2 culled" gplane2.setPosition(0, 0, texture_z_size * 2, viz.REL_GLOBAL) #bring to driver pos if viz.key.isDown(viz.KEY_UP): viz.MainView.move([0, 0, move_speed * viz.elapsed()], viz.BODY_ORI) elif viz.key.isDown(viz.KEY_DOWN): viz.MainView.move([0, 0, move_speed * viz.elapsed()], viz.BODY_ORI)
def mytimer(self, num): #Increment the angle self.angle += self.speed * viz.elapsed() #Calculate the new position x = math.sin(viz.radians(self.angle)) * self.radius z = math.cos(viz.radians(self.angle)) * self.radius #Translate the object to the new position, accounting for the offset self.object.setAxisAngle(0, 1, 0, self.angle + 90) self.object.setPosition( [self.offset[0] + x, self.offset[1], self.offset[2] + z])
def updateView(self): """ Use joystick axes to move joystick node""" elapsed = viz.elapsed() x,y,z = self.joy.getPosition() twist = self.joy.getTwist() elevation_amount = 0 if self.joy.isButtonDown(self.KEYS['up']) and self.CAN_ELEVATE: elevation_amount = self.MOVE_SPEED * elapsed if self.joy.isButtonDown(self.KEYS['down']) and self.CAN_ELEVATE: elevation_amount = -self.MOVE_SPEED * elapsed move_amount = 0 if self.CAN_STRAFE: self.MOVE_SPEED * elapsed self.VIEW.setPosition([x*move_amount,elevation_amount,y*move_amount], viz.REL_LOCAL)
def update(): global grab #print 'analog getData', analog.getData() #add the analog data to a list so that interactions can be made leap = analog.getData() #if a hand is present (stops movement when hand is taken away) if leap[98] > 0.3: #if gesture is a fist (grab) if leap[96] >= 0.5: if grab is None: #grab the object grab = viz.grab(view, h) elif leap[96] < 0.5: if grab is not None: grab.remove() grab = None if leap[2] < -40: view.move([0,0,MOVE_SPEED*viz.elapsed()],viz.BODY_ORI) if leap[2] > 40: view.move([0,0,-MOVE_SPEED*viz.elapsed()],viz.BODY_ORI) if leap[0] < -40: view.setEuler([-TURN_SPEED*viz.elapsed(),0,0],viz.BODY_ORI,viz.REL_PARENT) if leap[0] > 40: view.setEuler([TURN_SPEED*viz.elapsed(),0,0],viz.BODY_ORI,viz.REL_PARENT)
def viewTrackerUpdate(self): #viewTracker constants speed = 2000000 # move speed rot_speed = 17 # rotate speed # print viz.elapsed() #about 0.003 @ 30 fps elapsed = viz.elapsed() fps_speed = elapsed*speed fps_rot_speed = elapsed*rot_speed viewTracker.setPosition(artTracker.x,artTracker.y,artTracker.z+depth/2) viewTracker.setEuler(artTracker.yaw,artTracker.pitch,artTracker.roll) self.cave_origin.setPosition(artTracker.jy*artTracker.x2*fps_speed, artTracker.jy*artTracker.y2*fps_speed, artTracker.jy*artTracker.z2*fps_speed,viz.REL_LOCAL) self.cave_origin.setEuler(fps_rot_speed*artTracker.jx,0.0,0.0,viz.REL_LOCAL)
def updateView(self): elapsed = viz.elapsed() x,y,z = self.joy.getPosition() twist = self.joy.getTwist() elevation_amount = 0 if self.joy.isButtonDown(self.KEYS['up']) and self.CAN_ELEVATE: elevation_amount = self.MOVE_SPEED * elapsed if self.joy.isButtonDown(self.KEYS['down']) and self.CAN_ELEVATE: elevation_amount = -self.MOVE_SPEED * elapsed move_amount = 0 if self.CAN_STRAFE: move_amount = self.MOVE_SPEED * elapsed # self.NODE.setPosition([0, 0, y * self.MOVE_SPEED * viz.getFrameElapsed()], viz.REL_LOCAL) self.NODE.setPosition([x*move_amount,elevation_amount,y*move_amount], viz.REL_LOCAL) turn_amount = self.TURN_SPEED * elapsed self.NODE.setEuler([twist*turn_amount,0,0], viz.REL_LOCAL)
def UpdateMovement(): elapsed = viz.elapsed() # Get the joystick position x,y,z = environment3D.joy.getPosition() # Get the twist of the joystick twist = environment3D.joy.getTwist() # Move the point based on xy-axis value move_amount = 10 * elapsed position = environment3D.point.getPosition() position = [position[0] + x*move_amount,position[1],position[2] + y*move_amount] # compute size direction and position of arrow environment3D.point.setPosition(position) if (training == True): environment3D.arrow.setPosition(position[0] + 2, 21, position[2] + 2) environment3D.arrow.setAxisAngle( [0, 1, 0 , windSpeed.computeWindDirection(position)] ) environment3D.arrow.setScale([windSpeed.computeWindSpeed(position) * 5 , 1, windSpeed.computeWindSpeed(position) * 5])
def UpdateMovement(): global positionList elapsed = viz.elapsed() # Get the joystick position x,y,z = environment.joy.getPosition() # Get the twist of the joystick twist = environment.joy.getTwist() # Move the point based on xy-axis value move_amount = parameters.joySpeed * elapsed position = environment.point.getPosition() if parameters.joystick: if ((position[0] + x*move_amount) > parameters.fieldsizeX): position[0] = parameters.fieldsizeX elif((position[0] + x*move_amount) < -parameters.fieldsizeX): position[0] = -parameters.fieldsizeX else: position[0]+= x*move_amount if ((position[2] + y*move_amount) > parameters.fieldsizeZ): position[2] = parameters.fieldsizeZ elif((position[2] + y*move_amount) < -parameters.fieldsizeZ): position[2] = -parameters.fieldsizeZ else: position[2]+= y*move_amount else: position = [position[0] + x*move_amount,position[1],position[2] + y*move_amount] environment.point.setPosition(position) # compute size direction and position of arrow if parameters.dreiDEnvironment: environment.shadow.setPosition(position[0], parameters.shadow_height, position[2]) if (parameters.intro or parameters.training): if parameters.dreiDEnvironment: #environment.arrow.setPosition(position[0], parameters.arrow_height3D, position[2]) environment.arrow.setPosition(0, parameters.arrow_height3D,0) else: environment.arrow.setPosition(position[0], parameters.arrow_height2D, position[2]) environment.arrow.setAxisAngle( [0, 1, 0 , windSpeed.computeWindDirection(position)] ) environment.arrow.setScale([windSpeed.computeWindSpeed(position) * parameters.arrow_size + parameters.arroa_min_size, windSpeed.computeWindSpeed(position) * parameters.arrow_size + parameters.arroa_min_size, windSpeed.computeWindSpeed(position) * parameters.arrow_size + parameters.arroa_min_size]) positionList.append(position)
def setPositionFromKeyboard(): #move view forward and backward if viz.key.isDown(viz.KEY_UP): viz.MainView.move([0,0,MOVE_SPEED*viz.elapsed()],viz.BODY_ORI) elif viz.key.isDown(viz.KEY_DOWN): viz.MainView.move([0,0,-MOVE_SPEED*viz.elapsed()],viz.BODY_ORI) #rotate view left and right if viz.key.isDown(viz.KEY_RIGHT): viz.MainView.setEuler([TURN_SPEED*viz.elapsed(),0,0],viz.BODY_ORI,viz.REL_PARENT) elif viz.key.isDown(viz.KEY_LEFT): viz.MainView.setEuler([-TURN_SPEED*viz.elapsed(),0,0],viz.BODY_ORI,viz.REL_PARENT) #move view up ('w') and down ('s') if viz.key.isDown('w'): viz.MainView.move([0,MOVE_SPEED*viz.elapsed(),0],viz.BODY_ORI) elif viz.key.isDown('s'): viz.MainView.move([0,-MOVE_SPEED*viz.elapsed(),0],viz.BODY_ORI)
def updateJoy(): elapsed = viz.elapsed() x,y,z = joystick.getPosition() move_amount = 5 * elapsed view.move([x*move_amount, 0, y*move_amount]) view.setPosition([view.getPosition()[0], 1.8, view.getPosition()[2]])
def _move(self, amount): self.camera.move([0, 0, amount * self.move_speed * viz.elapsed()], viz.BODY_ORI)
def _turn(self, amount): self.camera.setEuler([amount * self.turn_speed * viz.elapsed(), 0, 0], viz.BODY_ORI, viz.REL_PARENT)
def updatePositionLabel(self, num): """Timer function that gets called every frame. Updates parameters for saving""" """Here need to bring in steering bias updating from Trout as well""" if self.UPDATELOOP: dt = viz.elapsed() #print ("elapsed:", dt) #print ("frame elapsed:", viz.getFrameElapsed()) self.Trial_Timer = self.Trial_Timer + dt #print("UpdatingPosition...") #update driver view. if self.AUTOMATION: newSWApos = self.Trial_SWA_readout[self.Current_playbackindex] newSWApos *= np.sign( self.Trial_trialtype_signed) #flip if left hand bend if self.AUTOWHEEL: self.Wheel.set_position( newSWApos) #set steering wheel to position. newyawrate = self.Trial_YR_readout[self.Current_playbackindex] #add yawrateoffset. #if self.Trial_Timer > self.Trial_OnsetTime: #2 seconds into the bend. time_after_onset = self.Trial_Timer - self.Trial_OnsetTime transition_duration = .5 if time_after_onset > 0: newyawrate += smooth_step( time_after_onset / transition_duration ) * self.Trial_YawRate_Offset #positive offset = greater oversteering. self.Current_playbackindex += 1 newyawrate *= np.sign( self.Trial_trialtype_signed) #flip if left hand bend else: newyawrate = None UpdateValues = self.driver.UpdateView( YR_input=newyawrate ) #update view and return values used for update pos = self.caveview.getPosition() ori = self.getNormalisedEuler() ### #update Current parameters #### self.Current_pos_x = pos[0] self.Current_pos_z = pos[2] self.Current_SWA = UpdateValues[4] self.Current_yaw = ori[0] self.Current_RowIndex += 1 self.Current_Time = viz.tick() self.Current_YawRate_seconds = UpdateValues[0] self.Current_TurnAngle_frames = UpdateValues[1] self.Current_distance = UpdateValues[2] self.Current_dt = UpdateValues[3] self.Current_WheelCorrection = UpdateValues[5] self.Current_steeringbias, self.Current_closestpt = self.calculatebias( ) #update txtCurrent. if self.DEBUG: currentmessage = 'TrialTime: ' + str(round( self.Trial_Timer, 2)) + '\nLanePos: ' + str( round(self.Current_steeringbias, 2)) self.txtCurrent.message(currentmessage) if self.DEBUG_PLOT: #add to plot position array self.plot_positionarray_x.append(self.Current_pos_x) self.plot_positionarray_z.append(self.Current_pos_z) midpos = self.Trial_midline[self.Current_closestpt] self.plot_closestpt_x.append(midpos[0]) self.plot_closestpt_z.append(midpos[1]) if self.plottimer > self.plotinterval: self.UpdatePlot() self.plottimer = 0 self.plottimer += viz.elapsed() self.RecordData() #write a line in the dataframe.
def keyDown(whichKey): global debug global cursorPos global highlightedObj global highlightedObjType global selectedObj global selectedObjType global selectedIndex global blockState #print 'The following key was pressed: ', whichKey if whichKey == 'x': debug = not debug # navigation if whichKey == viz.KEY_UP: viz.MainView.move(0,0,Navigation.translation_speed*viz.elapsed(),viz.BODY_ORI) elif whichKey == viz.KEY_DOWN: viz.MainView.move(0,0,-Navigation.translation_speed*viz.elapsed(),viz.BODY_ORI) if whichKey == viz.KEY_LEFT: Navigation.yaw = Rotate.CCW elif whichKey == viz.KEY_RIGHT: Navigation.yaw = Rotate.CW if whichKey == ']': Navigation.pitch = Rotate.CCW elif whichKey == '[': Navigation.pitch = Rotate.CW if whichKey == '}': Navigation.roll = Rotate.CCW elif whichKey == '{': Navigation.roll = Rotate.CW if whichKey == 'i': Navigation.fly = Move.UP elif whichKey == 'k': Navigation.fly = Move.DOWN # cursor if whichKey == 'w': cursorPos[1] += 0.05 elif whichKey == 's': cursorPos[1] -= 0.05 if whichKey == 'a': cursorPos[0] -= 0.05 elif whichKey == 'd': cursorPos[0] += 0.05 if whichKey == 'e': cursorPos[2] += 0.05 elif whichKey == 'q': cursorPos[2] -= 0.05 # selection if whichKey == viz.KEY_RETURN: #picking a piece up if selectedObj == None and highlightedObj != None: if highlightedObjType == 'piece': for i in pieceAttr[selectedIndex].puzzleIndices: blockState[i] = False selectedObj = highlightedObj selectedObjType = highlightedObjType selectedIndex = pieces.index(selectedObj) pieceAttr[selectedIndex].placed = False # piece placement (try to drop a piece) elif selectedObj != None: if place_piece(): check_for_win() selectedObj = None selectedObjType = None selectedIndex = -1 # selection #2 (up/down piece selection) if whichKey == 'm': cycle_select(forward = True) elif whichKey == 'n': cycle_select(forward = False) # translation of the selected object is done by moving the cursor # orientation if selectedObj != None: if whichKey == 't': selectedObj.setEuler(0,90,0,viz.REL_LOCAL)#yaw,pitch,roll elif whichKey == 'g': selectedObj.setEuler(0,-90,0,viz.REL_LOCAL)#yaw,pitch,roll if whichKey == 'f': selectedObj.setEuler(90,0,0,viz.REL_LOCAL)#yaw,pitch,roll elif whichKey == 'h': selectedObj.setEuler(-90,0,0,viz.REL_LOCAL)#yaw,pitch,roll if whichKey == 'y': selectedObj.setEuler(0,0,90,viz.REL_LOCAL)#yaw,pitch,roll elif whichKey == 'r': selectedObj.setEuler(0,0,-90,viz.REL_LOCAL)#yaw,pitch,roll
def keyDown(whichKey): global debug global cursor global cursorPos global highlightedObj global highlightedObjType global selectedObj global selectedObjType global selectedIndex global blockState global absCursorPos absCursorPos = cursor.getPosition(viz.ABS_GLOBAL) # print 'The following key was pressed: ', whichKey if whichKey == "x": debug = not debug # navigation if whichKey == viz.KEY_UP: viz.MainView.move(0, 0, Navigation.translation_speed * viz.elapsed(), viz.BODY_ORI) elif whichKey == viz.KEY_DOWN: viz.MainView.move(0, 0, -Navigation.translation_speed * viz.elapsed(), viz.BODY_ORI) if whichKey == viz.KEY_LEFT: Navigation.yaw = Rotate.CCW elif whichKey == viz.KEY_RIGHT: Navigation.yaw = Rotate.CW if whichKey == "]": Navigation.pitch = Rotate.CCW elif whichKey == "[": Navigation.pitch = Rotate.CW if whichKey == "}": Navigation.roll = Rotate.CCW elif whichKey == "{": Navigation.roll = Rotate.CW if whichKey == "i": Navigation.fly = Move.UP elif whichKey == "k": Navigation.fly = Move.DOWN # cursor if whichKey == "w": cursorPos[1] += 0.05 elif whichKey == "s": cursorPos[1] -= 0.05 if whichKey == "a": cursorPos[0] -= 0.05 elif whichKey == "d": cursorPos[0] += 0.05 if whichKey == "e": cursorPos[2] += 0.05 elif whichKey == "q": cursorPos[2] -= 0.05 # selection if whichKey == viz.KEY_RETURN: selection() rem_piece() # #picking a piece up # if selectedObj == None and highlightedObj != None: # if highlightedObjType == 'piece': # for i in pieceAttr[selectedIndex].puzzleIndices: # blockState[i] = False # selectedObj = highlightedObj # selectedObjType = highlightedObjType # selectedIndex = pieces.index(selectedObj) # pieceAttr[selectedIndex].placed = False # rem_piece() # # # piece placement (try to drop a piece) # elif selectedObj != None: # if place_piece(): # check_for_win() # selectedObj = None # selectedObjType = None # selectedIndex = -1 # selection #2 (up/down piece selection) if whichKey == "m": cycle_select(forward=True) elif whichKey == "n": cycle_select(forward=False) # translation of the selected object is done by moving the cursor # orientation if selectedObj != None: if whichKey == "t": selectedObj.setEuler(0, 90, 0, viz.REL_LOCAL) # yaw,pitch,roll elif whichKey == "g": selectedObj.setEuler(0, -90, 0, viz.REL_LOCAL) # yaw,pitch,roll if whichKey == "f": selectedObj.setEuler(90, 0, 0, viz.REL_LOCAL) # yaw,pitch,roll elif whichKey == "h": selectedObj.setEuler(-90, 0, 0, viz.REL_LOCAL) # yaw,pitch,roll if whichKey == "y": selectedObj.setEuler(0, 0, 90, viz.REL_LOCAL) # yaw,pitch,roll elif whichKey == "r": selectedObj.setEuler(0, 0, -90, viz.REL_LOCAL) # yaw,pitch,roll
def UpdateView(self): elapsedTime = viz.elapsed( ) #retrieves amount of time passed from last function call. yawrate = 0.0 turnangle = 0.0 distance = 0.0 dt = elapsedTime #dt = 1.0/60.0 #not sure why but it's perceptually smoother with a constant. This shouldn't be the case. #Get steering wheel and gas position data = joy.getPosition() SteeringWheelValue = data[0] # on scale from -1 to 1. gas = data[1] if self.__automation: #keep heading up to date. ori = self.__view.getEuler() self.__heading = ori[0] elif not self.__automation: if viz.key.isDown(viz.KEY_UP): gas = -5 elif viz.key.isDown(viz.KEY_DOWN): gas = 5 if viz.key.isDown( viz.KEY_LEFT ): #rudimentary control with the left/right arrows. data[0] = -1 elif viz.key.isDown(viz.KEY_RIGHT): data[0] = 1 # #Compute drag # drag = self.__speed / 300.0 self.__dir = 1 yawrate = self.__dir * SteeringWheelValue * 35.0 #max wheel lock is 35degrees per s yawrate turnangle = yawrate * dt #amount of angular distance to move per frame. self.__heading += turnangle self.__pause = self.__pause + 1 #Update the viewpoint if self.__pause > 0: distance = self.__speed * dt #amount of metres that the camera needs to move per frame. #posnew = (0,0,self.__speed) posnew = (0, 0, distance) eulernew = (self.__heading, 0, 0) self.__view.setPosition(posnew, viz.REL_LOCAL) self.__view.setEuler(eulernew) #set absolutely. else: self.__heading = 0.0 self.__dir = 1.0 turnangle = 0.0 #return the values used in position update UpdateValues = [] UpdateValues.append(yawrate) UpdateValues.append(turnangle) UpdateValues.append(distance) UpdateValues.append(dt) UpdateValues.append(SteeringWheelValue) return (UpdateValues)