Commit b8a0fc90 authored by PERNOT Guillaume's avatar PERNOT Guillaume
Browse files

added scan2d and scan3d

parent 2a38b486
......@@ -41,3 +41,19 @@ If `repeat` is given, repeat the process `repeat` times.
```
echo "maa 0.1,0.2,0.3,0.4,0.5 4" | nc localhost 9999
```
### `scan2d y_inc z_inc n_y n_z time` - Scan a 2d area
`y_inc` and `z_inc` are the $`y`$ and $`z`$ increments, respectively.
`n_y` and `n_z` are the numbers of $`y`$ and $`z`$ steps, respectively.
### `scan3d x_inc y_inc z_inc n_x n_y n_z time` - Scan a 3d cube
`x_inc`, `y_inc` and `z_inc` are the $`x`$, $`y`$ and $`z`$ increments, respectively.
`n_y` and `n_z` are the numbers of $`x`$, $`y`$ and $`z`$ steps, respectively.
*e.g.* :
```
echo "scan3d 0.1 0.1 0.05 10 10 20 0.005" | nc localhost 9999
```
import cmd
import time
import logging
logging.basicConfig(filename='atsctl.log', level=logging.DEBUG)
class ATS_Shell(cmd.Cmd, object):
intro = """ ____ ________ __ _____
......@@ -14,9 +16,11 @@ class ATS_Shell(cmd.Cmd, object):
prompt = 'ATS>'
file = None
def __init__(self, config=None):
# Initialize the superclass
super().__init__()
self.x, self.y, self.z, self.theta, self.phi = 0, 0, 0, 0, 0
def do_stop(self, arg):
""" Immediately stops any movement """
......@@ -24,7 +28,19 @@ class ATS_Shell(cmd.Cmd, object):
def do_get_enc_position(self, arg):
""" Returns the current encoder position corrected for origin offset """
print('-1.1,2.2,-3.3,4.4,-5.5')
print('{},{},{},{},{}'.format(self.x, self.y, self.z, self.theta, self.phi))
def do_move_rel_pos_ats(self, arg):
x_inc, y_inc, z_inc, theta_inc, phi_inc = map(float, arg.split(','))
self.x += x_inc
self.y += y_inc
self.z += z_inc
self.theta += theta_inc
self.phi += phi_inc
logging.info(str(self))
def __str__(self):
return 'ats pos : {},{},{},{},{}'.format(self.x, self.y, self.z, self.theta, self.phi)
def do_wait_move(self, arg):
time.sleep(2)
......
......@@ -10,9 +10,16 @@ from astropy.io import fits
BIND_IP = '0.0.0.0'
BIND_PORT = 9999
ATSCTL_PATH = '/usr/bin/python /home/ogse/src/atsctl.git/ATS_control.py'
DEVEL = True
if DEVEL:
ATSCTL_PATH = 'python atstest.py'
ATIK_PATH = 'python atiktest.py'
else:
ATSCTL_PATH = '/usr/bin/python /home/ogse/src/atsctl.git/ATS_control.py'
ATIK_PATH = '/home/ogse/src/atikctl/atikctl'
ATSCTL_PROMPT = 'ATS>'
ATIK_PATH = '/home/ogse/src/atikctl/atikctl'
ATIK_PROMPT = 'AtikCtl>'
logging.basicConfig(filename='atsctl.log', level=logging.DEBUG)
......@@ -30,9 +37,13 @@ def cmd(proc, msg, expect, error):
def acquire_and_save(atsctl, atik, timestamp):
#float_re : '([+-]?\ *\d+\.?\d*)'
cmd(atsctl, 'get_enc_position',
r'([+-]?\ *\d+\.?\d*),([+-]?\ *\d+\.?\d*),([+-]?\ *\d+\.?\d*),([+-]?\ *\d+\.?\d*),([+-]?\ *\d+\.?\d*)',
'ERROR')
#cmd(atsctl, 'get_enc_position',
# r'\r\n(.+),(.+),(.+),(.+),(.+)\r\n',
# 'ERROR')
x, y, z, theta, phi = map(float, atsctl.match.groups())
logging.info('New position : {} {} {} {} {}'.format(x, y, z, theta, phi))
......@@ -54,51 +65,94 @@ def acquire_and_save(atsctl, atik, timestamp):
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).strip(), ATSCTL_PROMPT, 'ERROR')
cmd(atsctl, 'move_rel_pos_ats {}'.format(rel_pos), ATSCTL_PROMPT, 'ERROR')
cmd(atsctl, 'wait_move', ATSCTL_PROMPT, 'ERROR')
#float_re = '([+-]?\ *\d+\.?\d*)'
acquire_and_save(atsctl, atik, timestamp)
def scan2d(atsctl, atik, y_inc, z_inc, n_y, n_z, _time):
cmd(atik, '@time {}'.format(_time), '!TIME', '!ERROR')
for z in range(n_z):
for y in range(n_y):
timestamp = datetime.datetime.now()
acquire_and_save(atsctl, atik, timestamp)
cmd(atsctl, 'move_rel_pos_ats 0,{},0,0,0'.format(y_inc), ATSCTL_PROMPT, 'ERROR')
cmd(atsctl, 'wait_move', ATSCTL_PROMPT, 'ERROR')
cmd(atsctl, 'move_rel_pos_ats 0,0,{},0,0'.format(z_inc), ATSCTL_PROMPT, 'ERROR')
cmd(atsctl, 'wait_move', ATSCTL_PROMPT, 'ERROR')
y_inc = -y_inc # reverse scan
def scan3d(atsctl, atik, x_inc, y_inc, z_inc, n_x, n_y, n_z, _time):
cmd(atik, '@time {}'.format(_time), '!TIME', '!ERROR')
for z in range(n_z):
for y in range(n_y):
for x in range(n_x):
timestamp = datetime.datetime.now()
acquire_and_save(atsctl, atik, timestamp)
cmd(atsctl, 'move_rel_pos_ats {},0,0,0,0'.format(x_inc), ATSCTL_PROMPT, 'ERROR')
cmd(atsctl, 'wait_move', ATSCTL_PROMPT, 'ERROR')
cmd(atsctl, 'move_rel_pos_ats 0,{},0,0,0'.format(y_inc), ATSCTL_PROMPT, 'ERROR')
cmd(atsctl, 'wait_move', ATSCTL_PROMPT, 'ERROR')
x_inc = -x_inc # reverse scan
cmd(atsctl, 'move_rel_pos_ats 0,0,{},0,0'.format(z_inc), ATSCTL_PROMPT, 'ERROR')
cmd(atsctl, 'wait_move', ATSCTL_PROMPT, 'ERROR')
y_inc = -y_inc # reverse scan
def handle_client_connection(client_socket, atsctl, atik):
request = client_socket.recv(1024)
logging.debug('net command: {}'.format(request))
cmd = request.decode('utf-8').split()
cmd = request.decode('utf-8').strip().split()
error = None
if cmd[0] == 'maa':
# Move And Aquire command
# maa x,y,z,theta,phi [repeat [time]]
try:
move_and_acquire(atsctl, atik,
cmd[1], # rel_pos
int(cmd[2]) if len(cmd) >= 3 else 1,
float(cmd[3]) if len(cmd) >= 4 else 0.005
) # repeat
int(cmd[2]) if len(cmd) >= 3 else 1, # repeat
float(cmd[3]) if len(cmd) >= 4 else 0.005 # time
)
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
# scan2d y_inc z_inc n_y n_z time
# eg: scan2d 0.1 0.05 20 20 0.005
scan2d(atsctl, atik,
float(cmd[1]), # y_inc
float(cmd[2]), # z_inc
int(cmd[3]), # n_y
int(cmd[4]), # n_z
float(cmd[5]), # time
)
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
# 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
scan3d(atsctl, atik,
float(cmd[1]), # x_inc
float(cmd[2]), # y_inc
float(cmd[3]), # z_inc
int(cmd[4]), # n_x
int(cmd[5]), # n_y
int(cmd[6]), # n_z
float(cmd[7]), # time
)
else:
error = 'Unhandled command {}\n'.format(cmd[0])
if error:
client_socket.send(bytes(error, 'utf-8'))
else:
......
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