Building Lego Robots with Elixir
This is a modal window.
The media could not be loaded, either because the server or network failed or because the format is not supported.
Formal Metadata
Title |
| |
Alternative Title |
| |
Title of Series | ||
Number of Parts | 163 | |
Author | ||
License | CC Attribution - NonCommercial - ShareAlike 3.0 Unported: You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this | |
Identifiers | 10.5446/50048 (DOI) | |
Publisher | ||
Release Date | ||
Language |
Content Metadata
Subject Area | ||
Genre | ||
Abstract |
|
00:00
Erlang distributionRobotService (economics)Video gameProcess (computing)Enterprise architectureArithmetic meanAxiom of choiceTime zonePatch (Unix)MereologyInformation securityJava appletRoboticsBitSoftware frameworkReal numberService-oriented architectureLevel (video gaming)Touch typingMultiplication signErlang distributionNear-ringDistanceGoodness of fitExterior algebraVirtual machineMeeting/Interview
02:45
Grand Unified TheoryErlang distributionEmailElectronic mailing listFormal languageComputer animation
03:46
Programming languageProgramming paradigmLine (geometry)Point (geometry)Film editingLink (knot theory)Grand Unified TheoryProgramming paradigmBitCuboidGame controllerComputer programmingMereologyIntegrated development environmentFormal languageFault-tolerant systemQuicksortOffice suiteRoboticsMoment (mathematics)NumberSharewareDigitizingDiscounts and allowancesData managementErlang distributionRow (database)Electronic visual displayFamilyJava appletProgramming languageDisk read-and-write headVisualization (computer graphics)View (database)Video gameClosed setMultiplication signCountingData miningGroup actionOpen sourceCodeProcess (computing)Object-oriented programmingProduct (business)Device driverComputer animation
10:32
CodePlastikkarteErlang distributionInstallation artInterface (computing)System programmingAsynchronous Transfer ModeComputer fileEvent horizonWritingMacro (computer science)Function (mathematics)Computer configurationParameter (computer programming)Installation artGraph coloringTerm (mathematics)Goodness of fitGroup actionFunction (mathematics)Reading (process)File systemCategory of beingComputer fileBit rateErlang distributionElement (mathematics)Asynchronous Transfer ModePoint (geometry)Multiplication signLibrary (computing)Figurate numberHydraulic motorRevision controlUtility softwareClosed setCodeLine (geometry)Tablet computerFunctional programmingBitElectric generatorMaxima and minimaMathematicsIntegerPlastikkarteString (computer science)Computer configurationMoment (mathematics)Set (mathematics)Tape driveMacro (computer science)Hacker (term)Mixture modelDirectory serviceMereologySpeech synthesisNetwork topologyShape (magazine)Computer programmingTesselationFormal languageCASE <Informatik>System programmingInstance (computer science)JSONXML
16:44
PasswordComputer programOpen sourceSystem programmingMiniDiscTerm (mathematics)Kernel (computing)SoftwareInteractive televisionDistribution (mathematics)InformationEvent horizonState of matterWaveRoboticsRoundness (object)Goodness of fitLine (geometry)Degree (graph theory)INTEGRALIP addressTouchscreenMassTrailFood energyProcess (computing)CodeVideo game consoleRun time (program lifecycle phase)Multiplication signSource codeHydraulic motorBefehlsprozessorError message2 (number)SoftwareComputer virusConnected spaceMathematicsNumberSlide ruleSystem programmingComputer animation
21:58
Game controllerProcess (computing)MathematicsErlang distributionProxy serverMessage passingStatisticsLine (geometry)Computer architectureFunction (mathematics)Finite-state machineLimit (category theory)Proxy serverProcess (computing)CodeJava appletGraph coloringHysteresekurveHierarchyComputer clusterFunctional programmingBasis <Mathematik>Game controllerFitness functionObject-oriented programmingOrder (biology)NumberType theoryHydraulic motorArithmetic meanGoodness of fitMessage passingMultiplication signReading (process)BitSet (mathematics)State of matterInstance (computer science)Line (geometry)Finite-state machineComputer programmingAbstractionLibrary (computing)Erlang distributionEvent horizonRight angleSoftwareSimilarity (geometry)Computer architectureSystem programmingTerm (mathematics)Slide ruleVirtual machineCode refactoringGodKey (cryptography)Matching (graph theory)ChainControl flowStatement (computer science)Different (Kate Ryan album)VotingSystem callMathematicsTable (information)PlotterMultimediaPoint (geometry)CausalityCircleXMLUML
29:59
Finite-state machineEvent horizonState of matterMacro (computer science)InformationComputer hardwareProcess (computing)Directed setControl flowSoftwareLaptopSoftwareMacro (computer science)Process (computing)CodeGame controllerComputer programmingComputer fileLibrary (computing)Modal logicState of matterNeuroinformatikFunctional programmingEvent horizonSoftware repositoryPlastikkarteWindowControl systemGoodness of fitPhysicalismSoftware development kitAbstractionMusical ensembleMessage passingHydraulic motorGraph coloringReading (process)Finite-state machineFormal languageDisk read-and-write headRight angleCASE <Informatik>Erlang distributionComputer-generated imageryTelecommunicationTraffic reportingElectric generatorMultiplication signFrequencyLimit (category theory)Maxima and minimaPoint (geometry)DampingMereologyLine (geometry)Control flowCode2 (number)Proper mapOntologyComputer animation
38:00
Network operating systemOpcodeFunction (mathematics)Normal (geometry)SoftwareComputer programVirtual machineControl flowFile formatVariable (mathematics)String (computer science)Logical constantPrice indexLocal ringCodierung <Programmierung>Computer configurationBinary fileParameter (computer programming)Absolute valueData typeRevision controlElectric currentLibrary (computing)Computer programmingIntegrated development environmentCodierung <Programmierung>Message passingSoftware developerFirmwareResource allocationLogical constantOrder (biology)Type theorySign (mathematics)Function (mathematics)BitVirtual machinePlastikkarteWindowFunctional programmingFile systemAsynchronous Transfer ModeLibrary (computing)Parameter (computer programming)BootingPoint (geometry)Java appletRevision controlMereologyComputer fileData managementEntire functionMultiplication signSocial classView (database)Right angleStructured programmingProduct (business)File formatBoss CorporationAngleMusical ensembleForm (programming)Radio-frequency identificationDrop (liquid)Time travel1 (number)Menu (computing)OntologyOpen setComputer programmingIntegrated development environmentElement (mathematics)Hand fanGame theoryGoodness of fitWebsiteDevice driverCodeProcess (computing)Communications protocolMixture modelCodeComputer configurationJSONXMLUML
46:01
Text editorFunction (mathematics)RecursionProgramming languageIntegrated development environmentCodeDegree (graph theory)Computer programmingSequenceProcess (computing)RobotMessage passingTelecommunicationGame controllerElement (mathematics)Default (computer science)CurveSmoothingMereologyBitComputer programmingText editorGradientSemiconductor memoryIntegrated development environmentCommunications protocolTouchscreenConcurrency (computer science)Default (computer science)Social classServer (computing)Library (computing)Goodness of fitRoboticsPoint (geometry)CodeCommodore VIC-20Process (computing)MathematicsRecursionType theoryComputer scienceCurveSequencePhysicalismMultiplication signDampingFeedbackElement (mathematics)Presentation of a groupEntire functionVisualization (computer graphics)TelecommunicationWindowTrajectoryLimit (category theory)Cuboid2 (number)InjektivitätNeuroinformatikMessage passingEndliche ModelltheorieShift operatorCodeCausalitySpecial unitary groupMoment (mathematics)Line (geometry)DataflowTablet computerDigital electronicsFunctional programmingComputer configurationMappingFitness functionMachine visionState of matterOperator (mathematics)Game controllerData miningFormal languageJSONXMLUML
54:02
Game theoryJava appletVirtual machineWhiteboardEnterprise architectureErlang distributionVideo gamePresentation of a groupOperating systemDampingIntegrated development environmentLogic programmingAreaLink (knot theory)Computer programmingType theoryMacro (computer science)Host Identity ProtocolComputer animation
56:25
Software developerJSON
Transcript: English(auto-generated)
00:00
So, welcome. So I'm, and you can take your own interpretation, I'm the guy standing between you and a security session thing or the beers. It's your choice. School. School. That's good. We will try not to have too much beer in near proximity of this robot. It's my son's.
00:22
So we'll try to, afterwards you're allowed to come up and of course touch the thing but don't spill beer on it. I will not be a popular dad when I go home. So, my name is Tom Hoffman. I'm the CTO of Erlang Solutions where we predominantly do Erlang but we are also dabbling with Elixir because Elixir is just another way of doing Erlang or actually getting access to the wonderful virtual machine of Erlang.
00:47
And normally a part of the CTO role in Erlang Solutions is evangelising. It's running out to conferences where it's not necessarily a friendly crowd,
01:01
meaning that it could be people that have chosen to use some other technology. How they would end up with that choice is beyond me but there you go. But then you go out and then you meet these people. So this is how, I've been taught this and it actually matches up, this is how enterprise people look like.
01:24
Nice and friendly and everything and this is why they're talking Java, some Java framework, C Sharp, Microsoft services, whatever. This is their comfort zone there and it's a good idea to know what their comfort zone is
01:43
and if you're invited to speak at a conference, be a little smarter than me. I went to QCon and I was a little busy so I didn't check up on what is QCon. I'd spoken there once before and that goes against my ability to understand anything
02:00
but I didn't realise that it's a humongous Java conference. There's Java people all over the place. And then what do I do when I go on stage there? I go in there and ask people, anybody using Java in real life? And a lot of people put their hands up and go, shit, this is going to backfire. Because then I bring out the badge and I go, you know what, you can take this one,
02:25
it's a custom made one and you can put it up here, it'll take the pain away. Then we're started. And I can promise you it works for .NET as well, so it can tell you. But the problem is when you then, one thing is you can throw a joke at them but then when you really start going at it and you say there is an alternative to whatever you're doing today,
02:44
they turn into this. Stark raving orcs and they want your guts on a big plate. And it's like, okay. And you get used to it after a while there and you learn to live with your guts being all over the conference floor and everything.
03:01
Then you go around, okay, you deal with these things, you learn it and then you talk to the Erlang crowd. So these are famous Erlang people. Look how nice they are. Would you imagine how nice they look? So right there, that's Joe Armstrong, one of the main creators. And that's Robert Verding, also one of the main creators behind the language.
03:22
And others there, they're just nice Erlang people. These people are nice. So you look at them. Then you go on the mailing list. The Erlang mailing list is normally a very, very, very friendly place. Then some idiot, me, suggests, maybe I could use Elixir to teach young kids how to program.
03:48
So this is how Erlang has turned. This was a year ago, so maybe things have changed. But that's how they turned at that point. They really, really wanted my guts on a plate. So what do I do this year at Erlang user conference last week?
04:02
I bring out the Elixir badge and ask, is anybody using Erlang? Put it on. It'll take the pain of Erlang away. So I did not make new friends on LinkedIn last week. But the point here, and it's a point that Jan made yesterday, is that syntax is actually irrelevant.
04:23
Because a lot of this, especially when it comes down to debates between Erlang people and Elixir people. So the Erlang people, they call themselves Erlangers. That's the amount of innovation they could get to. We'll add an ER to it there. The Elixir people, they're calling themselves Alchemists.
04:41
Because we're doing magic there. But really, the syntax, the thinking is all the same. The thinking is actually everything when it comes to these things. You don't want to be focused on syntax. It's what you can do. And one of the things that shapes your thinking is the language you're talking. So go see Jan's talk online if you didn't see it yesterday.
05:02
It's really amazing. And then, language is actually everything. And now, if there's any managers in here, you'll be totally confused. Because language, the syntax doesn't matter. Language, blah blah blah. But the thing is, any paradigm you use is your language. This is how you can talk.
05:21
This is how you express things. And, if you are one of those, fill in your own adjective here, one of those persons working with Java, you will be thinking as a Java person. You will be thinking in objects and everything, and that's your paradigm. And the thing is, you need to learn as many paradigms as possible
05:41
because it makes your brain better. So that's the important part here. So, a little bit about languages and language wars and everything. And then, I need to turn this on. It's not a speedy boot, so we'll just take it now. So, Lego. In 2008, we had a family trip to Billon in Legoland.
06:04
And you run around, everything is awesome. Well, they didn't have it back then, but still, everything is awesome when you run around in Legoland. And my son and I, we saw this, ah, big display. Demo of Lego Mindstorms. And you can imagine how the engineering dad goes, whoa.
06:21
And I had these special views in my eyes, and my wife just looked at me and said, no buying, no buying, yeah, yeah, yeah, no buying, no buying. So we went in, and they had this set up where you're supposed to solve some exercises with this Lego Mindstorms set, and you had a visual environment and program again. And we had this.
06:41
A father-son moment. It was amazing. You're just sitting there, it was just fun. Oh, yes, this is looking really good. And then two weeks ago, I presented this in London. I had my son with me over there. There was an Erlang user group. And then I asked out because, of course, this cannot backfire.
07:03
Oh, son, do you remember this? Nope. Thank you for tagging along. And maybe there's something, there's a reason to why he felt like that because this wonderful environment is something they only have in the demo room.
07:21
I didn't realize that, so I ran out into the boutique, got a set, bought it, and I went out to the wife who looked like, what the? And then I compensated by buying her bag. So, yeah, that's a good trick, by the way. Get a bag when you do that kind of stupid thing, buying these things. So we go home, and it turns out
07:41
the environment for Lego Mindstorms is slightly different when you come at home because they have a protected environment in Billon. And then I started looking like this. Because the LabVIEW thing, it's something made for process engineers to control nuclear plants and things like that,
08:00
which is not the thing you want to control this little... Look at this. Look how nice it is. That doesn't need nuclear plant environments and everything. And it was really, really annoying because then there is a nice environment, and then you have these building blocks. You can drag them in, put them in, and then you put wires between them. Everything should be straightforward.
08:20
Straightforward, until you realize two blocks looking almost the same behaves widely different. And then also all this turning sequential programming into a big visual thing, it's a bad idea. So, trying to avoid a divorce at this point, I sold off the Lego Mindstorms set with a profit.
08:44
And that was sort of the saving grace on that one. We will not go into the digital slot car thing I had that I also had to sell, but a different story. We can take that over a beer. So, then, 2013, my son goes.
09:01
He's five years older. I want Lego Mindstorms. And then dad goes, father-son moment. Again, I didn't check with him at that point. It was okay there. So we get the Lego Mindstorms. This time, not on discount. But again, it was his wish. I promise you, I did not plant this in his head.
09:20
It was his wish on record. His wish there. So anyway, and we open up the box and we start building and everything. And you build the robot. It takes a while to get all these things together. And then you need to program it. And you open up. Lo and behold, it's still that view. So this is the feeling. So we were fighting with this over Christmas.
09:40
Me, feeling like, why am I here again? And my son just, dad, how does this work? And I don't know how it works. It's just painful. So we left it. And then it was lying for over a year. And then I thought, wait a minute. We have this 3,000-corner, that's 300-pound thing lying around. It's not doing anything. This could turn into a number of bags there.
10:03
So I needed to do something. So in 2015, I started looking with Elixir. And this is me in my office trying to do Elixir stuff because evidently if you program Elixir, it's with goggles on and magic stuff happening. So I sat down and I had a couple of nights
10:22
where I just told my wife, I'm doing something for our son. Don't disturb me. She didn't get it, but anyway. So I was hacking drivers and everything. And then after hacking some drivers, I showed the programs to my son, thinking now we have something. So he said, well, I can understand this code. And you can see me, oh, father-son moments,
10:42
this close, this close. Then he started copying some lines around and trying to do some changes. And then, of course, he made some syntax errors. And then the whole thing basically threw up in his face and he was just looking at the code. And my conclusion to that was, trying to understand it,
11:02
was Elixir will fit this programming, but you need to be able to program a bit. So I'm taking this poor young guy, the only thing he's ever been exposed to have been tablets and other things, and then, ah, come on, we'll do a little bit of Emacs hacking and put something together. And it's like, nah, not really.
11:22
So, but for you guys, this will not be a problem. So I'll explain to you how you get going with these things. So here you have the savior, ev3dev.org. It allows you to get Linux on an SD card. And you can see the SD card here, that's the little thing sticking out there. Well, the tape is, of course, not the SD card.
11:42
That's to make it easy for people with clumsy fingers to yank it out again. But that puts it on. Then you just do an install of Erlang, which is just up, get, install Erlang. And you unzip a pre-controlled Elixir. And then you get into one of those moments if you're an Elixir guy, an Erlang guy. Okay, by the way, the common term for those two things
12:02
are beamsters, because they both run on the beam there. Yeah, that's my creation, so you can mock it later. And then, of course, when you deal with these things, you need to do some alchemy. In this case, it's on the files, because everything where you need to talk to the motors here, so we have two motors here and some sensors,
12:24
everything comes up as something in the file system there. And for instance, on this particular EV3 version there, if you put in a motor, it'll show up in this wonderfully named directory, Taco Motor and then Taco Zero. And the funny thing is, if you take out the motor
12:43
and put it in again, it becomes Motor 1. You've got to love those things. And then you go in and you look in the file system and you go, whoa, there's a lot of files. What am I to tamper with here? This is documented very well, actually, on ev3dev.org.
13:01
So that's something you can deal with and do. And that's also any language. You can go in and you can write these file things. You don't have to do it in Elixir, but of course you want to do it in Elixir, so that's why you're there. And then the way it works is, you have something like the duty cycle SP. Yeah, good naming.
13:21
So you write a number between minus 100 and 100 to that one, and then you write a 1 to the run file. And then the motor will start running either forwards or backwards there. And while that's kind of fun, it reminds you of the days you were doing a simply code or microcode, it's also a bit tedious.
13:41
So you want to have a library for this. And then in Elixir, we have macros. So here we have things like, and the good thing here is you have a run macro, a run property here. It's writable and has a min and a max value. There's a duty cycle. There's a stop mode. You can actually make these things come to a sliding hold.
14:03
Well, it's not that fast, so a sliding hold would look remarkably similar to a grinding hold, but never mind. So anyway, and then the thing is with these macros. So here you have one thing where you want to read some values from the thing.
14:20
And what you want to look at here, so here we have some unquote and some unquote stuff. And here, here's the good quote. You avoid writing all of this every time you want to deal with a motor. You get the port for it, take out the element of that result, figure out what file path all of this will be. You use a utility thing to read from that file,
14:41
and you turn whatever you read, that string you're reading into an integer on Atom. So there's a function there that's a little bit intelligent. If it senses an integer, it'll turn it into an integer. Otherwise, it'll return an Atom. And then you're good to go. And then for the run thing, it actually has this, and this is the smart part, is that if you put in an option here,
15:01
like here, minimum value of zero, you can put it in here and it will generate code checking that you're writing something that's sensible to this file. Because I, okay, again, 3,000 corner, I'm not going to write minus one to run. It's just insane to do that kind of thing. You never know what happens.
15:21
With all this in place, all this macro's done, you can actually start doing things like this. You can tell one motor to go forward with one speed. And again, if you're not familiar with the Mindstorms, they have ports named A through D. That's the output port. And here you can just use an Atom out and then the name of the port.
15:41
And then you don't need to worry about all this motor fun. It's in the library. Motor zero, one, it'll figure it out there. And then you can also write to the color sensor and say, oh, I want to get the color and then there's a set mode, which I haven't figured out what it means. But then you're reading from this color sensor here. And at this point, at this point,
16:02
this is how I felt. Happy, happy, happy. I can code. Nice Elixir and everything. And this is also the point where you're going, I want to see the Lego in action. And normally I don't do live demos. I've done it twice. I have a 50% success rate.
16:22
So and this is how I feel inside right now. And why I normally don't do these things. So the idea is this guy should now follow the line of this thing. And it is not some nice person that we've squashed on it. It's just a random figure. I'm pretty sure psychologists could figure something out of that shape, but we'll see.
16:44
So let's see if we can connect to it. Oh, you probably want to see this. So you can see that I'm not tricking you. I've done this before.
17:01
And you can't see a thing on that one. Oh, can you see it good enough? No? No. Of course, thank you. And we have live console. Yes. Then, okay. Is this readable? Yeah, good. Thank you. Then we do a, we SSH into a Lego brick.
17:23
How cool is that? I'm SSHing into my Lego brick. Yeah. This is not what I said when I was a kid. Let's see. And, oh, wrong. And one second.
17:40
What IP address did you get? Oh, yep. The same one.
18:01
And we brace ourselves. Yes. Any guess on the password? No, no, no. Elixir, of course. Come on. Jesus. So, and then you need to tickle its network connection,
18:21
even though you've set it up to automatically connect. Nope, it has it fine. Everything's okay. Everything works. So, but the one thing you'll notice here is that it thinks we're back in year 2000. And that will not work really well. So, of course, do this just by remembering all your Unix commands.
18:49
And it's now, ah, we'll round it up. It's six o'clock. Good. And again. Ah, good.
19:03
Yes, excellent. And we will start up the animal. Yeah. So, so first, I've told the pure, pure CPU there to start up the, the, the beam, the run time environment.
19:22
This is taking about 50% of all the energy left in the batteries. It's just boom. Yeah, it's not a powerful thing there. So, and it's patience is, is, is a virtue here when you're dealing with these things. Yep, you're not falling over. Good.
19:44
Oh, hello. And, and, just for the faint of heart, with highlight degree of likelihood, the first thing will cause a lot of error messages to come on the screen.
20:03
I've tried it a number of times. It keeps failing on me. Don't worry. It's only processors that dies. Nobody else dies. And brrr, yeah. Lovely. Okay. Then, since this is probably a Heisenberg, we'll go again. Ah, yes.
20:25
Yeah, it actually works. And the way it works is it's trying to, to wave itself around and go slightly left, right, left, right, around the left edge of the line there. And then, of course, when one thing is being a little cautious about the money that went into this one,
20:48
so you protect it, another thing is that you of course try to protect the integrity of your little robot. So this one actually, you can see there's a bumper up here front. And, ah, okay, it doesn't do uphill, but at least it gets back on track.
21:08
So the thing is, then if it starts running into something, you don't want to keep it charging into something. It's not like it'll knock over a child or anything. It will actually do nothing. It'll just have the motors go, brrr, until they burn.
21:23
So you don't want to do that. So this one should, it should actually stop itself when it detects something bump up. There you go. Safety features, en masse. There we go. Good, good, good. Yeah, and of course, after I'm done, you can come up and you can look at my source code and everything and do things to it.
21:47
Well, no, you're not allowed to do things, but you can open my Emacs and have a look at some of the code and we can talk about that if you want to go into those details. I know there's at least one of you that wants to do that. It's always like that. Okay, so this worked.
22:01
So now I don't feel like a chicken. I don't know what I feel like. But we need to explain what went on here. So the naive approach to doing this, and of course, this one doesn't do the naive approach. But let's just try and see how we would approach these things there. And God forbid you being a Java person or a Python person, the naive approach when you get into these things,
22:25
it would be that you have one process that acts like the controller. And it will have a timer that triggers reading the sensors. So you will have a timer that tells, so this is the brain and there's a process in there because I'm doing Elixir now, so I'll spawn one process.
22:41
That's about the limit I can handle when I get into this. And then you have a timer that tells you to read the color sensor on a regular basis and also check the bumper to see if something happens there. And then depending on what you read, you change the settings for the motor so you can control the driving. This has no leverage of processes.
23:01
One process, it's like running a program single-threaded. Don't do that in Elixir. It's a bad fit. If you feel like this and this is how you want to program, continue programming Python. Please, don't try to do things in Elixir or Erlang for that matter.
23:20
I've worked on a system where I for three years programmed Erlang as if it was Python. That code was not fun to clean up. Not fun. So please don't do that there. But all this comes back to the golden trinity of Erlang. I have a nickname apart from the nickname of being CTO. I'm also known as the Erlang priest there.
23:41
I need to get a new name to cover that I'm also doing Elixir now. But in Erlang, you need to embrace the golden trinity to make things work. And that's about share nothing. So that's how you have processes that are not sharing anything and you can only do message passing. Then you need to embrace fail fast, meaning whenever you run into a problem,
24:01
you just kill yourself. Which is really, really weird. And again, it's your program you're killing. Not yourself. You don't have a seppuku knife lying next to your table. Ah, process failed. Don't do that. Don't do that. At least you can't blame me for encouraging that.
24:20
But in order for that to work, then you need to have some failure handling there and the supervision thing. So these are the things we need to build into our programs there. And I will focus on the processes here and how we do this there. So the natural idea as a beamster is that I want a process to be a proxy for each of the things you have here.
24:42
So that's one motor here. That's one process. Another motor. That's another process. Sensor. Another process. Bumper. Another process. And that means that when I'm reading stuff here, for instance from the color sensor, that triggering the repeat thing to check what color it's on, I'll put that inside that process.
25:04
And then that allows me to actually check when it's changing value. So instead of spamming my main process, the brain of my program, with every time, I'm reading black. I'm reading black. I'm reading black there. And it doesn't matter if you're black or white, but that's a different thing there.
25:21
So you don't want to do that. You only want to tell it when something is changing. So that you can build inside the abstraction for the color sensor. And that's awesome. And that means you have a good fit. Now you're beginning to feel like a beamster. And you feel like a beamster, you just, yeah, you're all over the course in your machine. So that's awesome to be there.
25:42
Good. Here we have the color sensor. And the goal for that actually, you read the color here. So you're using your library. You get the color. And you take a look at the history of what's been going on. And if you sense that you have now changed your color, and again, you have a little bit of hysteresis in there. If I'm reading four times black, and then I read a white,
26:02
I'm probably still black there. And then, once you detect the change, you tell the controller, I've changed, I'm reading a different color now. And then when you're done with all of this, you repeat. And that means you're sending yourself a little tick in the color sensor. I will read again after a little bit of time there.
26:22
And then you do it all over again. Good. And then you have the bumper. The bumper's actually simple. It just says, if it's pressed, I will tell the line follower or the brain that I've bumped into something. And I'll continue checking if I bumped into something. So this is nice and easy.
26:41
Very few lines of code there. Relatively easy to understand. So that should be all good. And then we come to this is where, I didn't prepare for it, but I'm pretty sure somebody will have some Kleenex around. So if you start crying over the beauty of this architecture, it's okay. Nobody will judge you. It's okay to take it out and dry away the tears.
27:02
And maybe if I get over ecstatic, you can give me some Kleenex. So anyway, so the thing is, what you want to do here is, you have the color sensor. So that's the process. We will draw that as a circle. And you have a controller. That's also a process. We will also draw that as a circle. And then the color sensor will be sending messages
27:23
to the controller of a certain type. And that actually equates to the, oh, look there. There's a wire here from the color sensor to the brick where the brain is. Ooh, similarities. That's good. And then from the controller, we'll have the left and right motor.
27:42
Also processes. And we'll be sending messages to that to control them. Very easy. Again, there's wires going from this one down to the motors. Good match here. And the bumper, it'll be sending in bumper hit events to the controller. This is nice. This is architecture that, in the software,
28:02
reflects the physical world. That means that the segmentic gap between what you're doing in terms of software and what you're dealing with is very small. It means that you can actually explain to other people what's going on. Go home and do this with a number of object-oriented hierarchies and whatever, and explain to other people what's going on.
28:23
Good? Yeah. So the line follower, and you saw that, it follows the left edge of the line. And it's actually implemented at GenFSM. The GenFSM is not present in Elixir. I wrote one, and they evicted my code from the code base at some point.
28:42
And I haven't found a way to bribe USA to put it in yet, but I'll find a way there. And then, on top of that, you have a number of small functions that controls the motors. Whenever you want to do a little change, you have a little function to do it, and then you'll change the states in that finite state machine. So here, yeah, this is nice code.
29:04
Oh, it's good, good. So let's see if we can explain it by looking at it together. So if I'm on the left side of the line, then I have to go forward slide right. And the forward slide right is, I give the left motor one speed,
29:21
and I give the right motor a different speed. And that, of course, means that the left motor is going slightly faster. You can't see that, but the slight turn factor is a number less than one there. So it'll go, bzzt, and get that done. And then it says, the next state in my state machine is, I'm on the left side, and in the on the left side thing,
29:42
whenever you get a color reading from the color sensor, that's a target we're looking for. So if I'm on the left side of the edge over here, so if I'm here on the left side, I'm going this way, by the way. You couldn't see that there. Then the next color I'm looking for is a black.
30:00
When I see black, I know that I don't need to turn right anymore. And that means that when I get that, I'm now on the right side of the edge of the line, and that means that I'll have a function that does exactly the same thing as on the left, only shifted for being on the right side of things there. And then, we didn't see that,
30:22
but if you don't get anywhere within a timeout period, the poor little thing will think it's lost, and it'll stop as a safety precaution. And I've had it sit there, and it tries, depending on the light, it'll sometimes totally lose its bearing, and it goes, you think it's found the line,
30:41
and now it's going to start, and then it goes, and you just don't want to stop it because you never know where it's going in those situations there. And then the all state events there, that's the bumper hit. No matter what state I'm in, if the bumper hits me, it's being hit, I should stop things.
31:02
And that, of course, means you have a little function here that says stop the motors and event generators, that would be the sensor and the bumper, and then just stop the state machine altogether. And notice here, naming the functions sensibly allows you to have a very readable code base here. The same principle was what we used
31:22
when I worked at Motorola, and we did telecom things. So you had things that explained exactly what you were doing, and then you, whatever ugly stuff this function is doing is somewhere else, and you can dig into it when you need to. So this just makes your code extremely readable. I can only recommend that.
31:42
Then, talked earlier about, we did some good macros. So this, all this tedious thing with the, trying to deal with the different file things, that was a good example of how to use macros. Very good one. I need to strengthen myself.
32:00
Unfortunately, we also decided for the sake of teaching people, we would show an example of how to use bad macros. So some of these, the NFSM things, we had this code at some point, it's still in the repo there. Yeah, actually, if you do a mistake, you should make it public to the world.
32:21
There's no need for everybody else to repeat that mistake there. So it had this kind of code, say, if I got an event in, next state will be this other state, and then some new state data. And that's like, okay. The problem was that this one expanded, being a macro, so you can see here,
32:41
but that state was a macro we created, that it actually expands to this thing. And here you can see some code I've highlighted. So if you get an event you were expecting in the code you wrote, you will do the sensible thing. Anything else you get, you're just going to throw it away.
33:01
Just like whenever you get a message from your wife that you don't understand and you just throw it away, it's a bad idea. The same thing goes for this when you're coding state data from anything in Erlang or Elixir. Don't just throw things away. If you get something you don't understand, kill yourself or kill the one that sent you the message.
33:23
Simply. And that also, warning here, warning here. I told earlier about having a language for things. So I'm telling you a language here about killing processes. You have supervisors and they've had children and you'll kill your children. The Ericsson people, when they invented this thing and talked about doing this, they talked this language in the subway.
33:43
Talking about killing your children when they do something wrong. Don't do it on the subway, please. You've been warned. But this one, that's a bad, bad macro. And I'm afraid every night that this guy will come and teach me that this was not the code
34:03
I should have been writing. But I've said it. I hope I'm clear now. That's not how you do it. Remember this thing. Fail fast. If you don't know what to do, the safest thing is to kill yourself. When you're programming in Elixir or Erlang. Only there.
34:22
Good. The nice thing about this approach is you have the motor here. And if you have enough time, like when they invent the 48 hour day, you could put in protection for this motor. Because one of the things you wouldn't do with motors,
34:41
apart from Lego being awesome and Mindstorms being awesome, they are still constrained by physics. So if you go in and you tell the motor, let's go. Forward, backward, forward, backward. Or like the Danish hip-hop band, Nick and Deco's. We go fan, atta be, facine, ta sine.
35:02
But you don't want to go there. Especially not listening to that music because it makes your brain go. But you could protect that motor in your process abstraction. So that if somebody controlling it had the idea of going back, back, back, doing this, give me the knife, please. Don't do that. It'll kill the motor. So you can put that into your protection.
35:21
And then you can allow your kit to program this thing without worrying it burning up. Good idea. Having your kit play with the library you created and burning up this expensive thing. Two bags. Don't go there. There. So, and then actually the reaction to the bumper was also nice in this, because then it's just an event.
35:41
It comes in nice. And then we saw with the color sensor that we were smoothing these readings so if there's some lighting and something, we don't overreact to colors here. We just, ah, it's probably all right and then we figure something out. So that's the kind of thing you can do when you have these processes and you can abstract things. And that also means that your main control loop
36:02
doesn't have to deal with all these weird corner cases. You build it in local to where the problem is. And this makes code nice. At least in my head it makes it nice. So, and then the thing is here. This required me to put Linux on an SD card
36:23
and do all sorts of weird commands. Actually, if you go into ev3dev.org, it'll explain to you how you get that image onto your SD card. And it comes with a huge warning. The following command will wipe out your entire computer if you write in the wrong name here. That's always the kind of commands
36:41
you like to fire off on your computer. It's just, whoa, yeah. And also, another thing is I do some programming. And of course I need to use Emacs so I'm not doing VI on the brick itself. Then I need to copy everything I've done over to the brick.
37:00
And then, yeah, that's just a painful work process. And that's all that throttling. There are people who love this Linux thing. There's a reason why I use a Mac is that I'm too old for that shit now. And then the main goal with all of this,
37:20
depending on who you are, but at least for me, my main goal with this one, I want to write some control software. Dealing with Linux, well, necessary evil, but let's not do that too much there. And then the question is, what if I could actually run the control software from my laptop? And look how inclusive I am here.
37:43
I'm not seeing it running it from my Mac. If you have a Windows computer or a Linux computer, you can also be part of this. So this is good. And what if we can do this? And luckily, this is where the telecom, I actually am very close to having tears in my eyes now.
38:03
You have a thing called direct commands with the EB3. So you yank out the SD card and you boot the normal EB3 software. And then it has a mode where you can send commands over Bluetooth and Wi-Fi to the brick here. And then the program you're running, it runs on your own machine.
38:21
And then you're controlling things over here. And then you need to read funny stuff like these instruction sets here, that this is an output stop and it has an opcode. Yeah, that's five minutes of crying right there. And then you have different things that have to go into some bytes here and then some weird stuff here that nobody understands.
38:41
This is nice stuff. When I see this kind of thing, and especially this kind of thing, because now we need to encode the commands. Just look at this. Oh, there will be a bit up here up front and then there will be something, is it a constant, is it a variable, long format, oh. And you look at this and go, yes, party time, party time.
39:02
Then you ask the people that are working on this inside, well, Erlang solution is a part of Trifold and we have some people working with Lego. They had to implement this fun stuff in Java and they didn't look like fun stuff when we were doing this. They were throwing four or five classes after this to get all of this sorted.
39:21
I don't know, this is easy because in Elixir you have this thing. And actually also at this point it's also okay to cry because this is amazing. So here you have a command type, the actual command, and then some options. Let's forget about that. The beauty is down here. This is where it gains insane view.
39:41
So it needs to have the size of the whole thing. So you take the byte size of the incoming command, plus five, and that's because these things together add up, those here, add up to five bytes. Aha. And then you tell it that the first one, you won't have that in 16 bits. Just ones or zeros, 16 bits.
40:01
And you wanted little Indian encoded. Go home and do this in C. Java, C++. Go home, feel the pain. Enjoy pain-driven development. That's what you want to do. And then you have the command type going in there,
40:20
and that's all good. And then down here. This is the beauty. Alloc local, that's six bits. It's not a full byte, it's just six bits. And then there's two bits here. And it all just comes out, and it looks very nice and everything. Of course I'm cheating a little bit here, because then you have some other things below it, some of the parameters.
40:41
And this, now, yes, yes. I can sleep good tonight after seeing this. So here you have a command encoding. So when the value is less than 32, you use the LC0 function. Where? You tell it it's a short format. One bit, constant. One bit, and then the value in six bits.
41:04
Nice. And then you of course have these other ones, and here you have the one, it's a long format, one bit, constant, blah, blah, blah, blah, blah. And then the magic zero in two bits. I didn't do this library, and I asked Jimmy, the guy that did it, and said, what the hell is that zero? No, I don't know.
41:20
It has to be there. It has to be two bits. No manual on it, yeah? And then some follow type here, and then the actual value in the last eight bit. This is beautiful. But trying to tell that to the Java people implementing this, they didn't. Again, that was another day where I didn't get any requests on LinkedIn to connect,
41:42
but there you go. You can't win them all. Unfortunately, so we do all this library encoding, and then, okay, I don't know if I'm constituted as manager of the year or the worst boss in hell. I told Jimmy to work with Lego for three weeks in work hours, so he was smiling.
42:03
So that was good. And then he also thought, ah, we need to do this thing as well. So he's coding, and he's doing all these nice encoding functions there. And then we run into a Bluetooth issue, latency. If you send too much to this poor thing over the Bluetooth, it will just, I don't know how to deal with this.
42:22
And actually, I tried it where I sent it a command, and I waited for the reply before sending anything else. When you've done that three times, the latency turns into 250 milliseconds. And I will, yes, I will not do it today. Don't worry. When you do that, this guy will be so out of whack
42:42
that he looks like he's been drinking for four days. It's just woo, woo, woo, woo. And it's, yeah, it's really horrible. And I promise you, he has not been hurt in this. We only did it once. We haven't done it again. So no Legos were hurt in the production of these slides. And the thing is, it might work over Wi-Fi.
43:01
That's my big hope there. So I went, of course, and bought the only Wi-Fi donkle in the world that would work with Lego Mindstorms. And you go, wait a minute, the only Wi-Fi donkle in the world that will work? The thing is, they've hard-coded the firmware. There's one chipset that works, and then there's one brand that works with it.
43:21
And you need to recompile the firmware to get other Wi-Fi donkles with the same thing to work. And the thing, it actually came, I was warned, it came with a big thing with a big sign on it, do not open. And then I open it, yank it in, doesn't work, and then I start reading the manual.
43:40
Yes. That's the order you do things in. And then it comes up with the killer argument there. And I haven't solved that problem yet. I'll fix it. You need to have a Windows machine to configure this Wi-Fi donkle. What? Yeah, 2015, you need to have a Windows machine to confine, yeah. Okay, so we're hoping that it might work over Wi-Fi,
44:01
and we'll see how that works out there. And then if you want to get hold of this library, by the way, that's Jimmy. He's the man here. He coded all of this according to my instructions. And he loved the old three weeks of it there. And then just a warning down here,
44:20
I've told you this now, it does not work with the current version of EV3DEV. I found out the very hard way. When I was trying to demo in London two weeks ago, my card didn't work. I had to do a file system check, and it ran for two hours, and then it still didn't work, so I said, I'll get a new SD card, and I'll put EV3DEV on it,
44:40
and I did all those things, including the weird command that could wipe the entire machine and everything. And then I booted it, and it turned out that the new version changed the entire file structure for all of this. So if somebody goes in and does something, you need to contact me and make sure you get the right EV3 version, or help us port the library to the new file structure.
45:02
That would be very welcome if somebody did that. So then all of this was nice, and you can hear that I took one of my colleagues to program this thing. So it's not my son. My son is not involved at this point, so I'm still having 3,000 corners worth of equipment standing there and doing nothing. Again, it was his own wish.
45:22
I think I got him another Christmas present just to compensate for it. Still, it was his wish. Trust you. So teaching programming, when you go to look at that, so if you take the EV3 visual environment, it is very difficult to do anything in it. Go try it.
45:41
It's insanely painful. And again, if you're into paint-driven development, go ahead, have fun there. And this library we created for Elixir, it's good, but you need to learn Elixir first. So I'm just staring at my son. Learn Elixir. Nothing happens there. But again, I don't know if he received my message
46:00
because he's a teenager, so you send a message, and it's not a synchronous protocol. It's an asynchronous thing. You might get a reply 10 years later. But there you go. So what I did, instead of screaming about it like a little baby, I decided I'll teach some kids to do Elixir.
46:21
So I've started this course at my son's school called Junior Beanster, where I'm teaching this Elixir to the upper grade classes. And all the material I've done so far is available for free, of course, on beanster.org there. And I had somebody throw in a logo there. So that's good. There are some quirks with it, so I'll be honest with you. I will not stand here and just claim huge success there.
46:46
And again, this not being programmed, I've failed at some point, but I have not killed myself doing it. So the initial learning is here. And this is also for you if you want to do the same thing and teach some people, some good kids. The command line is an alien concept.
47:03
So I go in there and I tell them, okay, open the command line. Hands go up. And you go, yeah, what's the command line? And you have to think about this because this is what we've created. The industry and everybody, we've created these people, these young people.
47:20
It's not their fault. We give them a tablet. And there's nothing there. There's no command line. Some of us grew up on a Commodore 64. Actually, my first one was a VIC-20 with a staggering three kilobytes of memory. But the stuff you could do there, but you were born on the command line. I was born on the command line.
47:40
So you're sitting there, but they didn't know how to do that. And actually, I hadn't used Windows computers for so many years. I actually didn't know how to start a command line anymore. I had erased that part of my memory. Windows computers, gone. Maybe it's hidden somewhere. Maybe I have to see a shrink to unlock that part of my memory, but we'll see. So that's one thing.
48:00
Then, editor, using an editor. So the first one, okay, we deal with the command line and everything. Then we install Atom because I thought that was a reasonably nice editor because, well, I'm crazy, but I'm not so crazy that I tell young kids, oh, you need to learn Emacs to do this thing. I'm not evil.
48:20
You must trust me on this one. I'm not evil. So then we installed Atom and everything and said, now you open the editor and you start typing these things. Just type what I've written on the screen there and then go down and look. Why do you have Word open? So they were typing in the program and I told them, no, this is not going to work. So we got that to work there.
48:43
Another thing here is that the good part here, functions, they're easy. They get that. That's just like having a lecture in math. That's good. So that's fine. Then, of course, you get a little bit over ecstatic when you're a computer scientist. Well, I'm an engineer, so I'm fucked up,
49:01
so don't worry about that. You throw in a recursion. It's not so easy. I still need to find out. It's coming along slowly there. Then the thing is I think I need to do some UI and I think I might have to turn to Elm and get more of the feedback loop running faster
49:22
because I want them to think and program there. So I might have to abandon Elixir for some time and then do something where the feedback loop is faster. But that's my lessons learned now. Now I have the entire summer vacation to think about what I want to do next year with these kids. And this is also where if you bring your kids
49:41
to a presentation and you ask them questions, like the father-son moment, so at this point I go, yes, but they're still talking to me. Also, my son is still talking to me. And then the little bastard is sitting there in the back and he says, just barely. Yeah, yeah, yeah, yeah.
50:02
So then you start dreaming. You're allowed to dream sometimes. What if you had a new visual language? You could start in a nice visual environment. This seems to work with a lot of beginners into programming. And then you open up the boxes in that visual environment. And then you change the code in there
50:22
and you stay with the same concept. And then after a while, you're doing this in text. You end up in Emacs or VI and you're coding your stuff. Wouldn't that be like the dream trajectory for young kids? To end up in Emacs? I think so. But you need to start them somewhere else there.
50:42
So other people have thought about this. So this is Scratch. They have a nice environment here. Very nice indeed there. The blocks are intuitive, but it's for sequential programming. And although there are bits of sequential programming when you do things in Elixir,
51:00
sequential programming is evil. You want to do the concurrency bits there. And to be fair here, if we can get... Yeah, they have sprites in Scratch so you can mimic processes there. So now I've said it, but it's still not the optimal thing. So what I'm looking for here is
51:20
I have Elixir. It has awesome concepts for robots because these processes with message passing. We saw that that just fitted things perfectly. So that's a good thing. And then the visual elements. We could just have a one-to-one. And I think we've seen this one before, but you can see here that these things, one-to-one mapping between physical things
51:40
and also an abstract entity like the controller, and then the wires you have in your physical thing, that's where the communication takes place. This is explainable to people. Very easy. So you just need somebody to create a visual environment and brace yourself. You will see now why I'm not doing visual stuff.
52:02
So I want all these elements to have a default behavior, and then you can double-click on the box and you can see what the default behavior is, and then you can write some code in there, change the code, or have some blocks like the Scratch one and put them together and do something. I think that this kind of approach would allow you to have the concept
52:22
get rolling with something, and then you can open up things and do more advanced stuff later. That means when you're talking about learning curves, you can take a very, very simple visual environment, that simple there, and that normally means you hit the ceiling very fast because then there are limits to what you can program there. Or you can take the complex one
52:40
that shifts with the Mindstorm and then the learning curve is insane. And I think it's a good idea that you sit with your kid if you're using the normal Mindstorms and explain to him or her that he's not insane because he doesn't understand the environment. He's okay. She's okay. We're all okay, but the visual environment isn't.
53:02
So the same concepts from start to end, smooth learning experience. So this is my vision, my dream here, to have somebody help me put this together there because then it allows me to have the thinking from day one, the basic concepts of processes, methods passing, and a modeling in my visual environment
53:21
and in my programming that fits with the physical world. And then I'll be a happy trooper. I'll be like that kitten we saw earlier, spinning away all day there. So that's what I want to have. And then again, I would be able to promote the golden trinity of Erlang. And it's actually the same thing for Elixir. Share nothing processes,
53:41
failing fast approach, haven't talked about that today, and in great detail, and also the failure handling. I would be able to start them off in an environment where these concepts are the same from the day they start to this day where they can call themselves beamsters and they're ready to do badass server programming. That is my dream.
54:00
And that actually, I think, concludes my talk. Thank you. And I actually have to say, one of the talks tomorrow, there will be a talk about Elixir meta-programming, and you will see all the examples of how to use macros and everything.
54:22
And if I haven't scared you away totally, I'm also giving a talk about how to do a board game logic in Elixir. Yeah, and I will be almost bus-code compliant when I do that talk. So wait for it there. Any questions?
54:41
Yeah? I think it's asynchronous. So that's actually a good thing. So I ought to play with that one. But I haven't seen anybody connect the Scratch environment to the Lego. So it might be that there's something there that could... That would be ideal. That would be ideal.
55:01
But you have to remember, my hidden mission in life is to spread the beam. The one true virtual machine. The one machine to rule them all. That's my... Yeah, yeah, yeah. Other questions? No more questions? I have stickers here.
55:21
It'll take the way of Enterprise C sharp and Java away, Elixir. And also some pain if you're doing Erlang. It'll also take that pain away. So come have some stickers. And on the way out, One more question?
55:46
Possibly. You could possibly do that. There are people that are installing Erlang on Sen. Yeah. You could probably do some things there and put it on some Hypervisor thing. I haven't tried that. But it would be interesting to do. Because Erlang, as you say,
56:00
it's an operating system in itself. That's how awesome the virtual machine in Erlang is. This is a commercial presentation. Erlang is awesome. Elixir is awesome. You will be dreaming this. Erlang, Elixir, awesome. I want to be a Beamstar. I want to be a Beamstar. Thank you, and vote on the way out.