diff --git a/ophyd_devices/galil/sgalil_ophyd.py b/ophyd_devices/galil/sgalil_ophyd.py index dc125ea..4b36f14 100644 --- a/ophyd_devices/galil/sgalil_ophyd.py +++ b/ophyd_devices/galil/sgalil_ophyd.py @@ -264,6 +264,9 @@ class GalilController(Controller): LimitError: Raised if the speed is above 2mm/s or below 0.02mm/s """ + + #time.sleep(0.2) + # Check limits # TODO check sign of stage, or not necessary check_values = [start_y, end_y, start_x, end_x] @@ -280,6 +283,8 @@ class GalilController(Controller): step_grid = (end_x - start_x) / interval_x n_samples = int(interval_y * interval_x) + # Hard coded to maximum offset of 0.1mm to avoid long motions. + self.socket_put_and_receive(f"off={(0*0.1/2*1000):f}") self.socket_put_and_receive(f"a_start={start_y:.04f};a_end={end_y:.04f};speed={speed:.04f}") self.socket_put_and_receive( f"b_start={start_x:.04f};gridmax={gridmax:d};b_step={step_grid:.04f}" @@ -289,13 +294,39 @@ class GalilController(Controller): # sleep 50ms to avoid controller running into time.sleep(0.1) self.socket_put_and_receive("XQ#SCANG") + #time.sleep(0.1) + #threading.Thread(target=_while_in_motion(3, n_samples), daemon=True).start() + #self._while_in_motion(3, n_samples) + + + + def _while_in_motion(self, thread_id: int, n_samples: int) -> tuple: last_readout = 0 + val_axis2 = [] # y axis + val_axis4 = [] # x axis + while self.is_thread_active(thread_id): + posct = int(self.socket_put_and_receive(f'MGposct').strip().split(".")[0]) + logger.info(f'SGalil is scanning - latest enconder position {posct+1} from {n_samples}') + time.sleep(1) + if posct > last_readout: + positions = self.read_encoder_position(last_readout, posct) + val_axis4.extend(positions[0]) + val_axis2.extend(positions[1]) + last_readout = posct+1 + logger.info(len(val_axis2)) + time.sleep(1) + #Readout of last positions after scan finished + posct = int(self.socket_put_and_receive(f'MGposct').strip().split(".")[0]) + logger.info(f'SGalil is scanning - latest enconder position {posct} from {n_samples}') + if posct > last_readout: + positions = self.read_encoder_position(last_readout, posct) + val_axis4.extend(positions[0]) + val_axis2.extend(positions[1]) - curren_encoder = self.socket_put_and_receive(f"MGposct") - # TODO add here loop for continous readout -> checks thread? + return val_axis4, val_axis2 - # TODO does not run from ipython - def read_encoder_position(fromval: int, toval: int) -> tuple: + + def read_encoder_position(self, fromval: int, toval: int) -> tuple: val_axis2 = [] # y axis val_axis4 = [] # x axis for ii in range(fromval, toval + 1):