{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Qcodes example with Thorlabs K10CR1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Initialization\n", "\n", "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." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from qcodes_contrib_drivers.drivers.Thorlabs.APT import Thorlabs_APT\n", "\n", "apt = Thorlabs_APT()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create an instance of `Thorlabs_K10CR1`, the actual driver class." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Connected to: Thorlabs K10CR1 (serial:55125694, firmware:SW Version 1.0.3) in 0.01s\n" ] } ], "source": [ "from qcodes_contrib_drivers.drivers.Thorlabs.K10CR1 import Thorlabs_K10CR1\n", "\n", "inst = Thorlabs_K10CR1(\"K10CR1\", 0, apt)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Moving the rotator\n", "\n", "### Moving home\n", "\n", "Move the rotator to its home position (zero) and recalibrate it." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Position: 0.0\n" ] } ], "source": [ "# Move to zero and recalibrate\n", "inst.move_home()\n", "\n", "# Read position\n", "print(\"Position:\", inst.position())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Moving to certain position\n", "\n", "Move to 120° with 10°/s" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Position: 120.0\n" ] } ], "source": [ "# Set target velocity to 10 deg/s\n", "inst.velocity_max(10)\n", "\n", "# Move to 120 and wait until it's finished\n", "inst.position(120)\n", "\n", "# Read position\n", "print(\"Position:\", inst.position())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Moving to certain position (asynchronously)\n", "\n", "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." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Position: 120.0\n", "Position: 120.33045196533203\n", "Position: 121.30647277832031\n", "Position: 122.93938446044922\n", "Position: 125.22875213623047\n", "Position: 127.80081939697266\n", "Position: 130.36468505859375\n", "Position: 132.91712951660156\n", "Position: 135.5030059814453\n", "Position: 138.07122802734375\n", "Position: 140.61135864257812\n", "Position: 143.18075561523438\n", "Position: 145.73727416992188\n", "Position: 148.30560302734375\n", "Position: 150.8717498779297\n", "Position: 153.4274444580078\n", "Position: 155.98837280273438\n", "Position: 158.54783630371094\n", "Position: 161.1175994873047\n", "Position: 163.6906280517578\n", "Position: 166.25445556640625\n", "Position: 168.7959442138672\n", "Position: 171.37112426757812\n", "Position: 173.93038940429688\n", "Position: 176.48873901367188\n", "Position: 179.0663604736328\n", "Position: 181.61782836914062\n", "Position: 184.19651794433594\n" ] } ], "source": [ "import time\n", "\n", "# Move to 300 without blocking\n", "inst.position_async(240)\n", "\n", "last_position = 120\n", "\n", "# Print current position every 250 ms, until 240 is reached\n", "while last_position < 180:\n", " last_position = inst.position()\n", " print(\"Position:\", last_position)\n", " time.sleep(0.25)\n", "\n", "# Stop at around 240 (before 280 is reached)\n", "inst.stop()\n", "\n", "# Read position\n", "print(\"Position:\", inst.position())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Clean up resources" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "inst.close()\n", "apt.apt_clean_up()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.0" }, "nbsphinx": { "execute": "never" } }, "nbformat": 4, "nbformat_minor": 4 }