-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
628 lines (622 loc) · 55.4 KB
/
index.html
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
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="generator" content="pandoc">
<meta name="author" content="Anthony Deschamps">
<meta name="dcterms.date" content="2018-09-26">
<title>Programming Robots with Elm</title>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<link rel="stylesheet" href="./reveal.js/css/reveal.css">
<style type="text/css">
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
</style>
<style type="text/css">
a.sourceLine { display: inline-block; line-height: 1.25; }
a.sourceLine { pointer-events: none; color: inherit; text-decoration: inherit; }
a.sourceLine:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode { white-space: pre; position: relative; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
code.sourceCode { white-space: pre-wrap; }
a.sourceLine { text-indent: -1em; padding-left: 1em; }
}
pre.numberSource a.sourceLine
{ position: relative; left: -4em; }
pre.numberSource a.sourceLine::before
{ content: attr(data-line-number);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; pointer-events: all; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
}
pre.numberSource { margin-left: 3em; padding-left: 4px; }
div.sourceCode
{ color: #cccccc; background-color: #303030; }
@media screen {
a.sourceLine::before { text-decoration: underline; }
}
code span.al { color: #ffcfaf; } /* Alert */
code span.an { color: #7f9f7f; font-weight: bold; } /* Annotation */
code span.at { } /* Attribute */
code span.bn { color: #dca3a3; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #f0dfaf; } /* ControlFlow */
code span.ch { color: #dca3a3; } /* Char */
code span.cn { color: #dca3a3; font-weight: bold; } /* Constant */
code span.co { color: #7f9f7f; } /* Comment */
code span.cv { color: #7f9f7f; font-weight: bold; } /* CommentVar */
code span.do { color: #7f9f7f; } /* Documentation */
code span.dt { color: #dfdfbf; } /* DataType */
code span.dv { color: #dcdccc; } /* DecVal */
code span.er { color: #c3bf9f; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #c0bed1; } /* Float */
code span.fu { color: #efef8f; } /* Function */
code span.im { } /* Import */
code span.in { color: #7f9f7f; font-weight: bold; } /* Information */
code span.kw { color: #f0dfaf; } /* Keyword */
code span.op { color: #f0efd0; } /* Operator */
code span.ot { color: #efef8f; } /* Other */
code span.pp { color: #ffcfaf; font-weight: bold; } /* Preprocessor */
code span.sc { color: #dca3a3; } /* SpecialChar */
code span.ss { color: #cc9393; } /* SpecialString */
code span.st { color: #cc9393; } /* String */
code span.va { } /* Variable */
code span.vs { color: #cc9393; } /* VerbatimString */
code span.wa { color: #7f9f7f; font-weight: bold; } /* Warning */
</style>
<link rel="stylesheet" href="./reveal.js/css/theme/black.css" id="theme">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? './reveal.js/css/print/pdf.css' : './reveal.js/css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
<!--[if lt IE 9]>
<script src="./reveal.js/lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<div class="slides">
<section id="title-slide">
<h1 class="title">Programming Robots with Elm</h1>
<p class="author">Anthony Deschamps</p>
<p class="date">September 26, 2018</p>
</section>
<section id="a-delightful-language" class="slide level2">
<h2>A delightful language</h2>
<p><img data-src="./img/elm-homepage.png" /></p>
</section>
<section id="section" class="slide level2" data-background-image="./img/robofest.jpg">
<h2></h2>
</section>
<section id="section-1" class="slide level2">
<h2></h2>
<p><img data-src="./img/robofest-bots.jpg" /></p>
</section>
<section id="section-2" class="slide level2">
<h2></h2>
<p><img data-src="./img/ev3.jpg" /></p>
</section>
<section id="section-3" class="slide level2">
<h2></h2>
<p><img data-src="./img/ev3-programming.jpg" /></p>
</section>
<section id="ev3dev" class="slide level2">
<h2>ev3dev</h2>
<p>(all the hard work I didn’t have to do)</p>
<p>A Debian distribution for LEGO Mindstorms with API bindings for C, C++, Python, Go, JavaScript</p>
<p><a href="https://www.ev3dev.org/" class="uri">https://www.ev3dev.org/</a></p>
<p><a href="https://github.com/ev3dev/ev3dev" class="uri">https://github.com/ev3dev/ev3dev</a></p>
</section>
<section id="questions" class="slide level2">
<h2>Questions</h2>
<ul>
<li class="fragment"><em>Can</em> Elm be used to program a robot?</li>
<li class="fragment">Is it an <em>effective</em> language for robots?</li>
<li class="fragment">Is it a <em>delightful</em> language for robots?</li>
</ul>
</section>
<section id="robotics-is-about-three-things" class="slide level2">
<h2>Robotics is about three things</h2>
<p><img data-src="./img/robotics-stick-figure.jpg" /></p>
</section>
<section id="mapping-to-the-elm-architecture" class="slide level2">
<h2>Mapping to the Elm architecture</h2>
<div class="sourceCode" id="cb1"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb1-1" data-line-number="1">Browser.sandbox <span class="fu">:</span></a>
<a class="sourceLine" id="cb1-2" data-line-number="2"> { init <span class="fu">:</span> model</a>
<a class="sourceLine" id="cb1-3" data-line-number="3"> , update <span class="fu">:</span> msg <span class="ot">-></span> model <span class="ot">-></span> model</a>
<a class="sourceLine" id="cb1-4" data-line-number="4"> , view <span class="fu">:</span> model <span class="ot">-></span> <span class="dt">Html</span> msg</a>
<a class="sourceLine" id="cb1-5" data-line-number="5"> }</a>
<a class="sourceLine" id="cb1-6" data-line-number="6"> <span class="ot">-></span> <span class="dt">Program</span> () model msg</a></code></pre></div>
</section>
<section id="an-elm-program-for-robots" class="slide level2">
<h2>An Elm program for robots</h2>
<div class="sourceCode" id="cb2"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb2-1" data-line-number="1">Robot.program <span class="fu">:</span></a>
<a class="sourceLine" id="cb2-2" data-line-number="2"> { init <span class="fu">:</span> state</a>
<a class="sourceLine" id="cb2-3" data-line-number="3"> , update <span class="fu">:</span> <span class="dt">Input</span> <span class="ot">-></span> state <span class="ot">-></span> state</a>
<a class="sourceLine" id="cb2-4" data-line-number="4"> , output <span class="fu">:</span> state <span class="ot">-></span> <span class="dt">Output</span></a>
<a class="sourceLine" id="cb2-5" data-line-number="5"> }</a>
<a class="sourceLine" id="cb2-6" data-line-number="6"> <span class="ot">-></span> <span class="dt">Robot</span> state</a>
<a class="sourceLine" id="cb2-7" data-line-number="7"></a>
<a class="sourceLine" id="cb2-8" data-line-number="8"><span class="kw">type</span> alias <span class="dt">Input</span> <span class="fu">=</span></a>
<a class="sourceLine" id="cb2-9" data-line-number="9"> { lightSensor <span class="fu">:</span> <span class="dt">Float</span>, <span class="co">{- ... -}</span> }</a>
<a class="sourceLine" id="cb2-10" data-line-number="10"></a>
<a class="sourceLine" id="cb2-11" data-line-number="11"><span class="kw">type</span> alias <span class="dt">Output</span> <span class="fu">=</span></a>
<a class="sourceLine" id="cb2-12" data-line-number="12"> { leftMotor <span class="fu">:</span> <span class="dt">Float</span>, rightMotor <span class="fu">:</span> <span class="dt">Float</span>, <span class="co">{- ... -}</span> }</a></code></pre></div>
</section>
<section id="a-simple-robot" class="slide level2">
<h2>A simple robot</h2>
<p>Follow a line</p>
</section>
<section id="zig-zag" class="slide level2">
<h2>Zig zag</h2>
<p><img data-src="./img/line-following.jpg" /></p>
</section>
<section id="follow-a-line" class="slide level2">
<h2>Follow a line</h2>
<div class="sourceCode" id="cb3"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb3-1" data-line-number="1">update <span class="fu">:</span> <span class="dt">Input</span> <span class="ot">-></span> <span class="dt">State</span> <span class="ot">-></span> <span class="dt">State</span></a>
<a class="sourceLine" id="cb3-2" data-line-number="2">update input _ <span class="fu">=</span></a>
<a class="sourceLine" id="cb3-3" data-line-number="3"> { lightSensor <span class="fu">=</span> input<span class="fu">.</span>lightSensor</a>
<a class="sourceLine" id="cb3-4" data-line-number="4"> }</a>
<a class="sourceLine" id="cb3-5" data-line-number="5"></a>
<a class="sourceLine" id="cb3-6" data-line-number="6">output <span class="fu">:</span> <span class="dt">State</span> <span class="ot">-></span> <span class="dt">Output</span></a>
<a class="sourceLine" id="cb3-7" data-line-number="7">output { lightSensor } <span class="fu">=</span></a>
<a class="sourceLine" id="cb3-8" data-line-number="8"> { leftMotor <span class="fu">=</span> lightSensor</a>
<a class="sourceLine" id="cb3-9" data-line-number="9"> , rightMotor <span class="fu">=</span> <span class="fl">1.0</span> <span class="fu">-</span> lightSensor</a>
<a class="sourceLine" id="cb3-10" data-line-number="10"> }</a></code></pre></div>
</section>
<section><section id="does-it-work" class="title-slide slide level1"><h1>Does it work?</h1></section></section>
<section><section id="how-does-this-work" class="title-slide slide level1"><h1>How does this work?</h1></section><section id="ports" class="slide level2">
<h2>Ports!</h2>
<div class="sourceCode" id="cb4"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb4-1" data-line-number="1">port <span class="kw">module</span> <span class="dt">Robot</span></a>
<a class="sourceLine" id="cb4-2" data-line-number="2"></a>
<a class="sourceLine" id="cb4-3" data-line-number="3">port inputs <span class="fu">:</span> (<span class="dt">Input</span> <span class="ot">-></span> msg) <span class="ot">-></span> <span class="dt">Sub</span> msg</a>
<a class="sourceLine" id="cb4-4" data-line-number="4"></a>
<a class="sourceLine" id="cb4-5" data-line-number="5">port outputs <span class="fu">:</span> <span class="dt">Output</span> <span class="ot">-></span> <span class="dt">Cmd</span> msg</a></code></pre></div>
</section><section id="platform.worker" class="slide level2">
<h2>Platform.worker</h2>
<div class="sourceCode" id="cb5"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb5-1" data-line-number="1"><span class="kw">type</span> alias <span class="dt">Config</span> state <span class="fu">=</span></a>
<a class="sourceLine" id="cb5-2" data-line-number="2"> { init <span class="fu">:</span> state</a>
<a class="sourceLine" id="cb5-3" data-line-number="3"> , update <span class="fu">:</span> <span class="dt">Input</span> <span class="ot">-></span> state <span class="ot">-></span> state</a>
<a class="sourceLine" id="cb5-4" data-line-number="4"> , output <span class="fu">:</span> state <span class="ot">-></span> <span class="dt">Output</span></a>
<a class="sourceLine" id="cb5-5" data-line-number="5"> }</a>
<a class="sourceLine" id="cb5-6" data-line-number="6"></a>
<a class="sourceLine" id="cb5-7" data-line-number="7">program <span class="fu">:</span> <span class="dt">Config</span> state <span class="ot">-></span> <span class="dt">Robot</span> state</a>
<a class="sourceLine" id="cb5-8" data-line-number="8">program config <span class="fu">=</span></a>
<a class="sourceLine" id="cb5-9" data-line-number="9"> Platform.worker</a>
<a class="sourceLine" id="cb5-10" data-line-number="10"> { init <span class="fu">=</span> \_ <span class="ot">-></span> ( { state <span class="fu">=</span> config<span class="fu">.</span>init }, Cmd.none )</a>
<a class="sourceLine" id="cb5-11" data-line-number="11"> , update <span class="fu">=</span> update config</a>
<a class="sourceLine" id="cb5-12" data-line-number="12"> , subscriptions <span class="fu">=</span> \_ <span class="ot">-></span> inputs <span class="dt">NewInput</span></a>
<a class="sourceLine" id="cb5-13" data-line-number="13"> }</a></code></pre></div>
</section><section id="wiring-in-elm" class="slide level2">
<h2>Wiring in Elm</h2>
<div class="sourceCode" id="cb6"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb6-1" data-line-number="1">update <span class="fu">:</span> <span class="dt">Config</span> <span class="ot">-></span> <span class="dt">Msg</span> <span class="ot">-></span> <span class="dt">Model</span> <span class="ot">-></span> ( <span class="dt">Model</span>, <span class="dt">Cmd</span> <span class="dt">Msg</span> )</a>
<a class="sourceLine" id="cb6-2" data-line-number="2">update config msg model <span class="fu">=</span></a>
<a class="sourceLine" id="cb6-3" data-line-number="3"> <span class="kw">case</span> msg <span class="kw">of</span></a>
<a class="sourceLine" id="cb6-4" data-line-number="4"> <span class="dt">NewInput</span> input <span class="ot">-></span></a>
<a class="sourceLine" id="cb6-5" data-line-number="5"> <span class="kw">let</span></a>
<a class="sourceLine" id="cb6-6" data-line-number="6"> newState <span class="fu">=</span></a>
<a class="sourceLine" id="cb6-7" data-line-number="7"> config<span class="fu">.</span>update input model<span class="fu">.</span>state</a>
<a class="sourceLine" id="cb6-8" data-line-number="8"></a>
<a class="sourceLine" id="cb6-9" data-line-number="9"> output <span class="fu">=</span></a>
<a class="sourceLine" id="cb6-10" data-line-number="10"> config<span class="fu">.</span>output newState</a>
<a class="sourceLine" id="cb6-11" data-line-number="11"></a>
<a class="sourceLine" id="cb6-12" data-line-number="12"> <span class="kw">in</span></a>
<a class="sourceLine" id="cb6-13" data-line-number="13"> ( { model <span class="fu">|</span> state <span class="fu">=</span> newState }, outputs output )</a></code></pre></div>
</section><section id="wiring-in-javascript" class="slide level2">
<h2>Wiring in JavaScript</h2>
<div class="sourceCode" id="cb7"><pre class="sourceCode js"><code class="sourceCode javascript"><a class="sourceLine" id="cb7-1" data-line-number="1"><span class="kw">function</span> <span class="at">updateInput</span>() <span class="op">{</span></a>
<a class="sourceLine" id="cb7-2" data-line-number="2"> <span class="va">app</span>.<span class="va">ports</span>.<span class="va">inputs</span>.<span class="at">send</span>(<span class="op">{</span></a>
<a class="sourceLine" id="cb7-3" data-line-number="3"> <span class="dt">lightSensor </span><span class="op">:</span> <span class="va">lightSensor</span>.<span class="at">reflectedLightIntensity</span><span class="op">,</span></a>
<a class="sourceLine" id="cb7-4" data-line-number="4"> <span class="co">// ...</span></a>
<a class="sourceLine" id="cb7-5" data-line-number="5"> <span class="op">}</span>)<span class="op">;</span></a>
<a class="sourceLine" id="cb7-6" data-line-number="6"><span class="op">}</span></a>
<a class="sourceLine" id="cb7-7" data-line-number="7"><span class="kw">function</span> <span class="at">handleOutputs</span>(outputs) <span class="op">{</span></a>
<a class="sourceLine" id="cb7-8" data-line-number="8"> <span class="va">leftMotor</span>.<span class="at">start</span>(<span class="va">Math</span>.<span class="at">round</span>(SPEED <span class="op">*</span> <span class="va">outputs</span>.<span class="at">leftMotor</span>))<span class="op">;</span></a>
<a class="sourceLine" id="cb7-9" data-line-number="9"> <span class="co">// ...</span></a>
<a class="sourceLine" id="cb7-10" data-line-number="10"><span class="op">}</span></a>
<a class="sourceLine" id="cb7-11" data-line-number="11"><span class="kw">var</span> app <span class="op">=</span> <span class="va">Elm</span>.<span class="va">Main</span>.<span class="at">init</span>()<span class="op">;</span></a>
<a class="sourceLine" id="cb7-12" data-line-number="12"><span class="va">app</span>.<span class="va">ports</span>.<span class="va">outputs</span>.<span class="at">subscribe</span>(handleOutputs)<span class="op">;</span></a>
<a class="sourceLine" id="cb7-13" data-line-number="13"><span class="at">setInterval</span>(updateInput<span class="op">,</span> <span class="dv">25</span>)<span class="op">;</span></a></code></pre></div>
</section><section id="its-that-simple" class="slide level2">
<h2>It’s that simple!</h2>
</section></section>
<section><section id="lets-make-it-more-challenging" class="title-slide slide level1"><h1>Let’s make it more challenging!</h1></section><section id="the-challenge" class="slide level2">
<h2>The challenge</h2>
<ul>
<li class="fragment">Follow a line around a track</li>
<li class="fragment">Grab things that you bump into</li>
<li class="fragment">Move them to the <em>outside</em> of the track</li>
</ul>
</section><section id="section-4" class="slide level2">
<h2></h2>
<p><img data-src="./img/dataflow.jpg" /></p>
</section><section id="the-model" class="slide level2">
<h2>The model</h2>
<div class="sourceCode" id="cb8"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb8-1" data-line-number="1"><span class="kw">type</span> alias <span class="dt">Model</span> <span class="fu">=</span></a>
<a class="sourceLine" id="cb8-2" data-line-number="2"> { perception <span class="fu">:</span> <span class="dt">Perception</span></a>
<a class="sourceLine" id="cb8-3" data-line-number="3"> , behaviour <span class="fu">:</span> <span class="dt">Behaviour</span></a>
<a class="sourceLine" id="cb8-4" data-line-number="4"> , control <span class="fu">:</span> <span class="dt">Control</span></a>
<a class="sourceLine" id="cb8-5" data-line-number="5"> }</a>
<a class="sourceLine" id="cb8-6" data-line-number="6"></a>
<a class="sourceLine" id="cb8-7" data-line-number="7">init <span class="fu">:</span> <span class="dt">Model</span></a>
<a class="sourceLine" id="cb8-8" data-line-number="8">init <span class="fu">=</span></a>
<a class="sourceLine" id="cb8-9" data-line-number="9"> { perception <span class="fu">=</span> Perception.init</a>
<a class="sourceLine" id="cb8-10" data-line-number="10"> , behaviour <span class="fu">=</span> Behaviour.init</a>
<a class="sourceLine" id="cb8-11" data-line-number="11"> , control <span class="fu">=</span> Control.init</a>
<a class="sourceLine" id="cb8-12" data-line-number="12"> }</a></code></pre></div>
</section><section id="the-update-function" class="slide level2">
<h2>The update function</h2>
<div class="sourceCode" id="cb9"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb9-1" data-line-number="1">update input { perception, behaviour, control } <span class="fu">=</span></a>
<a class="sourceLine" id="cb9-2" data-line-number="2"> <span class="kw">let</span></a>
<a class="sourceLine" id="cb9-3" data-line-number="3"> <span class="co">-- Perception</span></a>
<a class="sourceLine" id="cb9-4" data-line-number="4"> newPerception <span class="fu">=</span></a>
<a class="sourceLine" id="cb9-5" data-line-number="5"> Perception.update input perception</a>
<a class="sourceLine" id="cb9-6" data-line-number="6"></a>
<a class="sourceLine" id="cb9-7" data-line-number="7"> <span class="co">-- Control</span></a>
<a class="sourceLine" id="cb9-8" data-line-number="8"> newControl <span class="fu">=</span></a>
<a class="sourceLine" id="cb9-9" data-line-number="9"> Control.update newPerception control</a>
<a class="sourceLine" id="cb9-10" data-line-number="10"></a>
<a class="sourceLine" id="cb9-11" data-line-number="11"> <span class="co">-- Behaviour</span></a>
<a class="sourceLine" id="cb9-12" data-line-number="12"> ( newBehaviour, maybeControl ) <span class="fu">=</span></a>
<a class="sourceLine" id="cb9-13" data-line-number="13"> Behaviour.update newPerception newControl behaviour</a>
<a class="sourceLine" id="cb9-14" data-line-number="14"> <span class="kw">in</span></a>
<a class="sourceLine" id="cb9-15" data-line-number="15"> { perception <span class="fu">=</span> newPerception</a>
<a class="sourceLine" id="cb9-16" data-line-number="16"> , behaviour <span class="fu">=</span> newBehaviour</a>
<a class="sourceLine" id="cb9-17" data-line-number="17"> , control <span class="fu">=</span> maybeControl <span class="fu">|></span> <span class="dt">Maybe</span><span class="fu">.</span>withDefault newControl</a>
<a class="sourceLine" id="cb9-18" data-line-number="18"> }</a></code></pre></div>
</section><section id="perception-turns-raw-data-into-meaningful-information" class="slide level2">
<h2>Perception turns raw data into meaningful information</h2>
</section><section id="we-need-to-detect" class="slide level2">
<h2>We need to detect…</h2>
<ul>
<li class="fragment">Have we encountered an obstacle?</li>
<li class="fragment">What direction are we going?</li>
</ul>
</section><section id="lots-of-things-to-measure" class="slide level2">
<h2>Lots of things to measure</h2>
<div class="sourceCode" id="cb10"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb10-1" data-line-number="1"><span class="kw">module</span> <span class="dt">Perception</span></a>
<a class="sourceLine" id="cb10-2" data-line-number="2"></a>
<a class="sourceLine" id="cb10-3" data-line-number="3"><span class="kw">type</span> alias <span class="dt">Perception</span> <span class="fu">=</span></a>
<a class="sourceLine" id="cb10-4" data-line-number="4"> { time <span class="fu">:</span> <span class="dt">Int</span></a>
<a class="sourceLine" id="cb10-5" data-line-number="5"> , claw <span class="fu">:</span> <span class="dt">Claw.State</span></a>
<a class="sourceLine" id="cb10-6" data-line-number="6"> , bumper <span class="fu">:</span> <span class="dt">Bumper</span></a>
<a class="sourceLine" id="cb10-7" data-line-number="7"> , wheels <span class="fu">:</span> <span class="dt">WheelOdometers</span></a>
<a class="sourceLine" id="cb10-8" data-line-number="8"> , curvature <span class="fu">:</span> <span class="dt">Curvature.State</span></a>
<a class="sourceLine" id="cb10-9" data-line-number="9"> , travelDirection <span class="fu">:</span> <span class="dt">Maybe</span> <span class="dt">TravelDirection</span></a>
<a class="sourceLine" id="cb10-10" data-line-number="10"> , lightSensor <span class="fu">:</span> <span class="dt">Float</span></a>
<a class="sourceLine" id="cb10-11" data-line-number="11"> }</a>
<a class="sourceLine" id="cb10-12" data-line-number="12"></a>
<a class="sourceLine" id="cb10-13" data-line-number="13">update <span class="fu">:</span> <span class="dt">Input</span> <span class="ot">-></span> <span class="dt">Perception</span> <span class="ot">-></span> <span class="dt">Perception</span></a></code></pre></div>
</section><section id="detecting-obstacles" class="slide level2">
<h2>Detecting obstacles</h2>
<p>Just a boolean, but by a different name</p>
<div class="sourceCode" id="cb11"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb11-1" data-line-number="1">update <span class="fu">:</span> <span class="dt">Input</span> <span class="ot">-></span> <span class="dt">Perception</span> <span class="ot">-></span> <span class="dt">Perception</span></a>
<a class="sourceLine" id="cb11-2" data-line-number="2">update input perception <span class="fu">=</span></a>
<a class="sourceLine" id="cb11-3" data-line-number="3"> <span class="kw">let</span></a>
<a class="sourceLine" id="cb11-4" data-line-number="4"> bumper <span class="fu">=</span></a>
<a class="sourceLine" id="cb11-5" data-line-number="5"> <span class="kw">if</span> input<span class="fu">.</span>touchSensor <span class="kw">then</span></a>
<a class="sourceLine" id="cb11-6" data-line-number="6"> <span class="dt">BumperPressed</span></a>
<a class="sourceLine" id="cb11-7" data-line-number="7"> <span class="kw">else</span></a>
<a class="sourceLine" id="cb11-8" data-line-number="8"> <span class="dt">BumperUnpressed</span></a>
<a class="sourceLine" id="cb11-9" data-line-number="9"> <span class="kw">in</span></a>
<a class="sourceLine" id="cb11-10" data-line-number="10"> { bumper <span class="fu">=</span> bumper</a>
<a class="sourceLine" id="cb11-11" data-line-number="11"> <span class="co">-- ...</span></a>
<a class="sourceLine" id="cb11-12" data-line-number="12"> }</a></code></pre></div>
</section><section id="measure-curvature" class="slide level2">
<h2>Measure curvature</h2>
<div class="sourceCode" id="cb12"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb12-1" data-line-number="1"><span class="kw">module</span> <span class="dt">Curvature</span></a>
<a class="sourceLine" id="cb12-2" data-line-number="2"></a>
<a class="sourceLine" id="cb12-3" data-line-number="3"><span class="kw">type</span> <span class="dt">Curve</span> <span class="fu">=</span> <span class="dt">Unknown</span> <span class="fu">|</span> <span class="dt">Straight</span> <span class="fu">|</span> <span class="dt">Left</span> <span class="fu">|</span> <span class="dt">Right</span></a>
<a class="sourceLine" id="cb12-4" data-line-number="4"></a>
<a class="sourceLine" id="cb12-5" data-line-number="5"><span class="kw">type</span> <span class="dt">State</span></a>
<a class="sourceLine" id="cb12-6" data-line-number="6"> <span class="fu">=</span> <span class="dt">State</span></a>
<a class="sourceLine" id="cb12-7" data-line-number="7"> { previous <span class="fu">:</span> <span class="dt">Maybe</span> { left <span class="fu">:</span> <span class="dt">Int</span>, right <span class="fu">:</span> <span class="dt">Int</span> }</a>
<a class="sourceLine" id="cb12-8" data-line-number="8"> , curve <span class="fu">:</span> <span class="dt">Curve</span></a>
<a class="sourceLine" id="cb12-9" data-line-number="9"> , raw <span class="fu">:</span> <span class="dt">Float</span></a>
<a class="sourceLine" id="cb12-10" data-line-number="10"> , average <span class="fu">:</span> <span class="dt">Float</span></a>
<a class="sourceLine" id="cb12-11" data-line-number="11"> }</a></code></pre></div>
</section><section id="categorize-curve" class="slide level2">
<h2>Categorize curve</h2>
<p><img data-src="./img/curve-state-machine.jpg" /></p>
</section><section id="categorize-curve-1" class="slide level2">
<h2>Categorize curve</h2>
<div class="sourceCode" id="cb13"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb13-1" data-line-number="1">calculateCurve <span class="fu">:</span> <span class="dt">Float</span> <span class="ot">-></span> <span class="dt">Curve</span> <span class="ot">-></span> <span class="dt">Curve</span></a>
<a class="sourceLine" id="cb13-2" data-line-number="2">calculateCurve curvature current <span class="fu">=</span></a>
<a class="sourceLine" id="cb13-3" data-line-number="3"> <span class="kw">case</span> current <span class="kw">of</span></a>
<a class="sourceLine" id="cb13-4" data-line-number="4"> <span class="dt">Straight</span> <span class="ot">-></span></a>
<a class="sourceLine" id="cb13-5" data-line-number="5"> <span class="kw">if</span> curvature <span class="fu"><</span> <span class="fu">-</span><span class="fl">0.25</span> <span class="kw">then</span></a>
<a class="sourceLine" id="cb13-6" data-line-number="6"> <span class="dt">Left</span></a>
<a class="sourceLine" id="cb13-7" data-line-number="7"></a>
<a class="sourceLine" id="cb13-8" data-line-number="8"> <span class="kw">else</span> <span class="kw">if</span> curvature <span class="fu">></span> <span class="fl">0.25</span> <span class="kw">then</span></a>
<a class="sourceLine" id="cb13-9" data-line-number="9"> <span class="dt">Right</span></a>
<a class="sourceLine" id="cb13-10" data-line-number="10"></a>
<a class="sourceLine" id="cb13-11" data-line-number="11"> <span class="kw">else</span></a>
<a class="sourceLine" id="cb13-12" data-line-number="12"> current</a>
<a class="sourceLine" id="cb13-13" data-line-number="13"> <span class="co">-- ...</span></a></code></pre></div>
</section><section id="we-get-lost" class="slide level2">
<h2>We get lost!</h2>
<div class="sourceCode" id="cb14"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb14-1" data-line-number="1">newCurve <span class="fu">=</span></a>
<a class="sourceLine" id="cb14-2" data-line-number="2"> calculateCurve average state<span class="fu">.</span>curve</a>
<a class="sourceLine" id="cb14-3" data-line-number="3"> <span class="fu">|></span> resetIfExtreme average</a>
<a class="sourceLine" id="cb14-4" data-line-number="4"></a>
<a class="sourceLine" id="cb14-5" data-line-number="5"><span class="co">-- ...</span></a>
<a class="sourceLine" id="cb14-6" data-line-number="6"></a>
<a class="sourceLine" id="cb14-7" data-line-number="7">resetIfExtreme <span class="fu">:</span> <span class="dt">Float</span> <span class="ot">-></span> <span class="dt">Curve</span> <span class="ot">-></span> <span class="dt">Curve</span></a>
<a class="sourceLine" id="cb14-8" data-line-number="8">resetIfExtreme curvature current <span class="fu">=</span></a>
<a class="sourceLine" id="cb14-9" data-line-number="9"> <span class="kw">if</span> abs curvature <span class="fu">></span> <span class="fl">0.7</span> <span class="kw">then</span></a>
<a class="sourceLine" id="cb14-10" data-line-number="10"> <span class="dt">Unknown</span></a>
<a class="sourceLine" id="cb14-11" data-line-number="11"></a>
<a class="sourceLine" id="cb14-12" data-line-number="12"> <span class="kw">else</span></a>
<a class="sourceLine" id="cb14-13" data-line-number="13"> current</a></code></pre></div>
</section><section id="categorize-direction" class="slide level2">
<h2>Categorize direction</h2>
<div class="sourceCode" id="cb15"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb15-1" data-line-number="1"><span class="kw">type</span> <span class="dt">TravelDirection</span></a>
<a class="sourceLine" id="cb15-2" data-line-number="2"> <span class="fu">=</span> <span class="dt">Clockwise</span></a>
<a class="sourceLine" id="cb15-3" data-line-number="3"> <span class="fu">|</span> <span class="dt">CounterClockwise</span></a>
<a class="sourceLine" id="cb15-4" data-line-number="4"></a>
<a class="sourceLine" id="cb15-5" data-line-number="5"><span class="kw">type</span> alias <span class="dt">Perception</span> <span class="fu">=</span></a>
<a class="sourceLine" id="cb15-6" data-line-number="6"> { curvature <span class="fu">:</span> <span class="dt">Curvature.State</span></a>
<a class="sourceLine" id="cb15-7" data-line-number="7"> , travelDirection <span class="fu">:</span> <span class="dt">Maybe</span> <span class="dt">TravelDirection</span></a>
<a class="sourceLine" id="cb15-8" data-line-number="8"> <span class="co">-- ...</span></a>
<a class="sourceLine" id="cb15-9" data-line-number="9"> }</a></code></pre></div>
</section><section id="put-it-all-together" class="slide level2">
<h2>Put it all together</h2>
<div class="sourceCode" id="cb16"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb16-1" data-line-number="1"><span class="kw">let</span></a>
<a class="sourceLine" id="cb16-2" data-line-number="2"> curvature <span class="fu">=</span> Curvature.update <span class="co">{- ... -}</span></a>
<a class="sourceLine" id="cb16-3" data-line-number="3"></a>
<a class="sourceLine" id="cb16-4" data-line-number="4"> travelDirection <span class="fu">=</span></a>
<a class="sourceLine" id="cb16-5" data-line-number="5"> <span class="kw">case</span> Curvature.curve curvature <span class="kw">of</span></a>
<a class="sourceLine" id="cb16-6" data-line-number="6"> <span class="dt">Curvature.Unknown</span> <span class="ot">-></span> <span class="dt">Nothing</span></a>
<a class="sourceLine" id="cb16-7" data-line-number="7"> <span class="dt">Curvature.Left</span> <span class="ot">-></span> <span class="dt">Just</span> <span class="dt">CounterClockwise</span></a>
<a class="sourceLine" id="cb16-8" data-line-number="8"> <span class="dt">Curvature.Right</span> <span class="ot">-></span> <span class="dt">Just</span> <span class="dt">Clockwise</span></a>
<a class="sourceLine" id="cb16-9" data-line-number="9"> <span class="dt">Curvature.Straight</span> <span class="ot">-></span> perception<span class="fu">.</span>travelDirection</a>
<a class="sourceLine" id="cb16-10" data-line-number="10"><span class="kw">in</span></a>
<a class="sourceLine" id="cb16-11" data-line-number="11">{ travelDirection <span class="fu">=</span> travelDirection, <span class="co">-- ...</span></a>
<a class="sourceLine" id="cb16-12" data-line-number="12">}</a></code></pre></div>
</section><section id="perception-is" class="slide level2">
<h2>Perception is…</h2>
<ul>
<li class="fragment">Often very functional</li>
<li class="fragment">Small state machines</li>
<li class="fragment">Sometimes computationally heavy</li>
</ul>
</section><section id="control-makes-things-move" class="slide level2">
<h2>Control makes things move</h2>
</section><section id="like-a-slightly-stateful-view-function" class="slide level2">
<h2>Like a slightly stateful view function</h2>
<div class="sourceCode" id="cb17"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb17-1" data-line-number="1"><span class="kw">type</span> alias <span class="dt">Output</span> <span class="fu">=</span></a>
<a class="sourceLine" id="cb17-2" data-line-number="2"> { leftMotor <span class="fu">:</span> <span class="dt">Float</span></a>
<a class="sourceLine" id="cb17-3" data-line-number="3"> , rightMotor <span class="fu">:</span> <span class="dt">Float</span></a>
<a class="sourceLine" id="cb17-4" data-line-number="4"> , clawMotor <span class="fu">:</span> <span class="dt">Float</span></a>
<a class="sourceLine" id="cb17-5" data-line-number="5"> }</a>
<a class="sourceLine" id="cb17-6" data-line-number="6"></a>
<a class="sourceLine" id="cb17-7" data-line-number="7"><span class="co">-- module Control</span></a>
<a class="sourceLine" id="cb17-8" data-line-number="8"></a>
<a class="sourceLine" id="cb17-9" data-line-number="9">update <span class="fu">:</span> <span class="dt">Perception</span> <span class="ot">-></span> <span class="dt">Control</span> <span class="ot">-></span> <span class="dt">Control</span></a>
<a class="sourceLine" id="cb17-10" data-line-number="10"></a>
<a class="sourceLine" id="cb17-11" data-line-number="11">output <span class="fu">:</span> <span class="dt">Control</span> <span class="ot">-></span> <span class="dt">Perception</span> <span class="ot">-></span> <span class="dt">Output</span></a></code></pre></div>
</section><section id="control-constrains-the-things-the-robot-can-do" class="slide level2">
<h2>Control constrains the things the robot can do</h2>
<div class="sourceCode" id="cb18"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb18-1" data-line-number="1"><span class="kw">type</span> <span class="dt">Control</span></a>
<a class="sourceLine" id="cb18-2" data-line-number="2"> <span class="fu">=</span> <span class="dt">Idle</span></a>
<a class="sourceLine" id="cb18-3" data-line-number="3"> <span class="fu">|</span> <span class="dt">Grab</span> <span class="dt">Timer</span></a>
<a class="sourceLine" id="cb18-4" data-line-number="4"> <span class="fu">|</span> <span class="dt">Release</span> <span class="dt">Timer</span></a>
<a class="sourceLine" id="cb18-5" data-line-number="5"> <span class="fu">|</span> <span class="dt">FollowLine</span></a>
<a class="sourceLine" id="cb18-6" data-line-number="6"> <span class="fu">|</span> <span class="dt">MoveTo</span> { left <span class="fu">:</span> <span class="dt">Int</span>, right <span class="fu">:</span> <span class="dt">Int</span> }</a>
<a class="sourceLine" id="cb18-7" data-line-number="7"> <span class="fu">|</span> <span class="dt">MoveBy</span> { leftDelta <span class="fu">:</span> <span class="dt">Int</span>, rightDelta <span class="fu">:</span> <span class="dt">Int</span> }</a></code></pre></div>
</section><section id="some-control-is-trivial" class="slide level2">
<h2>Some control is trivial</h2>
<div class="sourceCode" id="cb19"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb19-1" data-line-number="1">idle <span class="fu">:</span> <span class="dt">Control</span></a>
<a class="sourceLine" id="cb19-2" data-line-number="2">idle <span class="fu">=</span> <span class="dt">Idle</span></a>
<a class="sourceLine" id="cb19-3" data-line-number="3"></a>
<a class="sourceLine" id="cb19-4" data-line-number="4">update <span class="fu">:</span> <span class="dt">Perception</span> <span class="ot">-></span> <span class="dt">Control</span> <span class="ot">-></span> <span class="dt">Control</span></a>
<a class="sourceLine" id="cb19-5" data-line-number="5">update perception control <span class="fu">=</span></a>
<a class="sourceLine" id="cb19-6" data-line-number="6"> <span class="kw">case</span> control <span class="kw">of</span></a>
<a class="sourceLine" id="cb19-7" data-line-number="7"> <span class="dt">Idle</span> <span class="ot">-></span></a>
<a class="sourceLine" id="cb19-8" data-line-number="8"> control</a>
<a class="sourceLine" id="cb19-9" data-line-number="9"></a>
<a class="sourceLine" id="cb19-10" data-line-number="10">output <span class="fu">:</span> <span class="dt">Control</span> <span class="ot">-></span> <span class="dt">Perception</span> <span class="ot">-></span> <span class="dt">Input</span> <span class="ot">-></span> <span class="dt">Output</span></a>
<a class="sourceLine" id="cb19-11" data-line-number="11">output control perception input <span class="fu">=</span></a>
<a class="sourceLine" id="cb19-12" data-line-number="12"> <span class="kw">case</span> control <span class="kw">of</span></a>
<a class="sourceLine" id="cb19-13" data-line-number="13"> <span class="dt">Idle</span> <span class="ot">-></span></a>
<a class="sourceLine" id="cb19-14" data-line-number="14"> { leftMotor <span class="fu">=</span> <span class="fl">0.0</span></a>
<a class="sourceLine" id="cb19-15" data-line-number="15"> , rightMotor <span class="fu">=</span> <span class="fl">0.0</span></a>
<a class="sourceLine" id="cb19-16" data-line-number="16"> , clawMotor <span class="fu">=</span> <span class="fl">0.0</span></a>
<a class="sourceLine" id="cb19-17" data-line-number="17"> }</a></code></pre></div>
</section><section id="some-control-is-stateless" class="slide level2">
<h2>Some control is stateless</h2>
<div class="sourceCode" id="cb20"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb20-1" data-line-number="1">output <span class="fu">:</span> <span class="dt">Control</span> <span class="ot">-></span> <span class="dt">Perception</span> <span class="ot">-></span> <span class="dt">Input</span> <span class="ot">-></span> <span class="dt">Output</span></a>
<a class="sourceLine" id="cb20-2" data-line-number="2">output control perception input <span class="fu">=</span></a>
<a class="sourceLine" id="cb20-3" data-line-number="3"> <span class="kw">case</span> control <span class="kw">of</span></a>
<a class="sourceLine" id="cb20-4" data-line-number="4"> <span class="dt">FollowLine</span> <span class="ot">-></span></a>
<a class="sourceLine" id="cb20-5" data-line-number="5"> { leftMotor <span class="fu">=</span> perception<span class="fu">.</span>lightSensor</a>
<a class="sourceLine" id="cb20-6" data-line-number="6"> , rightMotor <span class="fu">=</span> <span class="fl">1.0</span> <span class="fu">-</span> perception<span class="fu">.</span>lightSensor</a>
<a class="sourceLine" id="cb20-7" data-line-number="7"> , clawMotor <span class="fu">=</span> <span class="fl">0.0</span></a>
<a class="sourceLine" id="cb20-8" data-line-number="8"> , lights <span class="fu">=</span> <span class="dt">Nothing</span></a>
<a class="sourceLine" id="cb20-9" data-line-number="9"> }</a></code></pre></div>
</section><section id="some-control-is-a-bit-stateful" class="slide level2">
<h2>Some control is a bit stateful</h2>
<div class="sourceCode" id="cb21"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb21-1" data-line-number="1">update <span class="fu">:</span> <span class="dt">Perception</span> <span class="ot">-></span> <span class="dt">Control</span> <span class="ot">-></span> <span class="dt">Control</span></a>
<a class="sourceLine" id="cb21-2" data-line-number="2">update perception control <span class="fu">=</span></a>
<a class="sourceLine" id="cb21-3" data-line-number="3"> <span class="kw">case</span> control <span class="kw">of</span></a>
<a class="sourceLine" id="cb21-4" data-line-number="4"> <span class="dt">Grab</span> <span class="dt">Starting</span> <span class="ot">-></span></a>
<a class="sourceLine" id="cb21-5" data-line-number="5"> <span class="dt">Grab</span> (<span class="dt">Since</span> perception<span class="fu">.</span>time)</a>
<a class="sourceLine" id="cb21-6" data-line-number="6"></a>
<a class="sourceLine" id="cb21-7" data-line-number="7"> <span class="dt">Grab</span> (<span class="dt">Since</span> startTime) <span class="ot">-></span></a>
<a class="sourceLine" id="cb21-8" data-line-number="8"> <span class="kw">if</span> perception<span class="fu">.</span>time <span class="fu">-</span> startTime <span class="fu">></span> grabDuration <span class="kw">then</span></a>
<a class="sourceLine" id="cb21-9" data-line-number="9"> <span class="dt">Idle</span></a>
<a class="sourceLine" id="cb21-10" data-line-number="10"></a>
<a class="sourceLine" id="cb21-11" data-line-number="11"> <span class="kw">else</span></a>
<a class="sourceLine" id="cb21-12" data-line-number="12"> control</a></code></pre></div>
</section><section id="some-control-uses-state-machines" class="slide level2">
<h2>Some control uses state machines</h2>
<div class="sourceCode" id="cb22"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb22-1" data-line-number="1">update <span class="fu">:</span> <span class="dt">Perception</span> <span class="ot">-></span> <span class="dt">Control</span> <span class="ot">-></span> <span class="dt">Control</span></a>
<a class="sourceLine" id="cb22-2" data-line-number="2">update perception control <span class="fu">=</span></a>
<a class="sourceLine" id="cb22-3" data-line-number="3"> <span class="kw">case</span> control <span class="kw">of</span></a>
<a class="sourceLine" id="cb22-4" data-line-number="4"> <span class="dt">MoveBy</span> { leftDelta, rightDelta } <span class="ot">-></span></a>
<a class="sourceLine" id="cb22-5" data-line-number="5"> <span class="dt">MoveTo</span></a>
<a class="sourceLine" id="cb22-6" data-line-number="6"> { left <span class="fu">=</span> perception<span class="fu">.</span>wheels<span class="fu">.</span>left <span class="fu">+</span> leftDelta</a>
<a class="sourceLine" id="cb22-7" data-line-number="7"> , right <span class="fu">=</span> perception<span class="fu">.</span>wheels<span class="fu">.</span>right <span class="fu">+</span> rightDelta</a>
<a class="sourceLine" id="cb22-8" data-line-number="8"> }</a>
<a class="sourceLine" id="cb22-9" data-line-number="9"> <span class="dt">MoveTo</span> { left, right } <span class="ot">-></span></a>
<a class="sourceLine" id="cb22-10" data-line-number="10"> <span class="kw">if</span> within <span class="dv">5</span> left perception<span class="fu">.</span>wheels<span class="fu">.</span>left <span class="co">{- -}</span> <span class="kw">then</span></a>
<a class="sourceLine" id="cb22-11" data-line-number="11"> <span class="dt">Idle</span></a>
<a class="sourceLine" id="cb22-12" data-line-number="12"> <span class="kw">else</span></a>
<a class="sourceLine" id="cb22-13" data-line-number="13"> control</a></code></pre></div>
</section><section id="control-is" class="slide level2">
<h2>Control is…</h2>
<ul>
<li class="fragment">Often very functional</li>
<li class="fragment">Small state machines</li>
<li class="fragment">Layered</li>
</ul>
</section><section id="behaviour-is-the-core-of-your-elm-application" class="slide level2">
<h2>Behaviour is the core of your Elm application</h2>
</section><section id="section-5" class="slide level2">
<h2></h2>
<p><img data-src="./img/behaviour-state-machine.jpg" /></p>
</section><section id="behaviour-is-your-model" class="slide level2">
<h2>Behaviour is your model</h2>
<div class="sourceCode" id="cb23"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb23-1" data-line-number="1"><span class="kw">module</span> <span class="dt">Behaviour</span></a>
<a class="sourceLine" id="cb23-2" data-line-number="2"></a>
<a class="sourceLine" id="cb23-3" data-line-number="3"><span class="kw">type</span> <span class="dt">Behaviour</span></a>
<a class="sourceLine" id="cb23-4" data-line-number="4"> <span class="fu">=</span> <span class="dt">Initializing</span> { openedClaw <span class="fu">:</span> <span class="dt">Bool</span>, closedClaw <span class="fu">:</span> <span class="dt">Bool</span> }</a>
<a class="sourceLine" id="cb23-5" data-line-number="5"> <span class="fu">|</span> <span class="dt">FindingObject</span></a>
<a class="sourceLine" id="cb23-6" data-line-number="6"> <span class="fu">|</span> <span class="dt">CarryingObject</span></a>
<a class="sourceLine" id="cb23-7" data-line-number="7"> <span class="fu">|</span> <span class="dt">RemovingObject</span> (<span class="dt">List</span> <span class="dt">Control</span>)</a></code></pre></div>
</section><section id="behaviour-is-your-update-function" class="slide level2">
<h2>Behaviour is your update function</h2>
<div class="sourceCode" id="cb24"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb24-1" data-line-number="1"><span class="kw">module</span> <span class="dt">Behaviour</span></a>
<a class="sourceLine" id="cb24-2" data-line-number="2"></a>
<a class="sourceLine" id="cb24-3" data-line-number="3">update <span class="fu">:</span></a>
<a class="sourceLine" id="cb24-4" data-line-number="4"> <span class="dt">Perception</span></a>
<a class="sourceLine" id="cb24-5" data-line-number="5"> <span class="ot">-></span> <span class="dt">Control</span></a>
<a class="sourceLine" id="cb24-6" data-line-number="6"> <span class="ot">-></span> <span class="dt">Behaviour</span></a>
<a class="sourceLine" id="cb24-7" data-line-number="7"> <span class="ot">-></span> ( <span class="dt">Behaviour</span>, <span class="dt">Maybe</span> <span class="dt">Control</span> )</a>
<a class="sourceLine" id="cb24-8" data-line-number="8">update perception currentControl behaviour <span class="fu">=</span></a>
<a class="sourceLine" id="cb24-9" data-line-number="9"> <span class="co">-- ...</span></a></code></pre></div>
</section><section id="behaviour-should-be-readable" class="slide level2">
<h2>Behaviour should be <em>readable</em></h2>
<div class="sourceCode" id="cb25"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb25-1" data-line-number="1"><span class="kw">case</span> behaviour <span class="kw">of</span></a>
<a class="sourceLine" id="cb25-2" data-line-number="2"> <span class="dt">FindingObject</span> <span class="ot">-></span></a>
<a class="sourceLine" id="cb25-3" data-line-number="3"> <span class="kw">case</span> ( claw, bumper) <span class="kw">of</span></a>
<a class="sourceLine" id="cb25-4" data-line-number="4"> ( <span class="dt">Claw.Open</span>, <span class="dt">BumperPressed</span> ) <span class="ot">-></span></a>
<a class="sourceLine" id="cb25-5" data-line-number="5"> ( behaviour, <span class="dt">Just</span> Control.grab )</a>
<a class="sourceLine" id="cb25-6" data-line-number="6"></a>
<a class="sourceLine" id="cb25-7" data-line-number="7"> ( <span class="dt">Claw.Closed</span>, _ ) <span class="ot">-></span></a>
<a class="sourceLine" id="cb25-8" data-line-number="8"> ( <span class="dt">CarryingObject</span>, <span class="dt">Nothing</span> )</a>
<a class="sourceLine" id="cb25-9" data-line-number="9"></a>
<a class="sourceLine" id="cb25-10" data-line-number="10"> _ <span class="ot">-></span></a>
<a class="sourceLine" id="cb25-11" data-line-number="11"> ( behaviour, <span class="dt">Just</span> Control.followLine )</a></code></pre></div>
</section><section id="some-behaviours-are-parameterized" class="slide level2">
<h2>Some behaviours are parameterized</h2>
<div class="sourceCode" id="cb26"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb26-1" data-line-number="1">removeObject <span class="fu">:</span> <span class="dt">TravelDirection</span> <span class="ot">-></span> <span class="dt">Behaviour</span></a>
<a class="sourceLine" id="cb26-2" data-line-number="2"></a>
<a class="sourceLine" id="cb26-3" data-line-number="3"><span class="kw">type</span> <span class="dt">Behaviour</span></a>
<a class="sourceLine" id="cb26-4" data-line-number="4"> <span class="fu">=</span> <span class="dt">RemovingObject</span> (<span class="dt">List</span> <span class="dt">Control</span>) <span class="fu">|</span> <span class="co">-- ...</span></a>
<a class="sourceLine" id="cb26-5" data-line-number="5"></a>
<a class="sourceLine" id="cb26-6" data-line-number="6"><span class="kw">case</span> behaviour <span class="kw">of</span></a>
<a class="sourceLine" id="cb26-7" data-line-number="7"> <span class="dt">CarryingObject</span> <span class="ot">-></span></a>
<a class="sourceLine" id="cb26-8" data-line-number="8"> <span class="kw">case</span> perception<span class="fu">.</span>travelDirection <span class="kw">of</span></a>
<a class="sourceLine" id="cb26-9" data-line-number="9"> <span class="dt">Nothing</span> <span class="ot">-></span></a>
<a class="sourceLine" id="cb26-10" data-line-number="10"> ( behaviour, <span class="dt">Just</span> Control.followLine )</a>
<a class="sourceLine" id="cb26-11" data-line-number="11"></a>
<a class="sourceLine" id="cb26-12" data-line-number="12"> <span class="dt">Just</span> travelDirection <span class="ot">-></span></a>
<a class="sourceLine" id="cb26-13" data-line-number="13"> removeObject travelDirection</a></code></pre></div>
</section><section id="sequential-actions-are-slightly-awkward" class="slide level2">
<h2>Sequential actions are slightly awkward</h2>
<p>When we find an obstacle, we need to…</p>
<ul>
<li class="fragment">Grab it</li>
<li class="fragment">Turn</li>
<li class="fragment">Move forwards</li>
<li class="fragment">Let it go</li>
<li class="fragment">Move back</li>
<li class="fragment">Turn back</li>
</ul>
</section><section id="we-need-feedback-from-control" class="slide level2">
<h2>We need feedback from control</h2>
<div class="sourceCode" id="cb27"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb27-1" data-line-number="1">update perception currentControl behaviour <span class="fu">=</span></a>
<a class="sourceLine" id="cb27-2" data-line-number="2"> <span class="kw">case</span> behaviour <span class="kw">of</span></a>
<a class="sourceLine" id="cb27-3" data-line-number="3"> <span class="dt">RemovingObject</span> steps <span class="ot">-></span></a>
<a class="sourceLine" id="cb27-4" data-line-number="4"> <span class="kw">case</span> ( Control.isIdle currentControl, steps ) <span class="kw">of</span></a>
<a class="sourceLine" id="cb27-5" data-line-number="5"> ( <span class="dt">True</span>,<span class="ot"> next ::</span> remaining ) <span class="ot">-></span></a>
<a class="sourceLine" id="cb27-6" data-line-number="6"> ( <span class="dt">RemovingObject</span> remaining, <span class="dt">Just</span> next )</a>
<a class="sourceLine" id="cb27-7" data-line-number="7"></a>
<a class="sourceLine" id="cb27-8" data-line-number="8"> ( <span class="dt">True</span>, [] ) <span class="ot">-></span></a>
<a class="sourceLine" id="cb27-9" data-line-number="9"> findObject</a>
<a class="sourceLine" id="cb27-10" data-line-number="10"></a>
<a class="sourceLine" id="cb27-11" data-line-number="11"> ( <span class="dt">False</span>, _ ) <span class="ot">-></span></a>
<a class="sourceLine" id="cb27-12" data-line-number="12"> ( behaviour, <span class="dt">Nothing</span> )</a></code></pre></div>
</section><section id="behaviour-is" class="slide level2">
<h2>Behaviour is…</h2>
<ul>
<li class="fragment">Stateful</li>
<li class="fragment">Symbolic</li>
<li class="fragment">Explainable</li>
</ul>
</section></section>
<section><section id="does-it-work-1" class="title-slide slide level1"><h1>Does it work?</h1></section></section>
<section><section id="wrapping-up" class="title-slide slide level1"><h1>Wrapping Up</h1></section><section id="can-elm-be-used-to-program-a-robot" class="slide level2">
<h2>Can Elm be used to program a robot?</h2>
<p>Yes!</p>
</section><section id="is-it-effective" class="slide level2">
<h2>Is it effective?</h2>
<ul>
<li class="fragment">Is Elm an effective <em>platform</em> for robots?</li>
<li class="fragment">Is Elm an effective <em>language</em> for robots?</li>
</ul>
</section><section id="is-it-delightful" class="slide level2">
<h2>Is it delightful?</h2>
<p>I think so!</p>
<p>Decide for yourself!</p>
<p><a href="https://github.com/adeschamps/programming-robots-with-elm/" class="uri">https://github.com/adeschamps/programming-robots-with-elm/</a></p>
<p>Slack: anthony.deschamps</p>
<p>[email protected]</p>
</section><section id="thank-you" class="slide level2">
<h2>Thank you!</h2>
<p>Matt Griffith</p>
<p>Mike Onslow + Elm Detroit</p>
<p><a href="https://www.meetup.com/elm-detroit/" class="uri">https://www.meetup.com/elm-detroit/</a></p>
<p><img data-src="./img/elm-detroit.jpg" /></p>
</section></section>
</div>
</div>
<script src="./reveal.js/lib/js/head.min.js"></script>
<script src="./reveal.js/js/reveal.js"></script>
<script>
// Full list of configuration options available at:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
// Push each slide change to the browser history
history: true,
// Transition style
transition: 'fade', // none/fade/slide/convex/concave/zoom
// Optional reveal.js plugins
dependencies: [
{ src: './reveal.js/lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: './reveal.js/plugin/zoom-js/zoom.js', async: true },
{ src: './reveal.js/plugin/notes/notes.js', async: true }
]
});
</script>
</body>
</html>