Commit 2a38b486 authored by NBI's avatar NBI
Browse files

acquire before move

parent d9ace967
......@@ -10,16 +10,17 @@ from astropy.io import fits
BIND_IP = '0.0.0.0'
BIND_PORT = 9999
ATSCTL_PATH = 'python3 atstest.py'
ATSCTL_PATH = '/usr/bin/python /home/ogse/src/atsctl.git/ATS_control.py'
ATSCTL_PROMPT = 'ATS>'
ATIK_PATH = 'python3 atiktest.py'
ATIK_PATH = '/home/ogse/src/atikctl/atikctl'
ATIK_PROMPT = 'AtikCtl>'
logging.basicConfig(filename='atsctl.log', level=logging.DEBUG)
def cmd(proc, msg, expect, error):
proc.sendline(msg)
i = proc.expect([expect, error], timeout=4)
print(msg)
i = proc.expect([expect, error], timeout=None)
if i == 1:
logging.error(proc.after)
raise Exception(proc.after)
......@@ -27,55 +28,75 @@ def cmd(proc, msg, expect, error):
logging.info(proc.after)
return proc.after
def acquire_and_save(atsctl, atik, timestamp):
def move_and_acquire(atsctl, atik, rel_pos, repeat=1):
cmd(atsctl, 'get_enc_position',
r'([+-]?\ *\d+\.?\d*),([+-]?\ *\d+\.?\d*),([+-]?\ *\d+\.?\d*),([+-]?\ *\d+\.?\d*),([+-]?\ *\d+\.?\d*)',
'ERROR')
x, y, z, theta, phi = map(float, atsctl.match.groups())
logging.info('New position : {} {} {} {} {}'.format(x, y, z, theta, phi))
cmd(atik, '@sint', '!SINT', '!ERROR')
# output.fits has been created
dst = 'outputs/{}.fits'.format(int(timestamp.timestamp()*1000))
try:
shutil.copyfile('output.fits', dst)
except Exception as e:
logging.error('An error occured while moving output.fits to {} : {}'.format(dst, e))
raise
# add timestamp header
with fits.open(dst, 'update') as hdul:
hdr = hdul[0].header
hdr['DATE-OBS'] = '{}.{}'.format(timestamp.strftime('%Y-%m-%dT%H:%M:%S'),
int(timestamp.microsecond/1000))
hdr['ENC-POS'] = '{},{},{},{},{}'.format(x, y, z, theta, phi)
logging.info('{} file written'.format(dst))
def move_and_acquire(atsctl, atik, rel_pos, repeat=1, _time=0.005):
cmd(atik, '@time {}'.format(_time), '!TIME', '!ERROR')
timestamp = datetime.datetime.now()
acquire_and_save(atsctl, atik, timestamp)
for i in range(repeat):
timestamp = datetime.datetime.now()
cmd(atsctl, 'move_rel_pos_ats {}'.format(rel_pos), ATSCTL_PROMPT, 'ERROR')
cmd(atsctl, 'move_rel_pos_ats {}'.format(rel_pos).strip(), ATSCTL_PROMPT, 'ERROR')
cmd(atsctl, 'wait_move', ATSCTL_PROMPT, 'ERROR')
#float_re = '([+-]?\ *\d+\.?\d*)'
cmd(atsctl, 'get_enc_position',
r'([+-]?\ *\d+\.?\d*),([+-]?\ *\d+\.?\d*),([+-]?\ *\d+\.?\d*),([+-]?\ *\d+\.?\d*),([+-]?\ *\d+\.?\d*)',
'ERROR')
x, y, z, theta, phi = map(float, atsctl.match.groups())
logging.info('New position : {} {} {} {} {}'.format(x, y, z, theta, phi))
cmd(atik, '@sint', '!SINT', '!ERROR')
# output.fits has been created
dst = 'outputs/{}.fits'.format(int(timestamp.timestamp()*1000))
try:
shutil.copyfile('output.fits', dst)
except Exception as e:
logging.error('An error occured while moving output.fits to {} : {}'.format(dst, e))
raise
# add timestamp header
with fits.open(dst, 'update') as hdul:
hdr = hdul[0].header
hdr['DATE-OBS'] = '{}.{}'.format(timestamp.strftime('%Y-%m-%dT%H:%M:%S'),
int(timestamp.microsecond/1000))
hdr['ENC-POS'] = '{},{},{},{},{}'.format(x, y, z, theta, phi)
logging.info('{} file written'.format(dst))
acquire_and_save(atsctl, atik, timestamp)
def handle_client_connection(client_socket, atsctl, atik):
request = client_socket.recv(1024)
logging.debug('net command: {}'.format(request))
cmd = request.split()
cmd = request.decode('utf-8').split()
error = None
if cmd[0] == b'maa':
if cmd[0] == 'maa':
# Move And Aquire command
try:
move_and_acquire(atsctl, atik,
cmd[1], # rel_pos
int(cmd[2]) if len(cmd) == 3 else 1) # repeat
int(cmd[2]) if len(cmd) >= 3 else 1,
float(cmd[3]) if len(cmd) >= 4 else 0.005
) # repeat
except Exception as e:
error = str(e)
elif cmd[0] == 'scan2d':
# Aquire 2d scene
# eg: scan2d y_inc,z_inc n_y,n_z time
# eg: scan2d 0.1,0.05 20,20 0.005
pass
elif cmd[0] == 'scan3d':
# Aquire 3d scene
# eg: scan3d x_inc,y_inc,z_inc n_x,n_y,n_z time
# eg: scan3d 0.1,0.1,0.05 20,20,20 0.005
pass
else:
error = 'Unhandled command {}\n'.format(cmd[0])
if error:
......@@ -109,6 +130,5 @@ if __name__ == '__main__':
cmd(atik, '@connect', '!CONNECT', '!ERROR')
cmd(atik, '@cool on', '!COOL', '!ERROR')
cmd(atik, '@time 0.005', '!TIME', '!ERROR')
tcp_server(atsctl, atik)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment