Skip to content

Commit 6b237f7

Browse files
authored
Update Reflectometry-Config-Training-‐-Exercise-2.md
1 parent 4062f39 commit 6b237f7

File tree

1 file changed

+114
-10
lines changed

1 file changed

+114
-10
lines changed

doc/specific_iocs/reflectometry/config_training/Reflectometry-Config-Training-‐-Exercise-2.md

Lines changed: 114 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The slits have already been set up with the addition of the `jaws.cmd` during th
2222
You will need to add a constant for the distance to these slits, `S1_Z`, which needs to be set to `10.0`.
2323
You can add slit parameters to your config with a helper method, e.g.:`add_slit_parameters(slit_number=1, include_centres=True)`, for this slit set the centres should be included.
2424
As with the supermirror in the previous exercise add a component for the slits, using `0.0`, `S1_Z`, and the `NATURAL_ANGLE` to set the `PositionAndAngle` of the component.
25-
Add another parameter here, but this time the axis parameter is a `POSITION` related to the height of the slit set.
25+
Add another parameter here, but this time the axis parameter is a `POSITION` related to the height of the slit set, which has to be called `S1OFFSET`.
2626
Add the driver for that parameter pointing at `MTR0301`.
2727

2828
### 2. Add Slit 2
@@ -31,24 +31,128 @@ The slits have already been set up with the addition of the `jaws.cmd` during th
3131
You will need to add a constant for the distance to these slits, `S2_Z`, which needs to be set to `S1_Z + 10`. Whilst these distances can be absolute, they are often given as relative to the previous item on the beamline.
3232
Add the slit parameters to your config with the helper method, including the centres and making sure you set the `slit_number` to `2`.
3333
As previously add a component for these slits, using `0.0`, `S2_Z`, and the `NATURAL_ANGLE` to set the `PositionAndAngle` of the component.
34-
Add another parameter here, but this time the axis parameter is a `POSITION` related to the height of the slit set.
34+
Add another parameter here, called `S2OFFSET`, with a `POSITION` axis parameter related to the height of the slit set.
3535
Add the driver for that parameter pointing at `MTR0302`.
3636

3737
### 3. Add the Sample stack
3838
The sample is placed after Slits 2.
3939
We added in the axes for this during the setup via the `axes.cmd`.
4040
Again, a distance will be needed, this time it is `SAMPLE_Z` and should be set to `S2_Z + 10.0`.
41-
Add parameters and drivers for the height, translation, phi, and psi.
41+
Add parameters and drivers for the height, translation, phi, and psi, which should be called `SAMPOFFSET`, `SAMPTRANS`, `SAMPPHI`, and `SAMPPSI`.
4242
The height (or vertical position) is a `POSITION` axis, on motor `MTR0307`, phi (or the pitch) is an `ANGLE` on `MTR0306`, psi (or the roll) is a `PSI` on `MTR0308`, and the translation (or horizontal position) is a `TRANS` on `MTR0305`.
4343
Perhaps counterintuitively, we do not want the sample to change the beam path! While the sample reflects the beam in the physical world, in the reflectometry server this is handled via a special parameter "Theta" which we will talk about more later. We do, however, want this component to track the beam in both height and angle, so it's a `TiltingComponent`.
4444

4545
## To Test
4646
Once you have added all these components, you should now be able to set the parameters and see the related motor axes move as in the previous exercise. You now also have enough in your beamline model to see beamline parameters react to changes in the beam.
4747
1. Go to the table of motors and make sure all are at a `0` position.
48-
1. Restart the IOC to pick up the updated `config.py`.
49-
1. Set an angle SP for `sm_angle`. I recommend 22.5 as this results in a reflection angle of 45 degrees - this produces tracked positions for downstream components that are easy to understand.
50-
1. When you move `sm_angle` to this setpoint you should now see the RBV of all downstream components change. This is because while the physical axes have not moved, the *beam* has, so their relative positions are now different.
51-
- `s2_offset` should read equivalent to its distance due to the 45 degree angle i.e. **-10** (negative because it is still centred on the natural beam i.e. below the new reflected beam
52-
- `sa_offset` similar to `s2_offset` i.e. should be at -20
53-
- `sa_phi` as still sitting perpendicular to the natural beam, but the reflected beam has been bounced up 45 degrees, i.e. this should now read back -45
54-
1. If you now click move on any of the downstream parameters, you should see it re-apply its last SP of 0, i.e. move to re-centre itself on the new, reflected beam. The Motor axis should now read back the offset required to move these parameters back into the beam i.e. 10, 20 and 45 respectively.
48+
2. Restart the IOC to pick up the updated `config.py`.
49+
3. When you look at the `Front Panel` you should now see fewer disconnected items, similarly there should be more values available in the following tabs.
50+
4. If you go to the `Collimation` tab, and set the SP of `SMANGLE` to `22.5` (this results in a reflection angle of 45 degrees - which produces tracked positions for downstream components that are easy to understand), when you click on `Move` you should now see the RBV of all downstream components change. This is because while the physical axes have not moved, the *beam* has, so their relative positions are now different.
51+
- `S2OFFSET` should read equivalent to its distance due to the 45 degree angle i.e. **-10** (negative because it is still centred on the natural beam i.e. below the new reflected beam
52+
- `SAMPOFFSET` similar to `S2OFFSET` i.e. should be at -20
53+
- `SAMPPHI` as still sitting perpendicular to the natural beam, but the reflected beam has been bounced up 45 degrees, i.e. this should now read back -45
54+
5. At this stage, if you look at the table of motors, only the supermirror angle will have moved, everything else is reported according to the relationship to the beam.
55+
6. If you now click move on any of the downstream parameters, you should see it re-apply its last SP of 0, i.e. move to re-centre itself on the new, reflected beam. When the move has finished the `Collimation` tab in the reflectometry perspective should have 0s for everthying except `SMANGLE`. The appropriate motor axes on the table of motors should now read back the offset required to move these parameters back into the beam i.e. 10, 20 and 45 respectively, alongside the value of 22.5 for the supermirror angle.
56+
57+
## Solution
58+
<details>
59+
<summary>Should you have trouble the following is what the code could look like</summary>
60+
61+
```python
62+
from typing import Dict
63+
64+
from ReflectometryServer.beamline import Beamline
65+
from ReflectometryServer.beamline_constant import BeamlineConstant
66+
from ReflectometryServer.components import (
67+
Component,
68+
ReflectingComponent,
69+
TiltingComponent,
70+
)
71+
from ReflectometryServer.config_helper import (
72+
add_component,
73+
add_constant,
74+
add_driver,
75+
add_mode,
76+
add_parameter,
77+
add_slit_parameters,
78+
get_configured_beamline,
79+
)
80+
from ReflectometryServer.geometry import ChangeAxis, PositionAndAngle
81+
from ReflectometryServer.ioc_driver import IocDriver
82+
from ReflectometryServer.parameters import AxisParameter
83+
from ReflectometryServer.pv_wrapper import MotorPVWrapper
84+
85+
# Beamline Constants
86+
NATURAL_ANGLE = 90
87+
S1_Z = 10.0
88+
SM_Z = 20.0
89+
S2_Z = SM_Z + 10.0
90+
SAMPLE_Z = S2_Z + 10.0
91+
92+
93+
def get_beamline(macros: Dict[str, str]) -> Beamline:
94+
#########################
95+
# FIXED BEAMLINE VALUES #
96+
#########################
97+
98+
# Constants
99+
add_constant(
100+
BeamlineConstant(
101+
"NATURAL_ANGLE",
102+
NATURAL_ANGLE,
103+
"The difference between the beam and straight through",
104+
)
105+
)
106+
add_constant(BeamlineConstant("S1_Z", S1_Z, "The distance to slits 1"))
107+
add_constant(BeamlineConstant("SM_Z", SM_Z, "The distance to the supermirror"))
108+
add_constant(BeamlineConstant("S2_Z", S2_Z, "The distance to slits 2"))
109+
110+
# Modes
111+
nr = add_mode("NR")
112+
113+
##############################
114+
# BEAMLINE MODEL STARTS HERE #
115+
##############################
116+
117+
# Slits 1
118+
add_slit_parameters(1, include_centres=True)
119+
s1_comp = add_component(Component("s1", PositionAndAngle(0.0, S1_Z, NATURAL_ANGLE)))
120+
add_parameter(AxisParameter("S1OFFSET", s1_comp, ChangeAxis.POSITION, nr))
121+
add_driver(IocDriver(s1_comp, ChangeAxis.POSITION, MotorPVWrapper("MOT:MTR0301")))
122+
123+
# Mirror
124+
mirror_comp = add_component(
125+
ReflectingComponent("Mirror", PositionAndAngle(0, SM_Z, NATURAL_ANGLE))
126+
)
127+
add_parameter(AxisParameter("SMANGLE", mirror_comp, ChangeAxis.ANGLE, nr))
128+
add_parameter(AxisParameter("SMOFFSET", mirror_comp, ChangeAxis.POSITION, nr))
129+
add_driver(IocDriver(mirror_comp, ChangeAxis.ANGLE, MotorPVWrapper("MOT:MTR0207")))
130+
add_driver(
131+
IocDriver(mirror_comp, ChangeAxis.POSITION, MotorPVWrapper("MOT:MTR0206"))
132+
)
133+
134+
# Slits 2
135+
add_slit_parameters(2, include_centres=True)
136+
s2_comp = add_component(Component("s2", PositionAndAngle(0.0, S2_Z, NATURAL_ANGLE)))
137+
add_parameter(AxisParameter("S2OFFSET", s2_comp, ChangeAxis.POSITION, nr))
138+
add_driver(IocDriver(s2_comp, ChangeAxis.POSITION, MotorPVWrapper("MOT:MTR0302")))
139+
140+
# SAMPLE
141+
sample_comp = add_component(
142+
TiltingComponent("sample", PositionAndAngle(0, SAMPLE_Z, NATURAL_ANGLE))
143+
)
144+
add_parameter(AxisParameter("SAMPOFFSET", sample_comp, ChangeAxis.POSITION, nr))
145+
add_parameter(AxisParameter("SAMPPHI", sample_comp, ChangeAxis.ANGLE, nr))
146+
add_parameter(AxisParameter("SAMPPSI", sample_comp, ChangeAxis.PSI, nr))
147+
add_parameter(AxisParameter("SAMPTRANS", sample_comp, ChangeAxis.TRANS))
148+
add_driver(
149+
IocDriver(sample_comp, ChangeAxis.POSITION, MotorPVWrapper("MOT:MTR0307"))
150+
)
151+
add_driver(IocDriver(sample_comp, ChangeAxis.ANGLE, MotorPVWrapper("MOT:MTR0306")))
152+
add_driver(IocDriver(sample_comp, ChangeAxis.PSI, MotorPVWrapper("MOT:MTR0308")))
153+
add_driver(IocDriver(sample_comp, ChangeAxis.TRANS, MotorPVWrapper("MOT:MTR0305")))
154+
155+
return get_configured_beamline()
156+
157+
```
158+
</details>

0 commit comments

Comments
 (0)