79 lines
2.3 KiB
Python
Executable File
79 lines
2.3 KiB
Python
Executable File
# Tool to align the solenoid on the gun.
|
|
# S. Bettoni, A. Gobbo, D. Voulot
|
|
# 06/06/2016
|
|
#Code ok with the GUI
|
|
|
|
# Procedure:
|
|
# switch off all the magnets between the gun solenoid and the screen or BPM used for the measurement
|
|
# change the current of the gun soleoid
|
|
# look at the centroid position (BPM or screen) downstream of the gun.
|
|
|
|
import datetime
|
|
|
|
mode = "server" # "server", "camtool", "bpm" or "direct"
|
|
camera_name = "simulation"
|
|
#camera_name = "SLG-LCAM-C041"
|
|
use_good_region=False
|
|
dry_run = True
|
|
|
|
if True: #get_exec_pars().source == CommandSource.ui:
|
|
I1 = 95.0
|
|
I2 = 100.0
|
|
dI = 1.0
|
|
settling_time = 0.1
|
|
plot_image = False
|
|
number_images = 3
|
|
use_background = True
|
|
multiple_background = True
|
|
number_backgrounds = 3
|
|
do_elog = False
|
|
centroid_excursion_plot = True
|
|
else:
|
|
centroid_excursion_plot = False
|
|
|
|
|
|
positioner = DummyPositioner("positioner")
|
|
|
|
original_gun_solenoid = positioner.read()
|
|
|
|
|
|
multiple_background = multiple_background and use_background
|
|
print "Parameters: ", I1, I2, dI, settling_time, plot_image, number_images, use_background, multiple_background, number_backgrounds
|
|
|
|
plot_name = datetime.datetime.fromtimestamp(time.time()).strftime('%H%M%S')
|
|
|
|
|
|
setup_camera_scan()
|
|
|
|
#switch_off_magnets()
|
|
|
|
|
|
r = None
|
|
|
|
|
|
try:
|
|
sensors = get_camera_scan_sensors()
|
|
r = lscan(positioner, sensors , I1, I2, dI, settling_time, before_read = before_sample_camera_scan, after_read = after_sample_camera_scan)
|
|
finally:
|
|
end_camera_scan()
|
|
|
|
positioner.write(original_gun_solenoid)
|
|
|
|
# take the result of the scan and generate convex hull plot
|
|
if centroid_excursion_plot:
|
|
(hx,hy)=add_convex_hull_plot ("Centroid excursion", r.getReadable(0),r.getReadable(1), plot_name)
|
|
else:
|
|
(hx,hy)= convex_hull(x=r.getReadable(0), y=r.getReadable(1))
|
|
hx.append(hx[0]); hy.append(hy[0])
|
|
|
|
# save the entry in the logbook
|
|
gsa_log_msg = "Data file: " + get_exec_pars().path
|
|
gsa_log_msg = gsa_log_msg + "\nImages: " + str(number_images)
|
|
gsa_log_msg = gsa_log_msg + "\nBackground: enabled=" + str(use_background) + " multiple=" + str(multiple_background) + " number=" + str(number_backgrounds)
|
|
gsa_log_msg = gsa_log_msg + "\n\n" + r.print()
|
|
if do_elog:
|
|
elog("Gun solenoid current scan", gsa_log_msg , get_plot_snapshots())
|
|
|
|
print gsa_log_msg
|
|
set_return([r, hx, hy])
|