-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIT6D_CA2_gpib.py
147 lines (126 loc) · 3.59 KB
/
IT6D_CA2_gpib.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import sys, os, subprocess
import datetime, time
#import Gpib
import numpy as np
import matplotlib.pyplot as plt
############################################################
class IT6D_CA2:
def __init__(self,my_gpb):
# equal to calls from terminal
subprocess.call(['sudo','gpib_config'])
subprocess.call(['sudo','chown','vfurtula:vfurtula','/dev/gpib0'])
# adr=9 for IT6D_CA2
self.v=Gpib.Gpib(0,my_gpb)
print("IT6D_CA2 microstepper GPIB port:", my_gpb)
def get_positions(self,*argv):
# interrogate one or both axes
if len(argv)==1 and argv[0]=='x':
self.v.write(''.join(['C1?\n']).encode())
x_ = self.v.read().decode()
# pick up the right values
x = x_[3:10]
# return the values
return x
elif len(argv)==1 and argv[0]=='y':
self.v.write(''.join(['C2?\n']).encode())
y_ = self.v.read().decode()
# pick up the right values
y = y_[3:10]
# return the values
return y
elif len(argv)==0:
self.v.write(''.join(['CC?\n']).encode())
x_and_y = self.v.read().decode()
# pick up the right values
x = x_and_y[3:10]
y = x_and_y[14:21]
# return the values
return x, y
else:
pass
def reset(self,axs):
#reset the microstepper
if axs=='x':
self.v.write('C1O\n'.encode())
time.sleep(15e-3)
elif axs=='y':
self.v.write('C2O\n'.encode())
time.sleep(15e-3)
elif axs=='xy':
self.v.write('CCO\n'.encode())
time.sleep(15e-3)
else:
pass
def move_abs(self,axs,pos_):
# convert to int if float received
pos=int(pos_)
# get axis pointer and read position file
if axs=='x':
pointer='1'
elif axs=='y':
pointer='2'
else:
pass
# write a position trace to the user
#print ''.join([axs.capitalize(),'_abs:']),pos
# move axis
if pos>0:
self.v.write(''.join(['I',pointer,'=+',str(pos),'!\n']).encode())
elif pos<0:
self.v.write(''.join(['I',pointer,'=',str(pos),'!\n']).encode())
elif pos==0:
self.v.write(''.join(['I',pointer,'=-',str(pos),'!\n']).encode())
else:
pass
# wait until the axis has come to rest
while True:
self.v.write(''.join(['I',pointer,'?\n']).encode())
time.sleep(15e-3)
if self.v.read().decode()==''.join(['AR',pointer,' ',chr(47)]):
#self.v.write(''.join(['C',pointer,'?\n']).encode())
#print self.v.read().decode()
return None
def move_rel(self,axs,pos_):
# convert to int if float received
pos=int(pos_)
# get axis pointer and read position file
if axs=='x':
pointer='1'
elif axs=='y':
pointer='2'
else:
pass
# calculate absolute position using the relative position
# get x or y value
oldpos = self.get_positions(axs)
newpos=int(oldpos)+pos
# write a position trace to the user
#print ''.join([axs,'_rel:']),pos, ''.join([', ',axs.capitalize(),'_abs:']),newpos
# move and wait until movement finished
if newpos>0:
self.v.write(''.join(['I',pointer,'=+',str(newpos),'!\n']).encode())
elif newpos<0:
self.v.write(''.join(['I',pointer,'=',str(newpos),'!\n']).encode())
elif newpos==0:
self.v.write(''.join(['I',pointer,'=-',str(newpos),'!\n']).encode())
else:
pass
# wait until the axis has come to rest
while True:
self.v.write(''.join(['I',pointer,'?\n']).encode())
time.sleep(15e-3)
if self.v.read().decode()==''.join(['AR',pointer,' ',chr(47)]):
#self.v.write(''.join(['C',pointer,'?\n']).encode())
#print self.v.read().decode()
return None
def make_test():
move_x=-100
move_y=-100
it6d=IT6D_CA2(9)
it6d.move_rel('x',move_x)
it6d.move_rel('y',move_y)
it6d.move_abs('x',move_x)
it6d.move_abs('y',move_y)
it6d.reset('xy')
if __name__ == "__main__":
make_test()