Tilt homing

This commit is contained in:
e19752
2022-05-24 10:16:16 +02:00
parent 065e33ad05
commit 6de2af0dca
181 changed files with 5817 additions and 1017 deletions
+122
View File
@@ -0,0 +1,122 @@
import subprocess
import time
import traceback
running = False
counts = {}
def countHS(motor):
global counts
try:
time.sleep(1.0)
counts[motor]=0
def on_change(value):
global counts
print "HomeSW changed on" , motor, "to", value
if int(value) == 1:
counts[motor]=counts[motor]+1
with Channel(motor+".ATHM", callback=on_change, monitored=True, name="test") as ch:
if int(ch.read()) == 1:
counts[motor]=1
while(running==True):
time.sleep(0.1)
print "Home Switch motor "+motor +" reached "+ str(counts[motor]) + " times"
return counts[motor]
except:
print "Exception counting "+str(motor)
traceback.print_exc()
raise
def init():
try:
global running
running = True
print "startint CMU initilization"
x = caget('X11MA-OP-CM:ox')
y = caget('X11MA-OP-CM:oy')
z = caget('X11MA-OP-CM:oz')
Rx= caget('X11MA-OP-CM:oRx')
Ry= caget('X11MA-OP-CM:oRy')
Rz= caget('X11MA-OP-CM:oRz')
baf=caget('X11MA-OP2-CM:TRB.RBV')
print "Old motor positions: x = " +str(x)+ \
", y = " +str(y)+ \
", z = " +str(z)+ \
", Rx = " +str(Rx)+ \
", Ry = " +str(Ry)+ \
", Rz = " +str(Rz)+ \
", baffle = " +str(baf)
subprocess.call("X_X11MA_init-CMU.sh", shell=True)
print "Positions after initialisation: x = " +str(caget('X11MA-OP-CM:ox'))+ \
", y = " +str(caget('X11MA-OP-CM:oy'))+ \
", z = " +str(caget('X11MA-OP-CM:oz'))+ \
", Rx = " +str(caget('X11MA-OP-CM:oRx'))+ \
", Ry = " +str(caget('X11MA-OP-CM:oRy'))+ \
", Rz = " +str(caget('X11MA-OP-CM:oRz'))+ \
", baffle = " +str(caget('X11MA-OP2-CM:TRB.RBV'))
print "Restoring old motor positions"
caput('X11MA-OP-CM:y',y)
caput('X11MA-OP-CM:z',z)
caput('X11MA-OP-CM:Rx',Rx)
caput('X11MA-OP-CM:Ry',Ry)
caput('X11MA-OP-CM:Rz',Rz)
#check restored positions after restore
print "Restored positions: x = " +str(caget('X11MA-OP-CM:ox'))+ \
", y = " +str(caget('X11MA-OP-CM:oy'))+ \
", z = " +str(caget('X11MA-OP-CM:oz'))+ \
", Rx = " +str(caget('X11MA-OP-CM:oRx'))+ \
", Ry = " +str(caget('X11MA-OP-CM:oRy'))+ \
", Rz = " +str(caget('X11MA-OP-CM:oRz'))+ \
", baffle = " +str(caget('X11MA-OP2-CM:TRB.RBV'))
if(abs(caget('X11MA-OP-CM:ox')-x)>0.001):
print "X position not ok"
elif(abs(caget('X11MA-OP-CM:oy')-y)>0.001):
print "Y position not ok"
elif(abs(caget('X11MA-OP-CM:oz')-z)>0.001):
print "Z position not ok"
elif(abs(caget('X11MA-OP-CM:oRx')-Rx)>0.001):
print "Rx position not ok"
elif(abs(caget('X11MA-OP-CM:oRy')-Ry)>0.001):
print "Ry position not ok"
elif(abs(caget('X11MA-OP-CM:oRz')-Rz)>0.001):
print "Rz position not ok"
elif(abs(caget('X11MA-OP2-CM:TRB.RBV')-baf)>0.001):
print "baffle position not ok"
else:
print "All positions OK"
running = False
return 0
except:
print "Exception in init"
traceback.print_exc()
raise
#Fork and join
futures = fork(init,(countHS,("X11MA-OP2-CM:TRY",)), \
(countHS,("X11MA-OP2-CM:TRZ",)), \
(countHS,("X11MA-OP2-CM:ROX",)), \
(countHS,("X11MA-OP2-CM:ROY",)), \
(countHS,("X11MA-OP2-CM:ROZ",)), \
(countHS,("X11MA-OP2-CM:TRB",)) )
ret = join(futures)
#check home switch status after init
homesw=True
for i in range(1,5):
if(ret[i]!=1):
homesw=False
print "Home switch status for all motors: %s" %("OK" if homesw == True else "Not OK")
#final status report
if(homesw==True and ret[0]==0):
print "init-CMU: ==> done. OK!"
else:
print "init-CMU: ==> not done. NOT OK!"
+123
View File
@@ -0,0 +1,123 @@
import time
import traceback
running = False
counts = {}
encoder_raw = {}
def crossZero(encoder):
global counts
global encoder_raw
try:
time.sleep(1.0)
counts[encoder]=0
if caget(encoder+".RVAL") > 0:
encoder_raw[encoder]=1
elif caget(encoder+".RVAL") < 0:
encoder_raw[encoder]=-1
def on_change(value):
global counts
global encoder_raw
if (encoder_raw[encoder]==1 and value < 0):
counts[encoder]=counts[encoder]+1
encoder_raw[encoder]=-1
print "Zero on" , encoder, "crossed"
elif(encoder_raw[encoder]==-1 and value > 0):
counts[encoder]=counts[encoder]+1
encoder_raw[encoder]=1
print "Zero on" , encoder, "crossed"
#if int(value) == 0:
# print "Raw vlaue on" , encoder, "crossed", value
# counts[encoder]=counts[encoder]+1
with Channel(encoder+".RVAL", callback=on_change, monitored=True, name="test") as ch:
while(running==True):
time.sleep(0.1)
print "Encoder "+encoder +" crossed 0 "+ str(counts[encoder]) + " times"
return counts[encoder]
except:
print "Exception counting "+str(encoder)
traceback.print_exc()
raise
def init():
try:
global running
running = True
print "startint FE slit initilization"
cenV = caget('X11MA-FE-SV:center')
cenH = caget('X11MA-FE-SH:center')
offV = caget('X11MA-FE-DSVER.A')
offH = caget('X11MA-FE-DSHOR.A')
print "Old motor positions: centerV = " +str(cenV)+ \
", centerH = " +str(cenH)+ \
", offset V = " +str(offV)+ \
", offset H = " +str(offH)
print "Initializing UP motor."
caput('X11MA-FE-DSUP:II.PROC',1)
time.sleep(1.0)
cawait('X11MA-FE-SV1:TR1.DMOV', 1)
print "Initializing DOWN motor."
caput('X11MA-FE-DSDW:II.PROC',1)
time.sleep(1.0)
cawait('X11MA-FE-SV1:TR2.DMOV', 1)
print "Initializing RING motor."
caput('X11MA-FE-DSRI:II.PROC',1)
time.sleep(1.0)
cawait('X11MA-FE-SH1:TR1.DMOV', 1)
print "Initializing WALL motor."
caput('X11MA-FE-DSWA:II.PROC',1)
time.sleep(1.0)
cawait('X11MA-FE-SH1:TR2.DMOV', 1)
print "Setting offH and offV to 0."
caput('X11MA-FE-DSVER.A',0)
caput('X11MA-FE-DSHOR.A',0)
print "Checking encoder offset values."
if(abs(caget('X11MA-FE-SV1:EC1Off')+42683)>10):
print "Up position not ok"
elif(abs(caget('X11MA-FE-SV1:EC2Off')+41362)>10):
print "Down position not ok"
elif(abs(caget('X11MA-FE-SH1:EC1Off')+40782)>10):
print "Ring position not ok"
elif(abs(caget('X11MA-FE-SH1:EC2Off')+39548)>10):
print "Wall position not ok"
else:
print "All positions OK"
print "restoring Center and off values"
caput('X11MA-FE-SV:center',cenV)
caput('X11MA-FE-SH:center',cenH)
caput('X11MA-FE-DSVER.A',offV)
caput('X11MA-FE-DSHOR.A',offH)
running = False
return 0
except:
print "Exception in init"
traceback.print_exc()
raise
#Fork and join
futures = fork(init,(crossZero,("X11MA-FE-SV1:EC1",)), \
(crossZero,("X11MA-FE-SV1:EC2",)), \
(crossZero,("X11MA-FE-SH1:EC1",)), \
(crossZero,("X11MA-FE-SH1:EC2",)) )
ret = join(futures)
#check zero crossing status after init
zerocr=True
for i in range(1,4):
if(ret[i] != 2):
zerocr=False
#final status report
print "Zero crossing status for all motors: %s" %("OK" if zerocr == True else "Not OK")
print "init FE-slits: ==> done. %s" % ("OK" if zerocr == True else "Not OK")