-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsage.html
More file actions
441 lines (301 loc) · 19.5 KB
/
Copy pathUsage.html
File metadata and controls
441 lines (301 loc) · 19.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Usage — behaviour_box 0 documentation</title>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="index" title="Index"
href="genindex.html"/>
<link rel="search" title="Search" href="search.html"/>
<link rel="top" title="behaviour_box 0 documentation" href="index.html"/>
<link rel="next" title="Output Format" href="Output.html"/>
<link rel="prev" title="Hardware" href="hardware.html"/>
<script src="_static/js/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav" role="document">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search">
<a href="index.html" class="icon icon-home"> behaviour_box
</a>
<div class="version">
1
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<p class="caption"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="Installation.html">Install</a></li>
<li class="toctree-l1"><a class="reference internal" href="hardware.html">Hardware</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Usage</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#interactive-options">Interactive Options</a></li>
<li class="toctree-l2"><a class="reference internal" href="#adjusting-default-arguments">Adjusting Default Arguments</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="Output.html">Output Format</a></li>
<li class="toctree-l1"><a class="reference internal" href="details.html">Software Descriptions</a></li>
<li class="toctree-l1"><a class="reference internal" href="code.html">Code Reference</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">behaviour_box</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html">Docs</a> »</li>
<li>Usage</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/Usage.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="usage">
<h1>Usage<a class="headerlink" href="#usage" title="Permalink to this headline">¶</a></h1>
<p>A set of trials are run through the <code class="docutils literal"><span class="pre">SerialController.py</span></code> script. At
the windows command prompt cd to the root directory of the
behaviour_box repository.</p>
<p>When the program runs the first thing it does is make a new folder to
save the logs in. The base of the new directory can be specified by
<code class="docutils literal"><span class="pre">--datapath</span></code> and the new folder is always the current date is in the
format YYMMDD.</p>
<p>In addition it also creates two files, a raw log file which stores all
time stamped communications sent and received by the program, and a csv
file which contains the same data in tabulated form. The name pattern
for the csv is <code class="docutils literal"><span class="pre">{ID}_{date}_000.csv</span></code> where ID is given with the
<code class="docutils literal"><span class="pre">-ID</span></code> argument and date is in the format YYMMDD.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">It is important to note that the data files will be appended to each
time the program is run over the course of the day, unless a new ID is
specified.</p>
</div>
<p>Next the program checks the serial port specified by the <code class="docutils literal"><span class="pre">--port</span></code>
argument. By default, if no port is specified the program will search
the available ports for any Arduino that is plugged in. If more than
one Arduino is available it will print a warning, followed by a list
of Arduino ports. It will then select the first arduino.
On Windows the serial ports are specified by <code class="docutils literal"><span class="pre">COMx</span></code> where
<code class="docutils literal"><span class="pre">x</span></code> is some integer. If no communications are found the program
will exit.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If you always have the Arduino detected on the same port
you can adjust the default value of the <code class="docutils literal"><span class="pre">port</span></code> variable to avoid setting
this flag each run, see <a class="reference internal" href="#adjust-defaults"><span class="std std-ref">Adjusting Default Arguments</span></a>. This strategy applies to
all the variables that might remain invariant between sessions.</p>
</div>
<p>When the connection has been established the program first transmits a
number of configuration variables to the arduino, such as the lick
threshold, and timing information. These can be updated online later,
but it saves time to avoid sending them on each trial if they are
unchanged.</p>
<p>The program then begins to loop through the <code class="docutils literal"><span class="pre">trials</span></code> variable, which
is an iterable list of the stimulus durations. On each loop the program
tells the Arduino what duration to play, and whether or not to reward a
lick.</p>
<p>At this point the program sends the <code class="docutils literal"><span class="pre">START</span></code> message to the Arduino and
the trial begins. As the trial runs the program monitors the Arduino
status messages as they come in.</p>
<p>At the end of the trial the program collects all the status messages and
formats them into a Pandas DataFrame, which is then saved into
<code class="docutils literal"><span class="pre">{ID}_{date}_000.csv</span></code></p>
<div class="section" id="interactive-options">
<span id="interactivity"></span><h2>Interactive Options<a class="headerlink" href="#interactive-options" title="Permalink to this headline">¶</a></h2>
<p>The Python wrapper was written to allow for limited interaction with the
Arduino while a trial was being run without the need to touch the source code
and recompile. With animal experimentation in mind it was decided that it
would be best to avoid editing the control code during a run. The Arduino
exposes a number of relevant variables to the Serial Communications port,
which the Python wrapper reads and writes to.</p>
<p>Pressing any key (except for <code class="docutils literal"><span class="pre">SPACE</span></code> or <code class="docutils literal"><span class="pre">Enter</span></code>) while the SerialComms.py
script is running will pause the program loop. Pressing <code class="docutils literal"><span class="pre">Enter</span></code> or <code class="docutils literal"><span class="pre">SPACE</span></code>
will resume the program.</p>
<p>In addition a subset of relevant variables can be modified using key presses
outlined in the following table.</p>
<table border="1" class="docutils">
<colgroup>
<col width="14%" />
<col width="86%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">key</th>
<th class="head">option</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><code class="docutils literal"><span class="pre">H</span></code></td>
<td>This menu</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal"><span class="pre">P</span></code></td>
<td>Punish</td>
</tr>
<tr class="row-even"><td><code class="docutils literal"><span class="pre"><</span></code> /
<code class="docutils literal"><span class="pre">></span></code></td>
<td>increase / decrease the lick threshold</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal"><span class="pre">?</span></code></td>
<td>show threshold</td>
</tr>
<tr class="row-even"><td><code class="docutils literal"><span class="pre">[</span></code> /
<code class="docutils literal"><span class="pre">]</span></code></td>
<td>increase / decrease the minimum number of licks
required to get a reward</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal"><span class="pre">\</span></code></td>
<td>show lickcount</td>
</tr>
<tr class="row-even"><td><code class="docutils literal"><span class="pre">tab</span></code></td>
<td>toggle mode</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal"><span class="pre">:</span></code> /
<code class="docutils literal"><span class="pre">"</span></code></td>
<td>increase / decrease the time prior to a stimulus
in which a lick will end the trial</td>
</tr>
<tr class="row-even"><td><code class="docutils literal"><span class="pre">L</span></code></td>
<td>show noLick period</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal"><span class="pre">(</span></code> /
<code class="docutils literal"><span class="pre">)</span></code></td>
<td>increase / decrease the duration of a trial</td>
</tr>
<tr class="row-even"><td><code class="docutils literal"><span class="pre">T</span></code></td>
<td>show trial duration period</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal"><span class="pre">Y</span></code></td>
<td>toggle timeout (requires punish to take effect)</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="adjusting-default-arguments">
<span id="adjust-defaults"></span><h2>Adjusting Default Arguments<a class="headerlink" href="#adjusting-default-arguments" title="Permalink to this headline">¶</a></h2>
<p>The default parameters to the Python Script are all set in the file
<code class="docutils literal"><span class="pre">utilities\args.py</span></code>. The file looks something like this:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">argparse</span>
<span class="c1"># create the argument parsing object</span>
<span class="n">p</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">(</span><span class="n">description</span><span class="o">=</span><span class="s2">"This program"</span>
<span class="s2">"controls the Arduino"</span>
<span class="s2">"and reads from it too"</span>
<span class="p">)</span>
<span class="c1"># construct a dictionary of program parameters</span>
<span class="n">kwargs</span> <span class="o">=</span> <span class="p">{</span>
<span class="p">(</span><span class="s2">"-i"</span><span class="p">,</span> <span class="s2">"--ID"</span><span class="p">,</span> <span class="p">)</span> <span class="p">:</span> <span class="p">{</span>
<span class="s1">'default'</span> <span class="p">:</span> <span class="s2">"_"</span><span class="p">,</span>
<span class="s1">'help'</span> <span class="p">:</span> <span class="s2">"identifier for this animal/run"</span><span class="p">,</span>
<span class="p">},</span>
<span class="o">.</span>
<span class="o">.</span>
<span class="o">.</span>
<span class="p">(</span><span class="s2">"--port"</span><span class="p">,</span> <span class="p">)</span> <span class="p">:</span> <span class="p">{</span>
<span class="s1">'default'</span> <span class="p">:</span> <span class="kc">None</span><span class="p">,</span>
<span class="s1">'type'</span> <span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
<span class="s1">'help'</span> <span class="p">:</span> <span class="s2">"port that the Arduino is connected to"</span><span class="p">,</span>
<span class="p">},</span>
<span class="p">}</span>
<span class="c1"># load the argument parser with the parameters specified</span>
<span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
<span class="n">p</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="o">*</span><span class="n">k</span><span class="p">,</span> <span class="o">**</span><span class="n">v</span><span class="p">)</span>
<span class="c1"># read the command line arguments</span>
<span class="n">args</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">parse_args</span><span class="p">()</span>
</pre></div>
</div>
<p>Each of the parameters that can be supplied as arguments to the Python Script
are defined in the <code class="docutils literal"><span class="pre">kwargs</span></code> dictionary in this file. Supplying a new value to
the <code class="docutils literal"><span class="pre">'default'</span></code> key of any of these parameters will set the value that the
program loads with if no value for that parameter has been supplied at the
command line.</p>
<p>For example, here the Arduino is always located on the port <code class="docutils literal"><span class="pre">"COM5"</span></code>,
therefore the args.py file is modified as follows:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">argparse</span>
<span class="c1"># create the argument parsing object</span>
<span class="n">p</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">(</span><span class="n">description</span><span class="o">=</span><span class="s2">"This program"</span>
<span class="s2">"controls the Arduino"</span>
<span class="s2">"and reads from it too"</span>
<span class="p">)</span>
<span class="c1"># construct a dictionary of program parameters</span>
<span class="n">kwargs</span> <span class="o">=</span> <span class="p">{</span>
<span class="p">(</span><span class="s2">"-i"</span><span class="p">,</span> <span class="s2">"--ID"</span><span class="p">,</span> <span class="p">)</span> <span class="p">:</span> <span class="p">{</span>
<span class="s1">'default'</span> <span class="p">:</span> <span class="s2">"_"</span><span class="p">,</span>
<span class="s1">'help'</span> <span class="p">:</span> <span class="s2">"identifier for this animal/run"</span><span class="p">,</span>
<span class="p">},</span>
<span class="o">.</span>
<span class="o">.</span>
<span class="o">.</span>
<span class="hll"> <span class="p">(</span><span class="s2">"--port"</span><span class="p">,</span> <span class="p">)</span> <span class="p">:</span> <span class="p">{</span>
</span><span class="hll"> <span class="s1">'default'</span> <span class="p">:</span> <span class="s2">"COM5"</span><span class="p">,</span>
</span><span class="hll"> <span class="s1">'type'</span> <span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
</span><span class="hll"> <span class="s1">'help'</span> <span class="p">:</span> <span class="s2">"port that the Arduino is connected to"</span><span class="p">,</span>
</span><span class="hll"> <span class="p">},</span>
</span><span class="hll"><span class="p">}</span>
</span>
<span class="c1"># load the argument parser with the parameters specified</span>
<span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
<span class="n">p</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="o">*</span><span class="n">k</span><span class="p">,</span> <span class="o">**</span><span class="n">v</span><span class="p">)</span>
<span class="c1"># read the command line arguments</span>
<span class="n">args</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">parse_args</span><span class="p">()</span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="articleComments">
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="Output.html" class="btn btn-neutral float-right" title="Output Format" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="hardware.html" class="btn btn-neutral" title="Hardware" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
© Copyright 2017, Andrew Micallef.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'./',
VERSION:'0',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.StickyNav.enable();
});
</script>
</body>
</html>