From 623969de3496882e1ec6e9f2313f3c38c4c2e973 Mon Sep 17 00:00:00 2001 From: smathis Date: Tue, 22 Jul 2025 13:49:17 +0200 Subject: [PATCH] Renamed folder sinqAxis to sinqMotor --- tests/sinqMotor/__init__.py | 0 tests/sinqMotor/home.py | 41 +++++++++++++++++++ tests/sinqMotor/limits.py | 21 ++++++++++ tests/sinqMotor/turboPmac/__init__.py | 0 tests/sinqMotor/turboPmac/lin1/__init__.py | 0 tests/sinqMotor/turboPmac/lin1/prepare.py | 9 ++++ tests/sinqMotor/turboPmac/rot1/__init__.py | 0 tests/sinqMotor/turboPmac/rot1/conftest.py | 25 +++++++++++ tests/sinqMotor/turboPmac/rot1/test_common.py | 18 ++++++++ 9 files changed, 114 insertions(+) create mode 100644 tests/sinqMotor/__init__.py create mode 100644 tests/sinqMotor/home.py create mode 100644 tests/sinqMotor/limits.py create mode 100644 tests/sinqMotor/turboPmac/__init__.py create mode 100644 tests/sinqMotor/turboPmac/lin1/__init__.py create mode 100644 tests/sinqMotor/turboPmac/lin1/prepare.py create mode 100644 tests/sinqMotor/turboPmac/rot1/__init__.py create mode 100644 tests/sinqMotor/turboPmac/rot1/conftest.py create mode 100644 tests/sinqMotor/turboPmac/rot1/test_common.py diff --git a/tests/sinqMotor/__init__.py b/tests/sinqMotor/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/sinqMotor/home.py b/tests/sinqMotor/home.py new file mode 100644 index 0000000..3a3d1d7 --- /dev/null +++ b/tests/sinqMotor/home.py @@ -0,0 +1,41 @@ +import time + + +def home(motor, forward): + + encoder = motor.read_field('encoder_type') + if encoder == 'absolute': + is_absolute = True + elif encoder == 'incremental': + is_absolute = False + else: + raise ValueError(f'Unknown encoder type {encoder}') + + # Start a homing run and observe the motor behaviour depending on the + # encoder type + if forward: + motor.write_field('homeforward') + else: + motor.write_field('homereverse') + + # Give the record some time to react + time.sleep(0.5) + + if is_absolute: + # Motor should not move at all + assert motor.read_field('moving') == 0 + assert motor.read_field('donemoving') == 1 + assert not motor.has_error() + else: + # Motor should start movement + assert motor.read_field('moving') == 1 + assert motor.read_field('donemoving') == 0 + assert not motor.has_error() + assert not motor.is_homed() + + motor.wait_for_done() + + assert motor.read_field('moving') == 0 + assert motor.read_field('donemoving') == 1 + assert not motor.has_error() + assert motor.is_homed() diff --git a/tests/sinqMotor/limits.py b/tests/sinqMotor/limits.py new file mode 100644 index 0000000..fd28202 --- /dev/null +++ b/tests/sinqMotor/limits.py @@ -0,0 +1,21 @@ +import time + + +def reread_limits_from_hw(motor): + """ + sinqAxis motors usually read their limits from the hardware at each poll, + hence any values manually written to DHLM or DLLM should be overwritten + after the next poll at latest + """ + (high_limit, low_limit) = motor.limits() + motor.write_field('dialhighlimit', high_limit-+10) + motor.write_field('diallowlimit', low_limit-10) + + # After two seconds, at least one poll has been done + time.sleep(2) + + # Values should have been reread + assert motor.read_field('highlimit') == high_limit + assert motor.read_field('lowlimit') == low_limit + assert motor.read_field('dialhighlimit') == high_limit + assert motor.read_field('diallowlimit') == low_limit diff --git a/tests/sinqMotor/turboPmac/__init__.py b/tests/sinqMotor/turboPmac/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/sinqMotor/turboPmac/lin1/__init__.py b/tests/sinqMotor/turboPmac/lin1/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/sinqMotor/turboPmac/lin1/prepare.py b/tests/sinqMotor/turboPmac/lin1/prepare.py new file mode 100644 index 0000000..4d57e15 --- /dev/null +++ b/tests/sinqMotor/turboPmac/lin1/prepare.py @@ -0,0 +1,9 @@ +# Prepare + +import pytest +from common import TurboPMAC + + +@pytest.fixture +def lin1(): + return TurboPMAC() diff --git a/tests/sinqMotor/turboPmac/rot1/__init__.py b/tests/sinqMotor/turboPmac/rot1/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/sinqMotor/turboPmac/rot1/conftest.py b/tests/sinqMotor/turboPmac/rot1/conftest.py new file mode 100644 index 0000000..75299de --- /dev/null +++ b/tests/sinqMotor/turboPmac/rot1/conftest.py @@ -0,0 +1,25 @@ +# This module defines fixtures which are shared for all tests of motor "rot1". + +import pytest +from common import TurboPMAC, read_config + + +@pytest.fixture(autouse=True) +def motor(): + config = read_config() + return TurboPMAC(config['controllers']['turboPmac1']['ip'], + config['controllers']['turboPmac1']['port'], + config['pvprefix'] + 'turboPmac1:rot1') + + +def reset(motor): + """ + Reset the motor for the next test. This means the following things: + 1) Resetting all errors + 2) Enabling the motor + 3) Moving to zero + """ + motor.write_field('stop', 1) + motor.write_field('reseterrorpv', 1) + motor.write_field('enable', 1) + motor.move_and_wait(0) diff --git a/tests/sinqMotor/turboPmac/rot1/test_common.py b/tests/sinqMotor/turboPmac/rot1/test_common.py new file mode 100644 index 0000000..11829fa --- /dev/null +++ b/tests/sinqMotor/turboPmac/rot1/test_common.py @@ -0,0 +1,18 @@ +# Run a selection of common tests + +from tests.move import * +from tests.sinqAxis.limits import * +from tests.sinqAxis.turboPmac.rot1.conftest import reset + + +# def test_move_to_low_limit_switch(motor): +# reset(motor) +# move_to_low_limit_switch(motor) + + +# def test_move_to_high_limit_switch(motor): +# reset(motor) +# move_to_high_limit_switch(motor) + +def test_reread_limits_from_hw(motor): + reread_limits_from_hw(motor)