Skip to content

Commit

Permalink
allowing for bypassing detune check during motor move
Browse files Browse the repository at this point in the history
  • Loading branch information
lisazacarias committed Feb 8, 2024
1 parent 6510b5b commit 9faad68
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions lcls_tools/superconducting/scLinac.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
################################################################################
from datetime import datetime
from time import sleep
from typing import Callable, Dict, List, Type, Optional
from typing import Callable, Dict, List, Optional, Type

from numpy import sign

Expand Down Expand Up @@ -480,39 +480,48 @@ def move(
maxSteps: int = utils.DEFAULT_STEPPER_MAX_STEPS,
speed: int = utils.DEFAULT_STEPPER_SPEED,
changeLimits: bool = True,
check_detune: bool = True,
):
"""
:param numSteps: positive for increasing cavity length, negative for decreasing
:param maxSteps: the maximum number of steps allowed at once
:param speed: the speed of the motor in steps/second
:param changeLimits: whether to change the speed and steps
:param check_detune: whether to check for valid detune after each move
:return:
"""

self.check_abort()
maxSteps = abs(maxSteps)

if changeLimits:
# on the off chance that someone tries to write a negative maximum
self.max_steps = abs(maxSteps)
self.max_steps = maxSteps

# make sure that we don't exceed the speed limit as defined by the tuner experts
self.speed = (
speed if speed < utils.MAX_STEPPER_SPEED else utils.MAX_STEPPER_SPEED
)

if abs(numSteps) <= maxSteps:
print(f"{self.cavity} {numSteps} steps <= {maxSteps} max")
print(f"{self.cavity} {abs(numSteps)} steps <= {maxSteps} max")
self.step_des = abs(numSteps)
self.issueMoveCommand(numSteps)
self.issueMoveCommand(numSteps, check_detune=check_detune)
self.restoreDefaults()
else:
print(f"{self.cavity} {numSteps} steps > {maxSteps} max")
print(f"{self.cavity} {abs(numSteps)} steps > {maxSteps} max")
self.step_des = maxSteps
self.issueMoveCommand(numSteps)
self.issueMoveCommand(numSteps, check_detune=check_detune)
print(f"{self.cavity} moving {numSteps - (sign(numSteps) * maxSteps)}")
self.move(numSteps - (sign(numSteps) * maxSteps), maxSteps, speed, False)
self.move(
numSteps - (sign(numSteps) * maxSteps),
maxSteps,
speed,
changeLimits=False,
check_detune=check_detune,
)

def issueMoveCommand(self, numSteps):
def issueMoveCommand(self, numSteps: int, check_detune: bool = True):
# this is necessary because the tuners for the HLs move the other direction
if self.cavity.cryomodule.is_harmonic_linearizer:
numSteps *= -1
Expand All @@ -527,7 +536,8 @@ def issueMoveCommand(self, numSteps):

while self.motor_moving:
self.check_abort()
self.cavity.check_detune()
if check_detune:
self.cavity.check_detune()
print(f"{self} motor still moving, waiting 5s", datetime.now())
sleep(5)

Expand Down Expand Up @@ -1696,7 +1706,7 @@ def __init__(
stepper_class=StepperTuner,
piezo_class=Piezo,
):
# type: (str, Linac, Type[Cavity], Type[Magnet], Type[Rack], bool, Type[SSA], Type[StepperTuner], Type[Piezo],) -> None # noqa: E501
# type: (str, Linac, Type[Cavity], Type[Magnet], Type[Rack], bool, Type[SSA], Type[StepperTuner], Type[Piezo]) -> None # noqa: E501
"""
Parameters
----------
Expand Down

0 comments on commit 9faad68

Please sign in to comment.