{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# DummyMotor\n\nThis demo shows with the example of the ``DummyMotor``\nhow grabber and cameras are used in ``itom``.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import time\nfrom itom import actuator" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Initialisation of an actuator (e.g: ``DummyMotor``).\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "stage = actuator(\"DummyMotor\", 3)\n\n# show the toolbox\nstage.showToolbox()\n\n# Access the DummyStage with variable-name stage\n\n# Set parameter e.g. speed of the stage to 1000 mm / s\nstage.setParam(\"speed\", 1000)\n\n# Get the current speed, should be 1000 mm/s\nspeed = stage.getParam(\"speed\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Synchronous movement**: \n The script waits until the movement has been finished!\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Set pos of 1. axis (index 0) to the absolute value 10.2 mm\nstage.setPosAbs(0, 10.2)\n\n# Read the axis position of 1. axis, should be 10 (mm)\nstage.getPos(0)\n\n# Change the position of 1. axis by -6 mm relative to the current position\nstage.setPosRel(0, -6)\n\n# Read the axis position of 1. axis, should be 4 (mm)\nstage.getPos(0)\n\n# Address n-axis\n# Set the position of 1. and 3. axis to 5mm\nstage.setPosAbs(0, 5.0, 2, 5.0)\n\n# Read the axis position of 1./3. axis, should be 5 (mm) and 5 (mm)\n[x, z] = stage.getPos(0, 2)\nprint(\"x = \" + str(x) + \" z = \" + str(z))\n\n# Change the position of 1. axis and 2. by 2 mm relative to the current position\nstage.setPosRel(0, 2, 1, 2)\n\n# Read the axis position of 1./2./3. axis, should be 7 (mm), 2 (mm), 5 (mm)\n[x, y, z] = stage.getPos(0, 1, 2)\nprint(\"x = \" + str(x) + \" y = \" + str(y) + \" z = \" + str(z))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Asynchronous movement**: \n The script continuous its executing during the movement. However,\n the actuator is **blocked** until the end of the movement, since the script\n will wait before the next ``setParam``, ``setPosAbs``, ``setPosRel``,\n ``getPos``, ``getParam``, ``getStatus`` methods until any previous movement is finished.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# now switch the motor to an asychronous movement\nstage.setParam(\"async\", 1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Control the state of the actuator by the properties:\n``currentStatus``, ``currentPositions``, ``targetPositions``.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# use the currentStatus, currentPositions or targetPositions properties to control the state of the device\ntargetReached = False\nstage.setPosAbs(0, 2500.0, 1, -2070.5)\nwhile not targetReached:\n state = stage.currentStatus\n if all([s & actuator.actuatorAtTarget for s in state]):\n targetReached = True\n else:\n # print(\"Current state: %s, current positions: %s\" % (state, stage.currentPositions))\n time.sleep(0.1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Control the state of the actuator by connecting to the\n``actuatorStatusChanged`` (or ``targetChanged``) signals of the actuator.\n\n
The corresponding python methods can only be called if the current script\n executing is finished. Therefore, this approach is better suited for GUI applications which are\n mainly based on events.