-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostep_test.py
68 lines (52 loc) · 1.77 KB
/
postep_test.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
import time
import logging
import threading
import sys
from postep256usb import PoStep256USB
def wait_for_position():
while True:
data = postep.read_stream()
#print("Received: {}".format(data))
if data["pos"] == data["final"]:
print("Reached: {}".format(data["final"]))
break
time.sleep(0.1)
postep = PoStep256USB(logging.INFO)
# defined to show only errors as log values, set to logging.INFO or logging.DEBUG for more
# Check if driver was detected and configuration could be established
if postep.device is None:
print("Driver not found, exiting.")
sys.exit(0)
# enable streaming of real-time data
postep.enable_rt_stream()
# set the motor to run or sleep
postep.run_sleep(True)
# Example 1: Run motor with fixed speed
postep.move_speed(1000,"cw")
time.sleep(2)
# Example 2: Use motor position control
# First reset the position to known value (do not do this if you wish the motor to retain position during program restart). Power cycle resets this also.
postep.move_reset_to_zero()
#configure speed acceleration and deceleration and endswitch for move commands
postep.move_config(10000,1000,1000,None)
# Assuming there is a finite motion range defined, the end of range must be found first and configured to zero
# Move slowly for fixed time to reach the end of range.
postep.move_speed(100,"acw")
time.sleep(5)
# Now define this as zero position
postep.move_reset_to_zero()
# Move to a fixed position and wait
postep.move_to(10)
wait_for_position()
postep.move_to(100)
wait_for_position()
postep.move_to(1000)
wait_for_position()
postep.move_to(0)
wait_for_position()
#postep.move_speed(100,"acw")
while True:
data = postep.read_stream()
if data != None:
print("Received: {}".format(data))
time.sleep(1)