Ejemplo n.º 1
0
def getTorque():
    Gain = UL.BIP5VOLTS
    Chan = 0
    DataValue = UL.cbAIn(BoardNum, Chan, Gain)
    #return (UL.cbToEngUnits(BoardNum, Gain, DataValue))
    engUnits = UL.cbToEngUnits(BoardNum, Gain, DataValue)
    return (2.26*engUnits)
Ejemplo n.º 2
0
 def sampleTorque(self):
     Gain = UL.BIP5VOLTS
     Chan = 0
     try:
         DataValue = UL.cbAIn(self.BoardNum, Chan, Gain)
         engUnits = UL.cbToEngUnits(self.BoardNum, Gain, DataValue)
         self.Torque = 2.26 * engUnits  # - self.TorqueOffset;
     except:
         pass
Ejemplo n.º 3
0
 def sampleCurrent(self):
     Gain = UL.BIP5VOLTS
     Chan = 2
     try:
         DataValue = UL.cbAIn(self.BoardNum, Chan, Gain)
         engUnits = UL.cbToEngUnits(self.BoardNum, Gain, DataValue)
         self.Current = (engUnits) / .02 - self.CurrentOffset
     except:
         pass
Ejemplo n.º 4
0
 def sampleVoltage(self):
     Gain = UL.BIP5VOLTS
     Chan = 1
     try:
         DataValue = UL.cbAIn(self.BoardNum, Chan, Gain)
         engUnits = UL.cbToEngUnits(self.BoardNum, Gain, DataValue)
         self.Voltage = -1 * (
             (engUnits - 2.5) * 20.2030 - self.VoltageOffset)
     except:
         pass
 def startdisplayclicked(self):
     """Starts the data display"""
     #start functions and update handles
             
     self.stopdisplayclicked()  # Stop an existing timer
     if self.driftalert.isChecked():
         DataValue = UL.cbAIn(BoardNum, Chan, Gain)#raw input data for drift check
         initialValue = UL.cbToEngUnits(BoardNum, Gain, DataValue)#convert raw data to volts
     self._displayloop = self.startdisplayloop()   #start the display loop function
     self._timerId = self.startTimer(0)   # idle timer       
Ejemplo n.º 6
0
def get_some_data(npts):
#acquire from the board
    BoardNum=0
    Gain=ul.BIP5VOLTS
    Chan=0
    v=zeros(npts)
    for i in arange(npts):
        d=ul.cbAIn(BoardNum,Chan,Gain)
        v[i]=ul.cbToEngUnits(BoardNum,Gain,d)
    return v
def lick_detection_no_reward(SIDE):
    EngUnits = 0
    DataValue = 0
    if SIDE == 0:

        while ((EngUnits) * (EngUnits))**0.5 < 1.5:
            DataValue = UL.cbAIn(0, SIDE, UL.BIP5VOLTS)
            EngUnits = UL.cbToEngUnits(0, UL.BIP5VOLTS, DataValue)

        else:

            print 'nope'
def lick_detection(SIDE):
    EngUnits = 0
    DataValue = 0
    if SIDE == 0:

        while ((EngUnits) * (EngUnits))**0.5 < 1.55:
            DataValue = UL.cbAIn(0, SIDE, UL.BIP5VOLTS)
            EngUnits = UL.cbToEngUnits(0, UL.BIP5VOLTS, DataValue)

        else:

            get_reward(UL.FIRSTPORTA)
Ejemplo n.º 9
0
    def record_port(self, volt_interval=UL.BIP10VOLTS):
        """Reads the electrical voltage and transforms \
           the value with the scale factor and the offset.

        :param volt_interval: Interval of the electrical voltage of the machine
        :type volt_interval: int.
        :returns: The value of the machine
        :rtype: float
        """
        data = UL.cbAIn(self.board.id, self.id, volt_interval)
        volt = UL.cbToEngUnits(self.board.id, volt_interval, data)
        return self.scale_factor * volt + self.offset
Ejemplo n.º 10
0
def lick_detection(SIDE):
    EngUnits=0
    DataValue=0
    if SIDE==0:
        
        #threshold
        while ((EngUnits)*(EngUnits))**0.5<1.25:
            DataValue = UL.cbAIn(0, SIDE, UL.BIP5VOLTS)
            EngUnits = UL.cbToEngUnits(0, UL.BIP5VOLTS, DataValue)
            #print 1/(((EngUnits+1)*(EngUnits))**0.5)
          
        else: 
            print EngUnits+1
            print core.Clock()
            get_reward(UL.FIRSTPORTA)
Ejemplo n.º 11
0
def lick_detection(SIDE):
    EngUnits=0
    DataValue=0
    time.sleep(1.4)
    if SIDE==0:
        
        while ((EngUnits)*(EngUnits))**0.5<1.35:
            DataValue = UL.cbAIn(0, SIDE, UL.BIP5VOLTS)
            EngUnits = UL.cbToEngUnits(0, UL.BIP5VOLTS, DataValue)
            #print EngUnit
          
        else: 
            print EngUnits
            print core.Clock()
            get_reward(UL.FIRSTPORTA)
 def startdisplayloop(self):
     """Continuously updates graph and acquires data"""
     counter = 0 #runtime counter, counts number of iterations
     while 1:
         counter = counter + 1 #increment counter
         """DAQ Capture and storage"""
         DataValue = UL.cbAIn(BoardNum, Chan, Gain)#raw input data
         EngUnits = UL.cbToEngUnits(BoardNum, Gain, DataValue)#convert raw data to volts
         data.append( EngUnits )                 #DAQ at high frequency but not displayed
         times.append( time.time()-tstart )      #time stamps at high frequency but not displayed
         if(len(data)>10000): #10 second capture interval, upper bound = (capture frequency)*10
             data.pop(0)    #remove first data point in list
             times.pop(0)   #remove first time point in list
         """DAQ downsample and display"""
         if counter % 1000:                  #downsampling by (1/(modulo value)) for display
             smalldata.append( EngUnits )                 #add plotted data point
             smalltimes.append( time.time()-tstart )      #add plotted time point
             if(len(smalldata)>100):#len(data)/modulo value, defines number of points plotted
                 smalldata.pop(0)    #remove first plotted data point in the list
                 smalltimes.pop(0)   #remove first plotted time point in the list
                 if self.trapalert.isChecked():  #if checking for trapping is enabled
                     trapCheck = (np.mean(smalldata[10:50])-np.mean(smalldata[50:100]))     #calculate the difference between two averages
                     trapCheck = (trapCheck/np.mean(smalldata[10:15]))
                     if(trapCheck > 0.20): #put trapping threshold here
                         self.stopdisplayclicked()
                         self.sendemailalert()
                 if self.driftalert.isChecked(): #if the voltage has depreciated by 75%
                         if (np.mean(smalldata[10:100]) < (initialValue*0.60)):
                             self.stopdisplayclicked()
                             self.sendemailalert()                        
         # force an image redraw on every 3rd data capture
         if counter % 2000:                 #downsampled values are plotted as they are added
             self.displaywindow.canvas.ax.clear()  #clear plot
             self.displaywindow.canvas.ax.plot(smalltimes,smalldata,'g')  #plot downsampled values
             self.displaywindow.canvas.draw()    #force image redraw                
         """Delay and yield for proper capture frequency"""
         time.sleep(0.001)#1kHz  
         yield
Ejemplo n.º 13
0
    def startdisplayclicked(self):
        """Starts the data display"""
        #start functions and update handles                
        self.stopdisplayclicked()  # Stop an existing timer

        if self.driftalert.isChecked():
            DataValue = UL.cbAIn(BoardNum, Chan, Gain)#raw input data for drift check
            initialValue = UL.cbToEngUnits(BoardNum, Gain, DataValue)#convert raw data to volts
            QdriftThreshold = self.driftpercent.text()  #get text from UI
            SdriftThreshold = str(QdriftThreshold)  #convert to string
            driftThreshold = int(SdriftThreshold)   #convert to int
            driftThreshold = driftThreshold/100     #convert to percent
        if self.trapalert.isChecked():
            QtrapThreshold = self.trappercent.text()
            StrapThreshold = str(QtrapThreshold)
            trapThreshold = int(StrapThreshold)
            trapThreshold = trapThreshold/100
        Qsamplefrequency = self.frequencyinput.text()   #get sampling frequency from ui
        samplefrequency = int(Qsamplefrequency)        
        datalength = 10*samplefrequency                 #10 second storing interval
        
        self._displayloop = self.startdisplayloop(samplefrequency,datalength)   #start the display loop function
        self._timerId = self.startTimer(0)   # idle timer       
Ejemplo n.º 14
0
#     * Neither the name of the California Institute of Technology nor
#       the names of its contributors may be used to endorse or promote
#       products derived from this software without specific prior
#       written permission.

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# Author: Andrew Straw

import UniversalLibrary as UL

BoardNum = 0
Gain = UL.BIP5VOLTS
Chan = 0

while 1:
    DataValue = UL.cbAIn(BoardNum, Chan, Gain)
    EngUnits = UL.cbToEngUnits(BoardNum, Gain, DataValue)

    print DataValue, EngUnits

def lick_detection(SIDE):
    EngUnits = 0
    DataValue = 0
    if SIDE == 0:

        while ((EngUnits) * (EngUnits))**0.5 < 1.55:
            DataValue = UL.cbAIn(0, SIDE, UL.BIP5VOLTS)
            EngUnits = UL.cbToEngUnits(0, UL.BIP5VOLTS, DataValue)
            print((EngUnits) * (EngUnits))**0.5

        else:

            get_reward(UL.FIRSTPORTA)


a = np.zeros((1000, 1))
i = 0
for i in range(1000):
    DataValue = UL.cbAIn(0, 0, UL.BIP5VOLTS)
    EngUnits = UL.cbToEngUnits(0, UL.BIP5VOLTS, DataValue)
    a[i] = EngUnits
    i = i + 1

b = np.linspace(0, 999, 1000)
print 'mean ', np.mean(a)
print 'max ', np.max(a)
print 'min ', np.min(a)
plt.plot(b, a)
plt.show()