fix: online changes sgalil e20636

This commit is contained in:
e20636 2023-09-09 10:14:28 +02:00
parent 76f88efa31
commit 592ddfe6da

View File

@ -5,7 +5,7 @@ from typing import List
import numpy as np import numpy as np
from bec_lib.core import bec_logger from bec_lib.core import bec_logger
from ophyd import Component as Cpt from ophyd import Component as Cpt, DeviceStatus
from ophyd import Device, PositionerBase, Signal from ophyd import Device, PositionerBase, Signal
from ophyd.status import wait as status_wait from ophyd.status import wait as status_wait
from ophyd.utils import LimitError, ReadOnlyError from ophyd.utils import LimitError, ReadOnlyError
@ -155,8 +155,8 @@ class GalilController(Controller):
def stop_all_axes(self) -> str: def stop_all_axes(self) -> str:
# return self.socket_put_and_receive(f"XQ#STOP,1") # return self.socket_put_and_receive(f"XQ#STOP,1")
# Command stops all threads and motors! # Command stops all threads and motors!
# self.socket_put_and_receive(f"ST") self.socket_put_and_receive(f"CB8")
return self.socket_put_and_receive(f"AB") return self.socket_put_and_receive(f"ST")
def axis_is_referenced(self) -> bool: def axis_is_referenced(self) -> bool:
return bool(float(self.socket_put_and_receive(f"MG allaxref").strip())) return bool(float(self.socket_put_and_receive(f"MG allaxref").strip()))
@ -243,6 +243,7 @@ class GalilController(Controller):
# @threadlocked # @threadlocked
def fly_grid_scan( def fly_grid_scan(
self, self,
status: DeviceStatus,
start_y: float, start_y: float,
end_y: float, end_y: float,
interval_y: int, interval_y: int,
@ -272,7 +273,8 @@ class GalilController(Controller):
""" """
# #
axes_referenced = self.axis_is_referenced() if not self.axis_is_referenced():
raise GalilError("Axis are not referenced")
sign_y = self._axis[ord("c") - 97].sign sign_y = self._axis[ord("c") - 97].sign
sign_x = self._axis[ord("e") - 97].sign sign_x = self._axis[ord("e") - 97].sign
# Check limits # Check limits
@ -309,10 +311,19 @@ class GalilController(Controller):
# sleep 50ms to avoid controller running into # sleep 50ms to avoid controller running into
time.sleep(0.1) time.sleep(0.1)
self.socket_put_and_receive("XQ#SCANG") self.socket_put_and_receive("XQ#SCANG")
# self._block_while_active(3)
# time.sleep(0.1) # time.sleep(0.1)
# threading.Thread(target=_while_in_motion(3, n_samples), daemon=True).start() threading.Thread(target=self._block_while_active, args=(3,status), daemon=True).start()
# self._while_in_motion(3, n_samples) # self._while_in_motion(3, n_samples)
def _block_while_active(self,thread_id:int, status) -> None:
while self.is_thread_active(thread_id):
time.sleep(1)
time.sleep(1)
while self.is_thread_active(thread_id):
time.sleep(1)
status.set_finished()
# TODO this is for reading out positions, readout is limited by stage triggering # TODO this is for reading out positions, readout is limited by stage triggering
def _while_in_motion(self, thread_id: int, n_samples: int) -> tuple: def _while_in_motion(self, thread_id: int, n_samples: int) -> tuple:
last_readout = 0 last_readout = 0
@ -680,21 +691,30 @@ class SGalilMotor(Device, PositionerBase):
self.controller.stop_all_axes() self.controller.stop_all_axes()
return super().stop(success=success) return super().stop(success=success)
def kickoff( def kickoff(self) -> DeviceStatus:
status = DeviceStatus(self)
self.controller.fly_grid_scan(
status,
self._kickoff_params.get("start_y"),
self._kickoff_params.get("end_y"),
self._kickoff_params.get("interval_y"),
self._kickoff_params.get("start_x"),
self._kickoff_params.get("end_x"),
self._kickoff_params.get("interval_x"),
self._kickoff_params.get("exp_time"),
self._kickoff_params.get("readout_time"),
)
return status
def configure(
self, self,
metadata: dict, parameter: dict,
**kwargs, **kwargs,
) -> None: ) -> None:
self.controller.fly_grid_scan( self._kickoff_params = parameter
kwargs.get("start_y"),
kwargs.get("end_y"),
kwargs.get("interval_y"),
kwargs.get("start_x"),
kwargs.get("end_x"),
kwargs.get("interval_x"),
kwargs.get("exp_time"),
kwargs.get("readout_time"),
)
if __name__ == "__main__": if __name__ == "__main__":