Beispiel #1
0
def go_initialize():
   DataReadWrite.initializeDatabase(dirname,fileName)
   DataReadWrite.openDatabase(dirname,fileName)
   numberOfSamples=int(NUMBEROFSAMPLES.get())
   duration=int(DURATION.get())
   startPosition=int(START_POSITION.get())
   #xyzRobot.resetValuesToZero()   
   setInitials=INITIALS.get()
   standardTemp=float(RHTEMP2000TEMP.get())
   standardRH = float(RHTEMP2000HUMIDITY.get())


   tempCorrection=standardTemp-float(xyzRobot.getTemperature())
   rhCorrection=standardRH-float(xyzRobot.getHumidity())
   logger.debug( "standardTemp: %f",standardTemp)
   logger.debug( "standardRH: %f",standardRH)
   logger.debug( "Temp: %f",xyzRobot.getTemperature())
   logger.debug( "RH: %f",xyzRobot.getHumidity())
   logger.debug( "tempCorrection: %f", tempCorrection)
   logger.debug( "rhCorrection: %f ",rhCorrection)
   
   runID = weighAllCrucibles(setInitials,numberOfSamples,LOGINT,duration,
   								startPosition,tempCorrection,rhCorrection,
          						robotStatus,POSITION,MCOUNT,CURRENTSTEP,
          						STATUS,DURATION,LOGGERINTERVAL,
          						RUNID,NUMBEROFSAMPLES,TIMEREMAINING)
   return True;
Beispiel #2
0
def preFire():

   status="Pre-firing"


   prefire.wm_title("Pre-Fire")

   RHTEMP2000TEMP.set(xyzRobot.getTemperature())
   RHTEMP2000HUMIDITY.set(xyzRobot.getHumidity())
   PRECISIONTEMP.set(xyzRobot.getTemperature())

   INITIALSL = Label(prefire, text="Initials").grid(row=1, column=0, sticky=W)
   INITIALSE = Entry(prefire, textvariable=INITIALS).grid(row=1, column=1, sticky=W)

   RUNIDL = Label(prefire, text="Run ID").grid(row=2, column=0, sticky=W, padx=2, pady=2)
   RUNIDE = Entry(prefire, textvariable=RUNID).grid(row=2, column=1, sticky=W,padx=2, pady=2)
   NAMEL = Label(prefire, text="Name of sample set (e.g., Mississippian ):").grid(row=3, column=0, sticky=W, padx=2, pady=2)
   NAMEE = Entry(prefire, textvariable=NAME).grid(row=3, column=1, sticky=W,padx=2, pady=2)
   Label(prefire, text="Sample Location (e.g., LMV):").grid(row=4, column=0, sticky=W, padx=2, pady=2)
   Entry(prefire, textvariable=LOCATION).grid(row=4, column=1, sticky=W,padx=2, pady=2)

   NUMSAML = Label(prefire, text="Number of Samples").grid(row=5, column=0, sticky=W, padx=2, pady=2)
   NUMSAME = Entry(prefire, textvariable=NUMBEROFSAMPLES).grid(row=5, column=1, sticky=W, padx=2, pady=2)
   STARTPOS= Label(prefire, text="Start Position").grid(row=6, column=0, sticky=W)
   STARTPOS= Entry(prefire, textvariable=START_POSITION).grid(row=6, column=1, sticky=W)

   DURATIONL= Label(prefire, text="Duration of Measurements").grid(row=7, column=0, sticky=W, padx=2, pady=2)
   DURATIONE = Entry(prefire, textvariable=DURATION).grid(row=7, column=1, sticky=W, padx=2, pady=2)
   INTERVALL= Label(prefire, text="Sampling interval (seconds)").grid(row=8, column=0, sticky=W, padx=2, pady=2)
   INTERVALE = Entry(prefire, textvariable=INTERVAL).grid(row=8, column=1, sticky=W, padx=2, pady=2)
   REPSL= Label(prefire, text="Repetitions").grid(row=9, column=0, sticky=W, padx=2, pady=2)
   REPSE = Entry(prefire, textvariable=REPS).grid(row=9, column=1, sticky=W, padx=2, pady=2)
   TEMPL= Label(prefire, text="Temperature (C)").grid(row=10, column=0, sticky=W, padx=2, pady=2)
   TEMPE = Entry(prefire, textvariable=TEMP).grid(row=10, column=1, sticky=W, padx=2, pady=2)
   HUMIDITYL= Label(prefire, text="Relative Humidity").grid(row=11, column=0, sticky=W, padx=2, pady=2)
   HUMIDITYE = Entry(prefire, textvariable=HUMIDITY).grid(row=11, column=1, sticky=W, padx=2, pady=2)

   TEMPL=Label(prefire,text="Madge Tech Temperature:").grid(row=12,column=0,sticky=W,padx=2,pady=2)
   TEMPE=Entry(prefire,textvariable=RHTEMP2000TEMP).grid(row=12,column=1,sticky=W,padx=2,pady=2)
   RHL=Label(prefire,text="Madge Tech RH:").grid(row=13,column=0,sticky=W,padx=2,pady=2)
   RHE=Entry(prefire,text=RHTEMP2000HUMIDITY).grid(row=13,column=1,sticky=W,padx=2,pady=2)

   PTEMP1=Label(prefire,text="Precision Temp").grid(row=14,column=0,sticky=W)
   PTEMP2=Label(prefire,textvariable=PRECISIONTEMP).grid(row=14,column=1,sticky=W)
   HUMIDITY1=Label(prefire,text="Humidity").grid(row=15,column=0,sticky=W)
   HUMIDITY2=Label(prefire,textvariable=HUMIDITY).grid(row=15,column=1,sticky=W)


   DIRL=Label(prefire,text="Directory: ").grid(row=16,column=0,sticky=W,padx=2,pady=2)
   DIRE=Entry(prefire,textvariable=DBDIRECTORY).grid(row=16,column=1,sticky=W,padx=2,pady=2)

   DATAF=Label(prefire,text="Database filename to use:").grid(row=17,column=0,sticky=W)
   DATAL=Entry(prefire,textvariable=DATABASENAME).grid(row=17,column=1, sticky=W)

   INITBUTTON = Button(prefire, text="Start Pre Fire", command=go_preFire).grid(row=18, column=2, padx=2, pady=2)

   prefire.mainloop()
Beispiel #3
0
   print "getTemperature()"
   temp=xyzRobot.getTemperature()
   print "Temperature:",temp
   test += 1
   if temp>0:
      print "PASS"
      passed += 1
   else:
      print "FAIL"
   begin += 1


print "-------------------------------------------------------"

print "getHumidity()"
humidity=xyzRobot.getHumidity()
print "Humidity:",humidity
test += 1
if humidity>0:
    print "PASS"
    passed += 1
else:
    print "FAIL"

print "-------------------------------------------------------"
print "now testing going to various sample locations and returning to 0 point"

positionList = [1,4,6,8,9]
startAXpos=xyzRobot.getAbsoluteXPosition()
startAYpos=xyzRobot.getAbsoluteYPosition()
print "Initial Home Position:", startAXpos, " ", startAYpos
Beispiel #4
0
def weighAllSamplesPostFire(runID,duration,
      		intervalsec,numberOfSamples,startPosition,endOfFiring,
      		tempCorrection,rhCorrection,repeat,robotStatus,
      		POSITION,MCOUNT,CURRENTSTEP,STATUS,DURATION,
      		LOGGERINTERVAL,RUNID,NUMBEROFSAMPLES,TIMEREMAINING,TIMEELAPSED,REPS,CYCLE):
   ## print runID,"-",duration,"-",intervalsec,"-",numberOfSamples,"-",startPosition,"-",endOfFiring,"-",tempCorrection,"-",rhCorrection,"-",repeat
   logging.debug("weighAllSamplesPostFire( %d,%d,%d,%d,%d,%s,%f,%f,%d)" %
   				(runID,
   				duration,
      		intervalsec,
      		numberOfSamples,
      		startPosition,
      		endOfFiring,
      		tempCorrection,
      		rhCorrection,
      		repeat))
   # Find elapsed time
   #first put robot back to zero
   position=int(startPosition)

   if position=="":
      position=1

   #HomePosition()
   listOfValues=()
   STATUS.set("Initializing")
   crucibleWeight=0.0
   robotStatus.deiconify()
   preOrPost=2
   status="postfire"
   now = datetime.today()
   timeLapsedSinceFiring= now - endOfFiring
   Label(robotStatus,text="Run ID:").grid(row=0,column=0,sticky=W)
   Label(robotStatus,textvariable=RUNID).grid(row=0,column=1, sticky=W)
   Label(robotStatus,text="Current sample number:").grid(row=1,column=0,sticky=W)
   Label(robotStatus,textvariable=POSITION).grid(row=1,column=1, sticky=W) 
   Label(robotStatus,text="Cycle Number:").grid(row=3,column=0,sticky=W)
   Label(robotStatus,textvariable=CYCLE).grid(row=3,column=1,sticky=W)

   Label(robotStatus,textvariable=MCOUNT).grid(row=4,column=1,sticky=W)
   Label(robotStatus,text="Current measurement count:").grid(row=4,column=0,sticky=W)
   Label(robotStatus,text="Time elapsed since firing (min):").grid(row=5,column=0,sticky=W)
   Label(robotStatus,textvariable=TIMEELAPSED).grid(row=5,column=1,sticky=W)
   Label(robotStatus,text="Logging interval:").grid(row=6,column=0, sticky=W)
   Label(robotStatus,textvariable=LOGGERINTERVAL).grid(row=6,column=1,sticky=W)
   Label(robotStatus,text="Duration of Measurements:").grid(row=7,column=0, sticky=W)
   Label(robotStatus,textvariable=DURATION).grid(row=7,column=1,sticky=W)
   Label(robotStatus,text="Number of Samples:").grid(row=8,column=0,sticky=W)
   Label(robotStatus,textvariable=NUMBEROFSAMPLES).grid(row=8,column=1,sticky=W)
   Label(robotStatus,text="Time remaining for this sample:").grid(row=9,column=0,sticky=W)
   Label(robotStatus,textvariable=TIMEREMAINING).grid(row=9,column=1,sticky=W)
   Label(robotStatus,text="Status").grid(row=10,column=0, sticky=W)
   Label(robotStatus,textvariable=STATUS).grid(row=10,column=1,sticky=W)
   startTime=datetime.today()
   endPoint=timedelta(minutes=duration)
   endTime=startTime+endPoint
   POSITION.set(int(position))
   NUMBEROFSAMPLES.set(int(numberOfSamples))
   DURATION.set(duration)
   LOGGERINTERVAL.set(intervalsec)
   CYCLE.set(repeat)
  
   sleep(5)
   while position < numberOfSamples+1:
      
      logging.debug("Now on position: %d",int(position))
      ##goToSamplePosition(position)
      ##val=samplePickUp()
      ##if val == False:
      ##   return False
      ## zerothe balance for each sample
      ##DataReadWrite.zeroBalance()
      ##DataReadWrite.openBalanceDoor()
      ##goToOutsideBalanceFromOutside()
      ##goToInsideBalanceFromOutisde()
      ##val=putSampleOnBalance()
      ##if val == False:
      ##   return False
      ## may need to check to see if arm is clear of door.
      #goToOutsideBalanceFromInside()
      #DataReadWrite.closeBalanceDoor()
      crucibleWeight=double(DataReadWrite.getCrucibleWeight(runID,position))
      if (crucibleWeight is False):
         alertWindow("getCrucibleWeight returned an error.")
         exit(1)
      
      sampleID=int(DataReadWrite.getSampleID(runID,position))
      startTime=datetime.today()
      durationOfLogging=int(duration)
      endPoint=timedelta(minutes=durationOfLogging)
      
      endTime=startTime+endPoint
      count=0
      kcount=0
      repetition_count=0
      standard_weight=float(0.0)
      listOfValues=[]
      a=array([])
      statustext="Weighing sample # %d"% position
      STATUS.set(statustext)
      total_count=int(DataReadWrite.getMaxPostFireCount(runID,position))
      if (total_count==0 or total_count==""):
         total_count=0
      while datetime.today() < endTime:
         timeLeft=endTime-datetime.today()
         TIMEREMAINING.set(int(timeLeft.seconds/60))
         kcount=0
         standard_weight=0.0
         measurement=double(0.0)
         weight=double(0.0)
         result=[]
         (measurement,status)=DataReadWrite.readWeightFromBalance()
         weight=double(measurement)-double(crucibleWeight)
         if weight>0.0:
            a=append(a,double(weight))
            averageWeight=a.mean()
            stdevWeight=a.std()
            logger.debug( "Count: %i the average weight of sample # %i is %f with stdev of %f" % (count, position, averageWeight,stdevWeight))
            ## now update crucible position record 
            now = datetime.today()
            today = now.strftime("%m-%d-%y %H:%M:%S")
            total_count += 1
            count += 1
            repetition_count += 1
            MCOUNT.set(count)
            temperature=xyzRobot.getTemperature()
            humidity=xyzRobot.getHumidity()
            logger.debug( "TMP:  temp: %s, humidity: %s" % (temperature,humidity))
            
            standard_weight=0.0
            
            timeDiff=now - endOfFiring
            timeElapsed=int(timeDiff.seconds/60)
            TIMEELAPSED.set(timeElapsed)
            timeElapsedQuarterPower=double(pow(abs(timeElapsed),0.25))
 
            value=DataReadWrite.insertPostFireMeasurement(runID,sampleID,position,
          				weight,status,temperature,humidity,endOfFiring,
          				crucibleWeight,standard_weight,now,total_count,repeat,repetition_count,count)
            if (value is False):
               alertWindow("insertPostFireMeasurement returned with an error.")
               exit(1)
               ### check to see if enough measurements have been made. First at least 100 must have been done
            if (count > COUNTS_FOR_STATS):
               (mean,stdev,variance,tempMean,tempStdev,humidityMean,humidityStdev)=DataReadWrite.getStatsForPostFireWeightOfSample(runID,sampleID,count)
               logger.debug("TempMean: %d  TempStDev: %d HumidityMean: %d HumidityStdDev: %d" % (tempMean,tempStdev,humidityMean,humidityStdev))

               value=DataReadWrite.updateSamplePostFire(runID,sampleID,position,tempMean,tempStdev,humidityMean,humidityStdev,count,repeat,timeElapsed)

            sleep(intervalsec)
            if count==0:
               ## check to see if balance is giving anything
               (value,status)=DataReadWrite.readInstantWeightFromBalance()
               logger.debug( "Instant value from balance (unstable):  %f",float(value))
               if (value>0):
                  STATUS.set("Resetting clock")
                  logger.warning( "Since this is >0 the balance is reading but not stable")
                  logger.warning( "resetting clock. Waiting for a valid entry before storing data...")
                  startTime=datetime.today()
                  endPoint=timedelta(minutes=durationOfLogging)
                  endTime=startTime+endPoint
               else:
                  STATUS.set("Error. No output from balance. Trying again.")
                  logger.warning("There is a problem: no output from balance at all: Count: %d",int(kcount))
                  kcount += 1
                  if kcount==500:
                     STATUS.set("Tried 500 times but nothing from balance. Quitting")
                     logger.error( "There is a problem: no output for 500 counts -- quitting ")
                     ##KillMotors()
                     exit(1)
         sleep(intervalsec)
      statustext="Done! Going to retrieve sample from balance."
      STATUS.set(statustext)
      ##DataReadWrite.openBalanceDoor()
      ##goToInsideBalanceFromOutside()
      statustext="Picking up sample from balance."
      STATUS.set(statustext)
      #val=pickUpSampleFromBalance()
      #if val == False:
      #   return False
      STATUS.set("Going outside balance from inside")
      ##goToOutsideBalanceFromInside()
      statustext="Going to position %d" % int(position)
      STATUS.set(statustext)
      ##goToSamplePosition(position)
      STATUS.set("Putting sample down")
      ##val=samplePutDown()
      ##if val == False:
      ##   return False
      STATUS.set("Now going to home position.")
      #response=goHome()
      ##DataReadWrite.closeBalanceDoor()
      ##if response==False:
      ##   logger.error( "Was unable to go home. Quitting.")
      ##   return False
      position +=1
      POSITION.set(int(position))
      statustext="Now on position %d" % position
      STATUS.set(statustext)
   STATUS.set("Done!")
   #robotStatus.withdraw()
   return runID;
Beispiel #5
0
def go_postFire():
   dbName=DATABASENAME.get()
   dbDir=DBDIRECTORY.get()

   value=DataReadWrite.openDatabase(dbDir,dbName)
   if value is False:
      logger.error("There has been an error since openDatabase returned FALSE")
      alert.deiconify()
      Message(alert,text="There has been a problem. Cannot create database", bg='red', fg='ivory', relief=GROOVE)

   runID=int(RUNID.get())
   if (runID<1):
      alert.deiconify()
      alert.title("Alert: No RunID Number!")
      Message(alert,text="You must have a RunID to continue.", bg='red', fg='ivory', relief=GROOVE).grid(row=0, column=0, sticky=W+E+N+S)
      #Button(alert, text="Continue", command=backToMainWindow).grid(row=1,column=0)
      #Button(alert, text="Quit", command=KillProgram).grid(row=2,column=1)
      logger.debug("You must have a RunID entered in order to continue.")
      return False;
   
   setInitials=str(INITIALS.get())
   startPosition=int(START_POSITION.get())
   intervalsec=int(INTERVAL.get())
   numberOfSamples=int(NUMBEROFSAMPLES.get())
   repetitions=int(REPS.get())
   duration=int(DURATION.get())
   setTemperature=float(TEMP.get())
   setHumidity=float(HUMIDITY.get())
   standardTemp=float(RHTEMP2000TEMP.get())
   standardRH=float(RHTEMP2000HUMIDITY.get())

   temp=xyzRobot.getTemperature()
   humidity=xyzRobot.getHumidity()
   tempCorrection=standardTemp-temp
   rhCorrection=standardRH-humidity
   temperatureOfFiring=int(TEMPOFFIRING.get())
   durationOfFiring=DURATIONOFFIRING.get()*60
   preOrPost=2
   status="postfire"
 

   startPosition=START_POSITION.get()
   now = datetime.today()
   ## (locationCode,numberOfSamples,description,temperature,humidity,endOfFiring,durationOfFiring)=DataReadWrite.getRunInfo(runID)
   startdate=DATEOFFIRING.get()
   starttime=TIMEOFFIRING.get()
   sdate=startdate.split("-",3)
   stime=starttime.split(":",3)

   startOfFiring = datetime(int(sdate[2]), int(sdate[0]), int(sdate[1]), int(stime[0]), int(stime[1]), int(stime[2]))
   
   end = timedelta(minutes=durationOfFiring)
   endOfFiring = startOfFiring + end
   
   # minutes since firing ended
   diffTime = now - endOfFiring
  
   ## d_endOfFiring = endOfFiring.strftime("%m-%d-%y %H:%M:%S")
   intervalsec=int(INTERVAL.get())
   postMeasurementTimeInterval=int(DURATION.get()) 
   repetitions=int(REPS.get())
   #print runID,setInitials,status,durationOfFiring,temperatureOfFiring,postMeasurementTimeInterval,duration,repetitions,endOfFiring,startPosition,intervalsec
   logger.debug("updateRunPostFire( %d,%s,%s,%s,%d,%d,%d,%d,%d,%s,%d,%d )" % 
   							(runID,setInitials,status,startOfFiring,
       						durationOfFiring,temperatureOfFiring,intervalsec,
      						duration,repetitions,endOfFiring,startPosition,intervalsec))

   value=DataReadWrite.updateRunPostFire(runID,setInitials,
               status,startOfFiring,durationOfFiring,temperatureOfFiring,intervalsec,
               duration,repetitions,endOfFiring, startPosition,intervalsec)
   if (value is False):
      logger.error("There has been an error since updateRunPostFire returned FALSE")
      alert.deiconify()
      Message(alert,text="There has been a problem. The arm has returned to Home.", bg='red', fg='ivory', relief=GROOVE).pack(padx=1,pady=1)
     # Button(alert, text="Continue", command=backToMainWindow)
     # Button(alert, text="Quit", command=KillProgram)

   count=0
   repeat=1
   ## print runID,"-",duration,"-",intervalsec,"-",numberOfSamples,"-",startPosition,"-",endOfFiring,"-",tempCorrection,"-",rhCorrection,"-",repeat
 
   while repeat < (repetitions+1):
      CYCLE.set(repeat)
      weighAllSamplesPostFire(runID,duration,
               intervalsec,numberOfSamples,startPosition,
               endOfFiring,tempCorrection,rhCorrection,repeat,
               robotStatus,POSITION,MCOUNT,
               CURRENTSTEP,STATUS,DURATION,
               LOGGERINTERVAL,RUNID,NUMBEROFSAMPLES,
               TIMEREMAINING,TIMEELAPSED,REPS,CYCLE)
      repeat += 1
      #  update_windows()
   #postfire.update()
   #postfire.deiconify()
   #postfire.withdraw()
   return True;
Beispiel #6
0
def weighAllSamplesPreFire(runID,duration,loggingInterval,
            numberOfSamples,startPosition,
            tempCorrection,rhCorrection,repetition,
   			robotStatus,POSITION,MCOUNT,CURRENTSTEP,
   			STATUS,DURATION,LOGGERINTERVAL,RUNID,
   			NUMBEROFSAMPLES,TIMEREMAINING,CYCLE,MEAN,STDEV,VARIANCE):
   # Find elapsed time
   #first put robot back to zero
   position=int(startPosition)
   if position=="":
      position=1
   logger.debug("weighAllSamplesPreFire( %d,%d,%d,%d,%d )" % (runID,duration,loggingInterval,numberOfSamples,startPosition))
   
   status="prefire"
   preOrPost=1
   #HomePosition()
   listOfValues=()
   RUNID.set(runID)
   NUMBEROFSAMPLES.set(numberOfSamples)
   DURATION.set(duration)
   POSITION.set(position)
   CYCLE.set(repetition)
   MCOUNT.set(0)
   STATUS.set("Initializing")
   LOGGERINTERVAL.set(loggingInterval)
   crucibleWeight=0.0
   startTime=datetime.today()
   endPoint=timedelta(minutes=duration)
   endTime=startTime+endPoint
   robotStatus.deiconify()
   Label(robotStatus,text="Run ID:").grid(row=0,column=0,sticky=W)
   Label(robotStatus,textvariable=RUNID).grid(row=0,column=1, sticky=W)
   Label(robotStatus,text="Current sample number:").grid(row=1,column=0,sticky=W)
   Label(robotStatus,textvariable=POSITION).grid(row=1,column=1, sticky=W)
   Label(robotStatus,text="Total Number of Samples:").grid(row=2,column=0,sticky=W)
   Label(robotStatus,textvariable=NUMBEROFSAMPLES).grid(row=2,column=1,sticky=W)
   Label(robotStatus,text="Cycle Number:").grid(row=3,column=0,sticky=W)
   Label(robotStatus,textvariable=CYCLE).grid(row=3,column=1,sticky=W)
   Label(robotStatus,textvariable=MCOUNT).grid(row=4,column=1,sticky=W)
   Label(robotStatus,text="Current measurement count:").grid(row=4,column=0,sticky=W)
   Label(robotStatus,text="Logging interval:").grid(row=5,column=0, sticky=W)
   Label(robotStatus,textvariable=LOGGERINTERVAL).grid(row=5,column=1,sticky=W)
   Label(robotStatus,text="Duration of Measurements:").grid(row=6,column=0, sticky=W)
   Label(robotStatus,textvariable=DURATION).grid(row=6,column=1,sticky=W)
   Label(robotStatus,text="Number of Samples:").grid(row=7,column=0,sticky=W)
   Label(robotStatus,textvariable=NUMBEROFSAMPLES).grid(row=7,column=1,sticky=W)
   Label(robotStatus,text="Time remaining for this sample:").grid(row=8,column=0,sticky=W)
   Label(robotStatus,textvariable=TIMEREMAINING).grid(row=8,column=1,sticky=W)
   Label(robotStatus,text="Status").grid(row=9,column=0, sticky=W)
   Label(robotStatus,textvariable=STATUS).grid(row=9,column=1,sticky=W)
   sleep(5)

   while position < numberOfSamples+1:
      statustext="Now on sample %d",int(position)
      STATUS.set(statustext)
      logger.debug("Now on position: %d ", int(position))
      statustext="Go to position %d",int(position)
      STATUS.set(statustext)
      #goToSamplePosition(position)
      #val = samplePickUp()
      #if val == False:
      #   return False
      ## zero the balance for each sample
      logger.debug("Zero balance")
      #DataReadWrite.zeroBalance()
      logger.debug("Open balance door")
      #DataReadWrite.openBalanceDoor()
      statustext="Going to outside of balance"
      STATUS.set(statustext)
      #logger.debug("Go to outside balance.")
      #goToOutsideBalanceFromOutside()
      statustext="Going into the balance."
      STATUS.set(statustext)
      logger.debug("go to inside balance.")
      #goToInsideBalanceFromOutside()
      logger.debug("put sample on balance.")
      statustext="Putting sample on balance."
      STATUS.set(statustext)
      #val = putSampleOnBalance()
      #if val == False:
      #   return False
      ## may need to check to see if arm is clear of door.
      logger.debug("go to outsisde balance from the inside.")
      statustext="Going to outside of balance"
      STATUS.set(statustext)
      #goToOutsideBalanceFromInside()
      logger.debug("close balance door")
      #DataReadWrite.closeBalanceDoor()
      
      crucibleWeight=double(DataReadWrite.getCrucibleWeight(runID,position))
      if crucibleWeight==False:
         alertWindow("get Crucible Weight returned an error")
         
      sampleID=DataReadWrite.getSampleID(runID,position)
      startTime=datetime.today()
      durationOfLogging=int(duration)
      endPoint=timedelta(minutes=durationOfLogging)
      endTime=startTime+endPoint
      repetition_count=0
      kcount=0
      standard_weight=float(0.0)
      count=0
      
      #get the latest count for this sample
      total_count = int(DataReadWrite.getMaxPreFireCount(runID,position))
      if (total_count == 0 or total_count == ""):
         total_count=0
      listOfValues=[]
      a = array([])
      weight=double(0.0)
      statustext="Weighing sample # %d"% position
      STATUS.set(statustext)
      while datetime.today() < endTime:
         timeLeft=endTime-datetime.today()
         TIMEREMAINING.set(int(timeLeft.seconds/60))
         result=[]
         (measurement,status)=DataReadWrite.readWeightFromBalance()
         
         weight=double(crucibleWeight)-double(measurement)
         
         if weight>0.0:
            a=append(a,double(weight))
            averageWeight=a.mean()
            
            stdevWeight=a.std()
            logger.debug( "Count: %d the average weight of sample # %d is %f with stdev of %f" % (count,position,float(averageWeight),float(stdevWeight)))
            ## now update crucible position record 
            now = datetime.today()
            today = now.strftime("%m-%d-%y %H:%M:%S")
            repetition_count += 1
            total_count += 1
            MCOUNT.set(count)
            temperature=xyzRobot.getTemperature()
            humidity=xyzRobot.getHumidity()

            logger.debug( "TMP:  temp: %s, humidity: %s" % (temperature,humidity))

            standard_weight=0.0
            if (temperature==""):
               temperature=0.0
            if (humidity==""):
               humidity=0.0
               
            value=DataReadWrite.insertPreFireMeasurement(runID,sampleID,position,weight,status,
                     temperature,humidity,crucibleWeight,
                     standard_weight,today,total_count,repetition,repetition_count,count)
            if value==False:
               alertWindow("insertPreFireMeasurement has returned an error")

            count += 1
            ### check to see if enough measurements have been made. First at least 100 must have been done
            if (count > COUNTS_FOR_STATS):
               (mean,stdev,variance,tempMean,tempStdev,humidityMean,humidityStdev)=DataReadWrite.getStatsForPrefireWeightOfSample(runID,sampleID,count)
               MEAN.set(mean)
               STDEV.set(stdev)
               VARIANCE.set(variance)
               logger.debug("Mean: %d  Stdev: %d  Variance: %d TempMean: %d  TempStDev: %d HumidityMean: %d HumidityStdDev: %d" % (mean,stdev,variance,tempMean,tempStdev,humidityMean,humidityStdev))
               value=DataReadWrite.updateSamplePreFire(runID,sampleID,position,mean,stdev,tempMean,tempStdev,humidityMean,humidityStdev)
            sleep(loggingInterval)
         if count==0:
            ## check to see if balance is giving anything
            (value,status)=DataReadWrite.readInstantWeightFromBalance()
            logger.debug( "Instant value from balance (unstable): %f ",float(value))
            if (value>0):
               logger.debug( "Since this is >0 the balance is reading but not stable")
               logger.debug( "resetting clock. Waiting for a valid entry before storing data...")
               startTime=datetime.today()
               endPoint=timedelta(minutes=durationOfLogging)
               endTime=startTime+endPoint
            else:
               logger.error( "There is a problem: no output from balance at all: Count: %d ",int(kcount))
               kcount += 1
               if kcount==500:
                 logger.error( "There is a problem: no output for 500 counts -- quitting ")
                 KillMotors()
                 exit(1)   
      #DataReadWrite.openBalanceDoor()
      statustext="Going into balance."
      STATUS.set(statustext)
      #goToInsideBalanceFromOutside()
      statustext="Picking up sample."
      STATUS.set(statustext)
      #val=pickUpSampleFromBalance()
      #if val == False:
      #   return False
      statustext="Going to outside of balance."
      STATUS.set(statustext)
      #goToOutsideBalanceFromInside()
      statustext="Going to position %d." % position
      STATUS.set(statustext)
      #goToSamplePosition(position)
      statustext="Putting sample down."
      #val=samplePutDown()
      #if val == False:
      #   return False
      statustext="Going to home position."
      #response=goHome()
      #if response==False:
      #   logger.error( "Home point not reached. Stopping.")
      #   STATUS.set("Error: home point not reached.")
      #   return False
      #DataReadWrite.closeBalanceDoor()
      position += 1
      POSITION.set(int(position))
      statustext= "Now moving to the next sample %d." % position
      STATUS.set(statustext)
   STATUS.set("Done!")
   robotStatus.withdraw()
   return runID;
Beispiel #7
0
def go_preFire():
   dbName=DATABASENAME.get()
   dbDir=DBDIRECTORY.get()

   value=DataReadWrite.openDatabase(dbDir,dbName)
   if value is False:
      logger.error("There has been an error since openDatabase returned FALSE")
      alert.deiconify()
      Message(alert,text="There has been a problem. Cannot create database", bg='red', fg='ivory', relief=GROOVE)

   runID=int(RUNID.get())
   if (runID<1):
      alert.deiconify()
      alert.title("Alert: No RunID Number!")
      Message(alert,text="You must have a RunID to continue.", bg='red', fg='ivory', relief=GROOVE).grid(row=0,column=0,sticky=E+W+N+S)
      ##Button(alert, text="Continue", command=backToMainWindow).grid(row=1,column=0)
      ##Button(alert, text="Quit", command=KillProgram).grid(row=1,column=1)
      logger.debug("You must have a RunID entered in order to continue.")
      return False;
   preOrPost=1
   status="prefire"
   setInitials=str(INITIALS.get())
   startPosition=int(START_POSITION.get())
   setName=str(NAME.get())
   setLocation=str(LOCATION.get())
   intervalsec=int(INTERVAL.get())
   numberOfSamples=int(NUMBEROFSAMPLES.get())
   repetitions=int(REPS.get())
   duration=int(DURATION.get())
   setTemperature=float(TEMP.get())
   setHumidity=float(HUMIDITY.get())
   standardTemp=float(RHTEMP2000TEMP.get())
   standardRH=float(RHTEMP2000HUMIDITY.get())

   temp=xyzRobot.getTemperature()
   humidity=xyzRobot.getHumidity()
   tempCorrection=standardTemp-temp
   rhCorrection=standardRH-humidity

   now = datetime.today()
   today = now.strftime("%m-%d-%y %H:%M:%S")

   if (startPosition==""):
      startPosition=1
      
   runID=DataReadWrite.updateRunPreFire(runID,setInitials,setName,today,
   setLocation,preOrPost,intervalsec,setTemperature,setHumidity,
   status,duration,numberOfSamples,repetitions,startPosition)
   
   if (runID == False):
      logger.error("There has been an error since updateRunPreFire returned FALSE")
      alert.deiconify()
      Message(alert,text="There has been a problem. The arm has returned to Home.", bg='red', fg='ivory', relief=GROOVE).grid(row=0,column=0,sticky=W+E+N+S)
      ##Button(alert, text="Continue", command=backToMainWindow).grid(column=1,row=0)
      ##Button(alert, text="Quit", command=KillProgram).grid(row=1,column=1)
   count=1
   repeat=0

   while (count < (numberOfSamples+1)):

      (meanWeight, stdevWeight) = DataReadWrite.getCrucibleWeightStats(runID,count)
      # Now do an insert for tblSample for each sample include--- from here on we can then just update the record.
      sampleID = DataReadWrite.insertNewSample(runID,count,setName,now,setLocation,preOrPost,intervalsec,setTemperature,setHumidity,status,duration,repetitions,meanWeight,stdevWeight)

    
      if (sampleID is False):
         logger.error("There has been an error since insertNewSample returned FALSE")
         alert.deiconify()
         Message(alert,text="There has been a problem. The arm has returned to Home.", bg='red', fg='ivory', relief=GROOVE).grid(row=0,column=0,sticky=W+E+N+S)
         ##Button(alert, text="Continue", command=backToMainWindow).grid(column=1,row=0)
         ##Button(alert, text="Quit", command=KillProgram).grid(row=1,column=1)
         break
      count += 1

   repeat=0      
   ## repeat as many times as asked (all of the crucibles)
   while repeat < repetitions:
      weighAllSamplesPreFire(runID,duration,intervalsec,
            numberOfSamples,startPosition,standardTemp,
            standardRH,repeat,
            robotStatus,POSITION,MCOUNT,CURRENTSTEP,
            STATUS,DURATION,LOGGERINTERVAL,RUNID,
            NUMBEROFSAMPLES,TIMEREMAINING,CYCLE,MEAN,STDEV,VARIANCE)
      repeat += 1
      #prefire.update_windows()
   

   prefire.withdraw()
   return True
Beispiel #8
0
def weighAllCrucibles(initials,numberOfSamples,loggerInterval,
       duration,startPosition,tempCorrection,rhCorrection,robotStatus,
       POSITION,MCOUNT,CURRENTSTEP,STATUS,
       DURATION,LOGGERINTERVAL,RUNID,NUMBEROFSAMPLES,TIMEREMAINING):
   
   # Find elapsed time
   #first put robot back to zero
   logger.info("weightAllCrucibles: %s, %d, %d, %d, %d" % (initials,numberOfSamples,loggerInterval,duration,startPosition))
   position=int(startPosition)
   #HomePosition()
   listOfValues=()
   LOGGERINTERVAL.set(loggerInterval)
   DURATION.set(duration)
   POSITION.set(position)
   STATUS.set("Initializing")
   now = datetime.today()
   today = now.strftime("%m-%d-%y %H:%M:%S")
   ### set up gui #########
   robotStatus.deiconify()
   Label(robotStatus,text="Run ID:").grid(row=0,column=0,sticky=W)
   Label(robotStatus,textvariable=RUNID).grid(row=0,column=1, sticky=W)
   Label(robotStatus,text="Current sample number:").grid(row=1,column=0,sticky=W)
   Label(robotStatus,textvariable=POSITION).grid(row=1,column=1, sticky=W)
   Label(robotStatus,textvariable=MCOUNT).grid(row=2,column=1,sticky=W)
   Label(robotStatus,text="Current measurement count:").grid(row=2,column=0,sticky=W)
   Label(robotStatus,text="Logging interval:").grid(row=3,column=0, sticky=W)
   Label(robotStatus,textvariable=LOGGERINTERVAL).grid(row=3,column=1,sticky=W)
   Label(robotStatus,text="Duration of Measurements:").grid(row=4,column=0, sticky=W)
   Label(robotStatus,textvariable=DURATION).grid(row=4,column=1,sticky=W)
   Label(robotStatus,text="Number of Samples:").grid(row=5,column=0,sticky=W)
   Label(robotStatus,textvariable=NUMBEROFSAMPLES).grid(row=5,column=1,sticky=W)
   Label(robotStatus,text="Time remaining for this sample:").grid(row=6,column=0,sticky=W)
   Label(robotStatus,textvariable=TIMEREMAINING).grid(row=6,column=1,sticky=W)
   Label(robotStatus,text="Status").grid(row=7,column=0, sticky=W)
   Label(robotStatus,textvariable=STATUS).grid(row=7,column=1,sticky=W)
   NUMBEROFSAMPLES.set(numberOfSamples)
   sleep(5)
   
   #first create a new run so we have an ID.
   logger.debug("DataReadWrite.insertRun( %s,%s,%d )" %(initials,today,numberOfSamples))
   runID=DataReadWrite.insertRun(initials,today,numberOfSamples)
   statustext = "Run ID is %d" % int(runID)
   logger.info( statustext)
   RUNID.set(int(runID))
   while position < numberOfSamples+1:
      POSITION.set(position)
      #statustext="Going to position: %d"% int(position)
      #logger.info( statustext)
      #set this crucible for this run
      logger.debug("DataReadWrite.insertInitialCrucible(%d,%d,%s)" % (runID,position,today))
      DataReadWrite.insertInitialCrucible(runID,position,today)
      # assume we start in position 1 -- which is the 0,0 point for the grid
      #logger.info( "going to sample position: %d ", position)
      STATUS.set(statustext)
      #goToSamplePosition(position)
      #statustext="Picking up sample %d" % int(position)
      #STATUS.set(statustext)
      #logger.info( "picking up sample.")
      #val = samplePickUp()
      #if val == False:
      #   return False;
      
      ## zero the balance for each sample
      logger.debug("going to zero balance...")
      DataReadWrite.zeroBalance()
      logger.debug( "opening balance door.")
      #DataReadWrite.openBalanceDoor()
      #statustext="Going to outside of balance x: %d y: %d" %( BALANCE_OUTSIDE[X], BALANCE_OUTSIDE[Y])
      #STATUS.set(statustext)
      logger.debug( "go to outside of balance.")
      #goToOutsideBalanceFromOutside()
      logger.debug( "go to inside balance")
      #statustext="Going to inside balance x: %d y: %d" %( BALANCE_INSIDE[X], BALANCE_INSIDE[Y])
      #STATUS.set(statustext)
      #goToInsideBalanceFromOutside()
      logger.debug( "put sample on balance")
      STATUS.set("Putting sample on balance")
      #val = putSampleOnBalance()
      #if val==False:
      #   STATUS.set("ERROR")
      #   robotStatus.quit()
      #   return False;
      STATUS.set("Moving to outside balance.")
      logger.info( "Move to outside balance.")
      #goToOutsideBalanceFromInside()
      ## may need to check to see if arm is clear of door.
      #DataReadWrite.closeBalanceDoor()
      durationOfLogging=int(duration)
      startTime=datetime.today()
      endPoint=timedelta(minutes=durationOfLogging)
      endTime=startTime+endPoint
      listOfValues=[]
      weight=float(0.0)
      count=0
      kcount=0
      tempHumidityArray=[]
      statustext="Weighing sample # %d"% position
      STATUS.set(statustext)
      a = array([])
      tempArray=array([])
      humidityArray=array([])

      averageTemp=0.0
      stdevTemp=0.0
      averageHumidity=0.0
      stdevHumidity=0.0

      while datetime.today() < endTime:
         timeLeft=endTime-datetime.today()
         TIMEREMAINING.set(int(timeLeft.seconds/60))
         result=[]
         (weight,status)=DataReadWrite.readWeightFromBalance()
         temp=xyzRobot.getTemperature()
         humidity=xyzRobot.getHumidity()
         if weight>0.0:
            #print "NOW GOING TO UPDATE PLOT"
            #plotGraph.add_data_point(1, 23.2323)

            listOfValues.append(weight)
            a=append(a,float(weight))
            averageWeight=mean(a)
            stdevWeight=std(a)
            averageTemp=0.0
            averageHumidity=0.0
            stdevTemp=0.0
            stdevHumidity=0.0

            logger.debug( "temp: %f humidity: %f " % (temp, humidity))
            temp=xyzRobot.getTemperature()
            humidity=xyzRobot.getHumidity()

            if (temp==""):
               temp=0.0     
            if temp>0:
               tempArray=append(tempArray,temp)
               if (tempArray.size > 2):
                  averageTemp=mean(tempArray)
                  stdevTemp=std(tempArray)
               else:
                  averageTemp=temp
                  stdevTemp=0.0
            if humidity>0:
               humidityArray=append(humidityArray,humidity)
               if humidityArray.size > 2:
                  averageHumidity=mean(humidityArray)
                  stdevHumidity=std(humidityArray)
               else:
                  averageHumidity=humidity
                  stdevHumidity=0.0
            
            print "position:",position,"averageWeight:",averageWeight,"stdevWeight:",stdevWeight,"averageTemp:",averageTemp,"stdevTemp:",stdevTemp,"averageHumidity:",averageHumidity,"stdevHumidity:",stdevHumidity,"today:",today,"run:",runID,"count:",count
            print "position=%d,averageWeight=%s,stdevWeight=%s,averageTemp=%s,stdevTemp=%s,averageHumidity=%s,stdevHumidity=%s,today=%s,runID=%d,count=%d" % (position,averageWeight,stdevWeight,averageTemp,stdevTemp,averageHumidity,stdevHumidity,today,runID,count)
            logger.debug( "Count: %d the average weight of crucible # %i is: %f with stdev of: %f" %(count, position,averageWeight,stdevWeight))
            ## now update crucible position record 
            now = datetime.today()
            today = now.strftime("%m-%d-%y %H:%M:%S")
            count += 1
            MCOUNT.set(count)

            ## kludge
            averageWeight=16
            DataReadWrite.updateCrucible(position,averageWeight,stdevWeight,averageTemp,stdevTemp,averageHumidity,stdevHumidity,today,runID,count)
            sleep(loggerInterval)
            statustext="Weight recorded #%d %f %f" %(count,averageWeight,stdevWeight)
            STATUS.set(statustext)
         if count==0:
            ## check to see if balance is giving anything
            (value,status)=DataReadWrite.readInstantWeightFromBalance()
            logger.info( "Balance current reads: %f ",float(value))
            if (value>0):
               logger.info( "Since this is >0 the balance is reading but not stable")
               logger.info( "resetting clock. Waiting for a valid entry before storing data...")
               startTime=datetime.today()
               endPoint=timedelta(minutes=durationOfLogging)
               endTime=startTime+endPoint
            else:
               STATUS.set("Error: nothing from balance. Checking to see if this resolves itself")
               logger.info( "There is a problem: no output from balance at all: Count: %d",int(kcount))
               kcount += 1
               if kcount==500:
                 logger.error( "There is a problem: no output for 500 counts -- quitting ")
                 xyzRobot.KillMotors()
                 exit(1)
      logger.info("Open the balance door")
      #DataReadWrite.openBalanceDoor()
      STATUS.set("Go back into balance to get sample.")
      logger.info( "enter balance")
      #goToInsideBalanceFromOutside()
      logger.info( "pick up sample")
      STATUS.set("Pick up sample from balance")
      #val = pickUpSampleFromBalance()
      #if val == False:
      #   STATUS.set("Error: missing sample")
      #   robotStatus.quit()
      #   return False
      logger.info( "leave balance . . . ")
      STATUS.set("Leave balance.")
      #goToOutsideBalanceFromInside()
      statustext="Return to position %d", int(position)
      STATUS.set(statustext)
      logger.info( "now return to position: %d ", int(position))
      STATUS.set("Put sample down.")
      #goToSamplePosition(position)
      logger.info( "put the sample down. . . ")
      #val=samplePutDown()
      #if val == False:
      #   STATUS.set("Error sample held when there shouldn't be one")
      #   robotStatus.quit()
      #   return False;
      logger.info( "close the balance door . . ")
      #DataReadWrite.closeBalanceDoor()
      STATUS.set("Now go to home position")
      #response=goHome()
      #if response==False:
      #   logger.error( "Home point not reached. Stopping.")
      #   return False;
      
      position += 1
      POSITION.set(position)
      statustext="Now starting next sample: %d",position
      STATUS.set(statustext)
      statustext="go on to the next position: %d", int(position)
      logger.info(statustext)
   STATUS.set("Done!")
   robotStatus.withdraw()
   return (runID)