Ejemplo n.º 1
0
 def startdisplayloop(self,samplefrequency,datalength):
     """Continuously updates graph and acquires data"""
     rawdata = np.zeros(((samplefrequency//2)-1),np.int16)#set the number of samples acquired per scan, for display at 2Hz
     Options = UL.CONVERTDATA
     raw_mean = np.zeros(1,np.int16)
     
     while 1:
         ActualRate = UL.cbAInScan(0, 1, 1, ((samplefrequency//2)-1), samplefrequency, Gain, rawdata, Options)    #scan in data
         data.extend(rawdata)
         
         if len(data) > 10*samplefrequency:      #cap length of data at 10 seconds
             del data[0:((samplefrequency//2)-1)]
         smalldata.append(np.mean(rawdata))                  #add mean of scan to display data
         smalltimes.append( time.time()-tstart )     #add time points for display data
         if(len(smalldata)>20):
             smalldata.pop(0)
             smalltimes.pop(0)
             if self.trapalert.isChecked():  #if checking for trapping is enabled
                 trapCheck = (np.mean(smalldata[10:18])-np.mean(smalldata[2:10]))     #calculate the difference between two averages
                 trapCheck = (trapCheck/np.mean(smalldata[2:10]))
                 if(trapCheck > trapThreshold): #trappingThreshold
                     self.stopdisplayclicked()
                     self.sendemailalert()
             if self.driftalert.isChecked(): #if the voltage has depreciated by 75%
                 if (np.mean(smalldata[1:18]) < (initialValue*driftThreshold)):
                     self.stopdisplayclicked()
                     self.sendemailalert()             
         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                 
         yield
Ejemplo n.º 2
0
 def Adquire(self, Ch = 0):
     RawData = numpy.zeros(self._NSamples, numpy.int16)
     OPTS = UL.DMAIO
     if self.Trigger <> 'Auto':
         OPTS = UL.DMAIO + UL.EXTTRIGGER
     if Ch not in([0,1]):
         Ch = 0
     trueRate = UL.cbAInScan(0, Ch, Ch, self._NSamples, self._Rate, self._Range, RawData, OPTS)
     rpp = {'10V':20.0, '2.5V':5.0, '0.5V':1.0}
     voltsOut = numpy.uint16(RawData) * rpp[self.Range] / 2**16 - rpp[self.Range]/2.0
     self.dT = 1.0/trueRate
     ts = numpy.arange(len(voltsOut))  * self.dT
     return ts, voltsOut
Ejemplo n.º 3
0
    def sampleAllFast(self):
        Count = 300
        Rate = 5000
        Gain = UL.BIP5VOLTS
        Options = UL.CONVERTDATA + UL.BACKGROUND + UL.SINGLEIO
        ADData = numpy.zeros((Count, ), dtype=numpy.int16)

        UL.cbAInScan(self.BoardNum, 0, 2, Count, Rate, Gain, ADData, Options)
        time.sleep(Count / Rate)

        torqueVolts = UL.cbToEngUnits(self.BoardNum, Gain,
                                      int(numpy.mean(ADData[0::3])))
        voltageVolts = UL.cbToEngUnits(self.BoardNum, Gain,
                                       int(numpy.mean(ADData[1::3])))
        currentVolts = UL.cbToEngUnits(self.BoardNum, Gain,
                                       int(numpy.mean(ADData[2::3])))
        print(torqueVolts, voltageVolts, currentVolts)

        self.Torque = 2.26 * torqueVolts - self.TorqueOffset
        self.Voltage = -1 * (
            (voltageVolts - 2.5) * 20.2030 - self.VoltageOffset)
        self.Current = (currentVolts) / .02 - self.CurrentOffset
Ejemplo n.º 4
0
    def startsweepdisplay(self,sweepfrequency):
        """Continuously updates graph and acquires data"""
        srawdata = np.zeros(((sweepfrequency//2)-1),np.int16)#set the number of samples acquired per scan, for display at 2Hz
        Options = UL.CONVERTDATA
        """Acquire data from the UI"""
        Qsweepmodulo = self.sweepmoduloinput.text()     #get sweep modulo value from UI
        sweepmodulo = int(Qsweepmodulo)       
        Qstarttemp = self.starttemp.text()              #get starting temperature
        sweepstarttemp = int(Qstarttemp)
        Qstoptemp = self.stoptemp.text()                #get ending temperature
        sweepstoptemp = int(Qstoptemp)
        
        
        """Set up serial port"""
        ser = serial.Serial(3)   #COM4, must be equal to what com port the UT232R shows up as 
        ser.baudrate = 9600      #Baud rate must match laser controller
        ser.bytesize = serial.EIGHTBITS     #specific to RS-232 setup
        ser.parity = serial.PARITY_NONE     #specific to RS-232 setup
        ser.stopbits = serial.STOPBITS_ONE  #specific to RS-232 setup
        
        ser.write("TEC:T %d",sweepstoptemp) #set starting temperature
        numOfIterations = (10*sweepmodulo)*abs(sweepstarttemp-sweepstoptemp)  #calculate the number of steps needed
        
        counter = 0 #counter for modulo
        
        while counter < numOfIterations:
            """DAQ Capture and storage"""
            ActualRate = UL.cbAInScan(0, 1, 1, ((sweepfrequency//2)-1), sweepfrequency, Gain, srawdata, Options)    #scan in data            
            sweepdata.extend(srawdata)
            
            sweepsmalldata.append(np.mean(srawdata))                 #add plotted data point
            sweepsmalltimes.append( time.time()-tstart )      #add plotted time point                
            # force an image redraw canvas

            self.sweepwindow.canvas.ax.clear()  #clear plot
            self.sweepwindow.canvas.ax.plot(sweepsmalltimes,sweepsmalldata,'g')  #plot downsampled values
            self.sweepwindow.canvas.draw()    #force image redraw                
            """Delay and yield for user input"""
            if (counter%sweepmodulo) == 0:  #only happens when 
                ser.write("TEC:INC")        #increment TEC temperature
                
            counter = counter + 1
            yield        
Ejemplo n.º 5
0
# 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
import numpy

BoardNum = 0
UDStat = 0
Gain = UL.BIP5VOLTS

LowChan = 0
HighChan = 0

Count = 20
Rate = 3125

Options = UL.CONVERTDATA + UL.BACKGROUND + UL.SINGLEIO
ADData = numpy.zeros((Count,), dtype=numpy.int16)
print "a"
Rate = UL.cbAInScan(BoardNum, LowChan, HighChan, Count, Rate, Gain, ADData, Options)

Status = UL.RUNNING
while Status == UL.RUNNING:
    print "b"
    Status, CurCount, CurIndex = cbGetStatus(BoardNum, Status, CurCount, CurIndex, UL.AIFUNCTION)
Ejemplo n.º 6
0
#collect data in a loop until user asks to stop
nextSample=''
#nextSample=input('enter next sample name:\n')
nextSample=raw_input('enter next sample name:\n')
if nextSample=='x':
    cont=0
else:
    cont=1
    nextSample.replace(' ','_')
#%%
while cont==1:
    analogData=numpy.zeros((sampleNum,),dtype=numpy.int16)
    #actually collect the data
    print('starting data collection') 
    actualRate = UL.cbAInScan(boardNum, lowChan, highChan, sampleNum,
                              sampleRate, gain, analogData,Options)   
    print('data collection complete')
    voltData = numpy.asarray([ UL.cbToEngUnits(boardNum, gain, int(y)) for y in analogData])

    #take FFT
    #following matlab code to try and get scaling right--need to check
    complexFreqData=numpy.fft.fft(voltData)/sampleNum
    freqData=complexFreqData[:sampleNum/2+1]
    frequencies=actualRate*numpy.linspace(0,1,sampleNum/2+1)
    db=10*numpy.log10(2*numpy.abs(freqData))
    
    plt.figure(figsize=(16,6),dpi=50)
    plt.subplot(2,1,1)
    fakeX=numpy.linspace(0,sampleNum,sampleNum)/actualRate
    downsample=100
    plt.plot(fakeX[0::downsample],voltData[0::downsample],'-',linewidth=0.1)
Ejemplo n.º 7
0
# 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
import numpy

BoardNum = 0
UDStat = 0
Gain = UL.BIP5VOLTS

LowChan = 0
HighChan = 0

Count = 20
Rate = 3125

Options = UL.CONVERTDATA + UL.BACKGROUND + UL.SINGLEIO
ADData = numpy.zeros((Count, ), dtype=numpy.int16)
print 'a'
Rate = UL.cbAInScan(BoardNum, LowChan, HighChan, Count, Rate, Gain, ADData,
                    Options)

Status = UL.RUNNING
while Status == UL.RUNNING:
    print 'b'
    Status, CurCount, CurIndex = cbGetStatus(BoardNum, Status, CurCount,
                                             CurIndex, UL.AIFUNCTION)