Qcodes example with Thorlabs K10CR1

Initialization

Create an instance of Thorlabs_APT, which is a wrapper for the APT.dll of the APT server which is part of the Thorlabs drivers.

[1]:
from qcodes_contrib_drivers.drivers.Thorlabs.APT import Thorlabs_APT

apt = Thorlabs_APT()

Create an instance of Thorlabs_K10CR1, the actual driver class.

[2]:
from qcodes_contrib_drivers.drivers.Thorlabs.K10CR1 import Thorlabs_K10CR1

inst = Thorlabs_K10CR1("K10CR1", 0, apt)
Connected to: Thorlabs K10CR1 (serial:55125694, firmware:SW Version 1.0.3) in 0.01s

Moving the rotator

Moving home

Move the rotator to its home position (zero) and recalibrate it.

[3]:
# Move to zero and recalibrate
inst.move_home()

# Read position
print("Position:", inst.position())
Position: 0.0

Moving to certain position

Move to 120° with 10°/s

[4]:
# Set target velocity to 10 deg/s
inst.velocity_max(10)

# Move to 120 and wait until it's finished
inst.position(120)

# Read position
print("Position:", inst.position())
Position: 120.0

Moving to certain position (asynchronously)

The following commands will start a rotation to position 240°. This will happen asynchronously so that you can read out the current position in the meantime. After reaching 180° the motor will be stopped.

[5]:
import time

# Move to 300 without blocking
inst.position_async(240)

last_position = 120

# Print current position every 250 ms, until 240 is reached
while last_position < 180:
    last_position = inst.position()
    print("Position:", last_position)
    time.sleep(0.25)

# Stop at around 240 (before 280 is reached)
inst.stop()

# Read position
print("Position:", inst.position())
Position: 120.0
Position: 120.33045196533203
Position: 121.30647277832031
Position: 122.93938446044922
Position: 125.22875213623047
Position: 127.80081939697266
Position: 130.36468505859375
Position: 132.91712951660156
Position: 135.5030059814453
Position: 138.07122802734375
Position: 140.61135864257812
Position: 143.18075561523438
Position: 145.73727416992188
Position: 148.30560302734375
Position: 150.8717498779297
Position: 153.4274444580078
Position: 155.98837280273438
Position: 158.54783630371094
Position: 161.1175994873047
Position: 163.6906280517578
Position: 166.25445556640625
Position: 168.7959442138672
Position: 171.37112426757812
Position: 173.93038940429688
Position: 176.48873901367188
Position: 179.0663604736328
Position: 181.61782836914062
Position: 184.19651794433594

Clean up resources

[6]:
inst.close()
apt.apt_clean_up()