This commit is contained in:
2024-11-25 10:51:43 +01:00
parent 87d984d358
commit bea723d7f8

View File

@@ -1029,158 +1029,99 @@ enable plc 2
else: # scan=1 else: # scan=1
vsx=px/(pt2pt_time)*scale*CoordFeedTime # scaling for Deltatau vsx=px/(pt2pt_time)*scale*CoordFeedTime # scaling for Deltatau
vsy=py/(pt2pt_time)*scale*CoordFeedTime # scaling for Deltatau vsy=py/(pt2pt_time)*scale*CoordFeedTime # scaling for Deltatau
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)
tx,ty=nx//sx,ny//sy #total sections
#variables #variables
r,x0,y0,n,dx,dy,x1,y1,t,vx,vy=map(lambda x: f'L{x}',range(11)) cx,cy,dx,dy,n,k,sx,sy,tx,ty,vsx,vsy,vx,vy,x,x0,y,y0=map(lambda x: f'L{x}',range(16))
# replace in python code of hit_and_return.py setup_motion:
# (cx|cy|dx|dy|n|k|sx|sy|tx|ty|vsx|vsy|vx|vy|x|x0|y|y0) -> {\1}
# replace: [^{](x|y|x0|y0|cx|cy|x0|y0|n|dx|dy|vsx|vsy|vx|vy) -> {\1} # if ([^:]*): -> if \(\1\){{
prg+=f'''\ # else: -> }}else{{
g=kwargs['grid'] # elif ([^:]*): -> }}else if \(\1\){{
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)
tx,ty=nx//sx,ny//sy #total sections
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
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'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:
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:
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 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)
k,dx,dy=6,-1,0
vx,vy=-vsx,0
elif x0==0: #(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
'''
prg+=f'''\ prg+=f'''\
//mode 6: hit-and-return pvt motion //mode 6: hit-and-return pvt motion
{r}=0 // row
{x0}=0;{y0}=-1;{n}=0 // counter well in region {k}=-1 # key position
{dx}=0;{dy}=1 // motion pitch {cx},{cy}=0,0 # section counter
{x1}=0;{y1}=0 // counter region start {x0},{y0},{n}=0,0,0 # counter well in region
{t}=1 // motion pvt time scaling {dx},{dy}=0,1 # motion pitch
{vsx}={vsy}=1 # scaled velocity
{vx},{vy}=0,{vsy} # scaled velocity
pvt{pt2pt_time} abs pvt{pt2pt_time} abs
while(1){{ while(1){{:
//send 1"A:move(%d) X%g:%g Y%g:%g",{n},{ox}+{x0}+{x1}*{px},{dx},{oy}+{y0}+{y1}*{py},{dy} if ({cy}%2==0){{ # even rows
X({ox}+({x0}+{x1})*{px}):({vx}) Y({oy}+({y0}+{y1})*{py}):({vy}) {x}={sx}*{cx}+{x0};{y}={sy}*{cy}+{y0}
{x0}+={dx};{y0}+={dy} }}else{{ # odd rows
if ({t}!=1){{ {x}=({tx}-{cx})*{sx}-{x0}-1;{y}={sy}*{cy}+{y0}
pvt{pt2pt_time} abs;{t}=1 {vx}=-{vx}
}} }}
{x0}+={dx};{y0}+={dy}
//send 1"A:move(%d) X%g:%g Y%g:%g",{k},{x},{vx},{y},{vy}
X({x}):({vx}) Y({y}):({vy})
if ({k}>=0){{ #if keypoint not directly followed by an other keypoint, define future velocity
if ({k}==0 || {k}==4){{
{vx},{vy}=0,{vsy}
}}else if ({k}==2){{
{vx},{vy}=0,-{vsy}
}}else if ({k}==5){{
{vx},{vy}=-{vsx},0
}}else if ({k}==6){{
{n}+=1
}}else if ({k}==7){{
//send 1"next h section"
{cx}+=1
{x0},{y0},{n},{dx},{dy}=0,0,0,0,0
}}else if ({k}==8){{
//send 1"next v section"
{cx}=0;{cy}+=1
{x0},{y0},{n},{dx},{dy}=0,0,0,0,0
if ({cy}>={ty}){{
//send 1"finished whole grid"
break
}}
}}
//send 1"after keypoint %d: %g|%g",{k},{vx},{vy}
{k}=-1
if ({y0}=={sy}-1){{ if ({y0}=={sy}-1){{
if ({dy}==1){{ // (1) if ({dy}==1){{ #(1)
{dx}=1;{dy}=0 {dx},{dy}=1,0
{vx}={vsx}/2;{vy}={vsy}/2 {vx},{vy}={vsx}/2,{vsy}/2
}}else{{ }}else{{
{dx}=0;{dy}=-1// (2) {k},{dx},{dy}=2,0,-1#(2)
{vx}={vsx}/2;{vy}=-{vsy}/2 {vx},{vy}={vsx}/2,-{vsy}/2
}} }}
}}else if ({y0}==1 && {x0}<{sx}-1){{ }}else if ({y0}==1 && {x0}>0 && {x0}<{sx}-1){{
if ({dy}==-1){{ // (3) if ({dy}==-1){{ #(3)
{dx}=1;{dy}=0 {dx},{dy}=1,0
{vx}={vsx}/2;{vy}=-{vsy}/2 {vx},{vy}={vsx}/2,-{vsy}/2
}}else{{ }}else{{
{dx}=0;{dy}=1 // (4) {k},{dx},{dy}=4,0,1 #(4)
{vx}={vsx}/2;{vy}={vsy}/2 {vx},{vy}={vsx}/2,{vsy}/2
}}
}}else if ({y0}==0){{ }}else if ({y0}==0){{
if ({n}==1 && {x0}==1){{ // (7 or 8) if ({n}==1 && {x0}==1){{ #(7 or 8)
if ({r}%2==0 && {x1}+2*{sx}<={nx}){{ // (7 even) if ({cx}<{tx}-1){{
{x1}+={sx} {k},{dx},{dy}=7,-1,0
{vx}={vsx};{vy}=0 {vx},{vy}=0,0
pvt{pt2pt_time*tmx} abs;{t}={tmx} }}else{{ #(8)
{k},{dx},{dy}=8,{sx}-1,{sy}
{vx},{vy}=0,0
}} }}
else if ({r}%2==1 && {x1}>0){{ //(7 odd) }}else if ({x0}==1){{ #(6)
{x1}-={sx} {k},{dx},{dy}=6,-1,0
{vx}=0;{vy}=0 {vx},{vy}=-{vsx},0
pvt{pt2pt_time*tmx} abs;{t}={tmx} }}else if ({x0}==0){{ #(0)
}} {k},{dx},{dy}=0,0,1
else if ({y1}+2*{sy}<={ny}){{ //(8) {vx},{vy}=0,{vsy}
{y1}+={sy};{r}+=1 }}else if ({x0}=={sx}-1){{ #(5)
{vx}=0;{vy}={vsy} {k},{dx},{dy}=5,-1,0
pvt{pt2pt_time*tmy} abs;{t}={tmy} {vx},{vy}=-{vsx}/2,-{vsy}/2
}}else{{
break // finished whole grid
}}
//send 1"next regionA"
{x0}=0;{y0}=0;{n}=0
{dx}=0;{dy}=0
}}else if ({x0}==1){{ // (6)
{dx}=-1;{dy}=0;{n}+=1
{vx}=-{vsx};{vy}=0
pvt{pt2pt_time*sdl} abs;{t}={tmy}
}}else if ({x0}==0){{ // (0)
{dx}=0;{dy}=1
{vx}=0;{vy}={vsy}
}}else{{ // (5)
{dx}=-1;{dy}=0
{vx}=-{vsx}/2;{vy}=-{vsy}/2
}} }}
}} }}
}} }}