Commit 2aba80e4 authored by Yoann Sallaz Damaz's avatar Yoann Sallaz Damaz
Browse files

Version First beam

parent cf690ac5
......@@ -161,6 +161,10 @@ tab_nrj=[
("Ti", "K", 2.4963, 4.9664),
("Te", "L1", 2.5101, 4.9392)]
nrj = type('', (), {})()
for valuelist in tab_nrj:
setattr(nrj,"E_"+str(valuelist[3]).replace(".","_"),valuelist[3])
##########################################################################
# GEOFIP FUNCTION
......
from bliss.controllers.motor import CalcController
from bliss.common.logtools import *
from bliss import global_map
from bliss.controllers.tango_attr_as_counter import tango_attr_as_counter
from math import asin,sin
# class SyncMotors(controllers):
# def __init__(self, *args, **kwargs):
# CalcController.__init__(self, *args, **kwargs)
class bragg(CalcController):
def __init__(self, *args, **kwargs):
CalcController.__init__(self, *args, **kwargs)
inclino_name = self.config.get("inclino")
self.slope_source = float(self.config.get("slope_source"))
for counter in global_map.get_counters_iter():
if inclino_name == counter.name:
self.inclino = counter
break
# def initialize_axis(self, axis):
# CalcController.initialize_axis(self, axis)
# axis.no_offset = True
def initialize_axis(self, axis):
CalcController.initialize_axis(self, axis)
axis.no_offset = True
# def calc_from_real(self, positions_dict):
# log_info(self,"[SyncMotors] calc_from_real()")
# log_info(self,"[SyncMotors]\treal: %s" % positions_dict)
def calc_from_real(self, positions_dict):
bragg_angle = -self.slope_source + 2*self.inclino.value + positions_dict["beta"]
return {"calc_brag": bragg_angle}
# calc_dict = dict()
# calc_dict.update(
# {
# "hoffset": (positions_dict["back"] - positions_dict["front"]) / 2.0,
# "hgap": positions_dict["back"] + positions_dict["front"],
# }
# )
def calc_to_real(self, positions_dict):
real_pos = self.slope_source - 2*self.inclino.value + positions_dict["calc_brag"]
return {"beta": real_pos}
# log_info(self,"[SyncMotors]\tcalc: %s" % calc_dict)
class mirrorup(CalcController):
def __init__(self, *args, **kwargs):
CalcController.__init__(self, *args, **kwargs)
self.distancedetweenelevator = 650
# return calc_dict
def initialize_axis(self, axis):
CalcController.initialize_axis(self, axis)
# def calc_to_real(self, positions_dict):
# log_info(self,"[SyncMotors] calc_to_real()")
# log_info(self,"[SyncMotors]\tcalc: %s" % positions_dict)
def calc_from_real(self, positions_dict):
mirrorangle = asin((positions_dict["upfr"]-positions_dict["upbk"])/self.distancedetweenelevator)
mirroraltitude = (positions_dict["upfr"]+positions_dict["upbk"])/2.
return {"altitude":mirroraltitude, "angle":mirrorangle}
# real_dict = dict()
# slit_type = self.config.get("slit_type", default="both")
def calc_to_real(self, positions_dict):
sinangle = sin(positions_dict["angle"])
upfr = positions_dict["altitude"]-sinangle*self.distancedetweenelevator/2.
upbk = positions_dict["altitude"]+sinangle*self.distancedetweenelevator/2.
return {"upfr":upfr, "upbk":upbk}
# real_dict.update(
# {
# "back": (positions_dict["hgap"] / 2.0) + positions_dict["hoffset"],
# "front": (positions_dict["hgap"] / 2.0) - positions_dict["hoffset"],
# }
# )
# log_info(self,"[SyncMotors]\treal: %s" % real_dict)
# return real_dict
class inclino(tango_attr_as_counter):
def __init__(self, name, config):
tango_attr_as_counter.__init__(self, name, config)
self.offset = float(config.get("offset"))
self.sign = float(config.get("sign"))
def convert_func(self, raw_value):
# reecriture de cette fonction pour prendre en compte le signe et l'offset
"""
Apply to the <raw_value>:
* conversion_factor
* formatting
"""
log_debug(self, "raw_value=%s", raw_value)
attr_val = raw_value * self.conversion_factor
formated_value = float(
self.format_string % attr_val if self.format_string else attr_val
)
return self.sign*(formated_value-self.offset)
......@@ -6,7 +6,7 @@ from bliss.setup_globals import *
from bliss.common.standard import mv, mvr
import numpy as np
import datetime
from .geofip import geofip, tab_nrj
from .geofip import geofip, tab_nrj, nrj
from bliss.physics import trajectory
from bliss.common import axis
from bliss.common.motor_group import TrajectoryGroup
......@@ -80,6 +80,8 @@ def trajectoire_mono(nrj_target):
except:
print(" !!! Emergency stop - error or keyboard interupt !!!")
mono_stop()
umv(energy,nrj_target)
for motor in motor_list:
motor.apply_config(reload=True)
......@@ -101,7 +103,7 @@ def geofip_fill_beam_save():
optical_conf = cc.get("optical_setup")
for nrj in tab_nrj:
resu_geofip = geofip(nrj[3], VERBOSE=0)
resu_geofip = geofip(nrj[2], VERBOSE=0)
dict_pos_mot = {
"alpha1": round((resu_geofip.get("angle_m1")*180./math.pi), 4),
"beta": round((resu_geofip.get("mono_angle")*180./math.pi), 4),
......@@ -110,14 +112,14 @@ def geofip_fill_beam_save():
"moveh": round(resu_geofip.get("z_c1"), 4),
"alpha2": round((resu_geofip.get("angle_m2")*180./math.pi), 4)
}
if(optical_conf.get(str(nrj[2])) is None):
if(optical_conf.get(str(nrj[3])) is None):
new_conf = { "geofip": dict_pos_mot }
else:
new_conf = optical_conf.get(str(nrj[2]))
new_conf = optical_conf.get(str(nrj[3]))
new_conf["geofip"] = dict_pos_mot
new_conf.save()
optical_conf[str(nrj[2])]= new_conf
optical_conf[str(nrj[3])]= new_conf
optical_conf.save()
......@@ -129,10 +131,10 @@ def beam_save():
break
#Search for the closest idx
tab_nrj_kev = np.array([i[2] for i in tab_nrj])
tab_nrj_kev = np.array([i[3] for i in tab_nrj])
idx = (np.abs(tab_nrj_kev-(motenergy.position/1000.))).argmin()
tab_nrj_choice = [(str(i[2]), "%s(%s) %.2fkeV"%(i[0],i[1],i[2])) for i in tab_nrj]
tab_nrj_choice = [(str(i[3]), "%s(%s) %.2fkeV"%(i[0],i[1],i[2])) for i in tab_nrj]
dlg3 = UserChoice(label="Your are currently at %.2fkeV - Choose the energy for saving the current motors positions"%(motenergy.position/1000.), values=tab_nrj_choice, defval=idx)
new_nrg_to_save = BlissDialog( [ [ dlg3 ] ], title='Beam save').show()
if new_nrg_to_save is not False:
......@@ -143,7 +145,10 @@ def beam_save():
optical_conf = cc.get("optical_setup")
dict_pos_mot = {"omega2":omega.position,
"gamma2":gamma2.position,
"khi2":khi2.position
"khi2":khi2.position,
"utx":utx.position,
"utz":utz.position,
"moveh":moveh.position
}
today_str = datetime.datetime.today().strftime('%Y-%m-%d_%H-%M')
......@@ -203,11 +208,12 @@ def beam_select_setup():
optical_conf = cc.get("optical_setup")
list_nrj_setup = list(optical_conf.keys())
list_nrj_setup.remove("name")
list_nrj_setup.remove("selected")
if "selected" in list_nrj_setup:
list_nrj_setup.remove("selected")
list_nrj_setup = np.array([float(i) for i in list_nrj_setup])
list_nrj_setup.sort()
tab_nrj_kev = np.array([i[2] for i in tab_nrj])
tab_nrj_kev = np.array([i[3] for i in tab_nrj])
tab_nrj_choice = [(str(i), "%6s %6s"%(str(i),"-".join(tab_nrj[np.argwhere(tab_nrj_kev==i)[0][0]][0:2]))) for i in list_nrj_setup]
selected_conf = optical_conf.get("selected")
for idx in range(len(tab_nrj_choice)):
......@@ -236,4 +242,18 @@ def beam_select_setup():
else:
selected_conf[wanted_nrj] = wanted_conf
selected_conf.save()
optical_conf.save()
\ No newline at end of file
optical_conf.save()
def beammonitorIn():
print("Beam Monitor go to 0mm")
umv(beammonitor,0)
def absAluminiumIn():
print("Beam Monitor go to -66,7mm")
umv(beammonitor,-66.7)
def absCarbonIn():
print("Beam Monitor go to -33,8mm")
umv(beammonitor,-33.8)
......@@ -42,9 +42,9 @@ def wa(**kwargs):
dial.append(dial_position)
if axis_name == "alpha1" and inclino_m1 is not None:
inclino.append("inc="+str(inclino_m1.read()))
inclino.append("inc="+str(inclino_m1.value))
elif axis_name == "alpha2" and inclino_m2 is not None:
inclino.append("inc="+str(inclino_m2.read()))
inclino.append("inc="+str(inclino_m2.value))
else:
inclino.append("")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment