This commit is contained in:
2024-11-25 09:58:55 +01:00
parent ae7882651e
commit 527fcec7f5
3 changed files with 307 additions and 241 deletions

View File

@@ -30,16 +30,23 @@ class HitReturnEval:
h3=ax.plot(pts[:,0],pts[:,1],'g-')
h2=ax.plot(pts[:,0],pts[:,1],'y-')
h1=ax.plot(pts[:,0],pts[:,1],'r.')
ha=ax.arrow(4, 2, 0.5, 0.5, head_width=0.05, head_length=0.1, fc='k', ec='k')
#cid = fig.canvas.mpl_connect('button_press_event', self.onclick)
#fig.obj=self
plt.axis('equal')
plt.ion()
fig.show()
self._plt=(fig,ax,h1[0],h2[0])
self._plt=[fig,ax,h1[0],h2[0],ha]
def updatePlt(self,pts):
fig, ax, h1, h2=self._plt
def updatePlt(self,pts,vx,vy):
fig,ax,h1,h2,ha=self._plt
x,y=pts[-1][:2]
pts=np.array(pts)
ha.remove()
l=(vx**2+vy**2)**.5
ha=ax.arrow(x,y,.7*vx,.7*vy, head_width=.2, head_length=0.3*l, fc='k', ec='k',zorder=5)
self._plt[-1]=ha
h1.set_xdata((pts[:,0]))
h1.set_ydata((pts[:,1]))
h2.set_xdata((pts[:,0]))
@@ -56,8 +63,10 @@ class HitReturnEval:
g=kwargs['grid']
ox,oy=g['pos'] #origin position in um (or counts if scaled)
px,py=g['pitch'] #pitch to next position in um (or 1 if scaled)
nx,ny=g['count'] #total count of wells
sx,sy=kwargs['ssz'] #section size (in wells)
nx,ny=g['count'] #total count of wells
sx,sy=kwargs['ssz'] #section size (in wells)
tx,ty=nx//sx,ny//sy #total sections
#smv=kwargs['smv'] #time(in num of shots) to move to next section (horiz/vert)
#swait=kwargs['smv'] #wait after <swait> section for motion trigger. swait=0:never wait
@@ -72,45 +81,78 @@ class HitReturnEval:
# | | | | | | | | | | | |
# 1-2 1-2 1-2 1-2 1-2 1-2
r=0 #row
x0,y0,n=0,-1,0 # counter well in region
k=-1 # key position
cx,cy=0,0 # section counter
x0,y0,n=0,0,0 # counter well in region
dx,dy=0,1 # motion pitch
x1,y1=0,0 #counter region start
vsx=vsy=1 # scaled velocity
vx,vy=0,vsy # scaled velocity
mv=list()
while(True):
if cy%2==0: # even rows
x=sx*cx+x0;y=sy*cy+y0
else: # odd rows
x=(tx-cx)*sx-x0-1;y=sy*cy+y0
vx=-vx
x0+=dx;y0+=dy
print(f'{x0+x1} {y0+y1} ({dx}|{dy}|{n})')
mv.append((x0+x1+.1*n,y0+y1+.1*n,n))
self.updatePlt(mv)
print(f'X{x}:{vx} Y{y}:{vy} ({k}|{dx}|{dy}|{n})')
mv.append((x+.1*n,y+.1*n,n))
self.updatePlt(mv,vx,vy)
if k>=0: #if keypoint not directly followed by an other keypoint, define future velocity
if k in (0,4):
vx,vy=0,vsy
elif k==2:
vx,vy=0,-vsy
elif k==5:
vx,vy=-vsx,0
elif k==6:
n+=1
elif k==7:
print('next h section')
cx+=1
x0,y0,n,dx,dy=0,0,0,0,0
elif k==8:
print('next v section')
cx=0;cy+=1
x0,y0,n,dx,dy=0,0,0,0,0
if cy>=ty:
print('finished whole grid')
break #
else:
raise ValueError('should never happened')
print(f'vx|vy after keypoint {k}: ({vx}|{vy})')
k=-1
if y0==sy-1:
if dy==1: #(1)
dx,dy=1,0
vx,vy=vsx/2,vsy/2
else:
dx,dy=0,-1#(2)
elif y0==1 and x0<sx-1:
k,dx,dy=2,0,-1#(2)
vx,vy=vsx/2,-vsy/2
elif y0==1 and x0>0 and x0<sx-1:
if dy==-1: #(3)
dx,dy=1,0
vx,vy=vsx/2,-vsy/2
else:
dx,dy=0,1 #(4)
k,dx,dy=4,0,1 #(4)
vx,vy=vsx/2,vsy/2
elif y0==0:
if n==1 and x0==1: #(7 or 8)
if r%2==0 and x1+2*sx<=nx:#(7 even)
x1+=sx
elif r%2==1 and x1>0:#(7 odd)
x1-=sx
elif y1+2*sy<=ny:#(8)
y1+=sy;r+=1
else:
break #finished whole grid
print('next regionA')
x0,y0,n=0,0,0
dx,dy=0,0
if cx<tx-1:
k,dx,dy=7,-1,0
vx,vy=0,0
else: #(8)
k,dx,dy=8,sx-1,sy
vx,vy=0,0
elif x0==1: #(6)
dx,dy=-1,0;n+=1
k,dx,dy=6,-1,0
vx,vy=-vsx,0
elif x0==0: #(0)
dx,dy=0,1
else: #(5)
dx,dy=-1,0
k,dx,dy=0,0,1
vx,vy=0,vsy
elif x0==sx-1: #(5)
k,dx,dy=5,-1,0
vx,vy=-vsx/2,-vsy/2
def plot_trajectory(self):
pts = self.pts # X,Y array

View File

@@ -1040,27 +1040,27 @@ enable plc 2
{t}=1 // motion pvt time scaling
pvt{pt2pt_time} abs
while(1){{
{x0}+={dx};{y0}+={dy}
//send 1"A:move(%d) X%g:%g Y%g:%g",{n},{ox}+{x0}+{x1}*{px},{dx},{oy}+{y0}+{y1}*{py},{dy}
X({ox}+({x0}+{x1})*{px}):({vx}) Y({oy}+({y0}+{y1})*{py}):({vy})
{x0}+={dx};{y0}+={dy}
if ({t}!=1){{
pvt{pt2pt_time} abs;{t}=1
}}
if ({y0}=={sy}-1){{
if ({dy}==1){{ // (1)
{dx}=1;{dy}=0
{vx}={vsx};{vy}=0
{vx}={vsx}/2;{vy}={vsy}/2
}}else{{
{dx}=0;{dy}=-1// (2)
{vx}=0;{vy}=-{vsy}
{vx}={vsx}/2;{vy}=-{vsy}/2
}}
}}else if ({y0}==1 && {x0}<{sx}-1){{
if ({dy}==-1){{ // (3)
{dx}=1;{dy}=0
{vx}={vsx};{vy}=0
{vx}={vsx}/2;{vy}=-{vsy}/2
}}else{{
{dx}=0;{dy}=1 // (4)
{vx}=0;{vy}={vsy}
{vx}={vsx}/2;{vy}={vsy}/2
}}
}}else if ({y0}==0){{
if ({n}==1 && {x0}==1){{ // (7 or 8)
@@ -1071,7 +1071,7 @@ enable plc 2
}}
else if ({r}%2==1 && {x1}>0){{ //(7 odd)
{x1}-={sx}
{vx}=-{vsx};{vy}=0
{vx}=0;{vy}=0
pvt{pt2pt_time*tmx} abs;{t}={tmx}
}}
else if ({y1}+2*{sy}<={ny}){{ //(8)
@@ -1093,7 +1093,7 @@ enable plc 2
{vx}=0;{vy}={vsy}
}}else{{ // (5)
{dx}=-1;{dy}=0
{vx}=-{vsx};{vy}=0
{vx}=-{vsx}/2;{vy}=-{vsy}/2
}}
}}
}}
@@ -1299,8 +1299,8 @@ if __name__=='__main__':
elif mode==6:
grid={'pos':(-1000, -1200), 'pitch':(120, 120), 'count':(16, 20)}
# section size (in wells)
ssz=(4, 5)
#ssz=(6, 10)
#ssz=(4, 5)
ssz=(6, 10)
#ssz=(2, 5)
#sdelay=ssz[0]*ssz[1] # wait after <swait> section for motion trigger. swait=0:never wait
sp.setup_motion(fnPrg=fn+'.prg',scale=1.,cnt=1,dwell=100,mode=6,grid=grid,ssz=ssz)