Commit 4dad439f authored by Yoann Sallaz Damaz's avatar Yoann Sallaz Damaz
Browse files

tt

parent cf53dee4
Pipeline #55149 failed with stages
......@@ -47,9 +47,6 @@ class bac24(object):
# set the current position and the offset to 0
self.clearpos()
# set the keybord inactive 0 active 1
self.key(1)
# set the display decimal
self.send_and_read(b"$ADEC0;\r\n")
......@@ -57,6 +54,9 @@ class bac24(object):
# sends back two lines - 2 DevSerReadString
self.send_and_read(b"$ARAZAL;\r\n", 2)
# set the keybord inactive 0 active 1
self.key(1)
sleep(1);
# flush the rest of the input buffer (if any)
self.ser.flush()
......@@ -68,9 +68,10 @@ class bac24(object):
def ramp(self, start_pos, end_pos):
# Define the start_pos and end_pos for level 1 of output 1
start_step = start_pos * 12800 # in encoder steps
end_step = end_pos * 12800 # in encoder steps
end_step = end_pos* 12800 # in encoder steps
print("bac24_ramp: start: %d, end: %d"%(start_step, end_step))
self.send_and_read(b"$APLA1,1,%d,%d;\r\n"%(start_step, end_step),2)
sleep(1)
def ramp_cycle(self, start_pos, end_pos, next_periode_pos, bac_out_num=1):
# Define the start_pos and end_pos for level 1 of output 1 in cycle mode
......
......@@ -80,7 +80,7 @@ class fastscan:
buffer = self._proxy.command_inout("ReadIBuffer")
self.scanresult = []
for i in range(nbsteptoaccel,len(buffer)-nbsteptoaccel,4):
for i in range(nbsteptoaccel*4,len(buffer)-nbsteptoaccel*4,4):
value=0
for j in scanobj.counters:
value+= buffer[i+j]
......
......@@ -163,7 +163,8 @@ tab_nrj=[
nrj = type('', (), {})()
for valuelist in tab_nrj:
setattr(nrj,"E_"+str(valuelist[3]).replace(".","_"),valuelist[3])
setattr(nrj,"_"+str(valuelist[3]).replace(".","_")+"_"+valuelist[0]+"-"+valuelist[1],valuelist[3])
setattr(nrj,valuelist[0]+"-"+valuelist[1]+"_"+str(valuelist[3]).replace(".","_"),valuelist[3])
##########################################################################
......
......@@ -115,7 +115,7 @@ class SampleChangerState:
class grob_FIP(object):
GONIO_SAMPLE_COLLECT_STATE = 1
GONIO_SAMPLE_MOUNT_STATE = 2
def __init__(self, name, config, config_objects=None):
......@@ -129,6 +129,8 @@ class grob_FIP(object):
self.SIMU = config.get("SIMULATION")
self.NumSampleMounted_Simulated = 0
self.ABORT = False
self.command = { "stop":1, "home":2, "mount_sample":3, "dismount_sample":4,
"mount_plate":5, "dismount_plate":6, "mount_gonio":7, "dismount_gonio":8,
"send_setup":9, "wash":10, "anneal":11, "mount_versa_pin":12,
......@@ -273,6 +275,7 @@ class grob_FIP(object):
self.wago = self.config["wago"]
self.keyence = get_config().get(self.config["keyence"])
self.heatgun = self.config["heatgun"]
self.fastshut = self.config["fastshut"]
self.real_device_init=True
def _move_gonio(self, motor_list_first, target_list_first,
......@@ -327,6 +330,7 @@ class grob_FIP(object):
self.dstop.down()
self.cryoshort.up()
self.keyence.on()
self.fastshut.close_manual()
for retry in range(0,10):
if self.SIMU:
......@@ -394,6 +398,7 @@ class grob_FIP(object):
self.dstop.down()
self.cryoshort.down()
self.keyence.off()
self.fastshut.close_manual()
for retry in range(0,10):
if self.SIMU:
......@@ -506,20 +511,37 @@ class grob_FIP(object):
self.send_command("home")
def mount_sample(self, sample_number):
self.ABORT=False
if self.SIMU:
self.state_grob = 1
print("ABORT=",self.ABORT)
#gonio position to mount
if self.SIMU:
self.state_gonio = 2
time.sleep(1)
else:
if not self.move_accessories_in_sample_mount_geo():
self.move_accessories_in_sample_collect_geo()
return False
print("ABORT=",self.ABORT)
if self.ABORT:
self.move_accessories_in_sample_collect_geo()
print("ABORT=",self.ABORT)
if not self.move_motors_in_sample_mount_geo():
return False
print("ABORT=",self.ABORT)
if self.ABORT:
if self.move_motors_in_sample_collect_geo():
self.move_accessories_in_sample_collect_geo()
return False
#robot mount
if sample_number==0:
if self.SIMU:
......@@ -536,6 +558,7 @@ class grob_FIP(object):
else:
self.send_command("mount_sample", [sample_number])
print("ABORT=",self.ABORT)
time.sleep(3)
self.read_all_memory()
......@@ -543,6 +566,7 @@ class grob_FIP(object):
kappaactiondone = False
#with gevent.Timeout(15,False):
while self.Status==2: #self.NumSampleMounted != sample_number:
print("ABORT=",self.ABORT)
self.read_all_memory()
#print(self.NumSampleMounted)
if self.SmartMagnet == 3:
......@@ -806,4 +830,4 @@ class grob_FIP(object):
def mount_dismount_is_in_progress(self):
state_grob = self.get_state()
state_gonio = self.gonio_state()
return state_grob==SampleChangerState.Loading or state_gonio != self.GONIO_SAMPLE_COLLECT_STATE
return (state_grob==SampleChangerState.Loading or state_gonio != self.GONIO_SAMPLE_COLLECT_STATE) and not self.ABORT
......@@ -42,6 +42,22 @@ class mirrorup(CalcController):
upbk = positions_dict["altitude"]+sinangle*self.distancedetweenelevator/2.
return {"upfr":upfr, "upbk":upbk}
class c2bend_calc(CalcController):
def __init__(self, *args, **kwargs):
CalcController.__init__(self, *args, **kwargs)
def initialize_axis(self, axis):
CalcController.initialize_axis(self, axis)
def calc_from_real(self, positions_dict):
c2benddiff = positions_dict["c2bendfr"]-positions_dict["c2bendbk"]
c2bend = (positions_dict["c2bendfr"]+positions_dict["c2bendbk"])/2.
return {"c2benddiff":c2benddiff, "c2bend":c2bend}
def calc_to_real(self, positions_dict):
c2bendbk = positions_dict["c2bend"]-0.5*positions_dict["c2benddiff"]
c2bendfr = positions_dict["c2bend"]+0.5*positions_dict["c2benddiff"]
return {"c2bendbk":c2bendbk, "c2bendfr":c2bendfr}
#class inclino(tango_attr_as_counter):
......
......@@ -21,7 +21,7 @@ import scipy.optimize as opt
import matplotlib.pyplot as plt
from scipy import ndimage
from scipy.interpolate import interp1d
import enlighten
def gauss(x, p): # p[0]==mean, p[1]==stdev
return 1.0/(p[1]*np.sqrt(2*np.pi))*np.exp(-(x-p[0])**2/(2*p[1]**2))
......@@ -134,62 +134,80 @@ def beam_set(nrj_target, mono_only=False, force=False):
#comput the time need for the slowest motor to reach target
time_slowest = 0
slowest_axis = None
for motor in motor_list_traj:
motor.apply_config(reload=True)
distance = abs(motor.position-final_pos_dict.get(motor.name))
Xvmax = 0.5*motor.velocity*motor.velocity/motor.acceleration
if distance <= Xvmax*2:
moving_time = 2*sqrt(0.5*distance/motor.acceleration)
else:
moving_time = 2*motor.velocity/motor.acceleration + sqrt(2*(distance-2*Xvmax)/motor.acceleration)
print("%-10s velocity=%f distance=%f time_to_move=%f"%(motor.name, motor.velocity,distance, moving_time))
if moving_time > time_slowest:
time_slowest=moving_time
slowest_axis = motor
print("%s is the slowest axis all others follow its speed"%slowest_axis.name)
#change velocity for motor in traj
for motor in motor_list_traj:
distance = abs(motor.position-final_pos_dict.get(motor.name))
velocity = max(distance/time_slowest, motor.velocity*0.01)
motor.velocity=velocity
for motor in motor_list_traj:
motor.sync_hard()
motor.apply_config(reload=True)
distance = abs(motor.position-final_pos_dict.get(motor.name))
Xvmax = 0.5*motor.velocity*motor.velocity/motor.acceleration
if distance <= Xvmax*2:
moving_time = 2*sqrt(0.5*distance/motor.acceleration)
else:
moving_time = 2*motor.velocity/motor.acceleration + sqrt(2*(distance-2*Xvmax)/motor.acceleration)
print("%-10s velocity=%f distance=%f time_to_move=%f"%(motor.name, motor.velocity,distance, moving_time))
if moving_time > time_slowest:
time_slowest=moving_time
slowest_axis = motor
print("%s is the slowest axis all others follow its speed"%slowest_axis.name)
#change velocity for motor in traj
for motor in motor_list_traj:
distance = abs(motor.position-final_pos_dict.get(motor.name))
#print(motor.name, "vel_opti=",distance/time_slowest, "vel_min=",motor.velocity*0.01, "vel_max=",motor.velocity)
velocity = min(max(distance/time_slowest, motor.velocity*0.01),motor.velocity)
motor.velocity=velocity
#move motor to reach their target all at the same time (good speed)
motor_need_moving_list = []
for motor in motor_list:
motor.move(final_pos_dict.get(motor.name), wait=False)
motor_need_moving_list.append(motor)
#verif si un axe bouge pas et qui n'est pas à la position final stop de tout
ok = True
end_time = time.time()+time_slowest+3
while ok:
try:
print_str = "\033[94m Target reached in %ds"%(end_time-time.time())
ok = False
for motor in motor_need_moving_list:
if motor.is_moving:
ok = True
print_str=print_str+" "+\
motor.name+"="+\
"%.2f"%motor.position+"/"+\
"%.2f"%final_pos_dict.get(motor.name)
if motor.is_moving == False:
distance = abs(motor.position-final_pos_dict.get(motor.name))
if distance>0.1:
ok = False
print(" !!! Emergency stop - some motor can not move !!!")
for motor in motor_need_moving_list:
motor.stop()
sleep(1)
print(print_str, end="\r")
except KeyboardInterrupt:
break
except:
print(" !!! Emergency stop - error or keyboard interupt !!!")
mono_stop()
motor_need_moving_list = []
for motor in motor_list:
motor.move(final_pos_dict.get(motor.name), wait=False)
motor_need_moving_list.append(motor)
#verif si un axe bouge pas et qui n'est pas à la position final stop de tout
with enlighten.Manager() as manager:
progressbar = {}
for motor in motor_need_moving_list:
progressbar[motor]={"bar":manager.counter(
total=100,
desc='%s %f->%f'%(motor.name, motor.position, final_pos_dict.get(motor.name)),
bar_format=u'{desc}{desc_pad}{percentage:3.0f}%|{bar}',
counter_format=u'{desc}{desc_pad}DONE'),
"init":motor.position,
"final":final_pos_dict.get(motor.name)}
ok = True
motorfail = None
while ok:
try:
ok = False
for motor in motor_need_moving_list:
if motor.is_moving:
ok = True
progressbar[motor]["bar"].count=(100.*(motor.position-progressbar[motor]["init"])/(progressbar[motor]["final"]-progressbar[motor]["init"]))
else:
distance = abs(motor.position-final_pos_dict.get(motor.name))
if distance>0.1:
ok = False
motorfail=motor
else:
progressbar[motor]["bar"].update(100)
progressbar[motor]["bar"].refresh()
sleep(0.5)
except KeyboardInterrupt:
for motor in motor_need_moving_list:
motor.stop()
break
except Exception as e:
print(" !!! Emergency stop - error or keyboard interupt !!!")
print(e)
mono_stop()
umv(energy,nrj_target)
if not(motorfail is None):
print(" !!! Emergency stop - %s can not move !!!"%motorfail.name)
for motor in motor_need_moving_list:
motor.stop()
else:
beta.apply_config(reload=True)
umv(energy,nrj_target)
for motor in motor_list:
motor.apply_config(reload=True)
......@@ -332,6 +350,7 @@ def beam_select_setup():
cc = get_config()
cc.reload()
current_nrj = energy.position
optical_conf = cc.get("optical_setup")
list_nrj_setup = list(optical_conf.keys())
list_nrj_setup.remove("name")
......@@ -343,7 +362,10 @@ def beam_select_setup():
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")
defval=0
for idx in range(len(tab_nrj_choice)):
if abs(float(tab_nrj_choice[idx][0])-current_nrj)<0.005:
defval=idx
if selected_conf is None:
tab_nrj_choice[idx]= (tab_nrj_choice[idx][0], tab_nrj_choice[idx][1]+" (interpolate)")
else:
......@@ -351,16 +373,28 @@ def beam_select_setup():
if current_selected_conf is None:
tab_nrj_choice[idx]= (tab_nrj_choice[idx][0], tab_nrj_choice[idx][1]+" (interpolate)")
else:
tab_nrj_choice[idx]= (tab_nrj_choice[idx][0], tab_nrj_choice[idx][1]+" ("+current_selected_conf+")")
current_selected_conf_readable = current_selected_conf[:10]+' '+current_selected_conf[11:].replace("-",":")
tab_nrj_choice[idx]= (tab_nrj_choice[idx][0], tab_nrj_choice[idx][1]+" ("+current_selected_conf_readable+")")
dlg3 = UserChoice(label="Choose an available energy :", values=tab_nrj_choice)
dlg3 = UserChoice(label="Choose an available energy :", values=tab_nrj_choice, defval=defval)
wanted_nrj = BlissDialog( [ [ dlg3 ] ], title='Beam configuration editor', ok_text="Next").show()
if wanted_nrj is not False:
wanted_nrj = list(wanted_nrj.values())[0]
nrj_conf = list(optical_conf.get(str(wanted_nrj)))
nrj_conf.sort(reverse=True)
tab_nrj_conf_choice = [("interpolate", "interpolate")] + [(str(i), str(i)) for i in nrj_conf]
dlg3 = UserChoice(label="Choose an available energy :", values=tab_nrj_conf_choice)
defval=0
tab_nrj_conf_choice=[("interpolate", "interpolate")]
for conf in nrj_conf:
if wanted_nrj in selected_conf.keys():
if conf in selected_conf[wanted_nrj]:
defval=nrj_conf.index(conf)+1
if conf[0:2]=="20":
conf_readable = conf[:10]+' '+conf[11:].replace("-",":")
tab_nrj_conf_choice.append((str(conf), conf_readable))
else:
tab_nrj_conf_choice.append((str(conf), str(conf)))
dlg3 = UserChoice(label="Choose an available energy :", values=tab_nrj_conf_choice, defval=defval)
wanted_conf = BlissDialog( [ [ dlg3 ] ], title='Beam configuration editor', ok_text="Select").show()
if wanted_conf is not False:
wanted_conf = list(wanted_conf.values())[0]
......
Markdown is supported
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