Skip to content

Commit

Permalink
picomotor
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhood11 committed Feb 2, 2021
1 parent aa6077c commit 655f542
Show file tree
Hide file tree
Showing 5 changed files with 883 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Picomotor/picomotor-master/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__pycache__
.ipynb_checkpoints
380 changes: 380 additions & 0 deletions Picomotor/picomotor-master/Picomotor Control-GUI.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,380 @@
{
"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
}
Loading

0 comments on commit 655f542

Please sign in to comment.