Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add preset support for SQR1 #1255

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
IssueNumber Title
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you run the script to generate this file? I'm surprised the filename is standard but the title here isn't

#################

API Breaks
----------
- N/A

Features
--------
- N/A

Device Updates
--------------
- `sqr1` add preset support

New Devices
-----------
- N/A

Bugfixes
--------
- N/A

Maintenance
-----------
- N/A

Contributors
------------
- baljamal
30 changes: 29 additions & 1 deletion pcdsdevices/sqr1.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note: the new functionality you've added here is unit-testable if you have the time

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
from ophyd.status import MoveStatus as StatusBase
from ophyd.status import wait as status_wait

from pcdsdevices.interface import FltMvInterface

logger = logging.getLogger(__name__)


Expand All @@ -45,7 +47,7 @@ class Axis(str, enum.Enum):
rZ = 'rZ'


class SQR1Axis(PVPositionerIsClose):
class SQR1Axis(FltMvInterface, PVPositionerIsClose):
"""
Single axis of the square-one tri-sphere motion system.

Expand Down Expand Up @@ -290,6 +292,7 @@ def sync_setpoints(self):

def multi_axis_move(
self,
preset_pos: str | None = None,
x_sp: float | None = None,
y_sp: float | None = None,
z_sp: float | None = None,
Expand All @@ -304,6 +307,8 @@ def multi_axis_move(

Parameters
----------
preset_pos: str or None, optional
Move to a preset position labeled by the preset_pos string.
x_sp : float or None, optional
The desired position for the X-axis.If None (default), the current
position is used.
Expand Down Expand Up @@ -343,6 +348,19 @@ def multi_axis_move(
>>> tri_sphere = SQR1(prefix="SQR1:", name="tri_sphere")
>>> status = tri_sphere.multi_axis_move(x_sp=1.0, y_sp=2.0, z_sp=3.0)
"""

if preset_pos is not None:
axis_list = [self.x, self.y, self.z, self.rz, self.ry, self.rz]
if any(hasattr(a.presets.positions, preset_pos) for a in axis_list):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intended to be all instead of any, to force all the presets to exist before moving?

x_sp = (getattr(self.x.presets.positions, preset_pos)).pos
y_sp = (getattr(self.y.presets.positions, preset_pos)).pos
z_sp = (getattr(self.z.presets.positions, preset_pos)).pos
rx_sp = (getattr(self.rx.presets.positions, preset_pos)).pos
ry_sp = (getattr(self.ry.presets.positions, preset_pos)).pos
rz_sp = (getattr(self.rz.presets.positions, preset_pos)).pos
else:
logger.error('One of the axes is missing the desired state.')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this return or raise as well in the error state to prevent the rest of the function from running?


x_sp = self.x.readback.get() if x_sp is None else x_sp
y_sp = self.y.readback.get() if y_sp is None else y_sp
z_sp = self.z.readback.get() if z_sp is None else z_sp
Expand Down Expand Up @@ -373,3 +391,13 @@ def multi_axis_move(
def stop(self):
"""stop command for all axes."""
self.stop_signal.put(self.stop_value)

def preset_list(self):
"""return a list of preset positions."""
preset_list = []
axis_list = [self.x, self.y, self.z, self.rz, self.ry, self.rz]
for axis in axis_list:
for preset in list(vars(axis.presets.positions).keys()):
if preset not in preset_list:
preset_list.append(preset)
return preset_list