Files
motorDriverTests/setup/move.py
Stefan Mathis 7ab4486748 Restructured the test setup
General test configurations are now separated from specific axis test
definitions.
2025-08-11 12:01:37 +02:00

74 lines
2.1 KiB
Python
Executable File

import time
import pytest
from setup.classes import StartTimeoutError
def move_to_low_limit_switch(motor):
low_limit = motor.limits()[0]
motor.move_and_wait(low_limit)
assert motor.at_target()
# Field is currently not set in our drivers
#assert motor.get_pv('lowlimitswitch') == 1
assert not motor.has_error()
def move_to_high_limit_switch(motor):
low_limit = motor.limits()[1]
motor.move_and_wait(low_limit)
assert motor.at_target()
# Field is currently not set in our drivers
#assert motor.get_pv('highlimitswitch') == 1
assert not motor.has_error()
def move_while_move(motor, first_target, second_target, time_first_target):
"""
Start moving to a position which is sufficiently far away, then interrupt
this move command with another move command. This function assumes a
sufficiently large distance between the current motor position and
first_target so it has enough time to issue the second move command.
"""
motor.put_pv('writepv', first_target)
time.sleep(time_first_target)
motor.move_and_wait(second_target)
assert motor.at_target(second_target)
assert not motor.has_error()
def stop_then_move(motor, target):
motor.put_pv('stop', 1)
motor.wait_for_done()
motor.move_and_wait(target)
def stop(motor, target):
"""
Stop an motor while it is moving to a target. This function assumes a
sufficiently large distance between the current motor position and target.
"""
motor.put_pv('writepv', target)
time.sleep(1)
motor.put_pv('stop', 1)
motor.wait_for_done()
assert not motor.at_target(target)
assert not motor.has_error()
def invalid_target(motor, target):
current_pos = motor.get_pv('readpv')
try:
motor.move_and_wait(target)
pytest.fail('move_and_wait should throw a StartTimeoutError error')
except StartTimeoutError:
assert motor.at_target(current_pos)
def targets_outside_limits(motor):
"""
Try to move the motor outside its limits
"""
invalid_target(motor, motor.get_pv('lowlimit') - 10)
invalid_target(motor, motor.get_pv('highlimit') + 10)