コード例 #1
0
ファイル: MainGui.py プロジェクト: ginking/multC_tester
 def tellWhichFpga(self, xemNum, chanName, newWireIn):
     ctrl = self.ch_all[chanName] # Handle of the Tester channel
     ctrl.currValue = newWireIn
     if (ctrl.type == 'int32'):
         bitVal = convertType(floor(newWireIn),  fromType = 'i',  toType = 'I')
     elif (ctrl.type == 'float32'):
         bitVal = convertType(newWireIn, fromType = 'f', toType = 'I')
     bitVal2 = convertType(0.0, fromType = 'f', toType = 'I') # velocity
     self.nerfModel[xemNum].SendMultiPara(bitVal1 = bitVal, bitVal2=bitVal2,  trigEvent = ctrl.id)
コード例 #2
0
 def runExp(self):
     k = PyKeyboard()
     # Resetting both gammas
     k.type_string('s')
     k.type_string('d')
     
     for i in xrange(self.SWEEP_STEP_SIZE):           
         if (self.running):
             # Resetting gammaSta
             k.type_string('s')
             
             for j in xrange(self.SWEEP_STEP_SIZE):           
                 if (self.running):
                     self.currTrial = i*self.SWEEP_STEP_SIZE + j + 1
                 
                     # Reset and cool-down
                     for nagging in xrange(5):
                         k.type_string('0')
                         sleep(0.3)
                 
                     self.strong_damper.damping = 0.0     
                     
                     
                     # Perturbation
                     k.type_string('j')
                     sleep(3)
                     
                     
                     # Increasing gammaSta
                     k.type_string('w')
                     sleep(1.0)
                     
                     
                     # Add a strong damper to stop any motion
                     self.strong_damper.damping = 100.0
                     
                     # attmept to remove the residual torque.
                     bitVal = convertType(0.0, fromType = 'f', toType = 'I')
                     xem_spindle_bic.SendPara(bitVal = bitVal, trigEvent = 1) # Ia gain
                     xem_spindle_tri.SendPara(bitVal = bitVal, trigEvent = 1) 
                     xem_spindle_bic.SendPara(bitVal = bitVal, trigEvent = 10) # II gain
                     xem_spindle_tri.SendPara(bitVal = bitVal, trigEvent = 10) 
                     sleep(2.0)
                     bitVal = convertType(1.2, fromType = 'f', toType = 'I')
                     xem_spindle_bic.SendPara(bitVal = bitVal, trigEvent = 1) # Ia gain
                     xem_spindle_tri.SendPara(bitVal = bitVal, trigEvent = 1)
                     bitVal_II = convertType(2.0, fromType = 'f', toType = 'I') 
                     xem_spindle_bic.SendPara(bitVal = bitVal_II, trigEvent = 10) # II gain
                     xem_spindle_tri.SendPara(bitVal = bitVal_II, trigEvent = 10) 
             
             # Increasing gammaDyn
             k.type_string('e')
                     
     k.tap_key(k.escape_key)
コード例 #3
0
ファイル: MainGui.py プロジェクト: ginking/multC_tester
 def tellWhichFpga(self, xemNum, chanName, newWireIn):
     ctrl = self.ch_all[chanName]  # Handle of the Tester channel
     ctrl.currValue = newWireIn
     if (ctrl.type == 'int32'):
         bitVal = convertType(floor(newWireIn), fromType='i', toType='I')
     elif (ctrl.type == 'float32'):
         bitVal = convertType(newWireIn, fromType='f', toType='I')
     bitVal2 = convertType(0.0, fromType='f', toType='I')  # velocity
     self.nerfModel[xemNum].SendMultiPara(bitVal1=bitVal,
                                          bitVal2=bitVal2,
                                          trigEvent=ctrl.id)
コード例 #4
0
    def on_checkBox_2_clicked(self, checked):
        """
        Slot documentation goes here.
        """
        if (checked):
#            bitVal1 = convertType(400.0, fromType = 'f', toType = 'I')
#            bitVal2 = convertType(100.0, fromType = 'f', toType = 'I')
            # TODO: not implemented yet
            self.xemList[0].SendPara(bitVal = 1000, trigEvent = 8)
            self.xemList[1].SendPara(bitVal = 5000, trigEvent = 8)
            print self.xemList[0],  self.xemList[1]

        
        else:
            bitVal = convertType(0.0, fromType = 'f', toType = 'I')

            # TODO: not implemented yet
            self.xemList[0].SendPara(bitVal = bitVal, trigEvent = 8)
            self.xemList[1].SendPara(bitVal = bitVal, trigEvent = 8)
コード例 #5
0
ファイル: MVC_MainGUI.py プロジェクト: ginking/multC_tester
    def on_checkBox_2_clicked(self, checked):
        """
        Slot documentation goes here.
        """
        if (checked):
#            bitVal1 = convertType(400.0, fromType = 'f', toType = 'I')
#            bitVal2 = convertType(100.0, fromType = 'f', toType = 'I')
            # TODO: not implemented yet
            self.xemList[0].SendPara(bitVal = 1000, trigEvent = 8)
            self.xemList[1].SendPara(bitVal = 5000, trigEvent = 8)
            print self.xemList[0],  self.xemList[1]

        
        else:
            bitVal = convertType(0.0, fromType = 'f', toType = 'I')

            # TODO: not implemented yet
            self.xemList[0].SendPara(bitVal = bitVal, trigEvent = 8)
            self.xemList[1].SendPara(bitVal = bitVal, trigEvent = 8)
コード例 #6
0
    def controlLoopTriceps(self):
        
        while self.running:

            """   Get forces   """
#            force_bic_pre = max(0.0, xem_muscle_bic.ReadFPGA(0x32, "float32")) / 128 #- 0.2
#            emg_bic = xem_muscle_bic.ReadFPGA(0x20, "float32")  # EMG         
            self.spikecnt_tri = xem_muscle_tri.ReadFPGA(0x30, "int32")  
            force_tri_pre = max(0.0, xem_muscle_tri.ReadFPGA(0x32, "float32")) / 128 #- 2.64
            force_tri_pre = force_tri_pre * 1.0 # force adjustment for quick reflex return
            self.emg_tri = xem_muscle_tri.ReadFPGA(0x20, "float32")  # EMG
            self.timeref_tri = xem_spindle_tri.ReadFPGA(0x28, "float32")  # 
            
#            force_bic = force_bic_pre #+ pipeInData_bic[j]
            self.force_tri = force_tri_pre *self.torqueMultiplier #+ pipeInData_bic[j] 
            """  force curve (f-input spikes) saturation effect"""
#            self.force_tri = self.force_tri * (1-exp(-self.force_tri/self.fmax)) 
              
            """ extra data for close loop data acquisition"""  
#            Ia_afferent = xem_spindle_tri.ReadFPGA(0x22, "float32")  # EMG 
#            II_afferent = xem_spindle_tri.ReadFPGA(0x24, "float32")  # EMG    
#            MN1_spikes = xem_muscle_tri.ReadFPGA(0x22, "spike32")  #             
#            MN2_spikes = xem_muscle_tri.ReadFPGA(0x24, "spike32")  #             
#            MN3_spikes = xem_muscle_tri.ReadFPGA(0x26, "spike32")  #             
#            MN4_spikes = xem_muscle_tri.ReadFPGA(0x28, "spike32")  #             
#            MN5_spikes = xem_muscle_tri.ReadFPGA(0x2A, "spike32")  #             
#            MN6_spikes = xem_muscle_tri.ReadFPGA(0x2C, "spike32")  # 
###            
            
#            self.gForearm_body.torque = (self.force_bic - self.force_tri) * 0.06
            
            #lce = 1.0
                                 
            #angle = ((self.gForearm_body.angle + M_PI) % (2*M_PI)) - M_PI - self.gRest_joint_angle
            
            
            self.lce_tri = self.angle2length(self.angle)+ 0.02
#            self.lce_bic = 2.04 - self.lce_tri 
            
            # Send lce of biceps 
            bitVal = convertType(self.lce_bic, fromType = 'f', toType = 'I')
    #        bitVal2 = convertType(0.0,  fromType = 'f', toType = 'I')
    #        bitVal3 = convertType(sineBic[j],  fromType = 'I', toType = 'I')
            #try M1_extra - 200000
    #        xem_muscle_bic.SendMultiPara_TEMP(bitVal1 = bitVal, bitVal2 = 200000,  bitVal3 = bitVal3, trigEvent = 9) # bitVal2: extraCN1, bitVal: extraCN2 is int type
    #        xem_muscle_bic.SendPara(bitVal = bitVal, trigEvent = 9)
#            self.angularV = self.gForearm_body.angular_velocity

#            self.linearV = self.angular2LinearV(angularV)
    #        print linearV
#            self.scale = 500.0
#            bitVal_bic_i = convertType(-linearV*scale, fromType = 'f', toType = 'I')
            bitVal_tri_i = convertType(self.linearV*self.scale, fromType = 'f', toType = 'I')
            
#            xem_muscle_bic.SendMultiPara(bitVal1 = bitVal, bitVal2 = bitVal_bic_i,  trigEvent = 9)
#            xem_spindle_bic.SendPara(bitVal = bitVal, trigEvent = 9)
            
            """ Alpha-gamma coactivation """
#            ag_coact, ag_bias = 30.0, 50.0
#            gd_tri = force_tri * ag_coact + ag_bias
#            bitval = convertType(gd_tri, fromType = 'f', toType = 'I')
#            xem_spindle_tri.SendPara(bitVal = bitval,  trigEvent = 4) # 4 = Gamma_dyn
#            xem_spindle_tri.SendPara(bitVal = bitval,  trigEvent = 5) # 4 = Gamma_sta
            
            """ Send lce of triceps """
            bitVal = convertType(self.lce_tri, fromType = 'f', toType = 'I')
    #        bitVal2 = convertType(1.0,  fromType = 'f', toType = 'I')
        
    #        bitVal3 = convertType(sineTri[j],  fromType = 'I', toType = 'I')
    #        xem_muscle_tri.SendMultiPara_TEMP(bitVal1 = bitVal, bitVal2 = 200000,  bitVal3=bitVal3,  trigEvent = 9)  # bitVal2: extraCN1, bitVal: extraCN2 is int type
    #        xem_muscle_tri.SendPara(bitVal = bitVal, trigEvent = 9)
            xem_muscle_tri.SendMultiPara(bitVal1 = bitVal, bitVal2= bitVal_tri_i,   trigEvent = 9)
            xem_spindle_tri.SendPara(bitVal = bitVal, trigEvent = 9)

            """ Alpha-gamma coactivation """
    #        gd_tri = force_tri * ag_coact + ag_bias
    #        bitval = convertType(gd_tri, fromType = 'f', toType = 'I')
    #        xem_spindle_tri.SendPara(bitVal = bitval,  trigEvent = 4) # 4 = Gamma_dyn
            
    #        print "lce0 = %.2f :: lce1 = %.2f :: total_torque = %.2f" % (self.lce_bic, lce_tri, gForearm_body.torque),                           
    #        print "force0 = %.2f :: force1 = %.2f :: angle = %.2f :: gd_bic = %.2f :: angularV =%.2f" % (force_bic, force_tri,  angle,  gd_bic,  angularV )                          
            currentTime = time.time()
            self.elapsedTime_tri = currentTime- self.start_time
コード例 #7
0
    def controlLoopBiceps(self):
        
        while self.running:

            """   Get forces   """
            force_bic_pre = max(0.0, xem_muscle_bic.ReadFPGA(0x32, "float32")) / 128 #- 0.2
            #force_bic_pre = force_bic_pre * 1.0 # force adjustment for quick reflex return
            self.spikecnt_bic = xem_muscle_bic.ReadFPGA(0x30, "int32")  
            self.emg_bic = xem_muscle_bic.ReadFPGA(0x20, "float32")  # EMG 
            self.timeref_bic = xem_spindle_bic.ReadFPGA(0x28, "float32")  # 
            
            """ extra data for close loop data acquisition"""  
#            Ia_afferent = xem_spindle_bic.ReadFPGA(0x22, "float32")  # EMG 
#            II_afferent = xem_spindle_bic.ReadFPGA(0x24, "float32")  # EMG    
#            MN1_spikes = xem_muscle_bic.ReadFPGA(0x22, "spike32")  #             
#            MN2_spikes = xem_muscle_bic.ReadFPGA(0x24, "spike32")  #             
#            MN3_spikes = xem_muscle_bic.ReadFPGA(0x26, "spike32")  #             
#            MN4_spikes = xem_muscle_bic.ReadFPGA(0x28, "spike32")  #             
#            MN5_spikes = xem_muscle_bic.ReadFPGA(0x2A, "spike32")  #             
#            MN6_spikes = xem_muscle_bic.ReadFPGA(0x2C, "spike32")  # 
            
#            force_tri_pre = max(0.0, xem_muscle_tri.ReadFPGA(0x32, "float32")) / 128 #- 2.64
#            emg_tri = xem_muscle_tri.ReadFPGA(0x20, "float32")  # EMG
            
            self.force_bic = force_bic_pre*self.torqueMultiplier  #+ pipeInData_bic[j]
#            force_tri = force_tri_pre #+ pipeInData_bic[j] 
            """ overflow to opposite muscle test (helps to stabilize - eric)"""
#            temp_force_tri = self.force_tri
#            self.force_tri = self.force_tri + force_bic*0.3  # overflow to the opposite muscle
#            force_bic = force_bic + temp_force_tri*0.3       # overflow to the opposite muscle
            
                          

            """  force curve (f-input spikes) saturation effect"""
#            self.fmax =90.0
#            force_bic = force_bic * (1-exp(-force_bic/self.fmax)) 

    
#            self.force_bic = max(0, self.force_bic - self.force_tri * self.RATIO_RECIPROCAL_INHIBITION)
#            self.force_tri = max(0, self.force_tri - self.force_bic * self.RATIO_RECIPROCAL_INHIBITION)
            
            self.gForearm_body.torque = (self.force_bic - self.force_tri) * 0.02 #0.03 # was 0.06
                                            
            self.angle = ((self.gForearm_body.angle + M_PI) % (2*M_PI)) - M_PI - self.gRest_joint_angle
            
            
#            lce_tri = self.angle2length(angle)+ 0.02
            self.lce_bic = 2.04 - self.lce_tri 
            
            # Send lce of biceps 
            bitVal = convertType(self.lce_bic, fromType = 'f', toType = 'I')
    #        bitVal2 = convertType(0.0,  fromType = 'f', toType = 'I')
    #        bitVal3 = convertType(sineBic[j],  fromType = 'I', toType = 'I')
            #try M1_extra - 200000
    #        xem_muscle_bic.SendMultiPara_TEMP(bitVal1 = bitVal, bitVal2 = 200000,  bitVal3 = bitVal3, trigEvent = 9) # bitVal2: extraCN1, bitVal: extraCN2 is int type
    #        xem_muscle_bic.SendPara(bitVal = bitVal, trigEvent = 9)
            angularV = self.gForearm_body.angular_velocity

            self.linearV = self.angular2LinearV(angularV)
              
    
            
            
#            self.linearV = 0.0
    #        print linearV
            self.scale = 100.0 #15.0   # unstable when extra cortical signal is given, 30 is for doornik data collection
            
            #self.linearV = min(0, self.linearV ) # testing: only vel component in afferent active when lengthing 
            
            bitVal_bic_i = convertType(-self.linearV*self.scale, fromType = 'f', toType = 'I')
#            bitVal_tri_i = convertType(self.linearV*scale, fromType = 'f', toType = 'I')
            
            xem_muscle_bic.SendMultiPara(bitVal1 = bitVal, bitVal2 = bitVal_bic_i,  trigEvent = 9)
            xem_spindle_bic.SendPara(bitVal = bitVal, trigEvent = 9)
            """ udp sending """
            #self.sendUdp("%.4f" % self.emg_bic)
            
            
            """ Alpha-gamma coactivation """
#            ag_coact, ag_bias = 30.0, -70.0
#            ag_coact, ag_bias = 30.0, 50.0
#            gd_bic = force_bic * ag_coact + ag_bias
##            print gd_bic
#            bitval = convertType(gd_bic, fromType = 'f', toType = 'I')
#            xem_spindle_bic.SendPara(bitVal = bitval,  trigEvent = 4) # 4 = Gamma_dyn
#            xem_spindle_bic.SendPara(bitVal = bitval,  trigEvent = 5) # 4 = Gamma_sta
            
            """ Send lce of triceps """
#            bitVal = convertType(self.lce_tri, fromType = 'f', toType = 'I')
    #        bitVal2 = convertType(1.0,  fromType = 'f', toType = 'I')
        
    #        bitVal3 = convertType(sineTri[j],  fromType = 'I', toType = 'I')
    #        xem_muscle_tri.SendMultiPara_TEMP(bitVal1 = bitVal, bitVal2 = 200000,  bitVal3=bitVal3,  trigEvent = 9)  # bitVal2: extraCN1, bitVal: extraCN2 is int type
    #        xem_muscle_tri.SendPara(bitVal = bitVal, trigEvent = 9)
#            xem_muscle_tri.SendMultiPara(bitVal1 = bitVal, bitVal2= bitVal_tri_i,   trigEvent = 9)
#            xem_spindle_tri.SendPara(bitVal = bitVal, trigEvent = 9)
            
            """ Alpha-gamma coactivation """
    #        gd_tri = force_tri * ag_coact + ag_bias
    #        bitval = convertType(gd_tri, fromType = 'f', toType = 'I')
    #        xem_spindle_tri.SendPara(bitVal = bitval,  trigEvent = 4) # 4 = Gamma_dyn
            
            #print "lce0 = %.2f :: lce1 = %.2f :: total_torque = %.2f" % (self.lce_bic, self.lce_tri, self.gForearm_body.torque),                           
    #        print "force0 = %.2f :: force1 = %.2f :: angle = %.2f :: gd_bic = %.2f :: angularV =%.2f" % (force_bic, force_tri,  angle,  gd_bic,  angularV )                          
            currentTime = time.time()
            self.elapsedTime_bic = currentTime- self.start_time
コード例 #8
0
 def setGammaSta(self):
     bitVal = convertType(self.currGammaSta, fromType = 'f', toType = 'I')
     xem_spindle_bic.SendPara(bitVal = bitVal, trigEvent = 5) 
     xem_spindle_tri.SendPara(bitVal = bitVal, trigEvent = 5) 
コード例 #9
0
 def corticalGain(self, val):                    
    bitVal50 = convertType(val, fromType = 'f', toType = 'I')
    xem_muscle_bic.SendPara(bitVal = bitVal50, trigEvent = 10) 
    xem_muscle_tri.SendPara(bitVal = bitVal50, trigEvent = 10)
コード例 #10
0
 def tonicDrive(self, val):
     bitVal2 = convertType(val, fromType = 'f', toType = 'I')
     xem_cortical_tri.SendPara(bitVal = bitVal2, trigEvent = 8)