-
Notifications
You must be signed in to change notification settings - Fork 12
Add ability to move scintillator in to beam for i04 #1583
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
Changes from 20 commits
f209271
1efa5fd
5b747e2
f61d124
542db18
05453f9
512a942
aa826be
ba13e02
9d71e54
ec986c0
c5be74b
2aaf02f
fb5f26c
01d6f02
21b3eca
4ac32ae
ebd1f6c
d4a74c1
5fd13a6
7d9e676
9479360
78ba2f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,9 +8,10 @@ | |
|
|
||
|
|
||
| class InOut(StrictEnum): | ||
| """Currently Hyperion only needs to move the scintillator out for data collection.""" | ||
| """Moves scintillator in and out of the beam.""" | ||
|
|
||
| OUT = "Out" | ||
| OUT = "Out" # Out of beam | ||
| IN = "In" # In to beam | ||
| UNKNOWN = "Unknown" | ||
|
|
||
|
|
||
|
|
@@ -45,42 +46,63 @@ def __init__( | |
| self._scintillator_out_yz_mm = [ | ||
| float(beamline_parameters[f"scin_{axis}_SCIN_OUT"]) for axis in ("y", "z") | ||
| ] | ||
| self._scintillator_in_yz_mm = [ | ||
| float(beamline_parameters[f"scin_{axis}_SCIN_IN"]) for axis in ("y", "z") | ||
| ] | ||
| self._yz_tolerance_mm = [ | ||
| float(beamline_parameters[f"scin_{axis}_tolerance"]) for axis in ("y", "z") | ||
| ] | ||
|
|
||
| super().__init__(name) | ||
|
|
||
| def _get_selected_position(self, y: float, z: float) -> InOut: | ||
| current_pos = [y, z] | ||
| if all( | ||
| def _check_position(self, current_pos: list[float], pos_to_check: list[float]): | ||
| return all( | ||
| isclose(axis_pos, axis_in_beam, abs_tol=axis_tolerance) | ||
| for axis_pos, axis_in_beam, axis_tolerance in zip( | ||
| current_pos, | ||
| self._scintillator_out_yz_mm, | ||
| pos_to_check, | ||
| self._yz_tolerance_mm, | ||
| strict=False, | ||
| ) | ||
| ): | ||
| ) | ||
|
|
||
| def _get_selected_position(self, y: float, z: float) -> InOut: | ||
| current_pos = [y, z] | ||
| if self._check_position(current_pos, self._scintillator_out_yz_mm): | ||
| return InOut.OUT | ||
|
|
||
| elif self._check_position(current_pos, self._scintillator_in_yz_mm): | ||
| return InOut.IN | ||
|
|
||
| else: | ||
| return InOut.UNKNOWN | ||
|
|
||
| async def _check_aperture_parked(self): | ||
| if ( | ||
| await self._aperture_scatterguard().selected_aperture.get_value() | ||
| != ApertureValue.PARKED | ||
| ): | ||
| raise ValueError( | ||
| f"Cannot move scintillator if aperture/scatterguard is not parked. Position is currently {await self._aperture_scatterguard().selected_aperture.get_value()}" | ||
| ) | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is self._aperture_scatterguard().selected_aperture.get_value(), what we want here? I noticed that sometimes the error gives out Large or Small rather than an actual position - is that expected, and should I be testing that the correct error message is outputted?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's correct, the positions it can have are Large/Medium/Small |
||
| async def _set_selected_position(self, position: InOut) -> None: | ||
| match position: | ||
| case InOut.OUT: | ||
| current_y = await self.y_mm.user_readback.get_value() | ||
| current_z = await self.z_mm.user_readback.get_value() | ||
| if self._get_selected_position(current_y, current_z) == InOut.OUT: | ||
| return | ||
| if ( | ||
| self._aperture_scatterguard().selected_aperture.get_value() | ||
| != ApertureValue.PARKED | ||
| ): | ||
| raise ValueError( | ||
| "Cannot move scintillator out if aperture/scatterguard is not parked" | ||
| ) | ||
| await self._check_aperture_parked() | ||
| await self.y_mm.set(self._scintillator_out_yz_mm[0]) | ||
| await self.z_mm.set(self._scintillator_out_yz_mm[1]) | ||
| case InOut.IN: | ||
| current_y = await self.y_mm.user_readback.get_value() | ||
| current_z = await self.z_mm.user_readback.get_value() | ||
| if self._get_selected_position(current_y, current_z) == InOut.IN: | ||
| return | ||
| await self._check_aperture_parked() | ||
| await self.z_mm.set(self._scintillator_in_yz_mm[1]) | ||
| await self.y_mm.set(self._scintillator_in_yz_mm[0]) | ||
| case _: | ||
| raise ValueError(f"Cannot set scintillator to position {position}") | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could: This seems unrelated so technically shouldn't be part of this PR but it's just some docs so fine to keep here