 Okay, so welcome back, and let's welcome Radomir Doperalsky, who will tell us about making robots work with Python. And now the resolution is different. One moment, sorry about that. Okay, so I started to play with robots and Arduino's and small electronics and stuff like that about three years ago. And my goal was to build some cool robots, obviously. I wasn't happy with the robots on wheels, because they were too easy. And then, you know, you build them and they already work. So now you are stuck thinking what other interesting things you can do with them. And turns out it's very hard to do anything interesting with them. So I turned to walking robots because walking is already interesting and hard. So by the time you get it to walk, you are already happy and it's already awesome, right? And you don't have to think much about how to make them behave in an intelligent way or anything like that. Of course, you can, same as with wheeled robots, everything like that works. And some of them actually behave cool. But, anyways, if you have any questions, want to chat about robots or about electronics in general or about micropyton, this is my nickname. I'm on FreeNode, on IRC, I'm on Twitter, I'm on Hackaday IO, where all my projects are. You can just Google it or something. It should be Googleable, because quite, it's not a real world. The robots I'm building, they are walking robots, not crawling robots. The difference is when you walk, and you put your foot on the ground, it stays in that place until you lift that leg again. Pretty much in the same place. Maybe you rotate it a little or something. And when you crawl, you actually drag that foot sideways or behind you or you even drag your stomach behind you or whatever. So, I'm focusing on robots that actually properly walk, like they have proper support all the time and they can walk on any surface. If you are crawling, you are basing your motion on a friction, differences in friction on the surface. And then if there are different surfaces or you move from the floor to the carpet, for instance, the robot doesn't move so well anymore. This is an example of one of the robots. I don't have all my robots with me here. I only brought the ones that are most sturdy and robust, because I had to travel here from Switzerland. So, I just have this simplest one there. Walking looks pretty much like this. You can turn, stop, stop, stop, okay. Go for that again. Anyways, I will just leave it walking inside the circles. Yeah, it's quite fun. You can have different ways of walking. The way of walking is called a gate. And different gates, there is a broad categorization into two categories of gates. The statically stable gate is the one that you can stop at any moment and you will not fall down. Basically, animals use that when they are crawling, when they are talking, when they are moving slowly because they want to be able to stop at any moment. And it's the simplest one to do because you don't have to do dynamic balancing. Dynamically stable gates are the ones that are most interesting to researchers, such as the Boston Dynamics. You've seen probably the Big Dog, the Spot Mini movies on YouTube. Very cool, very nice stuff. But this is much harder, of course, because you take into account the changing center of gravity, the inertia and so on, and you have to plan your movements much better. Yeah, so two examples of those gates are creep and trot. Creep is how basically a cat walks when it starts its prey. And it doesn't connect the battery. And it's basically statically stable because it has to be able to stop at any moment and so on. It looks pretty much like this, so one leg at a time. And if you want to move faster than that, you can use a dynamically stable guide and move two legs at a time, like diagonal legs, like this. You see, because you move two legs at a time, it's basically twice as fast. But it's based on timing. If you stop with two legs in the air, you will be in stable, you will pretty much fall down. Okay, stop. Because my robots are so small, I actually violate one of the most important rules when you're building robots to have a big stop switch on them. Because you don't have to grapple with them. I will switch them off so the battery doesn't run out. Okay, the most important idea when you are designing a guide, when you are designing a robot that is walking, is the support area. The support area is basically the area between all of the legs, the convex outline of all of the legs that are at the moment on the ground. In case of a four-legged robot or a multi-legged robot, it's basically, usually the feet are just points, so you just make an outline like that. If you have a two-legged robot like this, you just need very large feet. It makes things easier. And when you lift one of the legs, the support area changes, of course. And there is only one rule you need to follow if you are making a statically stable robot. The center of gravity has to be above the area of support at all times. To achieve that, you move the body sideways before you lift a leg. So you move the body away from the leg before you lift it so that the center of gravity is further away from that leg so you can safely lift it. So basically, each step you have three animations going on at the same time. First of all, you are moving the robot body forward by moving all the legs backwards simultaneously. So it's like, until you run out of the legs, of course. At some point, you would just face plant. So there is the second thing, you move the body sideways or away from the leg that you are going to lift. And then, one by one, you are lifting the legs and putting them forward so that you don't run out of the legs. So you can continue moving all the legs backwards all the time with constant speed. And it's also important in what order you move the legs. And it turns out that for the creep guide, it's best to move them like in a figure eight order, like here. So front left first, then back right, then front right, and then back left again, and so on. And of course, changes. If you start to do rotations, if you start walking sideways, if you start having an event terrain event, because then the legs don't really, the shape that they form on the floor is not such nice anymore. And then you can invent very nice algorithms for determining which leg to move next and so on. So that's one interesting aspect of programming there. Second thing, if you want to be able to put the leg in a precise point in space, in three dimensional space, you need to have at least three degrees of freedom on its leg. For walking, you basically have to do that. There will be an exception, I will talk about that later. And you want to, when you are moving the servos, you specify the angle by which you want to move it. And I usually, when you want to move the leg somewhere, you specify coordinates. So there is a way to calculate the angles from the coordinates, it's called inverse kinematics. And that's not what I'm going to talk right now, because there is one more slide before that. This is what happens when you only have two degrees of freedom per leg. One servo to move the leg up and down, and one servo to move it forward and backward. And you can see that if you try to move the legs backward to propel the body forward, it has to move sideways a little bit. So you have this slipping on the floor and it's not proper walking anymore. And depends on the surface, depends on what the tip of your leg is made of and so on. It may not work so well. If your legs are very elastic, they will probably just bend a little and add up to that. Oh my God. Okay, inverse kinematics. This is basically a high school math, like geometry, and I won't get into details of that, but you can basically solve all the triangles in there and calculate the angles and then move your leg to the place you want to. And there is one exception for these three degrees of freedom. If you have a mammal robot like this, you can get away with only two degrees of freedom because the servos are mounted vertically on the same plane. So you are able to move the leg backwards by moving the two servos in the right proportions and it's still a straight line, right? But then you have problems with turning. You can only turn like tanks do by moving legs on one side faster and legs on the other side of the robot slower. And then you also have these things that tanks do when they turn, that they completely obliterate the ground they stand on. I don't know if you saw that. If you saw a construction site where a digger was moving on the tracks and it was turning, it's a horrible mess in there. So it happens here too. So there is always some problem. You could add a servo at the back to somehow, you know, on the spine of the robot, that's more advanced things. Okay, when you actually build the robot physically, you need, in one way or another, you need at least those parts for the robot. You need a battery to power it. And you need a power board to distribute the power and to adapt the voltage of the battery to the voltage you are actually using in your robot. Obviously, you need some kind of servo motors or other actuators that you are going to use to actually physically move things around. And you will need a controller board to actually send all the signals to those motors. And either it's an H-bridge for real motors or if it's a servo, you need a servo controller that generates the signal for the servos. Sometimes you can merge that with the brain that you are using. And the brain is obviously the main computer that runs the robot, that you program actually. Sometimes it's more convenient to have the servo controller separately because then you can debug them separately, you can have, like, easier time reading the code and so on. And of course, if you don't want your robots to be just radio-controlled toys like those, you need actual sensors and you need to process the sensor data. Yesterday we had that talk about using OpenCV, for instance, for processing image data. That's one way you can do it. I just used a distance sensor from the door. So the robot only knows there is something in front of it. Turns out you can do a lot of interesting stuff with that already. Yeah, so approaches to actually constructing that. I started with a remote brain. This robot doesn't actually, it only has a servo controller on board. It doesn't have, like, a main computer on it. It only has a Bluetooth dongle. And it runs from code, Python code I actually run on my computer. And it sends the servo positions to the robot. And this way you can very easily debug your code because you have it running on your computer. You can break at any moment. You can use the console to, you know, try other commands and so on. So that's convenient. But of course you need the other computer running. That's, and that's this robot. Yeah, I work at Red Hat, so. What you can use for control. Of course you can use radio, you can use Bluetooth, you can use Wi-Fi, you can use ZB, Lora, Irda, whatever. Those are controlled by infrared from, actually, a TV remote. The cheapest way you can have a remote for your robots. That's very easy. This is my first robot. It uses a different approach. I had a lot of trouble with it. I've rebuilt it many, many times because I didn't know what I was doing. So I replaced servos with stronger servos because the ones I used at the beginning weren't strong enough to actually carry the robot. And then I had to replace the battery and then I had to replace the servo controller and then I had to replace, because battery was heavier, I had to replace the servos again. And so, so this was really a lot of trouble. It's about this big. And then I decided that I'm building small robots because they are so much easier to control. They are so much cheaper because the parts don't have to be so strong. They're easier to build because you can use just plastic and glue and not metal and, I don't know, boards and so on. So I'm building small robots. This is much easier and you learn as much with them. So this is the second approach. Put the computer on the robot directly. It has a Raspberry Pi on it. And also the battery, of course. This is another one. This one has a Pi Zero on it. So it's quite small Raspberry Pi Zero and the Raspberry Pi Zero controls the servos directly using a servo blaster. So I don't even have a servo controller in there. And it has a camera from an old laptop. This thing in front is actually a working USB camera. So I can do stuff with open CV and so on on it. It's quite cool. The problem is, yeah, so you can put a smaller computer on it. And that works better because you have smaller robots. It's easier to maintain. It's easier to catch it if it runs away and so on. This is the smallest one I did. It's very similar to this guy here, except this one has Arduino for the servo controller on it and it just listens to the TV remote. That one actually has a chip from a Wi-Fi router. Chip Wi-Fi router, it runs OpenWRT on it. So Linux distribution and it also has a camera from a laptop and it streams from that camera. So you can explore under the bed and so on. It's quite cool. And it's controlled by Wi-Fi, of course, because it's a router chip, so it has already Wi-Fi built-in. Very nice approach. The problem is, it boots 10 minutes. So this is a problem when you are using a real computer on your robot. You basically have a perambulating data center there. You have to maintain that server. You have to install upgrades. You have to, I don't know, do all the care you would do with a server. It takes time to boot. If you just switch it off, it will start the fragmenting, fixing the file systems on the next boot and sometimes there will be some corrupted flash on it and sometimes you will have to restore from backup, so you will have to maintain backups for your robot. And so it's convenient because you can SSH it into it and just run code directly and so on. So that's convenient, but it's not really that good experience once you actually want to use the robot. So the next step is using microcontrollers. But I really wanted to program in Python. I can do some rudimentary for the server controller, for instance, or for simple walking robots like those, but for more advanced stuff, you really want to have Python. So this is a Espruino Pico board that runs MicroPython. You can use MicroPython. That's awesome Python port distribution, whatever you call it, that runs actually on microcontrollers. And yeah, microcontrollers can just switch it on and off whenever you want. It puts like in several microseconds or milliseconds and you can connect to it through Serial and still get a Python console. So you can still try your code live. You can have a cable to connect to the robot and see how it moves and so on. There is a cool board that runs MicroPython, it's called OpenMV. And I have a robot that uses it, but I never took the time to actually program it. The snout in front of it, it's actually a camera. And it does image recognition because the MicroPython on OpenMV has a built-in library that does hard cascade and optical slow and blob detection and a number of other useful visual algorithms are built in there. So you can actually hopefully I will program it and make it do cool stuff. Right now it's not yet working. There is ESP8266, which is a very tiny, no time, a really small chip that actually module the size of a post stamp, costs about $2, $2.50 and runs MicroPython and has Wi-Fi built in. So it's perfect for our use. The problem is it doesn't really have, so this is one robot I'm using it. You can see on the tail there is the ESP8266. Yes, it's a pony. It's really small, it's like it fits in your hand. The problem is it only has eight digital outputs. I have eight servers in here because this is the mammal configuration, so I don't have eight servers. That's fine. You wouldn't be able to build a spider robot with that. So for robots that have some more servers, I use Arduino as a server controller and just make the ESP8266 talk to it through I2C. That's much easier to do. This is a logicoma from Ghost in the Shell. It's transparent because it's in the cloaking mode, the invisible mode from the movie. And yeah, sensors, put whatever you want there. I won't dive into that. And that's all. Thank you very much. Okay, so we have time for one or two questions. Does anybody have some? So you've managed to use OpenCiggy on Raspberry Pi successfully, like the frame rate at which you could analyze frames. No, no, that's still something I have to explore. And if it's not fast enough, I will probably switch to a Raspberry Pi 3 or maybe try to write my own algorithms or I don't know. But the problem is I really love building physical things, but programming is not as fun. I do it as my day job, so it's not as exciting anymore. So I have a lot of robots that I have built physically and they are still waiting for programming. If anybody wants to, I don't know, collaborate. Hi there, great talk. So I wanted to ask you about the last word. You mentioned the SPA266. Yes. I heard that it's supposed, you can write a script for it in Lua. I don't know about the support for MicroPython. Do you have many issues getting it working? How was your experience with that? So the initial implementation that was done about a year ago by Damian, by the author of MicroPython, it was just a proof of concept done in three days and it was pretty bad. So it worked, it was a proof of concept that it worked, but it wasn't really either stable or very futureful or anything. But recently there was a Kickstarter for rewriting that basically at the beginning of this year. And it was a huge success. They got funded and some more on top of that. And the authors of MicroPython really sat down and rewrote the whole thing from scratch, not really from scratch, but rewrote it properly. And now it's quite stable. It's still experimental in the words of the authors because they are not so much confident in that they got everything exactly right. So I wouldn't put it in a hospital for keeping your grandfather alive, but it should be fine for Hoppe project. And it's really growing fast and a lot of libraries are being written for this by other people, not necessarily the developers themselves. And I hope it will really start nicely. Tomorrow there is an open space for MicroPython and I have some ESPA266 ports with me. Some other people have brought theirs also so we can have some fun with them. So if you are interested in that, please come tomorrow into the open space. Okay, thanks Radomil, please, great talk. Thank you.