def collect_position_data(pump, timeout_seconds, time_int): """Collect syringe fill level information during dosage, following the protocol above. Parameters ---------- pump : pump reference to syringe pump, here self.pump timeout_seconds : int when to give up waiting for the pump to stop pumping time_int : float time interval in ms (?) between readings of fill level Returns ------- tuple of t_data, fl_data; time in seconds and fill level in unit set for pump """ print("Collecting position data every {} ms".format(time_int)) timer = qmixbus.PollingTimer(timeout_seconds * 1000) message_timer = qmixbus.PollingTimer(time_int) result = True t_data = [] fl_data = [] while result and not timer.is_expired(): if message_timer.is_expired(): t = time_ns() / 1e9 fl = pump.get_fill_level() t_data.append(t) fl_data.append(fl) # print("Timer (s): {}; Fill level: {}".format(t, fl)) message_timer.restart() result = pump.is_pumping() return t_data, fl_data
def wait_dosage_finished(pump, timeout_seconds): """ The function waits until the last dosage command has finished until the timeout occurs. """ timer = qmixbus.PollingTimer(timeout_seconds * 1000) message_timer = qmixbus.PollingTimer(500) result = True while (result == True) and not timer.is_expired(): time.sleep(0.1) if message_timer.is_expired(): print("Fill level: ", pump.get_fill_level()) message_timer.restart() result = pump.is_pumping() return not result
def __init__(self, doCalibration=False): # calibration will move the plunger! try: self.bus = qmixbus.Bus() self.bus.open('vinnig', '') self.bus.start() self.pump = qmixpump.Pump() self.pump.lookup_by_device_index(0) self.pump.clear_fault() self.pump.enable(True) self.pump.set_volume_unit(qmixbus.UnitPrefix.milli, qmixpump.VolumeUnit.litres) self.pump.set_flow_unit(qmixbus.UnitPrefix.milli, qmixpump.VolumeUnit.litres, qmixbus.TimeUnit.per_second) self.valve = self.pump.get_valve() if (doCalibration): self.pump.calibrate() timeout_timer = qmixbus.PollingTimer(10000) timeout_timer.wait_until(self.pump.is_calibration_finished, True) except: print('Could not init device')
def step08_continuous_flow(self): """ Test continuous flow functionality """ flow_rate = self.contiflow_pump1.get_flow_rate_max() print("Starting continuous flow with flow rate ", flow_rate) self.contiflow_pump1.generate_flow(flow_rate) timer = qmixbus.PollingTimer(30000) while not timer.is_expired(): time.sleep(1) print("Current flow: ", self.contiflow_pump1.get_flow_is(), " Remaining seconds: ", timer.get_msecs_to_expiration() / 1000) flow_rate = flow_rate / 2 print("Starting continuous flow with flow rate ", flow_rate) self.contiflow_pump1.generate_flow(flow_rate) timer.set_period(34000) timer.restart() while not timer.is_expired(): time.sleep(1) print("Current flow: ", self.contiflow_pump1.get_flow_is(), " Remaining seconds: ", timer.get_msecs_to_expiration() / 1000) self.contiflow_pump1.stop_pumping() time.sleep(1)
def _wait_calibration_finished(self, timeout_sec): """ The function waits until pump calibration has finished or until the timeout occurs. """ if self.pump.is_calibration_finished(): yield silaFW_pb2.ExecutionInfo( commandStatus=silaFW_pb2.ExecutionInfo.CommandStatus. finishedSuccessfully, progressInfo=silaFW_pb2.Real(value=1)) return timer = qmixbus.PollingTimer(timeout_sec * 1000) message_timer = qmixbus.PollingTimer(period_ms=500) is_calibrating = False while not (is_calibrating or timer.is_expired()): time.sleep(0.1) timeout_sec -= 0.1 if message_timer.is_expired(): yield silaFW_pb2.ExecutionInfo( commandStatus=silaFW_pb2.ExecutionInfo.CommandStatus. running, progressInfo=silaFW_pb2.Real( value=(self.CALIBRATION_TIMEOUT - timeout_sec) / self.CALIBRATION_TIMEOUT), estimatedRemainingTime=silaFW_pb2.Duration( seconds=int(timeout_sec))) message_timer.restart() is_calibrating = self.pump.is_calibration_finished() if not is_calibrating and not self.pump.is_in_fault_state(): yield silaFW_pb2.ExecutionInfo( commandStatus=silaFW_pb2.ExecutionInfo.CommandStatus. finishedSuccessfully, progressInfo=silaFW_pb2.Real(value=1), estimatedRemainingTime=silaFW_pb2.Duration()) else: yield silaFW_pb2.ExecutionInfo( commandStatus=silaFW_pb2.ExecutionInfo.CommandStatus. finishedWithError, progressInfo=silaFW_pb2.Real(value=1), estimatedRemainingTime=silaFW_pb2.Duration()) logging.error("An unexpected error occurred: %s", self.pump.read_last_error())
def wait_target_reached(axis_system, timeout_seconds): """ The function waits until the given axis system has reached target position or until the timeout occurs. """ timer = qmixbus.PollingTimer(timeout_seconds * 1000) result = False while (result == False) and not timer.is_expired(): time.sleep(0.1) result = axis_system.is_target_position_reached() return result
def wait_homing_attained(axis_system, timeout_seconds): """ The function waits until the given axis system has finished homing move until the timeout occurs. """ timer = qmixbus.PollingTimer(timeout_seconds * 1000) result = False while (result == False) and not timer.is_expired(): time.sleep(0.1) result = axis_system.is_homing_position_attained() return result
def wait_calibration_finished(pump, timeout_seconds): """ The function waits until the given pump has finished calibration or until the timeout occurs. """ timer = qmixbus.PollingTimer(timeout_seconds * 1000) result = False while (not result) and not timer.is_expired(): sleep(0.1) result = pump.is_calibration_finished() return result
def step09_device_lookup(self): """ Tests lookup of conti flow pump declared in device properties XML file """ print("Looking up ContiFlowPump_1...") self.contiflow_pump2 = ContiFlowPump() self.contiflow_pump2.lookup_by_name("ContiFlowPump_1") self.setup_contiflow_parameters(self.contiflow_pump2, 1) if not self.contiflow_pump2.is_initialized(): self.contiflow_pump2.initialize() timeout_timer = qmixbus.PollingTimer(30000) timeout_timer.wait_until(self.contiflow_pump2.is_initialized, True)
def wait_axis_target_reached(axis, timeout_seconds): """ The function waits until the given axis has reached target position or until the timeout occurs. """ timer = qmixbus.PollingTimer(timeout_seconds * 1000) result = False while (result == False) and not timer.is_expired(): time.sleep(0.1) result = axis.is_target_position_reached() print("Position: ", axis.get_actual_position(), " Velocity: ", axis.get_actual_velocity(), " target reached: ", result) return result
def step10_volume_dosing(self): """ Tests volume dosing in continuous flow """ syringe_pump1 = self.contiflow_pump2.get_syringe_pump(0) max_syringe_level = syringe_pump1.get_volume_max() flow_rate = self.contiflow_pump2.get_flow_rate_max() target_volume = max_syringe_level * 1.5 print("Starting volume dosing with target volume ", target_volume) self.contiflow_pump2.pump_volume(target_volume, flow_rate) time.sleep(0.1) timer = qmixbus.PollingTimer(60000) while (self.contiflow_pump2.is_pumping() == True) and not timer.is_expired(): time.sleep(1) print("Dosed volume: ", self.contiflow_pump2.get_dosed_volume())
def step07_initialize_contiflow(self): """ This function tests the initialization procedure for the continuous flow pump """ print("Running reference move for both syringe pumps..") syringe_pump1 = self.contiflow_pump1.get_syringe_pump(0) syringe_pump1.calibrate() syringe_pump2 = self.contiflow_pump1.get_syringe_pump(1) syringe_pump2.calibrate() timeout_timer = qmixbus.PollingTimer(30000) timeout_timer.wait_until(syringe_pump1.is_calibration_finished, True) timeout_timer.wait_until(syringe_pump2.is_calibration_finished, True) print("Initializing continuous flow..") self.contiflow_pump1.initialize() timeout_timer.wait_until(self.contiflow_pump1.is_initialized, True)
def _wait_dosage_finished(self): """ The function waits until the last dosage command has finished or until a timeout occurs. The timeout is estimated from the dosage's flow and target volume """ if not self.pump.is_pumping(): yield silaFW_pb2.ExecutionInfo( commandStatus=silaFW_pb2.ExecutionInfo.CommandStatus.finishedSuccessfully, progressInfo=silaFW_pb2.Real(value=1) ) return target_volume = self.pump.get_target_volume() logging.debug("target volume: %f", target_volume) flow_in_sec = self.pump.get_flow_is() / self.pump.get_flow_unit().time_unitid.value if flow_in_sec == 0: # try again, maybe the pump didn't start pumping yet time.sleep(0.5) flow_in_sec = self.pump.get_flow_is() / self.pump.get_flow_unit().time_unitid.value if flow_in_sec == 0: yield silaFW_pb2.ExecutionInfo( commandStatus=silaFW_pb2.ExecutionInfo.CommandStatus.finishedWithError, progressInfo=silaFW_pb2.Real(value=1) ) logging.error("The pump didn't start pumping. Last error: %s", self.pump.read_last_error()) logging.debug("flow_in_sec: %f", flow_in_sec) dosing_time_s = self.pump.get_target_volume() / flow_in_sec + 2 # +2 sec buffer logging.debug("dosing_time_s: %fs", dosing_time_s) timer = qmixbus.PollingTimer(period_ms=dosing_time_s * 1000) message_timer = qmixbus.PollingTimer(period_ms=500) is_pumping = True while is_pumping and not timer.is_expired(): time.sleep(0.1) dosing_time_s -= 0.1 if message_timer.is_expired(): logging.info("Fill level: %s", self.pump.get_fill_level()) yield silaFW_pb2.ExecutionInfo( commandStatus=silaFW_pb2.ExecutionInfo.CommandStatus.running, progressInfo=silaFW_pb2.Real(value=self.pump.get_dosed_volume()/target_volume), estimatedRemainingTime=silaFW_pb2.Duration( seconds=int(dosing_time_s), nanos=int(dosing_time_s-int(dosing_time_s)) * 1000000000 ) ) message_timer.restart() is_pumping = self.pump.is_pumping() if not is_pumping and not self.pump.is_in_fault_state(): yield silaFW_pb2.ExecutionInfo( commandStatus=silaFW_pb2.ExecutionInfo.CommandStatus.finishedSuccessfully, progressInfo=silaFW_pb2.Real(value=1), estimatedRemainingTime=silaFW_pb2.Duration() ) else: yield silaFW_pb2.ExecutionInfo( commandStatus=silaFW_pb2.ExecutionInfo.CommandStatus.finishedWithError, progressInfo=silaFW_pb2.Real(value=1), estimatedRemainingTime=silaFW_pb2.Duration() ) logging.error("An unexpected error occurred: %s", self.pump.read_last_error())
def doCalibration(self): self.pump.calibrate() timeout_timer = qmixbus.PollingTimer(10000) timeout_timer.wait_until(self.pump.is_calibration_finished, True) return