Skip to content

Commit d520e5b

Browse files
author
Kay Kasemir (ky9)
committed
Alignment: Phoebus update
1 parent 336edf0 commit d520e5b

20 files changed

+1023
-1980
lines changed

clean

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
# Delete files generated by python and jython
3+
find . -name '*.class' -exec rm {} \;
4+
find . -name *.pyc -exec rm {} \;
5+
6+
# Delete doc
7+
(cd doc; make clean)
8+
9+
# Remove setup/bdist
10+
rm -rf build dist

doc/alignment_scan.png

58.8 KB
Loading

doc/commands.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
.. _scan_commands:
2-
31
Scan Commands
42
=============
53

doc/getting_started.rst

Lines changed: 88 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,84 +9,106 @@ Initial Setup
99
We assume that you already have a recent version of EPICS base installed
1010
with access to commands like `softIoc`, `caget`, `caput`.
1111

12-
Prepare the PyScanClient::
12+
Prepare the PyScanClient library and examples::
1313

1414
git clone https://github.com/PythonScanClient/PyScanClient.git
1515
cd PyScanClient
1616
python setup.py build
17+
export PYSCANCLIENT=`pwd`
1718

18-
In here, we don't "install" the library
19-
but simply access it via the python path.
20-
In addition, we list the folder with examples to be used later
21-
in the path::
22-
23-
export PYTHONPATH=`pwd`/build/lib:`pwd`/example
19+
In here, we don't "install" the library but simply access it via the python path.
20+
In addition to the library, clients also need access to the examples,
21+
so we add both to the path used by C-Python::
22+
23+
export PYTHONPATH=$PYSCANCLIENT/build/lib:$PYSCANCLIENT/example
2424

2525
The scan server is a CS-Studio service.
2626
Both the scan server and the CS-Studio GUI can be built
2727
from https://github.com/ControlSystemStudio/phoebus.
2828
More convenient binaries are available from
2929
https://controlssoftware.sns.ornl.gov/css_phoebus/nightly/
3030

31-
Create a settings file for CS-Studio that holds the path to
32-
this python library::
33-
34-
echo org.csstudio.display.builder.runtime/python_path=$PYTHONPATH >>my_settings.ini
35-
36-
You may also add common settings like CA or PVA address lists
37-
to that file, or add the `..runtime/python_path` setting to
38-
an already existing local settings file.
39-
40-
All CS-Studio tools are based on Java. The CS-Studio GUI binary
41-
may bundle a java runtime. If it includes a `jdk` folder, use that.
42-
Otherwise fetch a Java runtime from https://jdk.java.net
31+
All CS-Studio tools are implemented in Java. Some CS-Studio GUI binaries
32+
bundle a java runtime. If it includes a `jdk` folder, use that.
33+
Otherwise fetch a Java runtime from https://jdk.java.net.
4334
Either way, declare your JDK and add its `bin` folder to the PATH::
4435

4536
export JAVA_HOME=/path/to/jdk
4637
export PATH=$JAVA_HOME/bin:$PATH
4738
java -version
4839

40+
Both the scan server and the CS-Studio GUI likely need to access
41+
the same PVs, so you can create a common `my_settings.ini` for them.
42+
In here we start with just localhost::
43+
44+
echo org.phoebus.pv.ca/addr_list=127.0.0.1 >>my_settings.ini
45+
46+
For more on PV related settings, see
47+
https://control-system-studio.readthedocs.io/en/latest/preference_properties.html#pv
48+
49+
For the CS-Studio displays, we add the path to this python library and its examples::
50+
51+
echo org.csstudio.display.builder.runtime/python_path=$PYTHONPATH >>my_settings.ini
52+
53+
This `.../python_path` setting is for CS-Studio displays to locate display scripts.
54+
It is not required by the scan server, but for simplicity
55+
you may combnied settings in a common file loaded by all CS-Studio tools,
56+
since the tools will ignore settings that don't apply to them.
57+
58+
The scan server uses an additional configuration file.
59+
For a full example see https://github.com/ControlSystemStudio/phoebus/blob/master/services/scan-server/src/main/resources/examples/scan_config.xml
60+
61+
For these tests we use a simpler file based on this template
62+
to primarily set the path used by server-side scripts:
63+
64+
.. literalinclude:: ../example/server/scan_config_template.xml
65+
66+
Based on that template, create the file for your PyScanClient example path::
67+
68+
cat $PYSCANCLIENT/example/server/scan_config_template.xml |
69+
sed -e "s#<path>.*#<path>$PYSCANCLIENT/example/server</path>#" >my_scan_config.xml
70+
4971
Assuming you fetched a scan server binary, start the scan server like this::
5072

5173
unzip scan-server.zip
5274
rm scan-server.zip
5375
cd scan-server-*
54-
./scan-server.sh
55-
76+
./scan-server.sh -settings /path/to/my_settings.ini -config /path/to/my_scan_config.xml
77+
5678
On success, note the REST URL and list of console commands::
5779

58-
INFO ../ Scan Server (PID 1766187)
80+
INFO ... Scan Server (PID 1766187)
5981
INFO ... Scan Server REST interface on http://localhost:4810/index.html
6082
Scan Server Commands:
6183
help - Show commands
6284
...
6385
shutdown - Stop the scan server
6486

65-
You would stop the scan server by typing `shutdown`, then restart via `scan-server.sh`.
87+
You would stop the scan server by typing `shutdown`, then restart as just shown.
6688

6789

6890
Test Beamline
6991
-------------
7092

71-
Subsequent sections use a simple test beamline created by `simulation.db`.
93+
Subsequent sections use a test beamline created by `simulation.db`.
7294
The scan GUIs use additional databases.
7395
Start them all in one IOC like this::
7496

75-
cd PyScanClient/example
76-
softIoc -m S=Demo -d ioc/simulation.db -d ioc/table.db
97+
cd $PYSCANCLIENT/example/ioc
98+
softIoc -m S=Demo -d simulation.db -d table.db -d range.db -d fit.db
7799

78100
Assuming you fetched a binary for CS-Studio, start the associated GUI like this::
79101

80102
unzip phoebus-linux.zip
81103
rm phoebus-linux.zip
82104
cd phoebus-*/
83-
./phoebus.sh -settings /path/to/my_settings.ini -resource /path/to/PyScanClient/example/opi/1_BeamLine.bob
105+
./phoebus.sh -settings /path/to/my_settings.ini -resource $PYSCANCLIENT/example/opi/1_BeamLine.bob
84106

85107
.. image:: simulation.png
86108

87109
Familiarize yourself with the simulation.
88110

89-
* The "Beam" is mostly on, but occasionally turns off.
111+
* The "Beam" is mostly on, but turns itself off for brief periods.
90112
* Click on the "Shutter" to open or close it.
91113
While beam is on and the shutter open, the "Neutrons" counter increments.
92114
The "Proton Charge" increments as well, but you may
@@ -111,11 +133,11 @@ but point your web browser to http://localhost:4810 and try the following.
111133
some control system operator interface host to http://name_of_server:4810
112134
to check network connectivity to the scan server.
113135
* Follow the "/server/info" link.
114-
The XML format of the information is obviously not perfect for
136+
The XML format of the information is obviously not meant for
115137
interactive use. For example, you would have to convert a UNIX epoch
116138
start time of "1711118742626" into "2024-03-22 10:45:42 EDT" to verify
117139
the scan server start time,
118-
but if all else fails such direct REST access can help you debug
140+
but if all else fails such direct REST access can help you to debug
119141
your setup on a low level.
120142
* Back from the start page http://localhost:4810, click the
121143
"/scan/{name-of-new-scan}" link for submitting a new scan.
@@ -150,14 +172,14 @@ Scan Server Console
150172
"/scan/{name-of-new-scan}" link and submit anoter example scan.
151173

152174

153-
CS-Studio GUI
154-
-------------
175+
CS-Studio GUI Scan Tools
176+
------------------------
155177

156178
* In CS-Studio, invoke the menu Applications, Scan, Scan Monitor.
157179
You should see the last submitted scan as "Finished-OK",
158180
the others as simply "Logged".
159181
* Right-click on any scan and open the "Data Table".
160-
* Right-click no the "Finished" scan and open the "Scan Editor".
182+
* Right-click on the "Finished" scan and open the "Scan Editor".
161183
* In the scan editor, right-click to "Submit scan".
162184
It submits the same commands once more. While the scan is executing,
163185
the scan editor highlights the active command in green.
@@ -166,35 +188,34 @@ CS-Studio GUI
166188
.. image:: scan_monitor_editor.png
167189

168190
* In the scan editor, create a list of "Delay 1 sec" commands by deleting everything else,
169-
dragging noe "Delay" command from th palette into the editor,
191+
dragging one "Delay" command from the palette into the editor,
170192
then use copy/paste from the context menu or Control-drag-drop to
171193
create about 10 delays.
172194
* Submit the scan and note how it highlights the active delay command.
173195
Use the "pause" button in either the scan monitor or editor to pause and then resume
174196
the commands.
175197
* Quickly submit the scan multiple times from the scan editor.
176198
Use the "Re-submit Scan" entry from the scan monitor context menu.
177-
Note how one scan executes, and additional scans are queued up to
199+
Note how one scan executes, and additional scans queue up to
178200
be executed next. Idle scans can be moved up or down in the list of queued
179201
scans, or aborted.
180-
* In the scan monitor, selet a few older scans, right-click on them and "Remove selected".
202+
* In the scan monitor, select a few older scans, right-click on them and "Remove selected".
181203

182-
The scan monitor is very useful to monitor
183-
the progress of queued and active scans.
204+
The scan monitor is very useful to track the progress of queued and active scans.
184205

185206
The scan editor could be used to manually assemble small scans,
186207
but it's mainly meant to debug scans that have been submitted by other means.
187208

188209
The scan server will hold the commands of past scans in memory
189210
and persist the logged data on disk, but this
190211
is all meant to debug scans, not to replace data aquisition.
191-
Based on memory usage thresholds, the scan server will automatically change
192-
in-memory scans to only logged scans.
212+
Based on memory usage thresholds, the scan server will automatically reduce
213+
in-memory scans to logged scans.
193214
While the scan monitor can list many scans, reading the list of scans from
194-
the server and displaying it will use noticable CPU once there are 10000 and more
195-
scans in the list.
215+
the server and displaying it in the GUI will use noticable CPU once there are
216+
10000 and more scans in the list.
196217
Periodically, for example when a new series of experiments start,
197-
it is thus suggested to manually remove information for older scans,
218+
it is thus suggested to manually remove older scans,
198219
either by deleting selected scans or by invoking "Remove completed scans"
199220
from the scan monitor context menu.
200221

@@ -212,31 +233,30 @@ and run it::
212233
.. literalinclude:: ../example/commands1.py
213234

214235
Note how the python script assembles a list of commands.
215-
It builds the recipe for one "scan", submits it to the scan server,
216-
and exits.
236+
It builds the recipe, submits it to the scan server, and exits.
217237
The scan server then spends more than a minute to execute the submitted
218238
commands.
219239

220240
In the CS-Studio scan monitor, right-click on the running scan to open
221241
the "Scan Data Table" and watch how samples are added.
222242
This internal data logger is again not meant to replace data aquisition,
223-
but meant to assist in tracknig the progress of scans and to debug them.
243+
but assists in tracking the progress of scans.
224244

225-
At this point you may familiarize yourself with all the :ref:`scan_commands`,
245+
At this point you may familiarize yourself with all the :doc:`scan commands <commands>`,
226246
especially the many options of the :class:`.Set` command.
227-
The PyScanClient `tutorial` folder contains several examples
228-
to try.
247+
The PyScanClient `tutorial` folder contains several more example scripts.
229248

230249

231250
Default Device Settings
232251
-----------------------
233252

234-
A command to turn a power supply on or set a voltage may be instantaneous::
253+
The command to set a power supply voltage may be instantaneous::
235254

236-
commands = [ Set('PS42:Voltage', 12.0), Comment("PS is now on at 12 Volts")]
255+
commands = [ Set('PS42:Voltage', 12.0),
256+
Comment("PS is now on at 12 Volts") ]
237257

238258
But this device behavior tends to be the exception.
239-
When controlling a motor, the EPICS motor support allows using a "put-callback"
259+
When controlling a motor, the EPICS motor support allows a "put-callback"
240260
to the device which waits until the motor reaches the desired location.
241261
This mechanism is also referred to as "completion".
242262
A temperature controller might support completion on its temperature
@@ -256,7 +276,7 @@ Unfortunately, the "correct" way to set a PV is not discernible from the outside
256276
It requires knowledge about the implementation of a PV in the IOC.
257277
And even if the correct way to set a PV is known, having to type
258278
all parameters for each `Set` command can be cumbersone.
259-
The PyScanClient :ref:`scan_settings` provide a way to configure default parameters
279+
The PyScanClient :doc:`scan settings <scan_settings>` provide a way to configure default parameters
260280
for each PV.
261281
Wrappers for the basic `Set`, `Loop` and `Wait` commands then use these defaults.
262282
For an example, see `example/beamline_setup.py`:
@@ -366,6 +386,19 @@ without manual conversion to CSV.
366386
Alignment Scan
367387
--------------
368388

389+
One fairly common beamline procedure is the alignment.
390+
For example, a slit or sample is moved across a range of positions,
391+
the intensity of a signal is noted at each position,
392+
and we try to locate the maximum of that signal.
393+
394+
In CS-Studio, use the menu `File`, `Open` to open
395+
`PyScanClient/example/opi/1_BeamLine.bob`
396+
and in there set the "Y" motor to 3.0.
397+
Now open `PyScanClient/example/opi/4_Alignment_Scan.bob`.
398+
Adjust the settings as shown the following screenshot, then press "Submit".
399+
400+
.. image:: alignment_scan.png
401+
369402
TODO
370403
Custom script commands
371404

@@ -380,4 +413,5 @@ Both the scan server and the CS-Studio GUI are typically started by a site-speci
380413
launcher script that adds `-settings /path/to/site/settings.ini`.
381414

382415

383-
TODO: scan server's pre and post commands
416+
TODO: scan server's pre and post commands
417+

doc/overview.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ Use Case: Custom Python Scripts
3636
-------------------------------
3737

3838
Finally, custom Python scripts can assemble a set of commands,
39-
see :ref:`scan_client`
40-
and :ref:`scan_commands`.
39+
see :doc:`scan client <scan_client>`
40+
and :doc:`scan commands <commands>`.

doc/scan_client.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
.. _scan_client:
2-
31
Scan Client
42
===========
53

doc/scan_settings.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11

2-
32
.. automodule:: scan.util.scan_settings
43
:members:
54

example/beamline_setup.py

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,40 @@
11
"""Example for beamline specific setup
2-
3-
All scripts that access the scan server
4-
should start with
2+
All scripts that access the scan server should start with
53
64
'from beamline_setup import *'
75
"""
86

97
# Get all scan commands
108
from scan import *
11-
12-
# Replace basic Loop/Set/Wait commands with wrappers
13-
# that utilize custom scan settings
9+
# Replace basic Loop/Set/Wait commands with wrappers that use scan settings
1410
from scan.util import SettingsBasedLoop as Loop
1511
from scan.util import SettingsBasedSet as Set
1612
from scan.util import SettingsBasedWait as Wait
1713

18-
# Each "beamline" or more generally setup that uses
19-
# the PyScanClient should create its own ScanSettings
14+
# Implement ScanSettings for this beamline
2015
class BeamlineScanSettings(ScanSettings):
2116
def __init__(self):
2217
super(BeamlineScanSettings, self).__init__()
2318

24-
# Define settings based on PV name patterns
25-
# (regular expressions).
26-
# Order matters! List most generic patterns first,
27-
# specific PV names last.
28-
# For example, motors should use completion, and check a readback
19+
# Define settings based on PV name patterns (regular expressions).
20+
# Order matters! List patterns first, specific PVs last.
21+
# In general, motors should use completion, and check a readback
2922
self.defineDeviceClass("motor_.", completion=True, readback=True)
3023
# The specific motors in the simulation.db, however, don't support completion
3124
self.defineDeviceClass("motor_x", completion=False, readback=False)
3225
self.defineDeviceClass("motor_y", completion=False, readback=False)
3326
self.defineDeviceClass("shutter", readback=True)
34-
# The simulated "setpoint" uses a different PV "readback" as its readback.
35-
# (readback=False skips readback check
36-
# readback=True calls getReadbackName(pv) which typically returns the PV itself,
37-
# readback='whatever' uses provided PV
38-
# )
27+
# The simulated "setpoint" uses a different "readback" PV as its readback.
28+
# readback=False skips readback check
29+
# readback=True calls getReadbackName(pv) which typically returns the PV itself
30+
# readback='whatever' uses provided PV
3931
self.defineDeviceClass("setpoint", completion=False, readback="readback", tolerance=0.1, timeout=20)
4032
# When waiting for proton charge or neutron counts, use "increase by"
4133
self.defineDeviceClass("pcharge", comparison="increase by")
4234
self.defineDeviceClass("neutrons", comparison="increase by")
4335

4436
# Each site may add more to its site-specific configuration.
45-
# The example/opi for alignment uses these to
46-
# populate drop-downs
37+
# The example/opi for alignment uses these to populate drop-downs
4738
self.settable = [ "motor_x", "motor_y" ]
4839
self.waitable = [ "seconds", "time", "pcharge" ]
4940
self.loggable = [ "signal" ]
@@ -112,4 +103,4 @@ def table_scan(headers, rows):
112103
print("")
113104
print("Scan Client")
114105
print("===========")
115-
print(scan_client)
106+
print(scan_client)

0 commit comments

Comments
 (0)