This commit is contained in:
2018-10-16 16:30:27 +02:00
parent dc613706d6
commit d4edb2d133

View File

@@ -397,13 +397,6 @@ class HelicalScan(MotionBase):
#data=self.rec[int(idx*self.step),:]
#self.hCrist,pt=self.pltCrist(*data,h=self.hCrist)
def save_rec(self,fn_npz='/tmp/helicalscan.npz'):
param= self.param
meta= self.meta
points = self.points # target points
rec = self.rec
np.savez_compressed(fn_npz, rec=rec, points=points, param=param, meta=meta)
def load_rec(self,fn_npz='/tmp/helicalscan.npz'):
try:
fh=np.load(fn_npz)
@@ -660,6 +653,21 @@ class HelicalScan(MotionBase):
ax.set_ylim(v[0]-l2, v[0]+l2);
ax.set_zlim(v[1]-l2, v[1]+l2)
def setup_gather(self,acq_per=1):
'''
setup the channels to gather
kwargs:
acq_per : acquire period: acquire data all acq_per servo loops (default=1)
'''
comm=self.comm
gt=self.gather
gt.set_phasemode(False)
gt.set_address("Motor[4].ActPos","Motor[5].ActPos","Motor[3].ActPos","Motor[1].ActPos")
gt.set_property(MaxSamples=1000000, Period=acq_per)
ServoPeriod= .2 #0.2ms #Sys.ServoPeriod is dependent of !common() macro
#ServoPeriod=comm.gpascii.servo_period
self.meta = {'timebase': ServoPeriod*acq_per}
def setup_coord_trf(self,fnCrdTrf='/tmp/coordTrf.cfg'):
comm = self.comm
gpascii = comm.gpascii
@@ -799,7 +807,7 @@ close
time.sleep(.5)
gpascii.send_block('#1..7j/')
def setup_motion(self,prgId=2,fnPrg=None,mode=0,**kwargs):
def setup_motion(self,prgId=2,fnPrg='/tmp/prg.cfg',mode=0,**kwargs):
'''
kwargs:
acq_per : acquire period: acquire data all acq_per servo loops (default=1)
@@ -820,6 +828,9 @@ close
wRng : starting and ending angle
yRng : starting and ending height
'''
comm = self.comm
gpascii = comm.gpascii
param=self.param
prg=[]
acq_per=kwargs.get('acq_per',10)
gather={"MaxSamples":1000000, "Period":acq_per}
@@ -966,9 +977,29 @@ close
prg.append(' P1000=1')
prg.append('close')
prg.append('&1\nb%dr\n'%prgId)
#prg.append('&1\nb%dr\n'%prgId)
self.download(prg,mode=3,file='/tmp/prg.cfg')
prg='\n'.join(prg) + '\n'
gpascii.send_block(prg)
if self.verbose & 4:
print(prg)
if fnPrg is not None :
fh=open(fnPrg,'w')
fh.write(prg)
fh.close()
def gather_upload(self,fnRec='/tmp/helicalscan.npz'):
gpascii=self.comm.gpascii
gt=self.gather
gt.wait_stopped(verbose=True)
self.rec=rec=gt.upload()
channels = ["Motor[4].HomePos", "Motor[5].HomePos", "Motor[3].HomePos", "Motor[1].HomePos"]
ofs = np.ndarray(len(channels))
for i, v in enumerate(channels):
ofs[i] = gpascii.get_variable(v,float)
rec -= ofs
if fnRec:
np.savez_compressed(fnRec, rec=rec, points=self.points, param=self.param, meta=self.meta)
def download(self,prg=None,mode=0,file='/tmp/helicalscan.cfg'):
'''
@@ -1042,27 +1073,6 @@ close
self.save_rec()
class GpasciiCommunicator():
'''Communicates with the Delta Tau gpascii programm
'''
gpascii_ack="\x06\r\n"
gpascii_inp='Input\r\n'
def connect(self, host, username='root', password='deltatau',prompt='ppmac# ',verbose=0):
p=telnetlib.Telnet(host)
s=p.read_until('login: ')
if verbose: print(s)
p.write(username+'\n')
s =p.read_until('Password: ')
if verbose: print(s)
p.write(password+'\n')
s =p.read_until(prompt) # command prompt
if verbose: print(s)
p.write('gpascii -2\n') # execute gpascii command
s=p.read_until(self.gpascii_inp)
if verbose: print(s)
return p
if __name__=='__main__':
def run_test(args):
if args.host is None:
@@ -1075,7 +1085,7 @@ if __name__=='__main__':
hs.host=args.host # temporary
#hs.test_find_rot_ctr()
#hs.test_find_rot_ctr(n=5. ,per=1.,bias=2.31,ampl=4.12,phi=24.6)
fn='/tmp/helicalscan'
hs.calcParam()
#hs.calcParamSim()
#hs.param[0]=(15,2,0,3,0)#(z_i, y_i, x_i, r_i,phi_i)
@@ -1101,6 +1111,9 @@ if __name__=='__main__':
if mode&4:
hs.setup_coord_trf()
hs.setup_sync() # no sync at all
hs.setup_gather()
#hs.gen_prog(mode=-1)
#hs.gen_prog(mode=0,cntHor=1,cntVert=3,wRng=(120000,120000))
#hs.gen_prog(mode=0,cntHor=1)
@@ -1123,8 +1136,16 @@ if __name__=='__main__':
#hs.gen_prog(mode=1,pt2pt_time=100,cnt=1,cntVert=35,cntHor=7,hRng=(-.3,.3),wRng=(0,360000*3),yRng=(6.2,2.3))
#hs.gen_prog(mode=1,pt2pt_time=100,cnt=1,cntVert=10,cntHor=3,hRng=(-30,30),wRng=(0,36000),yRng=(-50,-100))
#hs.gen_prog(mode=1,cntHor=7,cntVert=2,hRng=(-100,50),wRng=(000,10000),smt=0)
hs.load_rec()
hs.show_pos();hs.show_vel()
hs.run()
print('temporary wait that the program started')
time.sleep(5)#temporary wait that the program started
hs.gather_upload(fn+'.npz')
hs.load_rec(fn+'.npz')
hs.show_pos()
hs.show_vel()
hs.interactive_anim()
#hs.show_vel(); plt.show()
#hs.show_pos(); plt.show()