-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvc_mover.py
51 lines (47 loc) · 1.88 KB
/
vc_mover.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# get data from virtual cathode
import sys, math, time
sys.path.insert(0, r'\\apclara1\ControlRoomApps\Controllers\bin\Release')
import VELA_CLARA_PILaser_Control
import epics
vert_pv = 'CLA-LAS-OPT-PICO-4C-PM-4:V:MREL'
horiz_pv = 'CLA-LAS-OPT-PICO-4C-PM-4:H:MREL'
# where do we want to put it?
try:
req_x = float(sys.argv[1]) # 6.15
req_y = float(sys.argv[2]) # 4.75
except IndexError:
print('Usage: vc_mover.py <required_x> <required_y>')
print('Positions in mm')
exit()
print('Target position:', req_x, req_y)
init = VELA_CLARA_PILaser_Control.init()
pilc = init.physical_PILaser_Controller()
x = pilc.getX() # h position
y = pilc.getY() # v position
sx = pilc.getSigX() # width
sy = pilc.getSigY() # height
print('Start position:', x, y)
print('Size:', sx, sy)
# how much to move at a time?
move_amount = 5 # seems OK for a small step
precision = 0.1 # as a fraction of sigma x or y
while abs(req_x - x) > sx * precision or abs(req_y - y) > sy * precision:
# Gotcha: a negative H move means the beam goes RIGHT, contrary to convention
h_step = math.copysign(move_amount, -(req_x - x)) if abs(req_x - x) > sx * precision else 0
# Do a bigger step in y
v_step = math.copysign(move_amount, req_y - y) if abs(req_y - y) > sy * precision else 0
print('Move amount', h_step, v_step)
pilc.setHstep(h_step)
assert pilc.moveH() # returns True on success, presumably False on fail?
time.sleep(0.1)
# vertical movement is currently not working in the controller - use EPICS instead
# pilc.setVstep(v_step)
# assert pilc.moveV()
epics.caput(vert_pv, -v_step) # have to reverse the sign
time.sleep(0.1)
x = pilc.getX() # h position
y = pilc.getY() # v position
sx = pilc.getSigX() # width
sy = pilc.getSigY() # height
print('Position:', x, y)
# print('How far away?', abs(req_x - x), abs(req_y - y), sx / 3, sy / 3)