-
Notifications
You must be signed in to change notification settings - Fork 29
/
get_position.py
42 lines (33 loc) · 940 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
40
41
#!/usr/bin/env python
"""
Usage: python get_position.py [<serial>]
This program reads the position of all APT controllers found, or the one
specified
"""
from __future__ import absolute_import
from __future__ import print_function
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 = [x for x in controllers if x[2] == serial]
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))