wip
This commit is contained in:
@@ -62,10 +62,11 @@ class MotionBase:
|
||||
flag1='Gate3[1].Chan[1].UserFlag'
|
||||
flag0='P0';flag1='P1'
|
||||
prg = '''
|
||||
Coord[1].Q[1]=1
|
||||
Coord[1].Q[1]=-2
|
||||
while({flag0}==0){{}}
|
||||
Coord[1].Q[1]=-1
|
||||
Gather.Enable=2
|
||||
while({flag1}==0){{}}
|
||||
Coord[1].Q[1]=2
|
||||
'''.format(plcId=plcId, crdId=crdId, flag0=flag0, flag1=flag1)
|
||||
self.sync_prg = prg
|
||||
self.sync_run = '&{crdId}b{prgId}r'''.format(prgId=prgId, plcId=plcId, crdId=crdId)
|
||||
@@ -77,9 +78,9 @@ class MotionBase:
|
||||
flag0='P0';flag1='P1'
|
||||
pt2pt_time=40
|
||||
prg='''
|
||||
Coord[1].Q[1]=1
|
||||
//Gather.Enable=2 if done in the sync program
|
||||
Coord[1].DesTimeBase=0
|
||||
Coord[1].Q[1]=2
|
||||
Coord[1].Q[1]=-1
|
||||
'''.format(plcId=plcId, crdId=crdId, flag0=flag0, flag1=flag1)
|
||||
self.sync_prg=prg
|
||||
self.sync_run='&{crdId}b{prgId}r'''.format(prgId=prgId, plcId=plcId, crdId=crdId)
|
||||
|
||||
@@ -287,6 +287,9 @@ class ShapePath(MotionBase):
|
||||
gt=self.gather
|
||||
gt.set_phasemode(False)
|
||||
address=("Motor[1].ActPos","Motor[2].ActPos","Motor[1].DesPos","Motor[2].DesPos","Gate3[1].Chan[1].UserFlag")
|
||||
address=("Motor[1].ActPos","Motor[2].ActPos","Motor[1].DesPos","Motor[2].DesPos","Sys.P[1]")
|
||||
#address=("Motor[1].ActPos","Motor[2].ActPos","Motor[1].DesPos","Motor[2].DesPos","Coord[1].Q[1]")
|
||||
|
||||
gt.set_address(*address)
|
||||
gt.set_property(MaxSamples=1000000, Period=acq_per)
|
||||
ServoPeriod= .2 #0.2ms #Sys.ServoPeriod is dependent of !common() macro
|
||||
@@ -318,13 +321,16 @@ class ShapePath(MotionBase):
|
||||
mode=-1 jog a 10mm square
|
||||
mode=0 linear motion
|
||||
mode=1 pvt motion
|
||||
kwargs: scale: scaling velocity (default=1. value=0 would stop at the point
|
||||
kwargs:
|
||||
pt2pt_time : time to move from one point to the next point
|
||||
sync_frq : synchronization mark all n points (default=10)
|
||||
scale : scaling velocity (default=1. value=0 would stop at the point
|
||||
cnt : move path multiple times (default=1)
|
||||
dwell : dwell time at end (default=100ms)
|
||||
|
||||
mode=2 spline motion
|
||||
mode=3 pvt motion using inverse fft velocity
|
||||
kwargs: scale: scaling velocity (default=1. value=0 would stop at the point
|
||||
kwargs:
|
||||
pt2pt_time : time to move from one point to the next point
|
||||
sync_frq : synchronization mark all n points
|
||||
kwargs: same as pvt motion
|
||||
'''
|
||||
prg=['close all buffers','open prog %d'%(prgId)]
|
||||
comm=self.comm
|
||||
@@ -364,6 +370,7 @@ class ShapePath(MotionBase):
|
||||
self.meta['pt2pt_time']=pt2pt_time
|
||||
cnt=kwargs.get('cnt', 1) # move path multiple times
|
||||
sync_frq=kwargs.get('sync_frq', 10) # synchronization mark all n points
|
||||
dwell=kwargs.get('dwell', 100) # synchronization mark all n points
|
||||
CoordFeedTime=1000. #Defaut deltatau value
|
||||
try:
|
||||
pt=self.ptsCorr
|
||||
@@ -403,17 +410,17 @@ class ShapePath(MotionBase):
|
||||
try: prg.extend(self.sync_prg.split('\n'))
|
||||
except AttributeError:
|
||||
#print('no sync code available')
|
||||
pass
|
||||
prg.append('Gather.Enable=2')
|
||||
prg.append('Gather.Enable=2')
|
||||
if cnt>1:
|
||||
prg.append('P100=%d'%cnt)
|
||||
prg.append('N100:')
|
||||
prg.append(' pvt%g abs'%pt2pt_time) #100ms to next position
|
||||
for idx in range(1,pv.shape[0]):
|
||||
if sync_frq is not None and idx%sync_frq==0:
|
||||
prg.append('Coord[1].Q[0]=%d'%(idx))
|
||||
prg.append('Coord[1].Q[1]=%d'%(idx))
|
||||
prg.append('X%g:%g Y%g:%g'%tuple(pv[idx,(0,2,1,3)]))
|
||||
prg.append('Coord[1].Q[0]=%d' % (idx))
|
||||
if sync_frq is not None:
|
||||
prg.append('Coord[1].Q[1]=%d' % (idx))
|
||||
prg.append('X%g Y%g' % tuple(pv[-1, (0,1)]))
|
||||
if cnt>1:
|
||||
prg.append('dwell 10')
|
||||
@@ -426,10 +433,7 @@ class ShapePath(MotionBase):
|
||||
prg.append('goto 100')
|
||||
prg.append('}')
|
||||
else:
|
||||
prg.append('dwell 1000')
|
||||
if sync_frq is not None:
|
||||
prg.append('Coord[1].Q[0]=-1')
|
||||
prg.append('Coord[1].Q[1]=0')
|
||||
prg.append('dwell %d'%dwell)
|
||||
prg.append('Gather.Enable=0')
|
||||
elif mode==2: #### spline motion
|
||||
try:
|
||||
@@ -562,6 +566,20 @@ class ShapePath(MotionBase):
|
||||
self.ax=ax
|
||||
self.hl=hl
|
||||
|
||||
idxTrigger = rec[:, 4]
|
||||
idxTrigger = np.where(np.diff(idxTrigger) == 1)[0] + 1
|
||||
if idxTrigger.shape[0]>0:
|
||||
hl=ax.plot(rec[idxTrigger,1],rec[idxTrigger,0],'xr') # actual path
|
||||
|
||||
fig = plt.figure('trigger')
|
||||
ax = fig.add_subplot(1, 1, 1)
|
||||
hl += ax.plot(rec[:,2], 'r-',label='desPos Mot1')
|
||||
hl += ax.plot(rec[:,3], 'g-',label='desPos Mot2')
|
||||
hl += ax.plot(rec[:, 4], 'b-',label='trigger')
|
||||
ax.legend(loc='best')
|
||||
plt.show(block=False)
|
||||
|
||||
|
||||
if mode&2:
|
||||
fig = plt.figure('position error')
|
||||
ax = fig.add_subplot(1, 1, 1)
|
||||
@@ -588,6 +606,7 @@ class ShapePath(MotionBase):
|
||||
# idxTrigger=np.hstack(([0],rec[:,4]))
|
||||
# doc.idxTrigger=idxTrigger=np.where(np.diff(idxTrigger)==1)[0]
|
||||
idxTrigger = rec[:, 4]
|
||||
|
||||
idxTrigger = np.where(np.diff(idxTrigger) == 1)[0] + 1
|
||||
idxInPos = [] # first point at idx 0
|
||||
try: # find approximate distance of 2 points
|
||||
@@ -785,7 +804,7 @@ if __name__=='__main__':
|
||||
sp.setup_gather(acq_per=2)
|
||||
sp.setup_sync(mode=2) #sync with timing system and PLC to sync speed (PROG)
|
||||
sp.setup_coord_trf() # reset to shape path system
|
||||
sp.setup_motion(fnPrg=fn + '.prg', mode=3, pt2pt_time=40,scale=1)
|
||||
sp.setup_motion(fnPrg=fn + '.prg', mode=3, pt2pt_time=40,scale=1,dwell=10)
|
||||
sp.run()
|
||||
sp.gather_upload(fnRec=fn+'.npz')
|
||||
sp.plot_gather(mode=11)
|
||||
|
||||
Reference in New Issue
Block a user