Example #1
0
 def __call__(self, robot):
   robot.Vent()
   if self.oz_to_meter == 0:
     logging.warning("oz_to_meter was zero, returning early.")
   self.initial_reading = robot.load_cell.recent_summary(secs=.2).mean
   tare = meter_common.tare(robot)
   self.tare_reading = tare.mean
   if not tare.healthy:
     self.unhealthy = True
     logging.error("UNHEALTHY TARE")
     with robot.OpenValve(self.valve_to_actuate):
       time.sleep(meter_common.SECONDS_PER_OZ * self.oz_to_meter)
       return
   self.target_reading = (tare.mean + meter_common.OZ_TO_ADC_VALUES * max(
       self.oz_to_meter - METER_OZ_OFFSET, .1))
   last_summary = tare
   print "Metering to oz %f or %s" % (self.oz_to_meter, self.target_reading)
   with robot.OpenValve(self.valve_to_actuate):
     while last_summary.mean < self.target_reading:
       time.sleep(.05)
       last_summary = robot.load_cell.recent_summary(secs=.1)
       self.current_reading = last_summary.mean
     self.final_reading = self.current_reading
   time.sleep(1)
   r = robot.load_cell.recent(secs=time.time() - tare.timestamp + 5)
   f = open('readings/readings_%s_%foz.csv' %
            (time.strftime("%Y%m%d_%H%M%S"), self.oz_to_meter), 'w')
   for ts, v in r:
     print >> f, "%s,%s" % (ts, v)
   f.close()
Example #2
0
 def __call__(self, robot):
   #robot.Vent()
   if self.oz_to_meter == 0:
     logging.warning("oz_to_meter was zero, returning early.")
   self.initial_reading = robot.load_cell.recent_summary(secs=.2).mean
   tare = meter_common.tare(robot)
   self.tare_reading = tare.mean
   if not tare.healthy:
     self.unhealthy = True
     logging.error("UNHEALTHY TARE")
     with robot.OpenValve(self.valve_to_actuate):
       time.sleep(meter_common.SECONDS_PER_OZ * self.oz_to_meter)
       return
   self.target_reading = (tare.mean + meter_common.OZ_TO_ADC_VALUES * max(
       self.oz_to_meter - METER_OZ_OFFSET, .1))
   last_summary = tare
   print "------------ Metering to oz %f or %s" % (self.oz_to_meter, self.target_reading)
   with robot.OpenValve(self.valve_to_actuate):
     while last_summary.mean < self.target_reading:
       time.sleep(.05)
       last_summary = robot.load_cell.recent_summary(n=1)
       self.current_reading = last_summary.mean
     self.final_reading = self.current_reading
Example #3
0
 def __call__(self, robot):
   if self.oz_to_meter == 0:
     logging.warning("oz_to_meter was zero, returning early.")
   start_ts = time()
   print "Waiting to tare"
   self.tare = tare(robot)
   print "Tared", _format_summary(start_ts, self.tare)
   self.adc_units_to_meter = self.oz_to_meter * OZ_TO_ADC_VALUES
   self.target_reading = self.adc_units_to_meter + self.tare.mean
   print "target_reading=%s oz_to_meter=%s self.tare.mean=%s" % (
       self.target_reading, self.oz_to_meter, self.tare.mean)
   self.measured_actuation_delay = 2.
   last_print = 0
   self.last_readings = self.tare
   while (self.last_readings.mean <
          (self.adc_units_to_meter * .8) + self.tare.mean):
     with robot.OpenValve(self.valve_to_actuate):
       for info in _wait_until_filled(
           tare=self.tare,
           load_cell=robot.load_cell,
           target_reading=self.target_reading,
           deadline=self.tare.timestamp + MAX_METER_SECS):
         self.info = info
         self.elapsed = time() - self.tare.timestamp
         self.time_remaining = info.target_ts - time()
         self.measured_actuation_delay = info.m_actuation_delay
         if time() - last_print > (1 if not info.m_actuation_delay else .2):
           print "Info mad=%s target_ts=%s elapsed=%s time_remaining=%s slope=%s intercept=%s %s" % (
               info.m_actuation_delay, info.target_ts, self.elapsed,
               self.time_remaining, info.slope, info.intercept,
               _format_summary(start_ts, info.summary))
           last_print = time()
     print "Valve was open for %s seconds." % (time() - self.tare.timestamp)
     sleep(max(2 * (self.measured_actuation_delay or 0), 1))
     self.last_readings = robot.load_cell.recent_summary(secs=.3)
     print "Readings after sleep: %s" % (
         _format_summary(start_ts, self.last_readings))