diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7d40575..53800f3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,11 +1,12 @@ # This file is a template, and might need editing before it works on your project. # Official language image. Look for the different tagged releases at: # https://hub.docker.com/r/library/python/tags/ -image: "python:3.8" +image: python:3.8 + #commands to run in the Docker container before starting each job. before_script: - pip install -r ./requirements.txt - - pip install -e . + - pip install -e . # different stages in the pipeline stages: - Formatter @@ -18,7 +19,6 @@ formatter: pytest: stage: Test script: - - apt-get update && apt-get install -y git - - git clone https://oauth2:$CI_BEC_KEY@gitlab.psi.ch/bec/bec.git - - pip install -e ./bec/bec_utils - - pytest -v ./tests + - git clone https://oauth2:$CI_BEC_KEY@gitlab.psi.ch/bec/bec.git + - pip install -e ./bec/bec_utils + - pytest -v ./tests diff --git a/ophyd_devices/galil/galil_ophyd.py b/ophyd_devices/galil/galil_ophyd.py index 694f1f0..261e330 100644 --- a/ophyd_devices/galil/galil_ophyd.py +++ b/ophyd_devices/galil/galil_ophyd.py @@ -134,8 +134,10 @@ class GalilController(Controller): f"Expected return value of ':' but instead received {return_val}" ) - def is_axis_moving(self, axis_Id) -> bool: - return bool(float(self.socket_put_and_receive(f"MG_BG{axis_Id}"))) + def is_axis_moving(self, axis_Id, axis_Id_numeric) -> bool: + is_moving = bool(float(self.socket_put_and_receive(f"MG_BG{axis_Id}")) != 0) + backlash_is_active = bool(float(self.socket_put_and_receive(f"MGbcklact[axis]")) != 0) + return bool(is_moving or backlash_is_active) def is_thread_active(self, thread_id: int) -> bool: val = float(self.socket_put_and_receive(f"MG_XQ{thread_id}")) @@ -250,12 +252,13 @@ class GalilReadbackSignal(GalilSignalRO): return current_pos / step_mm def read(self): + self._metadata["timestamp"] = time.time() val = super().read() if self.parent.axis_Id_numeric == 2: try: - self.parent.device_manager.devices[ - self.parent.rt - ].obj.controller.set_rotation_angle(val[self.parent.name]["value"]) + rt = self.parent.device_manager.devices[self.parent.rt] + if rt.enabled: + rt.obj.controller.set_rotation_angle(val[self.parent.name]["value"]) except KeyError: logger.warning("Failed to set RT value during readback.") return val @@ -305,6 +308,8 @@ class GalilSetpointSignal(GalilSignalBase): self.controller.socket_put_confirmed(f"ntarget={target_val:.3f}") self.controller.socket_put_confirmed("movereq=1") self.controller.socket_put_confirmed("XQ#NEWPAR") + while self.controller.is_thread_active(0): + time.sleep(0.005) else: raise GalilError("Not all axes are referenced.") @@ -322,7 +327,7 @@ class GalilMotorIsMoving(GalilSignalRO): @threadlocked def _socket_get(self): return ( - self.controller.is_axis_moving(self.parent.axis_Id) + self.controller.is_axis_moving(self.parent.axis_Id, self.parent.axis_Id_numeric) or self.controller.is_thread_active(0) or self.controller.is_thread_active(2) ) @@ -493,9 +498,10 @@ class GalilMotor(Device, PositionerBase): position, atol=self.tolerance, ) - self._done_moving(success=success) + if not success: print(" stop") + self._done_moving(success=success) logger.info("Move finished") threading.Thread(target=move_and_finish, daemon=True).start() diff --git a/ophyd_devices/rt_lamni/rt_lamni_ophyd.py b/ophyd_devices/rt_lamni/rt_lamni_ophyd.py index 0d4433b..1bd22a8 100644 --- a/ophyd_devices/rt_lamni/rt_lamni_ophyd.py +++ b/ophyd_devices/rt_lamni/rt_lamni_ophyd.py @@ -363,7 +363,7 @@ class RtLamniController(Controller): mode, number_of_positions_planned, current_position_in_scan = self.get_scan_status() time.sleep(0.01) if current_position_in_scan > 5: - while current_position_in_scan > read_counter: + while current_position_in_scan > read_counter + 1: return_table = (self.socket_put_and_receive(f"r{read_counter}")).split(",") # logger.info(f"{return_table}") logger.info(f"Read {read_counter} out of {number_of_positions_planned}") diff --git a/ophyd_devices/utils/socket.py b/ophyd_devices/utils/socket.py index 30a9cce..858f5c5 100644 --- a/ophyd_devices/utils/socket.py +++ b/ophyd_devices/utils/socket.py @@ -6,10 +6,12 @@ import time import typing import numpy as np +from bec_utils import bec_logger from ophyd import Signal from ophyd.utils.errors import DisconnectedError -logger = logging.getLogger("socket") +logger = bec_logger.logger +# logger = bec_logger.logger("socket") def raise_if_disconnected(fcn): diff --git a/tests/test_galil.py b/tests/test_galil.py index ba98480..4d60a19 100644 --- a/tests/test_galil.py +++ b/tests/test_galil.py @@ -40,6 +40,7 @@ def test_axis_get(pos, msg, sign): b"ntarget=0.000\r", b"movereq=1\r", b"XQ#NEWPAR\r", + b"MG_XQ0\r", ], [ b"1.00", @@ -48,6 +49,7 @@ def test_axis_get(pos, msg, sign): b":", b":", b":", + b"-1", ], ), ], diff --git a/tests/test_socket.py b/tests/test_socket.py index f02d74a..dc33c0d 100644 --- a/tests/test_socket.py +++ b/tests/test_socket.py @@ -1,5 +1,5 @@ -import pytest import socket + from ophyd_devices.utils.socket import SocketIO