forked from freespace/pyAPT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_position.py
40 lines (31 loc) · 863 Bytes
/
get_position.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
#!/usr/bin/env python
"""
Usage: python get_position.py [<serial>]
This program reads the position of all APT controllers found, or the one
specified
"""
import time
import pylibftdi
import pyAPT
def main(args):
print 'Looking for APT controllers'
drv = pylibftdi.Driver()
controllers = drv.list_devices()
if len(args)>1:
serial = args[1]
else:
serial = None
if serial:
controllers = filter(lambda x:x[2] == serial, controllers)
if controllers:
for con in controllers:
print 'Found %s %s S/N: %s'%con
with pyAPT.MTS50(serial_number=con[2]) as con:
print '\tPosition (mm) = %.2f [enc:%d]'%(con.position(), con.position(raw=True))
return 0
else:
print '\tNo APT controllers found. Maybe you need to specify a PID'
return 1
if __name__ == '__main__':
import sys
sys.exit(main(sys.argv))