forked from freespace/pyAPT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_velocity_params.py
56 lines (46 loc) · 1.38 KB
/
set_velocity_params.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
#!/usr/bin/env python
"""
Usage: python get_status.py <acceleration (mm/s/s)> <max velocity (mm/s) [<serial>]
Gets the status of all APT controllers, or of the one specified
"""
from __future__ import absolute_import
from __future__ import print_function
import pylibftdi
import pyAPT
def set_vel_params(serial, acc, max_vel):
with pyAPT.MTS50(serial_number=serial) as con:
print('\tSetting new velocity parameters',acc,max_vel)
con.set_velocity_parameters(acc, max_vel)
min_vel, acc, max_vel = con.velocity_parameters()
print('\tNew velocity parameters:')
print('\t\tMin. Velocity: %.2fmm'%(min_vel))
print('\t\tAcceleration: %.2fmm'%(acc))
print('\t\tMax. Velocity: %.2fmm'%(max_vel))
def main(args):
if len(args)<3:
print(__doc__)
return 1
acc = float(args[1])
max_vel = float(args[2])
if len(args)>3:
serial = args[3]
else:
serial = None
if serial:
set_vel_params(serial, acc, max_vel)
return 0
else:
print('Looking for APT controllers')
drv = pylibftdi.Driver()
controllers = drv.list_devices()
if controllers:
for con in controllers:
print('Found %s %s S/N: %s'%con)
set_vel_params(con[2], acc, max_vel)
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))