 I'm a developer, a web developer, but I also play with robots. So I work as part of the Johnny 5 core team, building robots that work with JavaScript. And so that's what I want to talk to you guys about for the next 20 minutes. So my initial interest in computing really came from an interest in electronics. I love pulling things apart and kind of understanding how those things worked. For a kid that was growing up in the 1980s, doing anything that was not trivial with hardware was really difficult. It was really expensive to try and have access to hardware back in those days. The idea is of facilities like maker spaces and hacker spaces. Just it wasn't even a concept that existed at that point. So as a teenager, I kind of moved across from kind of tinkering in hardware into the world of software because there was more bang for your buck. You got more results faster, which was great for the attention span of a teenager. And I went into software as a career. And this was pretty much the case for most people that were kind of interested in computing, certainly back at that point in time. And that remained the case up until very recently. Hardware was very expensive up until this came along. So this is an Arduino, a form of an Arduino. So how many of you have played with an Arduino before? Chuck your hands up. All right, a few of you. So hardware was changed by the Arduino. The way that we think about hardware was very, very different as a result of this coming along. When this was launched maybe 10 years ago, it was designed to be only about 20 euros. But alongside that, it was all open sourced in terms of all the design around the hardware itself. And so as a result, people could take that, they could iterate it, make their own designs, but also go and get them fabricated anywhere in the world. And so over the last eight or nine years, the price of this has come down and down and down. So now you can go and get an Arduino for $2 or $3. So this has meant that hardware all of a sudden becomes much more accessible. And now it's accessible to kids, to students, to artists, and web developers. And with this, the ideas of these communities have really come into hardware as well. So ideas around art, around music, around software principles, architectural principles. And as a result of that, as a result of web developers starting to come into this hardware world, we've started to see these things start to be connected to the web. And so as a result of all of that, there's been some great work done within the Node.js community, particularly, to try and get hardware like this to talk to the web. And so that's really what I want to spend today talking about, you know, showing how some of this is going to work. So to do that, we're going to cover off these three areas. So we'll have a look at why would we use JavaScript for Robotics? We'll have a look at how the stack starts to go together. And then I'll show you some examples of the things that people have made and some demos as well, hopefully, if it works. So let's start by thinking about why JavaScript and hardware are actually really great when they start to go together. So in the hardware world, really for the last 30 years, the assumption has been that in hardware, you would use C. And that's pretty much still the case today. If you're working with cheap chips or kind of low-powered chips, that sort of thing, you still need to write C in order to kind of get it to work on the hardware. However, over the last year and kind of increasingly this year, what we started to see is that there's this rise of medium cost boards that are kind of in that $15 to $50 mark that are starting to run high-level languages natively. So we've got two here, the Tesla and the Pie Board. And these run JavaScript and Python on board. So high-level languages are starting to be able to run on chips like this, which is pretty cool. But why would I want to use JavaScript on my board, as opposed to say something else like Python or Ruby or Go or something like that? Well, for me, it comes down to two kind of main things. First is events, and the second is the way that we deal with objects within JavaScript. So anyone that's worked, particularly with Node, understands about event emitter, you would have come across this before. But JavaScript inherently has this amazing event system that most of us have pretty much taken for granted. As web developers, we sort of don't have this type of event system that exists in many other high-order languages. So being able to work with these types of events makes a lot of sense when you're working with the real world, because the real world is full of events. It's mostly what you're kind of decoding for when you're building real world applications. So say I wanted to build a system that talked to a door. So I have a door, I need to swipe a card to kind of open it. In JavaScript, this is really simple, because I can create an event listener to kind of listen to the swipe activity that can be emitted. I can go and do my authentication and come back and unlock or lock the door. I can do the same thing in C, and plenty of applications do this. I have to think a lot more. I have to think about how all my code goes together. I have to worry about state when I suspend it, to have to do interrupt service routines. I have to write interrupt handlers. I have to do garbage collection. I have to do all these things and hopefully not crash my door at the same time. And these are the sorts of considerations that I need as a C developer. Whereas really, I just want to unlock a door. So I don't want to have to kind of have all of these considerations. And JavaScript just does this natively. So that's one of the reasons why I think JavaScript is very powerful when you start looking at this, because it means that we produce clean, modular, and reusable and maintainable code as a result. Much more so than what we do in C. The other thing that I think makes JavaScript, in particular, a very powerful language for hardware is to do with the way that we work with objects. And in particular, the way that prototypes work and prototypical inheritance works inside JavaScript. So what that means practically is that I can construct objects that I can define an API in a shape to that object. So it takes something like a motor, for example. And then underneath that, we can create controllers that implement the different implementation details for how that motor might work with one chip versus another chip or one particular motor star versus another motor star. So as an end user, when you go away and actually try and use that motor, all you need to know is what controller that you need to work with. And then all of a sudden, you just use it exactly the same way. You just say, I want to set it turning in a particular direction and a particular speed. So we can abstract away a lot of this sort of stuff very, very easily. However, on top of that, it also means that say your example, your particular robot, has a particular gearing system or something like that, that means that you need to turn that motor twice as fast as the other one that's in your robot. Well, you can just redefine the start function and then you can just make it do that within the context of your application. So JavaScript being this very malleable language allows us to create these kind of composable interfaces for hardware much more effectively than what we ever would have been able to do in C. We can kind of do these sort of stuff in C, but it means lots and lots of bloat, it means very spaghetti code, lots of function pointers going everywhere, and it becomes very, very difficult. And so trying to do these types of things and create these kind of hardware abstractions in C is very, very difficult. So that's enough about why I think JavaScript and robotics go well together. Real JavaScript developers, we love it. So, you know, I won't bang on too much about that. So let's have a think about the node bot stack then. So node bots is really what we call JavaScript working with hardware through Node.js, and we can kind of do it in other instances as well. So things like Chrome bots and stuff straight out of the browser. But generally when we're working with hardware, we're working at the node level. So the core of node bots is really this idea of transport protocols. So we have these transport protocols that allow us to talk to the hardware over USB or maybe over wireless, over radio links, serial connections, all of these sorts of stuff. And then we wrap around all of that a library called Johnny 5. Now Johnny 5 is a hardware abstraction library. So what it allows us to do is think about hardware components as objects in JavaScript. And this sort of goes back to what I was talking about before with the motors. So you can create these objects and you can just interact with them just like you would any other JavaScript object. But it has a real world implication. So Johnny 5 was created by this lovely looking man, Rick Waldron, and he started this project up a few years ago. And now there's about 30 core contributors to that around the world and over 100 that have contributed to it over the last couple of years. Very active community and very welcoming ones. So I encourage all of you to get involved. And Johnny 5 is really what we sort of talk about when we're talking mostly about node bots. So this is what the typical JavaScript stack kind of looks like. So at the kind of base level, we have controllers. We have a controller board. So this might have things plugged into it. Sensors, actuators, the things that are gonna happen in the real world all sit on the controller board. Now like I said before, there's a sense that with particularly the cheaper boards, you may not be able to run JavaScript natively on those. So we have to put a firmware on it that establishes a protocol that allows that controller board to talk to something else. And that's what really kind of happens at the IO plugin level. So the IO plugin is a Johnny 5 ID that allows you to kind of create this protocol to be able to kind of talk to hardware in a consistent fashion. So I can have a Raspberry Pi or a BeagleBone or an Arduino, and as far as Johnny 5 is concerned, it all talks the same way. I don't have to worry about the specifics of each of those types of boards. So that's what an IO plugin does. Then we've got Johnny 5, and that's happening within the node kind of side of things. So Johnny 5 is that hardware abstraction library like I talked about, so that gives us things like motors and LEDs and control to turn that stuff on and off. And then as a side effect of that, we get the whole node ecosystem as a result of that. So now we can start wiring hardware up into things like the file system or into the network or kind of all these other things that are just about any other node library that you can think of as well. And then after that, we get back into the kind of territory that we are very familiar with as web developers. So we've got networking, security protocols, all that sort of stuff, and then things like clients so that we can do user interface and visualization and stuff like that. Now, a specific implementation of that might look something like this, and this is probably the most common one that you would come across. So in this case, our controller board is an Arduino and you just plug that in. Now, an Arduino can't talk JavaScript, so we have to put a firmware on it. And that, so our IO plugin in this case is a thing called Fermata, which runs on that, and that establishes that IO protocol that I was talking to. And then that just talks to Johnny 5. So you can see this bottom part stays the same. So even though that top bit will change from one instance to another, the whole bottom part, the part that we wanna work with mostly as developers stays the same, irrespective of whether I'm using a Raspberry Pi or a BeagleBone or a Spark Core or a Proton, whatever. This all works the same way. So to get up and running is pretty straightforward these days. Get your board development environment. So if you're using an Arduino, that'd be the Arduino ID. After that, you just flash the board with a protocol, so if you're using an Arduino, that would be Fermata, like I just mentioned a second ago. NPM install Johnny 5, that'll take a couple of minutes. Write some code, debug some code, write some more, debug some more, that sort of stuff, and make an awesome robot. So this first bit normally takes most people about five to 10 minutes. The other bit, yeah, fence, what you're trying to do. So this is pretty quick to get up and running with this sort of stuff. So that's what the stack looks like. So let's have a look at the sorts of things that people are actually doing with Johnny 5 and node bots, and then I'll show you some demos right at the end to give you a flavor of how we actually build this stuff. So the first one, this is a skirt that was made by a lady called Cassandra Perch, and this skirt has an, or it has a board embedded inside it, so everything is self-contained within the skirt. It has an accelerometer in it, it has some LEDs, this sort of stuff, all embedded inside the skirt, and it runs JavaScript natively. So as she moves around, it can change color, she can interact with it in different ways and stuff like that. So JavaScript is moved so far out of the browser. Like, you know, like this is so far from that. Right? So this is the future of where JavaScript is going, right? Our clothing, and you can see, look at this. These are LEDs as well. So she's about to put JavaScript in her shoes, I suspect, which is pretty cool. So this next one was made by a guy called Adrian Catalan, and he's playing around with physical displays and particularly how people can interact with those displays. And you can see here, he's got all these big LED panels and he's controlling that from this computer with noJAS, and he's using this to build games. And so most of you should recognize this game, you know, and he wants to kind of build this to kind of very large scale, to kind of do this sort of stuff. So you can build some interesting things with nodebots. The final example is a bit more robotic. This is built by a guy called Jonathan Buck, and he's part of the core nodebots team, and he's been doing a lot of work on building libraries to help with complex animation and movement problems to do with servos. So if you know anything about robotics, you know that inverse kinematics problems are very difficult to solve. So this is where you're trying to move a whole limb in one motion. So if I want to move my hand down to here, I have to know the position of my shoulder, my wrist, and my elbow in order to be able to do that. And calculating in that in real time is very complex mathematics. So this is real time, so this shows you how quickly it responds and he's actually hooked it up to a leap motion controller that is detecting the entire position of his hand, feeding that through and calculating the position that the body needs to be in on this six-legged robot in real time. So JavaScript robotics is solving very difficult real-world robotics problems, and we're really only at the start at the stuff that we're kind of doing with this, and this is why high-level languages are really good for hardware. So that's a few examples. So now I want to show you some demos. So the classic demo with the hardware world is we don't tend to have screens a lot in the hardware world, but we do have LEDs. So the start of this is that we want to turn an LED on and off. So I'll show you how that's all going to work. So we're going to use an Arduino, pretty much exactly like I described before. It's going to run Firmata, like I mentioned. And what we're going to do is we're going to plug in an LED into pin 10. So this one here is a little bit bigger than that little one on screen. So that way it should be a little bit more visible to you all. So I'll just put this in. All right, so it's going to run Firmata like I described, and then we're going to control it from Johnny 5. So this is the code that we use. So this is pretty much one of the most simple Johnny 5 applications that we can create. And you can see here, I've got my board that I've created, for it in Johnny 5, doing a little bit of error handling, and then I create my board that I'm connecting up to a serial terminal. And then I wait for my ready function to come back. It's a callback that gets emitted when it's ready to go. And then all I do is create my LED, tell it that I've plugged it into pin 10, and then I'm going to blink it every 500 milliseconds. And blink is just a nice convenience method that does timers and all that sort of stuff. So that makes it nice and easy to work with. All right, so let's flip to some code. All right, so I'm going to just run this from my terminal just here, but it's just running this code. So I'll just run that from my node process, and hopefully if it all works, you can see it blinking on and off. All right. So for those of you who are old enough to get the reference, this is like the blink tag in hardware. All right, so that's how that sort of works. All right, so very, very simple bit of code there. All right, so we're all web people, right? So, you know, that's all fine. So what about connecting something up to the browser? So why don't we use the same circuit, but this time instead of, you know, having it working off the terminal, why don't we have it interactive through a webpage, right? So if I can find my mouse, here we go. All right, so in this instance, what we're going to do is we're going to run Express, and we'll kind of use that to create a web application. And if you've used Express before, you know you need to create ports and routes and kind of all that sort of stuff. So most of the start of this is really just about getting Express to do what we want it to do. And then after that, what we'll do is rather than have the web application kind of make a post or a get to the server and then respond, we'll make it a little bit more real-time, right? So we'll use some web sockets to kind of talk to the hardware pretty much directly. So it's nice and responsive. And then so really that's all the kind of web sockets, socket IO stuff. And you can see here this line here in the middle. This is pretty much all of that gets distilled down into a toggle function. And all it's doing is it's taking the state of the button that we're going to have on the webpage and passing that all the way through down to the Arduino to tell it to turn on or off, depending on the state of the button. And then the very final bit is the same stuff that I just showed you before, setting up the board, getting it connected, making sure it's available. So this is what that looks like. So hopefully I can get this in the right direction. All right, so here we have a button in a presentation connected through web sockets talking to hardware as I'm clicking that on and off. So there you go. So that's, so anyone that's kind of interested in automation or anything like that, your mind is probably now starting to take long quite rapidly. All right, so, all right. So this final demonstration is a little bit more complex. So this is a little robot. It's called an Mbot. And it's made by a company called MakeBlock. It's got lots of sensors and motors and stuff like that. So I'm just going to put that down on the ground here while I show you the code. And we can talk to this over wireless to kind of talk to that. And in this instance, all we're really doing is I want to be able to drive it around. So based on my keyboard input, I can kind of drive it forwards, backwards and that sort of stuff. So this one's fairly simple, even though there's a fair amount of code in here. So all that's happening is I'm creating my motors. I wait for my board to kind of come up and then I create my motors down here to find the pins and things that I need to use to control those motors. And then really all I'm doing is I'm just processing standard in to kind of say, okay, how do I need to coordinate the two motors that are going on to go forwards and backwards and left and right as that kind of goes on. And that's pretty much it. Stop will be done by spacebar. All right, so if everything works, we should connect to this. All right, so it's just connecting over Bluetooth. All right, so hopefully now, here we go. So as I use my keyboard, I can drive this around and this is all just JavaScript messages being passed along over Bluetooth to control a robot remotely. So it's not flying, but it is, but it is mooching around. So, you know, you could hook up cameras to this, you could kind of do all sorts of other things. This is a very, very basic demonstration of this, but you can kind of take it really as far as you wanted to, as you wanted to go. All right, let me just bring my slides back up. All right, so to finish off then, here's a bunch of different resources. If you're kind of interested in this and you want to get started with it, this is a bunch of good places to start. There's a bunch of different resources there. Also, the Core NoBots team have written a book over the last year or so and this is available now. So if you want to go and get that, there's a code there that's for all of you here at JSFood that you can use to the end of the month at Maker Shed to be able to kind of do that sort of stuff. So you can get all sorts of different interesting ideas about how you can build robots and wearables and other things like that. So thank you very much for having me. Hopefully that's been insightful as for the sort of stuff that is going on. Very quickly about the workshop. Okay, so if you are really interested in hardware, if you're not doing anything tomorrow or even if you are doing something tomorrow, cancel it. There is a workshop on that we're doing as part of JSFood on NoBots. We're going to be doing it all day. So it's very hands-on. You're going to be actually working with hardware and the objective is to build a robot sort of similar to the one that I've just showed you and we're going to have a robot battle at the end of the day. So we'll be getting you into teams. You'll have to build robots and then battle them out to find out who is the best robotics building team here at JSFood. So if you want to come to that, go to the registration desk. I think there's still spaces available and we can get you signed up for that. So thank you again. And if you've got any questions, maybe come and grab me and we can kind of talk through it. Thanks. So the tickets are available at the registration counter for everyone who wants to join us.