Skip to content

Instantly share code, notes, and snippets.

@cfobel
Last active July 4, 2018 17:03
Show Gist options
  • Save cfobel/3886fd1d968aed87c30e8dfeb9fe9c7b to your computer and use it in GitHub Desktop.
Save cfobel/3886fd1d968aed87c30e8dfeb9fe9c7b to your computer and use it in GitHub Desktop.
DropBot capacitance updates

Jupyter notebook demonstrating connecting to DropBot capacitance update events.

Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from __future__ import division, print_function, unicode_literals\n",
"import logging\n",
"import time\n",
"\n",
"from IPython.display import display, Image, Markdown\n",
"import dropbot as db\n",
"import ipywidgets as ipyw\n",
"import numpy as np\n",
"import si_prefix as si\n",
"\n",
"logging.basicConfig(level=logging.DEBUG)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# SCI-BOTS 90-pin array v3 channel map\n",
"\n",
"The image below show the channel mapping for the electrodes on the \n",
"\n",
"![Image](chip-orientation.jpg)\n",
"![Image](SCI-BOTS 90-pin array v3.png)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"DEBUG:trollius:Using selector: SelectSelector\n",
"DEBUG:base_node_rpc.async:`ProactorEventLoop` required, not `<class 'trollius.windows_events._WindowsSelectorEventLoop'>`loop in background thread.\n",
"DEBUG:base_node_rpc.async:Execute new loop in background thread.\n",
"DEBUG:trollius:Using proactor: IocpProactor\n",
"DEBUG:base_node_rpc.async:`ProactorEventLoop` required, not `<class 'trollius.windows_events._WindowsSelectorEventLoop'>`loop in background thread.\n",
"DEBUG:base_node_rpc.async:Execute new loop in background thread.\n",
"DEBUG:trollius:Using proactor: IocpProactor\n",
"DEBUG:base_node_rpc.proxy:Attempt to connect to device on port COM4 (baudrate=115200)\n",
"DEBUG:serial_device.threaded:Open `COM4` and monitor connection status\n",
"DEBUG:serial_device.threaded:connection_made: `COM4` `<ReaderThread(Thread-9, started daemon 3968)>`\n",
"DEBUG:base_node_rpc.proxy:Wait for connection to port COM4\n",
"INFO:base_node_rpc.proxy:Successfully connected to dropbot on port COM4\n"
]
},
{
"data": {
"text/plain": [
"array([ 3, 7, 11, 15, 19, 23, 27, 30, 31, 35, 39, 43, 47,\n",
" 51, 55, 59, 60, 64, 68, 72, 76, 80, 84, 88, 89, 92,\n",
" 96, 100, 104, 108, 112, 116])"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"try:\n",
" # Close existing connection (if it exists) to allow this cell\n",
" # to be run multiple times.\n",
" proxy.terminate()\n",
"except:\n",
" pass\n",
"\n",
"proxy = db.SerialProxy()\n",
"disabled_channels = proxy.disabled_channels_mask\n",
"\n",
"# Disable channels for electrodes covered by copper tape.\n",
"disabled_channels[[30, 89]] = 1\n",
"\n",
"# Disable channels not connected to electrodes on Sci-Bots 90-pin array v3 chip.\n",
"not_connected = [3, 7, 11, 15, 19, 23, 27, 31, 35, 39,\n",
" 43, 47, 51, 55, 59, 60, 64, 68, 72, 76,\n",
" 80, 84, 88, 92, 96, 100, 104, 108, 112, 116]\n",
"disabled_channels[not_connected] = 1\n",
"proxy.disabled_channels_mask = disabled_channels\n",
"display(np.where(proxy.disabled_channels_mask)[0])"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"hv_output_selected True\n",
"hv_output_enabled True\n",
"channel_count 120\n",
"frequency 10000\n",
"voltage 100\n",
"target_capacitance 0\n",
"capacitance_update_interval_ms 0\n",
"dtype: object"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Query runtime properties of DropBot.\n",
"proxy.state"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"hv_output_selected True\n",
"hv_output_enabled True\n",
"channel_count 120\n",
"frequency 10000\n",
"voltage 100\n",
"target_capacitance 0\n",
"capacitance_update_interval_ms 0\n",
"dtype: object"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Actuation voltage: 100.8 V\n"
]
}
],
"source": [
"# Set `hv_output_enabled` to `True` to turn on high voltage output.\n",
"proxy.update_state(hv_output_enabled=True)\n",
"# Display updated DropBot runtime state\n",
"display(proxy.state)\n",
"# Measure high voltage output.\n",
"print('Actuation voltage: %sV' % si.si_format(proxy.measure_voltage()))"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"120"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Query number of channels available.\n",
"proxy.number_of_channels"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,\n",
" 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,\n",
" 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
" 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
" 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
" 0, 0, 0, 0, 0], dtype=uint8)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Query current state of channels (1=actuated).\n",
"proxy.state_of_channels"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"--------------------------------------------------------------------"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Example: display latest capacitance reported from DropBot."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\r",
"capacitance: 49.9 pF (message=`OrderedDict([(u'event', u'capacitance-updated'), (u'new_value', 4.98611e-11), (u'start', 3903965419L), (u'end', 3903966392L), (u'n_samples', 50), (u'V_a', 100.585)])`)"
]
}
],
"source": [
"def dump_capacitance_update(message):\n",
" '''\n",
" Display latest capacitance reported from DropBot.\n",
" '''\n",
" print('\\rcapacitance: %sF (message=`%s`)' % (si.si_format(message['new_value']),\n",
" message), end='')\n",
" \n",
"\n",
"# Connect to capacitance updated DropBot events.\n",
"proxy.signals.signal('capacitance-updated').connect(dump_capacitance_update)\n",
"# Set `capacitance_update_interval_ms` to non-zero value to enable\n",
"# periodic DropBot `capacitance-updated` events.\n",
"proxy.update_state(capacitance_update_interval_ms=100)\n",
"pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Disconnect `capacitance-updated` handler"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"# Set `capacitance_update_interval_ms` to zero value to disable\n",
"# DropBot `capacitance-updated` events.\n",
"proxy.update_state(capacitance_update_interval_ms=0)\n",
"# (optional) Disconnect event handler\n",
"proxy.signals.signal('capacitance-updated').disconnect(dump_capacitance_update)\n",
"pass"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.14"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment