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