FULLY WORKING incl. sync. but have to fix the display. fy seems wrong
This commit is contained in:
@@ -47,7 +47,7 @@ class MotionBase:
|
||||
gpascii = self.comm.gpascii
|
||||
if mode == 0:
|
||||
try:
|
||||
del self.sync_wait
|
||||
del self.sync_prg
|
||||
except AttributeError:
|
||||
pass
|
||||
self.sync_run = '&{crdId}b{prgId}r'''.format(prgId=prgId, crdId=crdId)
|
||||
@@ -61,25 +61,57 @@ class MotionBase:
|
||||
# - waits raising edge of <flag> and the sets DesTimeBase=ServoPeriod
|
||||
|
||||
# flag ='PowerBrick[0].GpioData[0].0.1==1'
|
||||
flag = 'Gate3[1].Chan[0].UserFlag==1'
|
||||
flag = 'Gate3[1].Chan[0].UserFlag==0'
|
||||
prg = '''close all buffers
|
||||
disable plc {plcId}
|
||||
open plc {plcId}
|
||||
Coord[{crdId}].DesTimeBase=0 // freezes timebase at boot
|
||||
while(flag){{}}
|
||||
L0=Sys.PhaseCount
|
||||
send 1"sync0 %d:%d\\n",Sys.PhaseCount,Sys.PhaseCount-L0
|
||||
while({flag}){{}}
|
||||
send 1"sync1 %d:%d\\n",Sys.PhaseCount,Sys.PhaseCount-L0
|
||||
L1=Sys.PhaseCount
|
||||
while(1)
|
||||
{{
|
||||
if({flag})
|
||||
{{
|
||||
PowerBrick[0].GpioData[0].16.8=255
|
||||
PowerBrick[0].GpioData[0].16.1=1
|
||||
Coord[{crdId}].DesTimeBase=Sys.ServoPeriod
|
||||
send 1"sync2 %d:%d\\n",Sys.PhaseCount,Sys.PhaseCount-L1
|
||||
break
|
||||
}}
|
||||
}}
|
||||
disable plc {plcId}
|
||||
close
|
||||
'''.format(plcId=plcId, crdId=crdId, flag=flag)
|
||||
gpascii.send_block(prg)
|
||||
self.sync_wait = 'Coord[{crdId}].DesTimeBase=0;enable plc {plcId}'.format(plcId=plcId, crdId=crdId)
|
||||
self.sync_run = 'Coord[{crdId}].DesTimeBase=0;&{crdId}b{prgId}r'''.format(prgId=prgId, plcId=plcId, crdId=crdId)
|
||||
self.sync_prg = 'Coord[{crdId}].DesTimeBase=0'.format(prgId=prgId, plcId=plcId, crdId=crdId)
|
||||
self.sync_run = 'enable plc {plcId};&{crdId}b{prgId}r'''.format(prgId=prgId, plcId=plcId, crdId=crdId)
|
||||
|
||||
elif mode == 2:
|
||||
# code block to insert in the program
|
||||
# - waits untis <flag> is false
|
||||
# - waits raising edge of <flag> and the sets DesTimeBase=ServoPeriod
|
||||
|
||||
# flag ='PowerBrick[0].GpioData[0].0.1==1'
|
||||
flag = 'Gate3[1].Chan[0].UserFlag==0'
|
||||
prg = '''
|
||||
//L0=Sys.PhaseCount
|
||||
//send 1"sync0 %d:%d\\n",Sys.PhaseCount,Sys.PhaseCount-L0
|
||||
while({flag}){{}}
|
||||
//send 1"sync1 %d:%d\\n",Sys.PhaseCount,Sys.PhaseCount-L0
|
||||
//L1=Sys.PhaseCount
|
||||
while(1)
|
||||
{{
|
||||
if({flag})
|
||||
{{
|
||||
//PowerBrick[0].GpioData[0].16.8=255
|
||||
//send 1"sync2 %d:%d\\n",Sys.PhaseCount,Sys.PhaseCount-L1
|
||||
break
|
||||
}}
|
||||
}}
|
||||
'''.format(plcId=plcId, crdId=crdId, flag=flag)
|
||||
self.sync_prg = prg
|
||||
self.sync_run = '&{crdId}b{prgId}r'''.format(prgId=prgId, plcId=plcId, crdId=crdId)
|
||||
|
||||
def run(self):
|
||||
'runs the code sync_run which has been generated with setup_sync()'
|
||||
|
||||
@@ -105,7 +105,8 @@ class HelicalScanGui():
|
||||
x= x.reshape(-1,1).dot(np.ones((1,y.shape[1])))
|
||||
lbl=('cx','cz','w','fy')
|
||||
#plt.plot(x, y,label=lbl)
|
||||
for i in range(y.shape[1]):
|
||||
#for i in range(y.shape[1]):
|
||||
for i in range(len(lbl)):
|
||||
plt.plot(x[:,i], y[:,i],label=lbl[i])
|
||||
|
||||
plt.legend()
|
||||
@@ -115,8 +116,10 @@ class HelicalScanGui():
|
||||
y = rec
|
||||
#plt.ion()
|
||||
fig = plt.figure(figsize=(20,6))
|
||||
c='bgrc'
|
||||
lbl=('cx','cz','w','fy')
|
||||
if y.shape[1]==4:
|
||||
c='bgrc';lbl=('cx','cz','w','fy')
|
||||
else:
|
||||
c='bgrcm';lbl=('cx','cz','w','fy','sync')
|
||||
dx=.25/len(lbl)
|
||||
for i in range(rec.shape[1]):
|
||||
if i==0:
|
||||
@@ -149,8 +152,8 @@ class HelicalScanGui():
|
||||
obj = event.canvas.figure.obj
|
||||
data = event.canvas.figure.data
|
||||
if(event.xdata):
|
||||
idx=round(event.xdata)
|
||||
msg='%d: cx:%.3f cz:%.3f w:%.1f fy:%.3f'%((idx,)+tuple(data[idx,:]))
|
||||
idx=int(round(event.xdata))
|
||||
msg='%d: cx:%.3f cz:%.3f w:%.1f fy:%.3f'%((idx,)+tuple(data[idx,:4]))
|
||||
#print msg
|
||||
event.canvas.toolbar.set_message(msg)
|
||||
|
||||
@@ -338,7 +341,7 @@ class HelicalScanGui():
|
||||
|
||||
def update_anim(self,frm):
|
||||
rec=self.helScn.rec
|
||||
(cx, cz, w, fy)=rec[int(frm),:]
|
||||
(cx, cz, w, fy)=rec[int(frm),:4]
|
||||
#data/=. #scale from um to mm
|
||||
w*=d2r/1000 # scale from deg to rad
|
||||
if self.manip:
|
||||
@@ -738,7 +741,8 @@ class HelicalScan(MotionBase):
|
||||
comm=self.comm
|
||||
gt=self.gather
|
||||
gt.set_phasemode(False)
|
||||
gt.set_address("Motor[4].ActPos","Motor[5].ActPos","Motor[3].ActPos","Motor[1].ActPos")
|
||||
#gt.set_address("Motor[4].ActPos","Motor[5].ActPos","Motor[3].ActPos","Motor[1].ActPos")
|
||||
gt.set_address("Motor[4].ActPos","Motor[5].ActPos","Motor[3].ActPos","Motor[1].ActPos","Gate3[1].Chan[0].UserFlag")
|
||||
gt.set_property(MaxSamples=1000000, Period=acq_per)
|
||||
ServoPeriod= .2 #0.2ms #Sys.ServoPeriod is dependent of !common() macro
|
||||
#ServoPeriod=comm.gpascii.servo_period
|
||||
@@ -908,23 +912,6 @@ close
|
||||
gpascii = comm.gpascii
|
||||
param=self.param
|
||||
prg=[]
|
||||
acq_per=kwargs.get('acq_per',10)
|
||||
gather={"MaxSamples":1000000, "Period":acq_per}
|
||||
#Sys.ServoPeriod is dependent of !common() macro
|
||||
ServoPeriod= .2 #0.2ms
|
||||
#ServoPeriod = .05
|
||||
self.meta = {'timebase': ServoPeriod*gather['Period']}
|
||||
#channels=["Motor[1].ActPos","Motor[2].ActPos","Motor[3].ActPos"]
|
||||
# CX CZ W FY
|
||||
channels=["Motor[4].ActPos","Motor[5].ActPos","Motor[3].ActPos","Motor[1].ActPos"]
|
||||
prg.append('Gather.Enable=0')
|
||||
prg.append('Gather.Items=%d'%len(channels))
|
||||
for k,v in gather.items():
|
||||
prg.append('Gather.%s=%d'%(k,v))
|
||||
for i,c in enumerate(channels):
|
||||
prg.append('Gather.Addr[%d]=%s.a'%(i,c))
|
||||
|
||||
|
||||
prg.append('open prog %d'%(prgId))
|
||||
prg.append(' P1000=0')
|
||||
# this uses Coord[1].Tm and limits with MaxSpeed
|
||||
@@ -1025,6 +1012,10 @@ close
|
||||
prg.append(' linear abs')
|
||||
prg.append(' X%g Z%g B%g Y%g' % tuple(pv[0, (0,1,2,3)]))
|
||||
prg.append(' dwell 10')
|
||||
try: prg.extend(self.sync_prg.split('\n'))
|
||||
except AttributeError:
|
||||
# print('no sync code available')
|
||||
pass
|
||||
prg.append(' Gather.Enable=2')
|
||||
if cnt>1:
|
||||
prg.append(' P100=%d'%cnt)
|
||||
@@ -1073,14 +1064,14 @@ close
|
||||
ofs = np.ndarray(len(channels))
|
||||
for i, v in enumerate(channels):
|
||||
ofs[i] = gpascii.get_variable(v,float)
|
||||
rec -= ofs
|
||||
rec[:,:4]-=ofs
|
||||
if fnRec:
|
||||
np.savez_compressed(fnRec, rec=rec, points=self.points, param=self.param, meta=self.meta)
|
||||
|
||||
|
||||
if __name__=='__main__':
|
||||
def run_test(args):
|
||||
args.host=None
|
||||
#args.host=None
|
||||
if args.host is None:
|
||||
comm=gather=None
|
||||
else:
|
||||
@@ -1093,23 +1084,23 @@ if __name__=='__main__':
|
||||
#hs.test_find_rot_ctr()
|
||||
#hs.test_find_rot_ctr(n=5. ,per=1.,bias=2.31,ampl=4.12,phi=24.6)
|
||||
fn='/tmp/helicalscan'
|
||||
hs.load_rec(fn+'.npz')
|
||||
hs.param[:4]+=np.pi/2.#add 90 deg
|
||||
#hs.load_rec(fn+'.npz')
|
||||
#hs.param[:4]+=np.pi/2.#add 90 deg
|
||||
|
||||
hsg=HelicalScanGui(hs);hsg.interactive_anim()
|
||||
hsg=HelicalScanGui(hs);hsg.interactive_anim(manip=True)
|
||||
#hsg=HelicalScanGui(hs);hsg.interactive_anim()
|
||||
#hsg=HelicalScanGui(hs);hsg.interactive_anim(manip=True)
|
||||
#while True:hsg.update_anim(0)
|
||||
#hs.param = np.ndarray((2,5))
|
||||
#hs.param[0]=(15,2,0,3,0)#(z_i, y_i, x_i, r_i,phi_i)
|
||||
#hs.param[1]=(15,4,0,2,np.pi/4)#(z_i, y_i, x_i, r_i,phi_i)
|
||||
|
||||
hsg=HelicalScanGui(hs);hsg.interactive_cx_cz_w_fy()
|
||||
hsg=HelicalScanGui(hs);hsg.interactive_cx_cz_w_fy(manip=True)
|
||||
#hsg=HelicalScanGui(hs);hsg.interactive_cx_cz_w_fy()
|
||||
#hsg=HelicalScanGui(hs);hsg.interactive_cx_cz_w_fy(manip=True)
|
||||
#while True: hsg.update_cx_cz_w_fy() #for debug purpose
|
||||
|
||||
|
||||
hsg=HelicalScanGui(hs);hsg.interactive_dx_dz_w_y()
|
||||
hsg=HelicalScanGui(hs);hsg.interactive_dx_dz_w_y(manip=True)
|
||||
#hsg=HelicalScanGui(hs);hsg.interactive_dx_dz_w_y()
|
||||
#hsg=HelicalScanGui(hs);hsg.interactive_dx_dz_w_y(manip=True)
|
||||
#while True: hsg.update_dx_dz_w_y() #for debug purpose
|
||||
#return
|
||||
|
||||
@@ -1125,12 +1116,9 @@ if __name__=='__main__':
|
||||
# 120deg 574.8 619.8 -1797.5
|
||||
# 240deg 580.0 -900.0 -2496.3
|
||||
|
||||
hs.calcParam(x = ((-762.5, 731.7, -1282.8), (-1023.4, 619.8, -900.0)),
|
||||
y = (258.5,580.0),
|
||||
z = (( -396.4,-1896.9,-2496.5),(-696.8,-1797.5,-2496.3)))
|
||||
#&1p
|
||||
#B0.3504637004225515 X5.101934282692127 Y586.5400000000002 Z96.49435276710267
|
||||
|
||||
#hs.calcParam(x = ((-762.5, 731.7, -1282.8), (-1023.4, 619.8, -900.0)),
|
||||
# y = (258.5,580.0),
|
||||
# z = (( -396.4,-1896.9,-2496.5),(-696.8,-1797.5,-2496.3)))
|
||||
|
||||
#cpx X0 Z0 B0 Y258
|
||||
#cpx X0 Z0 B120000 Y258
|
||||
@@ -1139,11 +1127,50 @@ if __name__=='__main__':
|
||||
#cpx X0 Z0 B120000 Y580
|
||||
#cpx X0 Z0 B240000 Y580
|
||||
|
||||
#cpx X-100Z0B0Y258.5
|
||||
|
||||
# 0deg 1405.7 -1154.4 -1309.6
|
||||
# 120deg 1401.7 216.3 -1010.9
|
||||
# 240deg 1407.9 -250.7 -2410.3
|
||||
# 0deg 1053.9 -1330.2 -1219.4
|
||||
# 120deg 1019.2 340.9 -918.8
|
||||
# 240deg 984.0 -230.4 -2510.4
|
||||
|
||||
#hs.calcParam(x = ((-1154.4, 216.3, -250.7), ( -1330.2, 340.9, -230.4)),
|
||||
# y = (1405.7,1019.2),
|
||||
# z = ((-1309.6, -1010.9, -2410.3),( -1219.4, -918.8, -2510.4)))
|
||||
|
||||
|
||||
#&1p
|
||||
#cpx X0 Z0 B0 Y1405
|
||||
#cpx X0 Z0 B120000 Y1405
|
||||
#cpx X0 Z0 B240000 Y1405
|
||||
#cpx X0 Z0 B0 Y1019
|
||||
#cpx X0 Z0 B120000 Y1019
|
||||
#cpx X0 Z0 B240000 Y1019
|
||||
|
||||
|
||||
#1600.5 -1484.0 -1264.2
|
||||
#1599.0 234.6 -663.3
|
||||
#1599.9 28.5 -2264.7
|
||||
# 468.3 629.9 -2663.3
|
||||
# 472.2 25.3 -164.4
|
||||
# 470.9 -1841.3 -1965.0
|
||||
|
||||
#hs.calcParam(x = ((-1484.0, 234.6, 28.5), ( 629.9, 25.3,-1841.3)),
|
||||
# y = (1600.,470.),
|
||||
# z = ((-1264.2, -663.3,-2264.7),(-2663.3, -164.4,-1965.0)))
|
||||
|
||||
|
||||
#cpx X0 Z0 B0 Y1405
|
||||
#cpx X0 Z0 B120000 Y1405
|
||||
#cpx X0 Z0 B240000 Y1405
|
||||
#cpx X0 Z0 B0 Y1019
|
||||
#cpx X0 Z0 B120000 Y1019
|
||||
#cpx X0 Z0 B240000 Y1019
|
||||
fh=open("/sf/bernina/config/swissmx/exchange/helical.cmd")
|
||||
s=fh.read();s=s.replace('calcParam','hs.calcParam')
|
||||
eval(s)
|
||||
|
||||
#hs.calcParamSim()
|
||||
#hs.param[0]=(15,2,0,3,0)#(z_i, y_i, x_i, r_i,phi_i)
|
||||
#hs.param[1]=(15,4,0,3,0)#(z_i, y_i, x_i, r_i,phi_i)
|
||||
@@ -1158,17 +1185,14 @@ if __name__=='__main__':
|
||||
#0:1 config simulated motors
|
||||
#1:2 config real motors
|
||||
#2:4 config coord trf
|
||||
mode=4#5#4#0
|
||||
os.chdir(os.path.join(os.path.dirname(__file__),'../cfg'))
|
||||
if mode&1:
|
||||
hs.download(file='sim_8_motors.cfg')
|
||||
if mode&2:
|
||||
hs.download(['$$$***','!common()','!SAR-EXPMX1()','#1..7j/','enable plc 1','Motor[1].MaxSpeed=25','Motor[2].MaxSpeed=25'])
|
||||
raw_input('press return when homed')
|
||||
if mode&4:
|
||||
hs.setup_coord_trf()
|
||||
|
||||
hs.setup_sync() # no sync at all
|
||||
#os.chdir(os.path.join(os.path.dirname(__file__),'../cfg'))
|
||||
#'sim_8_motors.cfg'
|
||||
#['$$$***','!common()','!SAR-EXPMX1()','#1..7j/','enable plc 1','Motor[1].MaxSpeed=25','Motor[2].MaxSpeed=25'])
|
||||
# raw_input('press return when homed')
|
||||
hs.setup_coord_trf()
|
||||
|
||||
hs.setup_sync(mode=2) # None: no sync at all mode=1: sync on timing UserFlag
|
||||
hs.setup_gather()
|
||||
|
||||
#hs.gen_prog(mode=-1)
|
||||
@@ -1185,7 +1209,7 @@ if __name__=='__main__':
|
||||
#hs.gen_prog(mode=0,cntHor=3,cntVert=10,hRng=(-5,5),wRng=(0,120000))
|
||||
#hs.gen_prog(mode=0,cntHor=3,cntVert=25,hRng=(-5,5),wRng=(0,120000))
|
||||
#hs.gen_prog(mode=1,cntHor=3,cntVert=25,hRng=(-5,5),wRng=(0,120000),smt=0,pt2pt_time=300)
|
||||
hs.setup_motion(mode=1,cntHor=5,cntVert=15,hRng=(-150,150),wRng=(0,120000),smt=0,pt2pt_time=300)
|
||||
hs.setup_motion(mode=1,cntHor=5,cntVert=15,hRng=(-150,150),wRng=(0,120000),smt=0,pt2pt_time=200)
|
||||
#hs.gen_prog(mode=1,cntHor=5,cntVert=25,hRng=(-100,100),wRng=(0,120000),smt=0,pt2pt_time=40)
|
||||
#hs.gen_prog(mode=1,cntHor=3,cntVert=20,hRng=(-5,5),wRng=(0,1200),smt=0,pt2pt_time=200)
|
||||
#hs.gen_prog(mode=1, cntHor=2, cntVert=2, wRng=(0, 360000), smt=0)
|
||||
@@ -1196,19 +1220,15 @@ if __name__=='__main__':
|
||||
|
||||
|
||||
hs.run()
|
||||
print('temporary wait that the program started')
|
||||
time.sleep(5)#temporary wait that the program started
|
||||
print('wait until gather finished:')
|
||||
hs.gather_upload(fn+'.npz')
|
||||
|
||||
hs.load_rec(fn+'.npz')
|
||||
|
||||
hsg=HelicalScanGui(hs)
|
||||
hsg.show_pos()
|
||||
hsg.show_vel()
|
||||
hsg.interactive_anim()
|
||||
#hs.show_vel(); plt.show()
|
||||
#hs.show_pos(); plt.show()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
from optparse import OptionParser, IndentedHelpFormatter
|
||||
|
||||
@@ -212,12 +212,10 @@ class ShapePath(MotionBase):
|
||||
prg.append(' linear abs')
|
||||
prg.append('X%g Y%g' % tuple(pv[0, (0,1)]))
|
||||
prg.append('dwell 10')
|
||||
try:
|
||||
prg.append(self.sync_wait)
|
||||
try: prg.extend(self.sync_prg.split('\n'))
|
||||
except AttributeError:
|
||||
#print('no sync code available')
|
||||
pass
|
||||
else:
|
||||
print('no sync code available')
|
||||
prg.append('Gather.Enable=2')
|
||||
if cnt>1:
|
||||
prg.append('P100=%d'%cnt)
|
||||
|
||||
Reference in New Issue
Block a user