forked from mcleu/PyAPT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExample.py
52 lines (40 loc) · 1.56 KB
/
Example.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
# -*- coding: utf-8 -*-
"""
Example code showing how to control Thorlabs TDC Motors using PyAPT
V1.2
20141125 V1.0 First working version
20141201 V1.0a Updated to short notation
20150324 V1.1 Added more descriptions
20150417 V1.2 Implemented motor without serial
Michael Leung
mcleung@stanford.edu
"""
# Import APTMotor class from PyAPT
from PyAPT import APTMotor
import time
# Create object corresponding to the motor.
Motor1 = APTMotor(83828393, HWTYPE=31) # The number should correspond to the serial number.
# Use help APTMotor to obtain full list of hardware (HW) supported.
# Note: You can control multiple motors by creating more APTMotor Objects
# Obtain current position of motor
print(Motor1.getPos())
# You can control multiple motors by creating more APTMotor Objects
# Serial numbers can be added later by using setSerialNumber and initializeHardwareDevice
# This functionality is particularly useful in the GUI setup.
Motor2 = APTMotor()
Motor2.setSerialNumber(83828393)
Motor2.initializeHardwareDevice()
print(Motor2.getPos())
# Move motor forward by 1mm, wait half a second, and return to original position.
# mRel is move relative. mAbs is move absolute (go to position xxx)
Motor1.mRel(1) # advance 1mm
time.sleep(.5)
Motor1.mRel(-1) # retract 1mm
time.sleep(1)
# Move motor forward by 1mm, wait half a second, and return to original position, at a velocity of 0.5mm/sec
motVel = 0.5 #motor velocity, in mm/sec
Motor1.mcRel(1, motVel) # advance 1mm
time.sleep(.5)
Motor1.mcRel(-1, motVel) # retract 1mm
# Clean up APT object, free up memory
Motor1.cleanUpAPT()