def addCaveWall(cave): """Create visualization of cave walls""" walls = cave.getWalls() group = viz.addGroup() for w in walls: mat = viz.Matrix() mat.setQuat(w.getQuat()) mat.setPosition(w.getCenter()) wall_node = vizshape.addQuad([w.getWidth(),w.getHeight()],transform=mat,parent=group) wall_node.color(viz.GRAY) wall_node.alpha(0.3) wire_node = vizshape.addQuad([w.getWidth(),w.getHeight()],transform=mat,parent=group) wire_node.color(viz.BLACK) wire_node.polyMode(viz.POLY_WIRE) wire_node.zoffset() group.disable(viz.LIGHTING) return group
def updateViewHQ(): viz.MainView.setEuler(0,90,270) viz.MainView.setPosition(0.15,0.85,0.5) #[y,z,x] viz.cam.setReset() vizact.onkeydown(' ',viz.cam.reset) targetL = vizshape.addQuad(size=(SL_Left,0.15),axis=vizshape.AXIS_Y, cullFace=False, color=viz.GREEN, pos=(SL_Left/2,0.01,0.7)) targetL_bottom = vizshape.addQuad(size=(0.01,0.35),axis=vizshape.AXIS_Y, cullFace=False, color=viz.RED, pos=(SL_Left - 3*sd_Left,0.01,0.7)) targetL_top = vizshape.addQuad(size=(0.01,0.35),axis=vizshape.AXIS_Y, cullFace=False, color=viz.RED, pos=(SL_Left + 3*sd_Left,0.01,0.7)) targetR = vizshape.addQuad(size=(SL_Right,0.15),axis=vizshape.AXIS_Y, cullFace=False, color=viz.BLUE, pos=( SL_Right/2 ,0.01,0.3)) targetR_bottom = vizshape.addQuad(size=(0.01,0.35),axis=vizshape.AXIS_Y, cullFace=False, color=viz.RED, pos=(SL_Right - 3*sd_Right,0.01,0.3)) targetR_top = vizshape.addQuad(size=(0.01,0.35),axis=vizshape.AXIS_Y, cullFace=False, color=viz.RED, pos=(SL_Right + 3*sd_Right,0.01,0.3))
def updateViewHQ(LeftAnkle, RightAnkle, LeftGTO, RightGTO): viz.MainView.setEuler(0,90,270) xyzCamera = qualisys.getMarker(RightGTO).getPosition() # print xyzCamera xyzCamera1 = qualisys.getMarker(2).getPosition() # print xyzCamera1 viz.MainView.setPosition(0.1,0.5,.4) viz.cam.setReset() vizact.onkeydown(' ',viz.cam.reset) positionL = qualisys.getMarker(LeftAnkle).getPosition() #print positionL positionR = qualisys.getMarker(RightAnkle).getPosition() #print positionR analog = qualisys.getAnalog(0) #print analog ForcePlates = analog.getData() #print ForcePlates calibrationFz= 1000 # 3,3 value in Bertec calibation matrix GRFL = ForcePlates[3]*calibrationFz GRFR = ForcePlates[10]*calibrationFz #print "Left", GRFL #print "Right", GRFR positionL_Hip = qualisys.getMarker(LeftGTO).getPosition() positionR_Hip = qualisys.getMarker(RightGTO).getPosition() targetL = vizshape.addQuad(size=(SL_Left, .15,),axis=vizshape.AXIS_Y, cullFace=False,color=viz.GREEN,pos=(SL_Left/2,0.01,positionL[2])) targetL2 = vizshape.addQuad(size=(SL_Left*8, .15,),axis=vizshape.AXIS_Y, cullFace=False,color=viz.GREEN,pos=(-4*SL_Left,0.01,positionL[2])) targetL_bottom = vizshape.addQuad(size=(0.01, .25,),axis=vizshape.AXIS_Y, cullFace=False,color=viz.RED,pos=(SL_Left - 2*sd_Left,0.01,positionL[2])) targetL_top = vizshape.addQuad(size=(0.01, .25,),axis=vizshape.AXIS_Y, cullFace=False,color=viz.RED,pos=(SL_Left + 2*sd_Left,0.01,positionL[2] )) targetR = vizshape.addQuad(size=(SL_Right, .15,),axis=vizshape.AXIS_Y, cullFace=False,color=viz.BLUE,pos=( SL_Right/2 ,0.01,positionR[2])) targetR2 = vizshape.addQuad(size=(SL_Right*8, .15,),axis=vizshape.AXIS_Y, cullFace=False,color=viz.BLUE,pos=(-4*SL_Right,0.01,positionR[2])) targetR_bottom = vizshape.addQuad(size=(0.01, .25,),axis=vizshape.AXIS_Y, cullFace=False,color=viz.RED,pos=(SL_Right - 2*sd_Right,0.01,positionR[2])) targetR_top = vizshape.addQuad(size=(0.01, .25,),axis=vizshape.AXIS_Y, cullFace=False,color=viz.RED,pos=(SL_Right + 2*sd_Right,0.01,positionR[2] ))
def __init__(self,**kw): group = viz.addGroup(**kw) viz.VizNode.__init__(self,group.id) self._quad = vizshape.addQuad([1,1],parent=self) self._quad.color(viz.RED) self._quad.polyMode(viz.POLY_WIRE) viz.startLayer(viz.LINES) viz.vertexColor(viz.RED) for x in range(8): viz.vertex([0,0,0]) self._lines = viz.endLayer(parent=self) self._lines.dynamic() self.zoffset(-2) self.lineWidth(2) self.disable(viz.LIGHTING) self._wall = None self._tracker = None vizact.onupdate(viz.PRIORITY_LAST_UPDATE,self.updateFrustum)
def _setup_environment(self): """ Setup all objects to create the environments. Environments can be switched with the R key on the keyboard. """ # Add the comfortable "kitchen" room self._room = viz.addChild("Room.osgb") self._room.setScale(.01, .01, .01) # Create the clean "ground" environment (just a white round ground). # This environment isn't saved in a osgb file, because the lights couldn't be configured to use the light group 1 instead of 0. # Only 8 lights are allowed per light group. Room has already 8 lights. img = viz.addTexture('assets/ground.png') self._ground = vizshape.addQuad() self._ground.setScale(6, 6, 6) self._ground.setEuler(0, 90, 0) self._ground.texture(img) # Create the lights for the "ground" envirtonment. light_positions = [ [0, 5, 0], # From top [0, -5, 0], # From bottom [3, 1.5, 0], [-3, 1.5, 0], [0, 1.5, 3], [0, 1.5, -3] ] for light_position in light_positions: light = viz.addLight(group=1) light.setParent(self._ground) light.spread(45) light.intensity(1) light.spotexponent(3) light.setPosition(light_position, mode=viz.ABS_GLOBAL) light.lookAt(self._ground.getPosition()) # Hide the second environment until the environment gets changed self._ground.visible(False)
import viz import vizshape viz.go( viz.FULLSCREEN ) #h = vizshape.addSphere(0.125,20,20) h = vizshape.addQuad(size=[1,1]) h.setParent(viz.SCREEN) h.setPosition(0.5,0.5,0) #h = viz.addChild('ball.wrl') #h = viz.addChild('hidesphere.wrl',scale=[0.1,0.1,0.1]) h.color(1,1,1) h.disable(viz.LIGHTING) viz.MainView.setPosition(0,0,-1)
def getOutputTexture(self): return self._output_texture def remove(self): self._cam.remove() self._projector.remove() viz.VizNode.remove(self) if __name__ == '__main__': import vizshape import vizcam viz.setMultiSample(4) viz.fov(60) viz.go() vizcam.WalkNavigate() piazza = viz.addChild('piazza.osgb') capture = ViewAccumulator(frame_weight=0.5, aperture_scale=0.5) capture.setPosition(0, 1.8, 3.0) # add debug quad output_quad = vizshape.addQuad() output_quad.texture(capture.getOutputTexture()) output_quad.disable(viz.LIGHTING) output_quad.renderOnlyToWindows( [viz.addWindow(pos=[0.5, 0.5], size=[0.5, 0.5])]) viz.link(capture, output_quad)
walkway = viz.addChild('ground.osgb', scale=[0.0167, 1, walkdistance]) walkway.setPosition(0, 0, (walkdistance * 50) / 2) #start at one end of the walkway sky = viz.addChild('sky_day.osgb') grass1 = viz.addChild('ground_grass.osgb') grass1.setPosition(0, -0.01, 0) grass2 = viz.addChild('ground_grass.osgb') grass2.setPosition(0, -0.01, 50) grass3 = viz.addChild('ground_grass.osgb') grass3.setPosition(0, -0.01, 50) #create a divider line global divider divider = vizshape.addQuad(size=(0.01, walkdistance * 50), axis=-vizshape.AXIS_Y, cullFace=False, cornerRadius=0) divider.setPosition(0, 0.001, (walkdistance * 50) / 2) divider.color(255, 255, 255) #make the Right targets rt = {} for x in range(1, int((walkdistance * 50) / (targetSL * 2)), 1): # rt["T{0}".format(x)]=vizshape.addQuad((0.1,targettol),axis=-vizshape.AXIS_Y,cullFace=False,cornerRadius=0) rt["T{0}".format(x)] = vizshape.addBox(size=[0.25, 0.02, 2 * targettol]) rt["T{0}".format(x)].setPosition(0.2, 0.011, x * 2 * targetSL) rt["T{0}".format(x)].color(0, 0, 0) lt = {} for x in range(1, int((walkdistance * 50) / (targetSL * 2)), 1): # rt["T{0}".format(x)]=vizshape.addQuad((0.1,targettol),axis=-vizshape.AXIS_Y,cullFace=False,cornerRadius=0)
def StepLength( flagL, flagR, stepLengthLeft, stepLengthRight, L=LeftAnkle, R=RightAnkle, width=0.05, length=0.05 ): # R: index in QTM for ankle marker right, L = index in QTM for ankle marker left positionL = qualisys.getMarker(L).getPosition() positionR = qualisys.getMarker(R).getPosition() analog = qualisys.getAnalog(0) ForcePlates = analog.getData() calibrationFz = 1000 # 3,3 value in Bertec calibation matrix GRFL = ForcePlates[3] * calibrationFz GRFR = ForcePlates[10] * calibrationFz temp_stepLengthLeft = positionL[0] - positionR[0] temp_stepLengthRight = positionR[0] - positionL[0] # LEFT LEG if (GRFL > 30): # --> leg is in stance phase, hide ankle location markerL = vizshape.addQuad(size=(length, width), axis=-vizshape.AXIS_Y, cullFace=True, cornerRadius=0.05, pos=positionL) if (flagL == 1): if (temp_stepLengthLeft > 0): stepLengthLeft.append(temp_stepLengthLeft) flagL = 0 stepLengthLeft.sort(reverse=True) # print stepLengthLeft # max_stepLengthLeft = stepLengthLeft[:100] filepath = 'C:\\Users\\User\\Documents\\Chang\\LeftStepLength' + filename f = open(filepath, 'w') json.dump(stepLengthLeft, f) f.close() # f_test = open('C:\Users\User\Documents\Natalia\QTM\LeftStepLengthtest.txt','w') # for item in max_stepLengthLeft: # f_test.write("%s\n" % item) # mean_stepLengthLeft = float(sum(max_stepLengthLeft)) / len(max_stepLengthLeft) # sd_Left = float(((sum(sd_Left_temp))/len(max_stepLengthLeft))**0.5) # f1 = open('C:\Users\User\Documents\Natalia\QTM\Left_MeanStepLength.txt','w') # json.dump(mean_stepLengthLeft,f1) # f1.close() else: # --> leg is in swing phase, track ankle location markerL = vizshape.addQuad(size=(length, width), axis=-vizshape.AXIS_Y, cullFace=False, cornerRadius=0.05, pos=positionL) fadeOut = vizact.fadeTo(0, time=.05) markerL.addAction(fadeOut) temp_stepLengthLeft = positionL[0] - positionR[0] flagL = 1 # RIGHT LEG if (GRFR > 30): # --> Right is in stance phase, hide ankle location markerR = vizshape.addQuad(size=(length, width), axis=-vizshape.AXIS_Y, cullFace=True, cornerRadius=0.05, pos=positionR) if (flagR == 1): if (temp_stepLengthRight > 0): stepLengthRight.append(temp_stepLengthRight) flagR = 0 stepLengthRight.sort(reverse=True) max_stepLengthRight = stepLengthRight[:100] print stepLengthRight filepath2 = 'C:\\Users\\User\\Documents\\Chang\\RightStepLength' + filename f1 = open(filepath2, 'w') json.dump(stepLengthRight, f1) f1.close() # f_testR = open('C:\Users\User\Documents\Natalia\QTM\RightStepLengthtest.txt','w') # for item in max_stepLengthRight: # f_testR.write("%s\n" % item) # mean_stepLengthRight = float(sum(max_stepLengthRight)) / len(max_stepLengthRight) # f3 = open('C:\Users\User\Documents\Natalia\QTM\Right_MeanStepLength.txt','w') # json.dump(mean_stepLengthRight,f3) # f3.close() else: # --> leg is in swing phase, track ankle location markerR = vizshape.addQuad(size=(length, width), axis=-vizshape.AXIS_Y, cullFace=False, cornerRadius=0.05, pos=positionR) fadeOut = vizact.fadeTo(0, time=.05) markerR.addAction(fadeOut) temp_stepLengthRight = positionR[0] - positionL[0] flagR = 1
def StepLength(filename, stepLengthLeft, stepLengthRight, COP_L, COP_R, width=0.05, length=0.05): global flagL, flagR analog = qualisys.getAnalog(0) #print "analog", analog ForcePlates = analog.getData() # [Zero, Fx1, Fy1, ..., My2, Mz2] #print "ForcePlates", ForcePlates # calibration/offset factors // QTM options > Force Data > Calibration Fcal = (500, 500, 1000, 800, 400, 400 ) # Fx,Fy,Fz,Mx,My,Mz // Calibration Matrix Xoff = 0.2795 # X offset (for right force plate, invert to be -0.2795) Yoff = 0.889 h = 0 # Zoff = h # left force plate COP_L = [0, 0] FxL = ForcePlates[1] * Fcal[0] FyL = ForcePlates[2] * Fcal[1] GRFL = ForcePlates[3] * Fcal[2] MxL = ForcePlates[4] * Fcal[3] MyL = ForcePlates[5] * Fcal[4] # right force plate COP_R = [0, 0] FxR = ForcePlates[8] * Fcal[0] FyR = ForcePlates[9] * Fcal[1] GRFR = ForcePlates[10] * Fcal[2] MxR = ForcePlates[11] * Fcal[3] MyR = ForcePlates[12] * Fcal[4] # LEFT LEG if (200 < GRFL < 2000): # stance phase...# Does it need to change if (flagL == 1): # swing phase flag flagL = 0 # not swing phase anymore # COP calculation // constants added to change coordinate system from Plate to LAB # [+Xlab, +Ylab] = [+Yplate + 0.8162, +Xplate + 0.7798] COP_L = [(-Yoff + (((-h * FyL) + MxL) / GRFL) + 0.8162), (Xoff + (((-h * FxL) - MyL) / GRFL) + 0.7798)] COP_R = [(-Yoff + (((-h * FyR) + MxR) / GRFR) + 0.8154), (-Xoff + (((-h * FxR) - MyR) / GRFR) + 0.2124)] SL_L = COP_L[0] - COP_R[0] #left step length markerL = vizshape.addQuad(size=(length, width), axis=-vizshape.AXIS_Y, cullFace=False, cornerRadius=0.05, pos=[SL_L, 0.15, 0.7]) fadeOut = vizact.fadeTo(0, time=0.7) markerL.addAction(fadeOut) #print "COP_L x", COP_L[0], "COP_R x", COP_R[0] print "step length", SL_L stepLengthLeft.append(SL_L) # step length list #stepLengthLeft.sort(reverse = True) # greatest first #print "stepLengthLeft", stepLengthLeft #should not overlap with the previous trial filepath = 'C:\\Users\\User\\Documents\\Chang\\LeftStepLength' + filename f = open(filepath, 'w') json.dump(stepLengthLeft, f) f.close() elif (GRFL <= 100): # swing phase... flagL = 1 # RIGHT LEG if (200 < GRFR < 2000): # stance phase... if (flagR == 1): # swing phase flag flagR = 0 # not swing phase anymore # COP calculation // constants added to change coordinate system from Plate to LAB # [+Xlab, +Ylab] = [+Yplate + 0.8154, +Xplate + 0.2124] COP_R = [(-Yoff + (((-h * FyR) + MxR) / GRFR) + 0.8154), (-Xoff + (((-h * FxR) - MyR) / GRFR) + 0.2124)] COP_L = [(-Yoff + (((-h * FyL) + MxL) / GRFL) + 0.8162), (Xoff + (((-h * FxL) - MyL) / GRFL) + 0.7798)] SL_R = COP_R[0] - COP_L[0] #right step length markerR = vizshape.addQuad(size=(length, width), axis=-vizshape.AXIS_Y, cullFace=False, cornerRadius=0.05, pos=[SL_R, 0.15, 0.3]) fadeOut = vizact.fadeTo(0, time=0.7) markerR.addAction(fadeOut) #print "COP_R x", COP_R[0], "COP_L x", COP_L[0] print "step length", SL_R stepLengthRight.append(SL_R) # step length list #stepLengthRight.sort(reverse = True) # greatest first print "stepLengthRight", stepLengthRight filepath2 = 'C:\\Users\\User\\Documents\\Chang\\RightStepLength' + filename f1 = open(filepath2, 'w') json.dump(stepLengthRight, f1) f1.close() elif (GRFR <= 100): # swing phase... flagR = 1
import viz import vizshape viz.go(viz.FULLSCREEN) #h = vizshape.addSphere(0.125,20,20) h = vizshape.addQuad(size=[1, 1]) h.setParent(viz.SCREEN) h.setPosition(0.5, 0.5, 0) #h = viz.addChild('ball.wrl') #h = viz.addChild('hidesphere.wrl',scale=[0.1,0.1,0.1]) h.color(1, 1, 1) h.disable(viz.LIGHTING) viz.MainView.setPosition(0, 0, -1)
Laptop.setEuler([-10, 0, 0]) avatar = viz.addAvatar('vcc_male2.cfg', pos=[-5.7, -5.2, 0]) avatar.state(1) sofa = viz.addChild('F:\Objects\max\obj2.ive') sofa.setScale([.030, .030, .030]) sofa.setPosition([-9.2, 0.15, -0]) sofa.setEuler([-90, 0, 0]) #stand=viz.addChild('F:\Objects\max\obj1.ive') #stand.setScale([.00030,.00030,.00030]) #stand.setPosition([-0,0.15,-0]) #stand.setEuler([0,0,0]) shadow_texture = viz.addTexture('shadow.png') shadow = vizshape.addQuad(parent=avatar, axis=vizshape.AXIS_Y) shadow.texture(shadow_texture) shadow.zoffset() avatarMove = [[-5.7, -5.2, 300], [-5.7, 6.5, 270], [0, 8, 0], [5.7, 6.5, 70], [5.7, 2.6, 70], [5.7, 1, 130]] actions = [] RandomWait = vizact.waittime(vizact.randfloat(0, 0)) for loc in avatarMove: if loc == avatarMove[2]: RandomWait = vizact.waittime(vizact.randfloat(5, 10)) else: RandomWait = vizact.waittime(vizact.randfloat(0, 0)) actions.append(vizact.method.playsound('footsteps.wav', viz.LOOP))
walkway = viz.addChild('ground.osgb',scale = [0.0167,1,walkdistance]) walkway.setPosition(0,0,(walkdistance*50)/2)#start at one end of the walkway sky = viz.addChild('sky_day.osgb') grass1 = viz.addChild('ground_grass.osgb') grass1.setPosition(0,-0.01,0) grass2 = viz.addChild('ground_grass.osgb') grass2.setPosition(0,-0.01,50) grass3 = viz.addChild('ground_grass.osgb') grass3.setPosition(0,-0.01,50) #create a divider line global divider divider = vizshape.addQuad(size=(0.01,walkdistance*50), axis=-vizshape.AXIS_Y, cullFace=False, cornerRadius=0) divider.setPosition(0,0.001,(walkdistance*50)/2) divider.color(255,255,255) #make the Right targets rt = {} for x in range(1,int((walkdistance*50)/(targetSL*2)),1): # rt["T{0}".format(x)]=vizshape.addQuad((0.1,targettol),axis=-vizshape.AXIS_Y,cullFace=False,cornerRadius=0) rt["T{0}".format(x)]=vizshape.addBox(size=[0.25,0.02,2*targettol]) rt["T{0}".format(x)].setPosition(0.2,0.011,x*2*targetSL) rt["T{0}".format(x)].color(0,0,0) lt = {} for x in range(1,int((walkdistance*50)/(targetSL*2)),1): # rt["T{0}".format(x)]=vizshape.addQuad((0.1,targettol),axis=-vizshape.AXIS_Y,cullFace=False,cornerRadius=0)
def StepLength(COP_L, COP_R, width=0.05, length=0.05): global flagL, flagR, SL_Left, SL_Right, sd_Left, sd_Right, successL_count, successR_count, start_L, start_R # offset factors // QTM options > Force Data > Calibration Xoff = 0.2795 # X offset (for right force plate, invert to be -0.2795) Yoff = 0.889 h = 0 # Zoff = h FPtemp = qtm_receive() # force plate data # left force plate COP_L = [0,0] FxL = FPtemp[0] FyL = FPtemp[1] GRFL = FPtemp[2] MxL = FPtemp[3] MyL = FPtemp[4] # right force plate COP_R = [0,0] FxR = FPtemp[6] FyR = FPtemp[7] GRFR = FPtemp[8] MxR = FPtemp[9] MyR = FPtemp[10] # LEFT LEG if ( 80<GRFL<2000 ): # stance phase... if (flagL == 1): # swing phase flag flagL = 0 # not swing phase anymore start_L.append(time.clock()) #want to time btw heel strike # print start_L # COP calculation // constants added to change coordinate system from Plate to LAB # [+Xlab, +Ylab] = [+Yplate + 0.8162, +Xplate + 0.7798] COP_L = [ (-Yoff + (((-h*FyL)+MxL)/GRFL) + 0.8162) , (Xoff + (((-h*FxL)-MyL)/GRFL) + 0.7798) ] COP_R = [ (-Yoff + (((-h*FyR)+MxR)/GRFR) + 0.8154) ,(-Xoff + (((-h*FxR)-MyR)/GRFR) + 0.2124) ] SL_L = COP_L[0]-COP_R[0] #left step length markerL = vizshape.addQuad(size=(length, width),axis= -vizshape.AXIS_Y,cullFace=False,cornerRadius=0.05,pos=[SL_L,0.02,0.7]) fadeOut = vizact.fadeTo(0,time=0.7) markerL.addAction(fadeOut) # stepLengthLeft.append(SL_L) # step length list #stepLengthLeft.sort(reverse = True) # greatest first # print "stepLengthLeft", stepLengthLeft # should not overlap with the previous trial # filepath='C:\\Users\\User\\Documents\\Chang\\LeftStepLength'+test_no+filename # f = open(filepath,'w') # json.dump(stepLengthLeft,f) # f.close() #print "COP_L x", COP_L[0], "COP_R x", COP_R[0] #print "left step length", SL_L # if abs(SL_L-SL_Left) <= (2*sd_Left + 0.01): # success message # successL = viz.addText('Success!', parent=viz.SCREEN, scene = viz.MainScene, color=viz.GREEN, fontSize=80, pos=[0.2,0.05,0]) # fadeOut4 = vizact.fadeTo(0,time=0.5) # successL.addAction(fadeOut4) # # successL_count += 1 ## f = open('C:\Users\User\Documents\Chang\save_successL_count.txt','w') ## json.dump(successL_count,f) ## f.close() # # print "successL_count", successL_count ## time.sleep(0.15) elif ( GRFL<=80 ): # swing phase... flagL = 1 # RIGHT LEG if ( 80<GRFR<2000 ): # stance phase... if (flagR == 1): # swing phase flag flagR = 0 # not swing phase anymore start_R.append(time.clock()) # print "startR",start_R # COP calculation // constants added to change coordinate system from Plate to LAB # [+Xlab, +Ylab] = [+Yplate + 0.8154, +Xplate + 0.2124] COP_R = [ (-Yoff + (((-h*FyR)+MxR)/GRFR) + 0.8154) ,(-Xoff + (((-h*FxR)-MyR)/GRFR) + 0.2124) ] COP_L = [ (-Yoff + (((-h*FyL)+MxL)/GRFL) + 0.8162) , (Xoff + (((-h*FxL)-MyL)/GRFL) + 0.7798) ] SL_R = COP_R[0]-COP_L[0] #right step length markerR = vizshape.addQuad(size=(length, width),axis= -vizshape.AXIS_Y,cullFace=False,cornerRadius=0.05,pos=[SL_R,0.02,0.3]) fadeOut = vizact.fadeTo(0,time=0.7) markerR.addAction(fadeOut) # stepLengthRight.append(SL_R) # step length list #stepLengthRight.sort(reverse = True) # greatest first # print "stepLengthRight", stepLengthRight # filepath2='C:\\Users\\User\\Documents\\Chang\\RightStepLength'+test_no+filename # f1 = open(filepath2,'w') # json.dump(stepLengthRight,f1) # f1.close() #print "COP_R x", COP_R[0], "COP_L x", COP_L[0] #print "right step length", SL_R # if abs(SL_R-SL_Right) <= (2*sd_Right + 0.01): # success message # successR = viz.addText('Success!', parent=viz.SCREEN, scene = viz.MainScene, color=viz.BLUE, fontSize=80, pos=[0.55,0.05,0]) # fadeOut5 = vizact.fadeTo(0,time=0.5) # successR.addAction(fadeOut5) # # successR_count += 1 ## f = open('C:\Users\User\Documents\Chang\save_successR_count.txt','w') ## json.dump(successR_count,f) ## f.close() # print "successR_count", successR_count # time.sleep(0.15) elif ( GRFR<=80 ): # swing phase... flagR = 1
def AnkleTracking(flagL, flagR, LeftAnkle, RightAnkle, LeftGTO, RightGTO, ankleHeightL, ankleHeightR, successL_count, successR_count): global start_L, start_R, scoreText_L, scoreText_R # Show steps # Text_3d.message('{}'.format(numsteps)) # fadeOut4 = vizact.fadeTo(0,time=0.5) # Text_3d.addAction(fadeOut4) positionL = qualisys.getMarker(LeftAnkle).getPosition() #print positionL positionR = qualisys.getMarker(RightAnkle).getPosition() #print positionR analog = qualisys.getAnalog(0) #print analog ForcePlates = analog.getData() #print ForcePlates calibrationFz = 1000 # 3,3 value in Bertec calibation matrix GRFL = ForcePlates[3] * calibrationFz GRFR = ForcePlates[10] * calibrationFz #print "Left", GRFL #print "Right", GRFR positionL_Hip = qualisys.getMarker(LeftGTO).getPosition() positionR_Hip = qualisys.getMarker(RightGTO).getPosition() temp_stepLengthLeft = positionL[0] - positionR[0] temp_stepLengthRight = positionR[0] - positionL[0] # LEFT LEG if (50 < GRFL < 2000): # --> leg is in stance phase, hide ankle location markerposL = positionL[0] - positionR[0] markerL = vizshape.addQuad(size=(0.05, 0.05), axis=-vizshape.AXIS_Y, cullFace=True, cornerRadius=0.05, pos=(markerposL, positionL[1], positionL[2])) ankleHeightL = positionL[1] fadeOut = vizact.fadeTo(0, time=0.00) markerL.addAction(fadeOut) if (flagL == 1): if (temp_stepLengthLeft > 0): flagL = 0 if (abs(markerposL - median_stepLengthLeft) < 8 * sd_Left + 0.01) & (scoreText_L == True): # if (positionL[1] < ankleHeightL and # abs (positionL[2] - positionL_Hip[2] ) < 0.05): # successL_score = int( round(10 - 10 * abs(1 - (markerposL / SL_Left)))) # save_successL_count.append(successL_score) # print total_successR_count # f = open('C:\Users\User\Documents\Natalia\QTM\save_successL_count.txt','w') # json.dump(save_successL_count,f) # f.close() print successL_score Text_3d.message('{}'.format(successL_score)) # fadeOut = vizact.fadeTo(0,time=0.2) scoreText_L = False ##################################################### ###### ADJUST BASED ON TM SPEED, FOR SPEED>0.5 USE ~.5 ##### FOR SPEED < 0.5 USE ~.7 ####################### ##################################################### # time.sleep(.15) elif (GRFL < 50): # --> leg is in swing phase, track ankle location markerposL = positionL[0] - positionR[0] markerL = vizshape.addQuad(size=(0.05, 0.05), axis=-vizshape.AXIS_Y, cullFace=False, cornerRadius=0.05, pos=(markerposL, positionL[1], positionL[2])) fadeOut = vizact.fadeTo(0, time=0.00) markerL.addAction(fadeOut) temp_stepLengthLeft = positionL[0] - positionR[0] flagL = 1 scoreText_L = True # RIGHT LEG if (50 < GRFR < 2000): # --> leg is in stance phase, hide ankle location markerposR = positionR[0] - positionL[0] markerR = vizshape.addQuad(size=(0.05, 0.05), axis=-vizshape.AXIS_Y, cullFace=True, cornerRadius=0.05, pos=(markerposR, positionR[1], positionR[2])) ankleHeightR = positionR[1] fadeOut = vizact.fadeTo(0, time=0.00) markerR.addAction(fadeOut) if (flagR == 1): if (temp_stepLengthRight > 0): flagR = 0 start_R.append(time.clock()) if (abs(median_stepLengthRight - markerposR) < 8 * sd_Right + 0.01) & (scoreText_R == True): # if (positionR[1] < ankleHeightR and # abs (positionR[2] - positionR_Hip[2] ) < 0.05): # successR_score = int( round(10 - 10 * abs(1 - (markerposR / SL_Right)))) save_successR_count.append(successR_score) # print total_successR_count # f = open('C:\Users\User\Documents\Natalia\QTM\save_successR_count.txt','w') # json.dump(save_successR_count,f) # f.close() Text_3d_right.message('{}'.format(successR_score)) # ##################################################### ###### ADJUST BASED ON TM SPEED, FOR SPEED>0.5 USE ~.5 ##### FOR SPEED < 0.5 USE ~.7 ####################### ##################################################### scoreText_R = False elif (GRFR < 50): # --> leg is in swing phase, track ankle location markerposR = positionR[0] - positionL[0] markerR = vizshape.addQuad(size=(0.05, 0.05), axis=-vizshape.AXIS_Y, cullFace=False, cornerRadius=0.05, pos=(markerposR, positionR[1], positionR[2])) fadeOut = vizact.fadeTo(0, time=0.00) markerR.addAction(fadeOut) flagR = 1 scoreText_R = True
Laptop.setEuler([-10,0,0]) avatar = viz.addAvatar('vcc_male2.cfg',pos=[-5.7,-5.2,0]) avatar.state(1) sofa=viz.addChild('F:\Objects\max\obj2.ive') sofa.setScale([.030,.030,.030]) sofa.setPosition([-9.2,0.15,-0]) sofa.setEuler([-90,0,0]) #stand=viz.addChild('F:\Objects\max\obj1.ive') #stand.setScale([.00030,.00030,.00030]) #stand.setPosition([-0,0.15,-0]) #stand.setEuler([0,0,0]) shadow_texture = viz.addTexture('shadow.png') shadow = vizshape.addQuad(parent=avatar,axis=vizshape.AXIS_Y) shadow.texture(shadow_texture) shadow.zoffset() avatarMove = [[-5.7,-5.2,300],[-5.7,6.5,270],[0,8,0],[5.7,6.5,70],[5.7,2.6,70],[5.7,1,130]] actions = [] RandomWait = vizact.waittime(vizact.randfloat(0,0)) for loc in avatarMove: if loc == avatarMove[2]: RandomWait = vizact.waittime(vizact.randfloat(5,10)) else: RandomWait = vizact.waittime(vizact.randfloat(0,0)) actions.append(vizact.method.playsound('footsteps.wav',viz.LOOP)) actions.append(vizact.walkTo([loc[0],0,loc[1]],turnSpeed=250.0))
viz.vertexColor(0, 1, 0) viz.vertex(6.4, 0, 18.9) viz.vertex(-6.4, 0, 18.9) viz.vertex(0, 3.6, 18.9) viz.vertex(0, -3.6, 18.9) gridLines = viz.endLayer() squares = {} fbsquares = {} for i in range(len(position)): if i <= 11 and i != 10: squares['square' + str(i)] = vizshape.addBox(size=(size, size, 0.01), splitFaces=False, pos=position[str(i)]) fbsquares['fbsquare' + str(i)] = vizshape.addQuad(size=(size + 0.1, size + 0.1), pos=position[str(i)], color=(0, 0, 0)) else: squares['square' + str(i)] = vizshape.addBox(size=(keepsize, keepsize, 0.01), splitFaces=False, pos=position[str(i)]) fbsquares['fbsquare' + str(i)] = vizshape.addQuad( size=(keepsize + 0.1, keepsize + 0.1), pos=position[str(i)], color=(1, 0, 0)) texts = {} #Set text showing on the squares for i in range(len(position)): if i <= 11 and i != 10: