hit-and-return first release candidate

This commit is contained in:
2024-11-25 16:22:40 +01:00
parent f545812bc1
commit 9888377e13
2 changed files with 71 additions and 43 deletions

View File

@@ -17,7 +17,7 @@ import numpy as np
import matplotlib.pyplot as plt
class HitReturnEval:
class HitReturnSim:
def initPlt(self,grid):
nx,ny=grid['count']
@@ -56,12 +56,15 @@ class HitReturnEval:
#fig.show()
#fig.update()
def setup_motion(self,prgId=2,fnPrg=None,mode=0,**kwargs):
#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)
#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
def sim_motion(self,mode=0xff,**kwargs):
#mode: 0x01: print hints
#mode: 0x02: plot simulation
#kwargs:
#grid : grid parameters: {orig:(0,0),pitch(10,10),cnt:(10,10),mode:0}
#ssz : section size (in wells)
#smv : time(in num of shots) to move to next section (horiz/vert)
# default is (ssz[0]-1,ssz[1]+1)
#sdelay: shots count of delay. Default is ssz[0]*ssz[1]
#fast y (up/down) slow x(left/right)
# 8
@@ -73,8 +76,8 @@ class HitReturnEval:
# | | | | | | | | | | | |
# | | | | | | | | | | | |
# 1-2 1-2 1-2 1-2 1-2 1-2
g=kwargs['grid']
if mode&0x02: self.initPlt(g)
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
@@ -99,7 +102,7 @@ class HitReturnEval:
x0,y0,n=0,0,0 # counter well in region
dx,dy=0,1 # motion pitch
vx,vy=0,vsy # scaled velocity
mv=list()
pts=list()
while(True):
if cy%2==0: # even rows
x=sx*cx+x0;y=sy*cy+y0
@@ -107,11 +110,11 @@ class HitReturnEval:
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 mode&0x01: print(f'X{x}:{vx} Y{y}:{vy} ({k}|{dx}|{dy}|{n})')
pts.append((x+.1*n,y+.1*n,n))
if mode&0x02: self.updatePlt(pts,vx,vy)
if t !=1:
print('pvt 10')
if mode&0x01: 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
@@ -122,25 +125,40 @@ class HitReturnEval:
elif k==6:
n+=1
if tsd!=1:
print(f'pvt {10*tsd}');t=tsd;time.sleep(.1*tsd)
if mode&0x01: print(f'pvt {10*tsd}');t=tsd
for i in range(1,tsd):
pts.append((x+.9*i/tsd, y+.9*i/tsd, n))
if mode&0x02: self.updatePlt(pts, vx, vy)
elif k==7:
print('next h section')
if mode&0x01: 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
if mode&0x01: print(f'pvt {10*tsx}');t=tsx
xx=(sx-1)/tsx
if cy%2!=0: xx=-xx
for i in range(1,tsx):
pts.append((x+i*xx, y+.3, n))
if mode&0x02: self.updatePlt(pts, vx, vy)
x0,y0,n,dx,dy=0,0,0,0,0
elif k==8:
if mode&0x01: print('next v section')
cy+=1
if cy>=ty:
print('finished whole grid')
break #
if mode&0x01: print('finished whole grid')
break
if tsy!=1:
print(f'pvt {10*tsy}');t=tsy;time.sleep(.1*tsy)
if mode&0x01: print(f'pvt {10*tsy}');t=tsy
xx=(sx-2)/tsy
if cy%2!=1: xx=-xx
for i in range(1,tsy):
pts.append((x+i*xx, y+i*sy/tsy, n))
if mode&0x02: self.updatePlt(pts, vx, vy)
cx,x0,y0,n,dx,dy=0,0,0,0,0,0
else:
raise ValueError('should never happened')
print(f'vx|vy after keypoint {k}: ({vx}|{vy})')
if mode&0x01: print(f'vx|vy after keypoint {k}: ({vx}|{vy})')
k=-1
if y0==sy-1:
if dy==1: #(1)
@@ -173,6 +191,7 @@ class HitReturnEval:
elif x0==sx-1: #(5)
k,dx,dy=5,-1,0
vx,vy=-vsx/2,-vsy/2
return pts
def plot_trajectory(self):
pts = self.pts # X,Y array
@@ -236,15 +255,12 @@ if __name__=='__main__':
args=parser.parse_args()
_log.info('Arguments:{}'.format(args.__dict__))
obj=HitReturnEval()
obj=HitReturnSim()
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),smv=(4-1,5+1),sdelay=4*5)
obj.initPlt(grid)
obj.setup_motion(grid=grid,ssz=(6,10))
obj.initPlt(grid)
obj.setup_motion(grid=grid,ssz=(2,5))
obj.sim_motion(grid=grid,ssz=(4,5),smv=(4-1,5+1),sdelay=4*5)
obj.sim_motion(grid=grid,ssz=(6,10))
obj.sim_motion(grid=grid,ssz=(2,5))
print('done')
#------------------ Main Code ----------------------------------

View File

@@ -24,6 +24,7 @@ mode:
3 pvt motion using inverse fft velocity
4 pvt motion short code using grid parameters
5 pvt motion short code using grid parameters. Instead of continous motion it moves and waits as give in the parameter time
6 pvt motion 'hit and return using grid parameters. continous motion on 2n ells to pump then same 2n wells to probe, then go 2 rows down
sync:
0 real start and frame trigger with sync
@@ -70,6 +71,7 @@ _log=logging.getLogger(__name__)
import os, sys, time, re
import numpy as np
from hit_return_sim import HitReturnSim
import matplotlib.pyplot as plt
if __name__=="__main__":
@@ -725,7 +727,8 @@ class ShapePath(MotionBase):
common kwargs plus:
trf : transformation that will be done on 'grid points'
grid: grid parameters: {orig:(0,0),pitch(10,10),cnt:(10,10),mode:0}
mode:5 pvt motion short code using grid parameters. Instead of continous motion it moves and waits as give in the parameterstime
mode:5 pvt motion 'stop and go' short code using grid parameters.
Instead of continous motion it moves and waits as given in the parameters
common kwargs plus:
trf : transformation that will be done on 'grid points'
grid: grid parameters: {orig:(0,0),pitch(10,10),cnt:(10,10),mode:0}
@@ -738,7 +741,7 @@ class ShapePath(MotionBase):
grid : grid parameters: {orig:(0,0),pitch(10,10),cnt:(10,10),mode:0}
ssz : section size (in wells)
smv : time(in num of shots) to move to next section (horiz/vert)
default is (ssz[0]-1,ssz[1]+1)
default is (ssz[0]-1,ssz[1])
sdelay: shots count of delay. Default is ssz[0]*ssz[1]
'''
#scan=0 # snake motion X fast, Y slow
@@ -835,11 +838,9 @@ class ShapePath(MotionBase):
g=kwargs['grid']
nx,ny=g['count'] #total count of wells
#TODO: rework pt calculation
xx, yy=np.meshgrid(range(nx), range(ny))
xx=xx.T
yy=yy.T
pt=np.array([xx.reshape(-1), yy.reshape(-1)], dtype=np.float64).transpose() #*pitch
pt=np.tile(pt,(2,1)) # not yet perfect... but at least roughly ok
hrs=HitReturnSim()
pt=hrs.sim_motion(mode=0xff if verb&0x20 else 0x00 , **kwargs)
pt=np.array(pt)[:,:2]
try:
trf=kwargs['trf']
except KeyError as e:
@@ -1341,12 +1342,20 @@ if __name__=='__main__':
sp.setup_motion(fnPrg=fn+'.prg',scale=1.,cnt=1,dwell=100,mode=5,grid=grid,tmove=tmove,twait=twait)
elif mode==6:
grid={'pos':(-1000, -1200), 'pitch':(120, 120), 'count':(16, 20)}
# section size (in wells)
#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
ssz=(6, 10) # section size (in wells)
smv=(ssz[0]-1+4,ssz[1]+1+8) # time(in num of shots) to move to next section (horiz/vert)
sdelay=ssz[0]*ssz[1]+5 # 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,smv=smv,sdelay=sdelay)
elif mode==61: #other mode 6
grid={'pos':(-1000, -1200), 'pitch':(120, 120), 'count':(85, 60)}
ssz=(20, 12) # section size (in wells)
sp.setup_motion(fnPrg=fn+'.prg',scale=1.,cnt=1,dwell=100,mode=6,grid=grid,ssz=ssz)
elif mode==62: #other mode 6
grid={'pos':(-1000, -1200), 'pitch':(120, 120), 'count':(30, 20)}
ssz=(2, 10) # section size (in wells)
sp.setup_motion(fnPrg=fn+'.prg',scale=1.,cnt=1,dwell=100,mode=6,grid=grid,ssz=ssz)
else:
raise(ValueError(f'unsupported mode:{mode}'))
@@ -1378,6 +1387,9 @@ if __name__=='__main__':
'--host=SAR-CPPM-EXPMX1 -v0x5d',
'--host=localhost:10001:10002 -v0x59',
'--host=SAR-CPPM-EXPMX1 -v0x5d -m5',
'--host=localhost:10001:10002 -v0x7d -m6',
'--host=localhost:10001:10002 -v0x5d -m61',
'--host=localhost:10001:10002 -v0x7d -m62'
)
epilog=__doc__+'\nExamples:'+''.join(map(lambda s:cmd+s, exampleCmd))+'\n '
parser=argparse.ArgumentParser(epilog=epilog, formatter_class=argparse.RawDescriptionHelpFormatter)