From f545812bc16270f971d545828b1364dd7412ce06 Mon Sep 17 00:00:00 2001 From: Thierry Zamofing Date: Mon, 25 Nov 2024 14:04:26 +0100 Subject: [PATCH] wip(3) --- python/hit_return_evaluation.py | 38 +++++++--- python/shapepath.py | 125 ++++++++++++++++++-------------- 2 files changed, 99 insertions(+), 64 deletions(-) diff --git a/python/hit_return_evaluation.py b/python/hit_return_evaluation.py index 36f4457..cca55fd 100755 --- a/python/hit_return_evaluation.py +++ b/python/hit_return_evaluation.py @@ -60,13 +60,6 @@ class HitReturnEval: #vgrid: grid parameters: {orig:(0,0),pitch(10,10),cnt:(10,10),mode:0} #vp0: x/y koordinates of well to start (default 0,0) #vsz: size of wells to cycle (must be 2n x m) - 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 - #smv=kwargs['smv'] #time(in num of shots) to move to next section (horiz/vert) #swait=kwargs['smv'] #wait after section for motion trigger. swait=0:never wait @@ -81,11 +74,30 @@ class HitReturnEval: # | | | | | | | | | | | | # 1-2 1-2 1-2 1-2 1-2 1-2 + 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) + try: + tsx, tsy=kwargs['smv'] # time(in num of shots) to move to next section (horiz/vert) + except KeyError as e: + tsx=sx-1 + tsy=sy + try: + tsd=kwargs['sdelay'] + except KeyError as e: + tsd=sx*sy + tsd+=1-sx*sy # sdl are shots to wait at position #(6) + + tx,ty=nx//sx,ny//sy #total sections + vsx=vsy=1 # scaled velocity + + t=1 #motion pvt tome scaling 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): @@ -98,6 +110,8 @@ class HitReturnEval: 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 t !=1: + print('pvt 10') if k>=0: #if keypoint not directly followed by an other keypoint, define future velocity if k in (0,4): vx,vy=0,vsy @@ -107,10 +121,14 @@ class HitReturnEval: vx,vy=-vsx,0 elif k==6: n+=1 + if tsd!=1: + print(f'pvt {10*tsd}');t=tsd;time.sleep(.1*tsd) elif k==7: print('next h section') cx+=1 x0,y0,n,dx,dy=0,0,0,0,0 + if tsx!=1: + print(f'pvt {10*tsx}');t=tsx;time.sleep(.1*tsx) elif k==8: print('next v section') cx=0;cy+=1 @@ -118,6 +136,8 @@ class HitReturnEval: if cy>=ty: print('finished whole grid') break # + if tsy!=1: + print(f'pvt {10*tsy}');t=tsy;time.sleep(.1*tsy) else: raise ValueError('should never happened') print(f'vx|vy after keypoint {k}: ({vx}|{vy})') @@ -220,7 +240,7 @@ if __name__=='__main__': grid={'pos':(-1000, -1200), 'pitch':(120, 120), 'count':(20, 25)} grid={'pos':(0, 0), 'pitch':(1, 1), 'count':(16, 20)} obj.initPlt(grid) - obj.setup_motion(grid=grid,ssz=(4,5)) + obj.setup_motion(grid=grid,ssz=(4,5),smv=(4-1,5+1),sdelay=4*5) obj.initPlt(grid) obj.setup_motion(grid=grid,ssz=(6,10)) obj.initPlt(grid) diff --git a/python/shapepath.py b/python/shapepath.py index 47ef060..ead72ff 100755 --- a/python/shapepath.py +++ b/python/shapepath.py @@ -852,15 +852,15 @@ class ShapePath(MotionBase): self.mot_pts=(np.hstack((pt, np.ones((pt.shape[0], 1))))*np.asmatrix(trf)).A # pt*trf sx,sy=kwargs['ssz'] #section size (in wells) try: - tmx,tmy=kwargs['smv'] #time(in num of shots) to move to next section (horiz/vert) + tsx,tsy=kwargs['smv'] #time(in num of shots) to move to next section (horiz/vert) except KeyError as e: - tmx=sx-1 - tmy=sy+1 + tsx=sx-1 + tsy=sy try: - sdl=kwargs['sdelay'] + tsd=kwargs['sdelay'] except KeyError as e: - sdl=sx*sy - sdl+=1-sx*sy # sdl are shots to wait at position #(6) + tsd=sx*sy + tsd+=1-sx*sy # sdl are shots to wait at position #(6) prg+=f' linear abs\n X{ox-px:g} Y{oy-py:g}\n' # start one position out of grid prg+=' dwell 10\n' try: prg+=self.sync_prg @@ -1030,17 +1030,18 @@ enable plc 2 vsx=px/(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) + #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) + #tsx, tsy, tsd #time scale to pvt move to (next horiz|next vert| after position #6) tx,ty=nx//sx,ny//sy #total sections #variables - 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)) + cx,cy,dx,dy,n,k,t,vx,vy,x,x0,y,y0=map(lambda x: f'L{x}',range(13)) # 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} + # (cx|cy|dx|dy|n|k|sx|sy|tsd|tsx|tsy|tx|ty|vsx|vsy|vx|vy|x|x0|y|y0) -> {\1} # if ([^:]*): -> if \(\1\){{ # else: -> }}else{{ # elif ([^:]*): -> }}else if \(\1\){{ @@ -1048,80 +1049,94 @@ enable plc 2 prg+=f'''\ //mode 6: hit-and-return pvt motion - {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 + {t}=1 // motion pvt tome scaling + {k}=-1 // key position + {cx}=0;{cy}=0 // section counter + {x0}=0;{y0}=0;{n}=0 // counter well in region + {dx}=0;{dy}=1 // motion pitch + {vx}=0;{vy}={vsy} // scaled velocity pvt{pt2pt_time} abs - while(1){{: - if ({cy}%2==0){{ # even rows + while(1){{ + if ({cy}%2==0){{ // even rows {x}={sx}*{cx}+{x0};{y}={sy}*{cy}+{y0} - }}else{{ # odd rows + }}else{{ // odd rows {x}=({tx}-{cx})*{sx}-{x0}-1;{y}={sy}*{cy}+{y0} {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 + //send 1"A:move(%d) X%g:%g Y%g:%g",{k},{ox}+{x}*{px},{vx},{oy}+{y}*{py},{vy} + X({ox}+{x}*{px}):({vx}) Y({oy}+{y}*{py}):({vy}) + if ({t}!=1){{ + pvt{pt2pt_time} abs;{t}=1 + }} + if ({k}>=0){{ //if keypoint not directly followed by an other keypoint, define future velocity if ({k}==0 || {k}==4){{ - {vx},{vy}=0,{vsy} + {vx}=0;{vy}={vsy} }}else if ({k}==2){{ - {vx},{vy}=0,-{vsy} + {vx}=0;{vy}=-{vsy} }}else if ({k}==5){{ - {vx},{vy}=-{vsx},0 + {vx}=-{vsx};{vy}=0 }}else if ({k}==6){{ {n}+=1 + if ({tsd}!=1) {{ + pvt{pt2pt_time*tsd} abs;{t}={tsd} + }} }}else if ({k}==7){{ //send 1"next h section" {cx}+=1 - {x0},{y0},{n},{dx},{dy}=0,0,0,0,0 + {x0}=0;{y0}=0;{n}=0;{dx}=0;{dy}=0 + if ({tsx}!=1) {{ + pvt{pt2pt_time*tsx} abs;{t}={tsx} + }} }}else if ({k}==8){{ //send 1"next v section" {cx}=0;{cy}+=1 - {x0},{y0},{n},{dx},{dy}=0,0,0,0,0 + {x0}=0;{y0}=0;{n}=0;{dx}=0;{dy}=0 if ({cy}>={ty}){{ //send 1"finished whole grid" break }} + if ({tsy}!=1) {{ + pvt{pt2pt_time*tsy} abs;{t}={tsy} + }} }} //send 1"after keypoint %d: %g|%g",{k},{vx},{vy} {k}=-1 + }} if ({y0}=={sy}-1){{ - if ({dy}==1){{ #(1) - {dx},{dy}=1,0 - {vx},{vy}={vsx}/2,{vsy}/2 + if ({dy}==1){{ //(1) + {dx}=1;{dy}=0 + {vx}={vsx}/2;{vy}={vsy}/2 }}else{{ - {k},{dx},{dy}=2,0,-1#(2) - {vx},{vy}={vsx}/2,-{vsy}/2 + {k}=2;{dx}=0;{dy}=-1 //(2) + {vx}={vsx}/2;{vy}=-{vsy}/2 }} }}else if ({y0}==1 && {x0}>0 && {x0}<{sx}-1){{ - if ({dy}==-1){{ #(3) - {dx},{dy}=1,0 - {vx},{vy}={vsx}/2,-{vsy}/2 + if ({dy}==-1){{ //(3) + {dx}=1;{dy}=0 + {vx}={vsx}/2;{vy}=-{vsy}/2 }}else{{ - {k},{dx},{dy}=4,0,1 #(4) - {vx},{vy}={vsx}/2,{vsy}/2 + {k}=4;{dx}=0;{dy}=1 //(4) + {vx}={vsx}/2;{vy}={vsy}/2 + }} }}else if ({y0}==0){{ - if ({n}==1 && {x0}==1){{ #(7 or 8) + if ({n}==1 && {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 + {k}=7;{dx}=-1;{dy}=0 + {vx}=0;{vy}=0 + }}else{{ //(8) + {k}=8;{dx}={sx}-1;{dy}={sy} + {vx}=0;{vy}=0 }} - }}else if ({x0}==1){{ #(6) - {k},{dx},{dy}=6,-1,0 - {vx},{vy}=-{vsx},0 - }}else if ({x0}==0){{ #(0) - {k},{dx},{dy}=0,0,1 - {vx},{vy}=0,{vsy} - }}else if ({x0}=={sx}-1){{ #(5) - {k},{dx},{dy}=5,-1,0 - {vx},{vy}=-{vsx}/2,-{vsy}/2 + }}else if ({x0}==1){{ //(6) + {k}=6;{dx}=-1;{dy}=0 + {vx}=-{vsx};{vy}=0 + }}else if ({x0}==0){{ //(0) + {k}=0;{dx}=0;{dy}=1 + {vx}=0;{vy}={vsy} + }}else if ({x0}=={sx}-1){{ //(5) + {k}=5;{dx}=-1;{dy}=0 + {vx}=-{vsx}/2;{vy}=-{vsy}/2 }} }} }}