diff --git a/Andor/andorv1.0/andor/aqctl_andor.py b/Andor/andorv1.0/andor/aqctl_andor.py index d516a79..4c3a96e 100644 --- a/Andor/andorv1.0/andor/aqctl_andor.py +++ b/Andor/andorv1.0/andor/aqctl_andor.py @@ -8,8 +8,7 @@ import os import asyncio -#from andor.driver import andor -from driver import andor +from andor.driver import andor from sipyco.pc_rpc import simple_server_loop from sipyco import common_args diff --git a/Picomotor/__pycache__/picomotor_driver.cpython-38.pyc b/Picomotor/__pycache__/picomotor_driver.cpython-38.pyc deleted file mode 100644 index 72d62ab..0000000 Binary files a/Picomotor/__pycache__/picomotor_driver.cpython-38.pyc and /dev/null differ diff --git a/Picomotor/picomotor-master/.gitignore b/Picomotor/picomotor-master/.gitignore deleted file mode 100644 index eeb514c..0000000 --- a/Picomotor/picomotor-master/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -__pycache__ -.ipynb_checkpoints diff --git a/Picomotor/picomotor-master/Picomotor Control-GUI.ipynb b/Picomotor/picomotor-master/Picomotor Control-GUI.ipynb deleted file mode 100644 index 717e2db..0000000 --- a/Picomotor/picomotor-master/Picomotor Control-GUI.ipynb +++ /dev/null @@ -1,380 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Control Motor" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "ExecuteTime": { - "end_time": "2017-04-05T09:16:26.120393Z", - "start_time": "2017-04-05T09:16:26.063809" - }, - "collapsed": true - }, - "outputs": [], - "source": [ - "from picomotor import MSerial" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "m = MSerial('COM11', echo=True, wait=0.1)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "ExecuteTime": { - "end_time": "2017-04-05T00:11:32.689144Z", - "start_time": "2017-04-05T00:11:32.679622" - }, - "collapsed": true - }, - "outputs": [], - "source": [ - "m.echo = False" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print(m.status_msg())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "m.unit" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "donor_unit = dict(x=787, y=588, detector='donor')\n", - "accept_unit = dict(x=625, y=641, detector='acceptor')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "m.unit = donor_unit" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "m.unit" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "m.unit = accept_unit" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "m.unit" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "vel, acc = 500, 10000\n", - "settings = [\n", - " 'acc a1 0=%d' % acc,\n", - " 'acc a1 1=%d' % acc,\n", - " 'vel a1 0=%d' % vel,\n", - " 'vel a1 1=%d' % vel, \n", - "]\n", - "for s in settings:\n", - " m.serial.flush()\n", - " print(m.sendrecv(s))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "m.sendrecv('vel')\n", - "m.sendrecv('acc')" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "collapsed": true - }, - "source": [ - "# GUI" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "ExecuteTime": { - "end_time": "2017-04-04T22:36:26.442756Z", - "start_time": "2017-04-04T22:36:26.435364" - } - }, - "outputs": [], - "source": [ - "from IPython.display import display, Javascript\n", - "from ipywidgets import interact, interactive, fixed, interact_manual, Layout, HBox, VBox, Box, Label\n", - "import ipywidgets as widgets\n", - "widgets.__version__" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "ExecuteTime": { - "end_time": "2017-04-05T00:10:23.067393Z", - "start_time": "2017-04-05T00:10:22.857938" - } - }, - "outputs": [], - "source": [ - "items_base = dict(width='auto', height='40px', margin='6px')\n", - "items_layout = Layout(flex='1 1 auto', **items_base)\n", - "\n", - "detector = widgets.ToggleButton(description=\"Donor\", value=True, button_style='success',\n", - " layout=items_layout)\n", - "axis = widgets.ToggleButtons(\n", - " options=['X', 'Y'],\n", - " value='X',\n", - " description='Axis:',\n", - " disabled=False,\n", - " layout=Layout(flex='1 0 auto', height='auto', margin='5px'),\n", - ")\n", - "delta_wid = widgets.BoundedFloatText(description='Delta:', layout=items_layout)\n", - "movebutton = widgets.Button(description=\"Move!\", layout=items_layout)\n", - "out = widgets.Textarea(\n", - " value='',\n", - " description='Received:',\n", - " layout=Layout(flex='1 1 auto'),\n", - ")\n", - "\n", - "port = HBox([Label('Port:',\n", - " layout=Layout(flex='1 1 auto', width='6em', height='auto', margin='5px')), \n", - " widgets.Text(\n", - " value='COM11',\n", - " description='',\n", - " disabled=False,\n", - " layout=Layout(flex='1 1 auto', width='6em', height='auto', margin='5px'))]\n", - " )\n", - "connect = widgets.Button(description=\"Connect\", layout=items_layout)\n", - "status = widgets.Button(description=\"Check Status\", layout=items_layout)\n", - "status.button_style = 'info'\n", - "\n", - "vb_layout = Layout(flex='1 1 auto')\n", - "vbox = VBox([detector, axis, delta_wid, movebutton], layout=vb_layout)\n", - "\n", - "vba_layout = Layout(flex='1 1 auto', justify_content='space-between')\n", - "vboxa = VBox([port, connect, status], layout=vba_layout)\n", - "\n", - "ctrls = HBox([vboxa, vbox], layout=Layout(flex='1 0 auto'))\n", - "recv = widgets.Text(\n", - " value='',\n", - " description='Received:',\n", - " layout=Layout(flex='1 1 auto', width='95%'),\n", - ")\n", - "sent = widgets.Text(\n", - " value='',\n", - " description='Sent:',\n", - " layout=Layout(flex='1 1 auto', width='95%'),\n", - ")\n", - "sentrecv = VBox([sent, recv])\n", - "main = VBox([ctrls, recv])\n", - "tab = widgets.Tab(children=[vboxa, vbox])\n", - "tab.set_title(0, 'Configure')\n", - "tab.set_title(1, 'Move')\n", - "VBox([tab, sentrecv],\n", - " layout=Layout(overflow_x='scroll', max_width='45em', \n", - " flex='1 1 auto', ))#border='solid'))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "ExecuteTime": { - "end_time": "2017-04-05T00:10:23.505156Z", - "start_time": "2017-04-05T00:10:23.501027" - }, - "collapsed": true - }, - "outputs": [], - "source": [ - "js_dialog_code = \"\"\"require(\n", - " [\"base/js/dialog\"], \n", - " function(dialog) {\n", - " dialog.modal({\n", - " title: 'Driver Connection',\n", - " body: 'Please check that driver is connected to the %s detector!',\n", - " buttons: {\n", - " 'OK': {}\n", - " }\n", - " });\n", - " }\n", - ");\"\"\"" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "ExecuteTime": { - "end_time": "2017-04-05T00:10:24.236336Z", - "start_time": "2017-04-05T00:10:24.227961" - } - }, - "outputs": [], - "source": [ - "def on_button_clicked(b):\n", - " if b['new']:\n", - " b['owner'].button_style = 'success'\n", - " b['owner'].description = 'Donor'\n", - " m.unit = donor_unit\n", - " else:\n", - " b['owner'].button_style = 'danger'\n", - " b['owner'].description = 'Acceptor'\n", - " m.unit = accept_unit\n", - " display(Javascript(js_dialog_code % b['owner'].description))\n", - "detector.observe(on_button_clicked, names='value')\n", - "\n", - "def on_move(b):\n", - " m.move(delta_wid.value, axis=axis.value.lower(), vel=200, acc=1000)\n", - "movebutton.on_click(on_move)\n", - "\n", - "def on_checkstatus(b):\n", - " m.status_msg()\n", - "status.on_click(on_checkstatus)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "m.sendwidget = sent\n", - "m.recvwidget = recv\n", - "m.echo = True" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "m.move(1, axis='x', vel=200, acc=1000)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] - } - ], - "metadata": { - "anaconda-cloud": {}, - "hide_input": false, - "kernelspec": { - "display_name": "Python [default]", - "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.5.1" - }, - "nav_menu": {}, - "toc": { - "navigate_menu": true, - "number_sections": false, - "sideBar": true, - "threshold": 4, - "toc_cell": false, - "toc_section_display": "block", - "toc_window_display": false - }, - "widgets": { - "state": { - "e2e0008a58f84eec8ff65e7a4b08c54c": { - "views": [ - { - "cell_index": 1 - } - ] - } - }, - "version": "1.2.0" - } - }, - "nbformat": 4, - "nbformat_minor": 1 -} diff --git a/Picomotor/picomotor-master/Picomotor Control.ipynb b/Picomotor/picomotor-master/Picomotor Control.ipynb deleted file mode 100644 index 46d0729..0000000 --- a/Picomotor/picomotor-master/Picomotor Control.ipynb +++ /dev/null @@ -1,379 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "ExecuteTime": { - "end_time": "2017-04-05T09:16:26.120393Z", - "start_time": "2017-04-05T09:16:26.063809" - } - }, - "outputs": [], - "source": [ - "from picomotor import MSerial" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "m = MSerial('COM11', echo=True, wait=0.1)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "m.echo = True" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "r = m.status()\n", - "r" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "m.unit" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "donor_unit = dict(x=787, y=588, detector='donor')\n", - "accept_unit = dict(x=625, y=641, detector='acceptor')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "m.unit = donor_unit" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "m.unit" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "m.unit = accept_unit" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "m.unit" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "# m.serial.close()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "# m.echo = True\n", - "# m.wait = 0.1" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "vel, acc = 500, 10000\n", - "settings = [\n", - " 'acc a1 0=%d' % acc,\n", - " 'acc a1 1=%d' % acc,\n", - " 'vel a1 0=%d' % vel,\n", - " 'vel a1 1=%d' % vel, \n", - "]\n", - "for s in settings:\n", - " m.serial.flush()\n", - " print(m.sendrecv(s))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "m.sendrecv('vel')\n", - "m.sendrecv('acc')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "m.joystick_enable(True)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "m.joystick_enable(False)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "m.unit = donor_unit" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "m.unit = accept_unit" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "scrolled": false - }, - "outputs": [], - "source": [ - "m.move(0.04, axis='x', vel=200, acc=1000)\n", - "m.unit" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "scrolled": false - }, - "outputs": [], - "source": [ - "m.move(0.21, axis='y', vel=200, acc=1000)\n", - "m.unit" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "m.halt()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true, - "scrolled": false - }, - "outputs": [], - "source": [ - "steps, vel, acc = 1000, 1000, 10000\n", - "for ax in ('x', 'y'):\n", - " for s in (steps, -steps):\n", - " m.move(s, axis=ax, vel=vel, acc=acc)\n", - " while m.is_moving():\n", - " time.sleep(0.05)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true, - "scrolled": false - }, - "outputs": [], - "source": [ - "m.move(1000, axis='x', vel=200, acc=1000)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "m.halt()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "m.sendrecv('POS')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "m.sendrecv('SAV')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "m.sendrecv('INI')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] - } - ], - "metadata": { - "anaconda-cloud": {}, - "hide_input": false, - "kernelspec": { - "display_name": "Python [default]", - "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.5.2" - }, - "nav_menu": {}, - "toc": { - "colors": { - "hover_highlight": "#DAA520", - "running_highlight": "#FF0000", - "selected_highlight": "#FFD700" - }, - "moveMenuLeft": true, - "nav_menu": { - "height": "12px", - "width": "252px" - }, - "navigate_menu": true, - "number_sections": true, - "sideBar": true, - "threshold": 4, - "toc_cell": false, - "toc_section_display": "block", - "toc_window_display": false, - "widenNotebook": false - } - }, - "nbformat": 4, - "nbformat_minor": 1 -} diff --git a/Picomotor/picomotor-master/README.md b/Picomotor/picomotor-master/README.md deleted file mode 100644 index 22825af..0000000 --- a/Picomotor/picomotor-master/README.md +++ /dev/null @@ -1,6 +0,0 @@ -# picomotor - -Software to control, via a serial port, one or more [Newport actuators 8302](https://www.newport.com/p/8302) (micropositioners) -using the open-loop controller 8752 and the ethernet controller 8753. - -Reference: [87XX_Manual_RevC.pdf](https://github.com/tritemio/picomotor/files/1039338/87XX_Manual_RevC.pdf) diff --git a/Picomotor/picomotor-master/picomotor.py b/Picomotor/picomotor-master/picomotor.py deleted file mode 100644 index 60a3a1d..0000000 --- a/Picomotor/picomotor-master/picomotor.py +++ /dev/null @@ -1,116 +0,0 @@ -""" -Library to control the picomotor driver. -""" - -import serial, time - - -class MSerial: - axis_names = dict(x=0, y=1) - unit = dict(x=1, y=1) - - def __init__(self, port, echo=True, max_retry=2, wait=0.1, sendwidget=None, recvwidget=None, **serial_kws): - kws = dict(baudrate=19200, bytesize=serial.EIGHTBITS, - parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, - timeout=0, xonxoff=True, rtscts=False, dsrdtr=False) - kws.update(serial_kws) - self.serial = serial.Serial(port, **kws) - self.echo = echo - self.wait = wait - self.sendwidget = sendwidget - self.recvwidget = recvwidget - - def send(self, cmd): - """Send a command to the picomotor driver.""" - line = cmd + '\r\n' - retval = self.serial.write(bytes(line, encoding='ascii')) - self.serial.flush() - if self.echo: - self.log(cmd, widget=self.sendwidget) - return retval - - def readlines(self): - """Read response from picomotor driver.""" - return ''.join([l.decode('ASCII') for l in self.serial.readlines()]) - - def log(self, msg, widget=None): - if widget is None: - print(msg, flush=True) - else: - widget.value = msg - - def sendrecv(self, cmd): - """Send a command and (optionally) printing the picomotor driver's response.""" - res = self.send(cmd) - if self.echo: - time.sleep(self.wait) - ret_str = self.readlines() - self.log(ret_str, widget=self.recvwidget) - return res - - def set_axis(self, axis, vel=None, acc=None, driver='a1'): - """Set current axis ('x' or 'y') and (optionally) its velocity.""" - assert axis in self.axis_names - fmt = dict(driver=driver, axis=self.axis_names[axis]) - basecmd = '{cmd} {driver} {axis}={value}' - if acc is not None: - assert 0 < acc <= 32000, 'Acceleration out of range (1..32000).' - cmd = basecmd.format(cmd='ACC', value=acc, **fmt) - self.sendrecv(cmd) - if vel is not None: - assert 0 < vel <= 2000, 'Velocity out of range (1..2000).' - cmd = basecmd.format(cmd='VEL', value=vel, **fmt) - self.sendrecv(cmd) - cmd = 'chl {driver}={axis}'.format(**fmt) - return self.sendrecv(cmd) - - def move_steps(self, steps, axis, vel=None, acc=None, driver='a1', go=True): - """Send command to move `axis` of the given `steps`.""" - self.set_axis(axis, vel=vel, acc=acc, driver=driver) - cmd = 'rel {driver}={steps}'.format(driver=driver, steps=steps) - if go: - cmd = cmd + ' g' - return self.sendrecv(cmd) - - def move(self, units, axis, vel=None, acc=None, driver='a1', go=True): - """Send command to move `axis` of the given `units`. - Uses self.unit for conversion. - """ - steps = round(units * self.unit[axis]) - return self.move_steps(steps, axis, vel=None, acc=None, driver='a1', go=True) - - def go(self): - """Send 'go' command to execute all previously sent move commands.""" - return self.sendrecv('go') - - def halt(self): - """Send 'HAL' command to stop motion with deceleration.""" - return self.sendrecv('hal') - - def joystick_enable(self, enable=True): - """Enable or disable the joystick.""" - cmd = 'JON' if enable else 'JOF' - return self.sendrecv(cmd) - - def status_msg(self): - """Return the driver status byte as an integer (see manual pag. 185).""" - self.send('STA') - time.sleep(self.wait) - ret_str = self.readlines() - if self.echo: - self.log(repr(ret_str), widget=self.recvwidget) - return ret_str - - def status(self): - ret_str = self.status_msg() - i = ret_str.find('A1=') - if i >= 0: - status = int(ret_str[i+5:i+7], 16) - else: - raise IOError("Received: '%s'" % ret_str) - return status - - def is_moving(self): - """Return True if motor is moving, else False.""" - status = self.status() - return status & 0x01 \ No newline at end of file diff --git a/picomotor_repo/build/lib/picomotor/__init__.py b/picomotor_repo/build/lib/picomotor/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/picomotor_repo/build/lib/picomotor/aqctl_picomotor.py b/picomotor_repo/build/lib/picomotor/aqctl_picomotor.py new file mode 100644 index 0000000..c571b62 --- /dev/null +++ b/picomotor_repo/build/lib/picomotor/aqctl_picomotor.py @@ -0,0 +1,52 @@ +import argparse +import logging +import sys +import os +import asyncio + +from picomotor_driver import picomotor +from sipyco.pc_rpc import simple_server_loop +from sipyco import common_args + +logger = logging.getLogger(__name__) + +def get_argparser(): + parser = argparse.ArgumentParser( + description="ARTIQ controller for the picomotor") + common_args.simple_network_args(parser, 3210) + parser.add_argument( + "-d", "--device", default=None, + help="serial port.") + parser.add_argument( + "--softtrig", default=False, action="store_true", + help="Sets trigger to software. Default is hardware") + parser.add_argument( + "--num", default=1, + help="Sets number of images. Default is hardware") + parser.add_argument( + "--simulation", action="store_true", + help="Put the driver in simulation mode, even if --device is used.") + common_args.verbosity_args(parser) + return parser + +def main(): + args = get_argparser().parse_args() + common_args.init_logger_from_args(args) + if os.name == "nt": + asyncio.set_event_loop(asyncio.ProactorEventLoop()) + # if args.device is None: + # print("Starting in Simulation mode...") + # dev = andor(args.device if not args.simulation else None) + dev = picomotor("COM4") + #asyncio.get_event_loop().run_until_complete(dev.setup()) + try: + print("picomotor server startup on port",args.port,"successful...") + simple_server_loop( + {"picomotor": dev}, common_args.bind_address_from_args(args), args.port) + truthcounter=1 + finally: + print("Closing picomotor and server...") + dev.close() + +if __name__ == "__main__": + main() diff --git a/Picomotor/picomotor_driver.py b/picomotor_repo/build/lib/picomotor/picomotor_driver.py similarity index 100% rename from Picomotor/picomotor_driver.py rename to picomotor_repo/build/lib/picomotor/picomotor_driver.py diff --git a/picomotor_repo/dist/picomotor-0.0.0-py3.8.egg b/picomotor_repo/dist/picomotor-0.0.0-py3.8.egg new file mode 100644 index 0000000..a319f96 Binary files /dev/null and b/picomotor_repo/dist/picomotor-0.0.0-py3.8.egg differ diff --git a/picomotor_repo/doc/Makefile b/picomotor_repo/doc/Makefile new file mode 100644 index 0000000..298ea9e --- /dev/null +++ b/picomotor_repo/doc/Makefile @@ -0,0 +1,19 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) \ No newline at end of file diff --git a/picomotor_repo/doc/conf.py b/picomotor_repo/doc/conf.py new file mode 100644 index 0000000..116bf77 --- /dev/null +++ b/picomotor_repo/doc/conf.py @@ -0,0 +1,176 @@ +# -*- coding: utf-8 -*- +# +# Configuration file for the Sphinx documentation builder. +# +# This file does only contain a selection of the most common options. For a +# full list see the documentation: +# http://www.sphinx-doc.org/en/master/config + + +import os +import sys +from unittest.mock import Mock + +sys.path.insert(0, os.path.abspath('..')) + +mock_modules = ["asyncserial"] + +for module in mock_modules: + sys.modules[module] = Mock() + +# -- Project information ----------------------------------------------------- + +project = 'picomotor' +copyright = '2019, M-Labs' +author = 'M-Labs' + +# The short X.Y version +version = '1.0' +# The full version, including alpha/beta/rc tags +release = '1.0' + + +# -- General configuration --------------------------------------------------- + +# If your documentation needs a minimal Sphinx version, state it here. +# +# needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + 'sphinx.ext.autodoc', + 'sphinxarg.ext' +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# +# source_suffix = ['.rst', '.md'] +source_suffix = '.rst' + +# The master toctree document. +master_doc = 'index' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = None + + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = 'alabaster' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +# +# html_theme_options = {} + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# Custom sidebar templates, must be a dictionary that maps document names +# to template names. +# +# The default sidebars (for documents that don't match any pattern) are +# defined by theme itself. Builtin themes are using these templates by +# default: ``['localtoc.html', 'relations.html', 'sourcelink.html', +# 'searchbox.html']``. +# +# html_sidebars = {} + + +# -- Options for HTMLHelp output --------------------------------------------- + +# Output file base name for HTML help builder. +htmlhelp_basename = 'picomotordoc' + + +# -- Options for LaTeX output ------------------------------------------------ + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + (master_doc, 'picomotor.tex', 'picomotor Documentation', + 'M-Labs', 'manual'), +] + + +# -- Options for manual page output ------------------------------------------ + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + (master_doc, 'picomotor', 'picomotor Documentation', + [author], 1) +] + + +# -- Options for Texinfo output ---------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + (master_doc, 'picomotor', 'picomotor Documentation', + author, 'picomotor', 'One line description of project.', + 'Miscellaneous'), +] + + +# -- Options for Epub output ------------------------------------------------- + +# Bibliographic Dublin Core info. +epub_title = project + +# The unique identifier of the text. This can be a ISBN number +# or the project homepage. +# +# epub_identifier = '' + +# A unique identification for the text. +# +# epub_uid = '' + +# A list of files that should not be packed into the epub file. +epub_exclude_files = ['search.html'] diff --git a/picomotor_repo/doc/index.rst b/picomotor_repo/doc/index.rst new file mode 100644 index 0000000..6516bdc --- /dev/null +++ b/picomotor_repo/doc/index.rst @@ -0,0 +1,24 @@ +Welcome to picomotor's documentation! +======================================== + +API +--- + +.. automodule:: picomotor.driver + :members: + + +ARTIQ controller +---------------- + +.. argparse:: + :ref: picomotor.aqctl_picomotor.get_argparser + :prog: aqctl_picomotor + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/picomotor_repo/picomotor.egg-info/PKG-INFO b/picomotor_repo/picomotor.egg-info/PKG-INFO new file mode 100644 index 0000000..191b946 --- /dev/null +++ b/picomotor_repo/picomotor.egg-info/PKG-INFO @@ -0,0 +1,10 @@ +Metadata-Version: 1.0 +Name: picomotor +Version: 0.0.0 +Summary: UNKNOWN +Home-page: UNKNOWN +Author: UNKNOWN +Author-email: UNKNOWN +License: UNKNOWN +Description: UNKNOWN +Platform: UNKNOWN diff --git a/picomotor_repo/picomotor.egg-info/SOURCES.txt b/picomotor_repo/picomotor.egg-info/SOURCES.txt new file mode 100644 index 0000000..e9f4fd4 --- /dev/null +++ b/picomotor_repo/picomotor.egg-info/SOURCES.txt @@ -0,0 +1,9 @@ +setup.py +picomotor/__init__.py +picomotor/aqctl_picomotor.py +picomotor/picomotor_driver.py +picomotor.egg-info/PKG-INFO +picomotor.egg-info/SOURCES.txt +picomotor.egg-info/dependency_links.txt +picomotor.egg-info/entry_points.txt +picomotor.egg-info/top_level.txt \ No newline at end of file diff --git a/picomotor_repo/picomotor.egg-info/dependency_links.txt b/picomotor_repo/picomotor.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/picomotor_repo/picomotor.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/picomotor_repo/picomotor.egg-info/entry_points.txt b/picomotor_repo/picomotor.egg-info/entry_points.txt new file mode 100644 index 0000000..0a7b59a --- /dev/null +++ b/picomotor_repo/picomotor.egg-info/entry_points.txt @@ -0,0 +1,3 @@ +[console_scripts] +aqctl_picomotor = picomotor.aqctl_picomotor:main + diff --git a/picomotor_repo/picomotor.egg-info/top_level.txt b/picomotor_repo/picomotor.egg-info/top_level.txt new file mode 100644 index 0000000..444fc08 --- /dev/null +++ b/picomotor_repo/picomotor.egg-info/top_level.txt @@ -0,0 +1 @@ +picomotor diff --git a/picomotor_repo/picomotor/__init__.py b/picomotor_repo/picomotor/__init__.py new file mode 100644 index 0000000..c8183ba --- /dev/null +++ b/picomotor_repo/picomotor/__init__.py @@ -0,0 +1,2 @@ +from picomotor import aqctl_picomotor +from picomotor import picomotor_driver \ No newline at end of file diff --git a/picomotor_repo/picomotor/__pycache__/__init__.cpython-38.pyc b/picomotor_repo/picomotor/__pycache__/__init__.cpython-38.pyc new file mode 100644 index 0000000..a1dc5e2 Binary files /dev/null and b/picomotor_repo/picomotor/__pycache__/__init__.cpython-38.pyc differ diff --git a/picomotor_repo/picomotor/__pycache__/aqctl_picomotor.cpython-38.pyc b/picomotor_repo/picomotor/__pycache__/aqctl_picomotor.cpython-38.pyc new file mode 100644 index 0000000..dcc57ca Binary files /dev/null and b/picomotor_repo/picomotor/__pycache__/aqctl_picomotor.cpython-38.pyc differ diff --git a/picomotor_repo/picomotor/__pycache__/picomotor_driver.cpython-38.pyc b/picomotor_repo/picomotor/__pycache__/picomotor_driver.cpython-38.pyc new file mode 100644 index 0000000..7b74419 Binary files /dev/null and b/picomotor_repo/picomotor/__pycache__/picomotor_driver.cpython-38.pyc differ diff --git a/picomotor_repo/picomotor/aqctl_picomotor.py b/picomotor_repo/picomotor/aqctl_picomotor.py new file mode 100644 index 0000000..dbfa2c1 --- /dev/null +++ b/picomotor_repo/picomotor/aqctl_picomotor.py @@ -0,0 +1,52 @@ +import argparse +import logging +import sys +import os +import asyncio + +from picomotor.picomotor_driver import picomotor +from sipyco.pc_rpc import simple_server_loop +from sipyco import common_args + +logger = logging.getLogger(__name__) + +def get_argparser(): + parser = argparse.ArgumentParser( + description="ARTIQ controller for the picomotor") + common_args.simple_network_args(parser, 3210) + parser.add_argument( + "-d", "--device", default=None, + help="serial port.") + parser.add_argument( + "--softtrig", default=False, action="store_true", + help="Sets trigger to software. Default is hardware") + parser.add_argument( + "--num", default=1, + help="Sets number of images. Default is hardware") + parser.add_argument( + "--simulation", action="store_true", + help="Put the driver in simulation mode, even if --device is used.") + common_args.verbosity_args(parser) + return parser + +def main(): + args = get_argparser().parse_args() + common_args.init_logger_from_args(args) + if os.name == "nt": + asyncio.set_event_loop(asyncio.ProactorEventLoop()) + # if args.device is None: + # print("Starting in Simulation mode...") + # dev = andor(args.device if not args.simulation else None) + dev = picomotor("COM4") + #asyncio.get_event_loop().run_until_complete(dev.setup()) + try: + print("picomotor server startup on port",args.port,"successful...") + simple_server_loop( + {"picomotor": dev}, common_args.bind_address_from_args(args), args.port) + truthcounter=1 + finally: + print("Closing picomotor and server...") + dev.close() + +if __name__ == "__main__": + main() diff --git a/picomotor_repo/picomotor/picomotor_driver.py b/picomotor_repo/picomotor/picomotor_driver.py new file mode 100644 index 0000000..12008e9 --- /dev/null +++ b/picomotor_repo/picomotor/picomotor_driver.py @@ -0,0 +1,134 @@ +""" +Library to control the NewFocus 8732 picomotor driver. +""" +import serial +import time +import numpy as np +#import os + + +class picomotor: + axis_names = { "MOTz_x": "112", "MOTz_y": "122", "MOTy_x": "232", "MOTy_y": "242", "MOTx_x": "212", "MOTx_y": "222"} + steps_in_turn = { "MOTz_x": [15000, 16000], "MOTz_y":[16000, 16000], "MOTy_x": [16000, 16000], "MOTy_y": [16000, 16000], + "MOTx_x": [16000, 16000], "MOTx_y": [16000, 16000]} # [CW, CCW] number of steps for 1 turn + + + def __init__(self, COM_port): + """Open serial connection for NewFocus 8732 controller""" + """COM_port: ie 'COM3' (check device manager) """ + + self.serial = serial.Serial(timeout = 0.5) #19200 baud didn't work. 8 bits, no parity, 1 stop bit. + self.serial.baudrate = 9600 + self.serial.port = COM_port #'COM3' + try: + self.serial.open() + #print("Serial connection open: ", self.serial.open()) + response = self.sendreceive("*IDN?") + print(response) + #print(self.serial.is_open) + except: + self.serial.close() # don't know if this will help + print(self.serial.is_open) + print('Cannot open.') + + # Initialize positions + self.positions = dict.fromkeys(self.axis_names, 0) #{'MOTz_x': 0, 'MOTz_y': 0, ...} #units steps + + # Turn on the slots? + #self.sendreceive(':INST 1') #? not sure if I need this? + #INST:NSEL 1 + + + def sendreceive(self, cmd): + """Send command to the picomotor driver, and readlines""" + """ Send multiple commands with ;""" + """ 8732 ends with carriage return \r. Does not echo command, but always responds. """ + line = cmd + '\r' + retval = self.serial.write(bytes(line, encoding='ascii')) + self.serial.flush() # wait for outgoing serial data to complete + #time.sleep(0.01) #not sure if needed + response = self.serial.read_until(b'\r') + response = response[:-1] # get rid of \r + return response + + + def move(self, axis="MOTx_x", steps=1000, velocity=1500): + """ Move relative number of setups. Position CW, Negative CCW""" + """ Returns before finished moving. """ + + cmd1 = ":INST:NSEL " + self.axis_names[axis] + + cmd2 = ":SOUR:PULS:FREQ "+ str(round(velocity)) # integer divider of 1500 + + if steps < 0: + cmd3 = ":SOUR:DIR CCW" + else: + cmd3 = ":SOUR:DIR CW" + + cmd4 = ":SOUR:PULS:COUN " + str(round(abs(steps))) + + cmd = cmd1 + "; " + cmd2 + "; " + cmd3 #+ "; " + cmd4 + print(cmd) + self.sendreceive(cmd) + time.sleep(0.01) + self.sendreceive(cmd4) + + self.wait_for_move() + # Update position in move_abs and move_rel + #self.positions[axis] = self.positions[axis] + steps + + + def move_abs(self, axis, position, velocity=1500, ccw_correction=True): + """ Move to absolute position, and if CCW (negative steps), then use correct cw/ccw disparities""" + cw, ccw = self.steps_in_turn[axis] #number steps in turn + current_position = self.positions[axis] #get current position + steps = position - current_position + + if steps < 0: + steps = steps*(ccw/cw) + + self.move(axis, steps, velocity) + self.positions[axis] = position + return position + + def move_rel(self, axis, steps, velocity=1500, ccw_correction=True): + """ Move to absolute position, and if CCW (negative steps), then use correct cw/ccw disparities""" + cw, ccw = self.steps_in_turn[axis] #number steps in turn + + if steps < 0: + steps = steps*(ccw/cw) + + self.move(axis, steps, velocity) + self.positions[axis] = self.positions[axis] + steps #get current position + return self.positions[axis] + + + + def wait_for_move(self): + """ Wait for picomotor to finish moving """ + timeout = 120 # timeout seconds + moving = 0 + print("ran wait successfully") + while moving==0: #OPC returns 1 if all channels are finished + time.sleep(0.2) + text = self.sendreceive("*OPC?") + moving = int(text)# get 1 or 0 from text + + + def zero_positions(self): + """ Zero all positions """ + self.positions = dict.fromkeys(self.axis_names, 0) + + def zero_position(self, axis): + """ Zero single axis """ + self.positions[axis] = 0 + + + def get_position(self, axis): + """ Return current position """ + return self.positions[axis] + + + def close(self): + self.serial.close() + print(self.serial.is_open) \ No newline at end of file diff --git a/picomotor_repo/setup.py b/picomotor_repo/setup.py new file mode 100644 index 0000000..6e0e5c7 --- /dev/null +++ b/picomotor_repo/setup.py @@ -0,0 +1,12 @@ +from setuptools import setup, find_packages + +setup( + name="picomotor", + install_requires=[],#"sipyco", "asyncserial"], #I disabled these because the installs were messed up! + packages=find_packages(), + entry_points={ + "console_scripts": [ + "aqctl_picomotor = picomotor.aqctl_picomotor:main", + ], + }, +) diff --git a/Picomotor/test_driver.py b/picomotor_repo/testing/test_driver.py similarity index 100% rename from Picomotor/test_driver.py rename to picomotor_repo/testing/test_driver.py diff --git a/Picomotor/testing.py b/picomotor_repo/testing/testing.py similarity index 100% rename from Picomotor/testing.py rename to picomotor_repo/testing/testing.py