This commit is contained in:
gobbo_a
2017-09-22 10:58:17 +02:00
parent 0c1d63ae9a
commit 5a7afde16f
40 changed files with 975 additions and 483 deletions

View File

@@ -11,27 +11,27 @@
import datetime
import ch.psi.utils.Chrono as Chrono
mode = "camtool" # "camtool", "bpm" or "direct"
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 = 2.5
dI = 1.0
settling_time = 0.1
plot_image = False
number_images = 3
use_background = False
multiple_background = False
use_background = True
multiple_background = True
number_backgrounds = 3
do_elog = False
centroid_excursion_plot = True
else:
centroid_excursion_plot = False
check_camtool()
#laser_was_on = is_laser_on()
positioner = DummyPositioner("positioner")
@@ -44,69 +44,20 @@ print "Parameters: ", I1, I2, dI, settling_time, plot_image, number_images, use_
plot_name = datetime.datetime.fromtimestamp(time.time()).strftime('%H%M%S')
if mode == "camtool":
if use_background:
#laser_off()
if not multiple_background:
camtool.stop()
camtool.grabBackground(camera_name, number_backgrounds)
#camtool.stop()
#camtool.startPipeline(camera_name, 0, use_background, None, 0.0, None)
#camtool.startReceiver();
c = Chrono()
print "t1 = " , c.ellapsed
camtool.start(camera_name, 0, use_background, None, 0.0, None)
print "t2 = " , c.ellapsed
if camtool.value is not None: print "Started " , camtool.value.getTimestamp()
wait_camtool_message()
print "t3 = " , c.ellapsed
print "OK"
else:
if mode == "bpm":
add_device(BpmStats("image_stats", camera_name), True)
else:
add_device(ImageStats(PsiCamera("image_stats", camera_name)), True)
multiple_background = False
use_background = False
image_stats.setNumberOfImages(max(number_images,1))
setup_camera_scan()
#switch_off_magnets()
# add here gun phase setting see wiki page
def before_sample():
if mode == "camtool":
if multiple_background:
camtool.stop()
camtool.grabBackground(camera_name, number_backgrounds)
camtool.start(camera_name, 0, use_background, None, 0.0, None)
#laser_on()
wait_camtool_message(number_images) #Wait filing the averager cache
else:
image_stats.update()
def after_sample():
if multiple_background:
#laser_off()
pass
r = None
#if not multiple_background:
# laser_on()
try:
if mode == "camtool":
print "Getting sensors"
sensors = get_camtool_stats(number_images, good_region=use_good_region)
print "Sensors ok"
if plot_image:
sensors.append(camtool.getDataMatrix())
else:
sensors = [image_stats.com_x_mean, image_stats.com_y_mean, image_stats.com_x_stdev, image_stats.com_y_stdev]
r = lscan(positioner, sensors , I1, I2, dI, settling_time, before_read = before_sample, after_read = after_sample)
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:
if mode == "camtool": camtool.stop()
#pass
end_camera_scan()
positioner.write(original_gun_solenoid)
#if laser_was_on:
@@ -130,4 +81,5 @@ 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])