 It's still morning, 10 minutes to noon, so still good morning. And welcome to Singapore for our visitors and welcome to the talk. I'm going to talk about me and Shupin, we're going to talk about Ruby and Robots today. So can I begin? It's okay. So let me start by talking a little bit about myself. I work for a company called PayPal. We do payments. Before this, I used to work for HP, doing some research for HP Labs. Also work for Yahoo. And of course, obviously the reason why I'm here today is because I love Ruby. I've been doing Ruby about 10 years now. So did some recollection, I think I started off in 2005. It's just so quick, it's just 10 years for now. I like Ruby so much that I've actually written a few books on Ruby. And my last book was actually not exactly about Ruby, but it was close enough. But it was translated into multiple languages, so that was pretty cool. So I spoke in this conference since 2011, the first conference, together with Mark. So I'm glad to be here again. I've been speaking in 2012, 2013, I skipped last year and I'm back this year. But I'm back and I brought a friend with me. So let me introduce Shippong. Hello, can you hear me? Hi there, I'm Shippong. I'm a software engineer at PayPal as well. And I did my internship at Intel before. And here are some open source projects I've been working on. This is MiniQ. It is an open source quadcopterite design. And here is Jack Duno. It is a device that you can plug into your mobile phone that do data transmission from your audio jack. And here is Cashew. It is 3D sketching software. Sorry, it's a bit awkward that we have switched back and forth. So let me tell you a little bit about how we came up with the idea. In two years ago, Jim Warrick was here and he spoke exactly on this stage. I think it's two weeks exactly, it will be exactly two years. As before, the night before we had the conference, we had speakers dinner. And I sat next to Jim during the speakers dinner and we chatted about many different things. And one of the things that he showed me and something I want to show you now is this. You can't really hear it and it's a bit slow. But when I first saw this, it sort of totally blew me away. It was like, wow, you can actually do that. And of course Lightbulb started to flash in my mind and say, look, I got to do this and I wanted to try it. So last year I wanted to try something like this, but of course I couldn't make it last year. And at the beginning of this year, I was thinking, what should I do for RubyConf this year? And then I thought, hey, this is what I saw two years ago with Jim while Jim is no longer with us. I want to continue the spirit and talk about hardware and talk about robots. And this is how we arrived to this talk and this is why I'm here today. Okay, so in this talk, I'm actually going to just go through the journey about how we came out with the robot, how we've actually developed the robot. And unlike, I think I've seen some robot talks and I think some people talk to me about, hey, you're not going to talk about robots and you're not going to actually do a lot of stuff. So true enough, I'm actually not going to do a lot of stuff, but I'm going to show you how we actually went from almost nothing to actually building the robot and actually running it, making it work using Ruby. So let me start off with the hardware. When I first came up with the idea about doing a robot, I didn't actually want to do a drone because Jim did a drone and I know Shupang was actually good in drones. You saw his open source project, but I wanted to do something slightly different. So we went scouring around the internet to see what could we do and lo and behold, I saw on eBay something like, hey, this looks cool. What can I do with this? So as it turns out, this is actually a robot frame called Torobot is by a Chinese hardware company that specializes in building robot frames. So that was pretty nice and it's not that expensive as well. So I wanted to give it a try. As we dug a little bit deeper, I saw that actually has a clone of another robot company called LynxMotion. So the specific model is called LynxMotion Phoenix. Of course, the Phoenix was actually a little bit more expensive than the Torobot. So the Torobot is about $173 and the Phoenix was close to $800. So this means that this is the body as well as the servos. The servos are basically the motors that runs the robots. It has no electronics, of course, but that could come later. So I guess there's no question on which one we should actually go for. So we bought the Torobot frame and then we went shopping. And we went shopping on all kinds of places. We went to Dew Xtreme, we went to Qtan, which is a local company here, eBay, RS Online, selling electronics. And we bought a lot of stuff. So instead of the ones that came with the Phoenix, we bought the Tower Pro MG995. MG here is the Metal Gear servo. We bought 18 of them because it needs 18 servos to power the Hexapot, which is the robot you saw just now. It's pretty cheap here, $6, whereas the other ones that we bought from Lynx will be about $40 each. So we got this. Pretty nice and popular servo. To power it, we got the 32-channel servo controller. Again, from Torobot. It's reasonable price. The servo controller has power for the servo controller itself. So it actually requires two kinds of power. One kind of power for the controller and another power for the servo. So it needs two power sources. Then that's the input and output for the controller. And of course, that's the jacks for the servos themselves. So to power the servo controller, I got a... So occasionally if we shop, you get freemiums. So this is one of the freebies I got. So this powers the servo controller. To power the servos themselves, we got a battery pack of four double ASI's alkaline batteries. This costs about $2. It's about $1 for the pack itself and $2, $2 Singapore dollars in Daiso. We got the alkaline batteries. So this comes about $2. We thought, okay, that's 1500 milliamps per hour. Is it enough? Maybe not enough, but hey, it's just $2. So let's get three of them. So we got three of them. 450. That should be pretty good. So let's start building the legs now. Each leg actually has three degrees of freedom, which means really three servos per leg. And we model it... Well, this is actually model against the legs of an insect, which has the coxa, the femur, and the tibia. So we model against the insect leg. And this is how we actually build the legs with the coxa and femur servos. Then this is the actual femur and this is the tibia. So we build all these things separately, then we put them together. So this is the coxa, femur, and tibia. So that's one leg. You see each of this leg has a servo with the wires coming out. So it sticks out. The red and black is for the power in the ground and the orange is the signal cable that goes in. And this is how the leg and the servo controller works together. We have the wires sticking into the servo controller. So now we got the mechanical part of it. We have the legs. We have the controller able to control the legs. We need the brains. So what kind of brains do we use? We use the raspberry pi. So at that point in time, the raspberry pi came out with version 2. Say, hey, that's perfect. So we got one and we attached the raspberry pi to the servo controller using the GPIO output. So how do we control the raspberry pi? How do we actually communicate the raspberry pi? We use the USB Wi-Fi adapter and stuck it on the raspberry pi. So this is how it works now. So we have the raspberry pi. We have the servo controller and we have the legs. We have everything now. So we put it together. More pictures. You can see, like, resembling the robot. And finally, we have it. It's a little bit messy, but hey, that's not too bad. Fully resemble Hexapod version 1. And here you go. Let me just show you a quick video of it. It's coming, it's coming, coming. There you go. It moves. That's good. Next, we wanted to make it move more, right? So it should move more. So it needs to move. Otherwise, it can't be a robot. So let's make it move. Okay. Sort of moving, but it's not really going anywhere, right? So, okay. What's wrong? It's basically there's not enough power. So we went back. We pour through the specifications and say, hey, what's wrong? We look at the servos themselves. It's 400 milliamps when there's no load and 1 to 2 amps when there's under normal load. So we have 12 servos that powers the leg when it's standing up and 6 servos that are just not doing anything when it's standing up. That comes out to be about 21 amps. And the power required for that to drive it is 126 watts, right? Let's look at what we actually need, what we actually have in the AA battery packs. So we have each one of them. We tested the current and the voltage. So we got about 7 watts per pack. So we have 21 watts. So, of course, it wouldn't work, right? So, yeah, screwed up. Okay, that's what it is. So we went ahead and bought another battery. We went less cheapo this time round, right? So that was $2 each. So we bought this LiPo battery. LiPo is lithium polymer battery. This is actually used to power radio control helicopters. We bought this about $20. It's pretty okay. Not too expensive. And we calculated, really, our calculations again. 160 mAh x 20C. It's 32 amps. And the power we get is 237 watts. Well, that's a lot more than 126 watts. So, yep, should work. So, great. Let's get it moving. So we did some fancy soldering. This is actually me. I have not soldered for 22 years. So that was my first attempt. It actually failed miserably. So I got shipwreng to help me to soldered after that. And then we went ahead. It blew up. So what happened was I connected it. There was a sizzle. There's a snap. And then smoke started rising from the ear servos. So I made a really, really terrible mistake. So I thought it was 7.4 amps, 7.4 volts because it says 7.4 volts. Of course, I did not RTFM because the next line says actually it is not two cells. It's a three cell battery. So it's 11.1 volts. And 11.1 volts is definitely a lot more than the 7.2 max operating range of the servo. I got 7.4, a little bit more than 7.2. It should be okay, but it's actually a lot more. So, yep, smoke came out. The whole thing burned. And I lost eight servos. It's just totally demolished. Screw up. That's a rookie mistake. So, went back again, did more research and we found a voltage regulator. So what a voltage regulator does is it converts a power source of high voltage and convert it into a low voltage. We did some more fancy soldering. So I did some stuff and then went ahead. So what else could go wrong, right? So as it turns out, the Raspberry Pi that we got either is because it's just too many tries or it's just lazy handling or I did not put it. Whatever it is, hardware breaks and that was unstable. We could not communicate with the Raspberry Pi. It killed the SD card we put in. Whatever it is, it just did not work. So, that was really terrible. But we persisted and thought of a different way of communicating with the robot now. So instead of putting the Raspberry Pi in the brain directly on the robot, so what if we actually put the brain somewhere else and communicate with the robot remotely? So, we bought the JYMCU Bluetooth adapter and stuck it to the server controller instead of having it into the Raspberry Pi. And then we send signals from the computer through Bluetooth into the server controller. And then, here we go. Let's see how that works. This is it. It stands up. Good. Eh, it starts moving. So, flush with this success what we did was we went ahead and did some tweaking. It was actually quite noisy. I did not have the sound here but it was like hard metal heating the floor. It made a huge sound. Like woke up all the neighbors and everything. So, padded feet. So, I plug out some rubber padding from your pens and then stuck it as the legs. Use some cardboard and build a case. And then, we have the version tree. That's the version tree stretching its legs. That's the version tree ready to go. And here you go. Like standing up. Then, slowly strutting its way towards me. Slowly, slowly. And now, it moves. It's pretty good. It's not too bad. It didn't make a ruckus. It didn't wake up the neighbors. My wife wasn't complaining. It was just good. Then... So, it's hello world robot. And it works. So, that was the hardware. So, how do we actually control the software? Let's see how that works. So, as I said earlier on, we actually use a computer to send the signals through Bluetooth to the legs. But how does it actually do it? We send it through serial and we send text commands, really. So, the text commands have things like this. So, hash 1. 1 is a servo channel. So, it has a 32 channel. So, a servo channel means that the first channel is sent to. How much to rotate a servo? So, a servo is basically a motor that can only move to a certain degrees given the particular signal is sent. Here is 100... 100... 1500... whatever it is. And there's a rotation between 500 to 2500. And then the command after T is the speed from 100 to 9,999. So, that's controlling one servo. To control three servos, basically, you just string them together and you can string as many as you want to the servo controller. And the servo controller would then trigger off the legs. It's not that complicated. So, this here is servo 1, servo 2, servo 3. Now, that's pretty simple enough. So, to make it even simpler, build something called bots, simple library for controlling robots. And it's pretty simple. I'll show it to you later. So, time for some Ruby code. So, basically, we just model the servo, initialising it with a number, which is a servo channel. And then we do a rotation. The rotation does nothing else but we turn the string that indicates like the number to servo and how much rotation it should actually do given the degrees. And then we model a leg as well. So, each leg is a degree of freedom leg initialising with the coxa, the femur, and the tibia, which is a servo each. And then we actually convert the side of the robot. So, if it's the left side and the right side, there's actually 100 degree difference, 180 degree difference. So, we need to convert it. And then it just returns the three strings together. The single string containing the three servo controls together. And that's more code. So, we have this now. But testing the robot was kind of a dicey matter. So, we decided to build a physics simulator. And let me pass it on to Sipeng now to talk about the simulator. Hello? Okay, it's working now. Yeah, so one of the problems we had when we were developing the export was it's not really convenient to test and develop on the real device because export itself is kind of heavy and it's not easy to carry it around. And the battery gets drained pretty fast. So, we want to build a physics simulator so that we don't really need the real device. So, we can just run the simulator on our laptop and we can do development on the export on it. So, we created this Hackspot same project. It is a physics simulator for Hackspots. You can find the source code and instructions on how to run it in this GitHub repo. So, first, let me do show a demo video of how this simulator works. So, you can send commands through TCP port 5555. So, I just do a telnet so we can send commands to it. So, the commands we send to this simulator is server controller commands like the dash 1p something. So, once you send the command the Hackspot will move as the command says. So, now we combine two commands together so you can see both of the legs are moving and also you can drag robot around to see if anything is wrong. So, here is a demo video for Hackspot same. And quickly go through how the simulator is built. So, first, we send commands like this through the TCP port and then we will use this command to update the bullet physics engine and then we update the positions and rotations of all the objects we have in the same and render it with OpenGL so we can visualize the moments. Sorry, the simulator is written in C++. So, here is there are four items we need to define for creating a new simulator. First, you need to define a world so you can add different objects in it to create physics simulation and then you need to define shapes for each body part and then you can bind the shapes with rigid bodies and because each servos we have on the Hackspot is like a joint so you need to create this constraints so you need to create a constraint for each joint so the legs are moving correctly. Here is the code for how to create in the shapes. Basically the body part is just a box and the legs part is capsule shapes and here is the code to bind the shapes with rigid bodies and next is to add the constraints so this is a lack of Hackspot so it has three axis so what we can do is we can add hinge constraints here basically you just need to define the transformation matrix for the two bodies and then you can add this kind of constraints and this is the code for adding the hinge constraints and now I'll pass it back to Sasha for all together. So now we are able to control each one of the servos individually we are also able to control each leg but how do we actually make the robot walk and walk properly? So we model the Hackspot against that of an insect specifically of an ant so we wanted to see how an ant actually walks so by the way I did not actually take this video of an ant walking like I got it somewhere from YouTube so you notice this is how the ants walks and this is what is known as a tripod gate so it has a treelix moving at the time and then it was a treelix first and then the next treelix and then the next treelix and next treelix so this is how it walks this is a six-legged tripod gate so a tripod gate for an ant is really not a running gate it's actually just a walking gate and that's good enough I suppose for what we wanted to do so using this particular diagram we built that walking gate and let me just show you the code let me just show the actual code here so include the pod initialize the legs set the channels and then as we move it we set the tripod step one tripod step two tripod step three step four this is a little bit primitive there are other mechanisms of actually moving the robot legs and there are algorithms like the inverse kinematics so we actually use the simplest way possible that's the most primitive way but it works pretty okay not as smooth as it could have been but it works pretty okay so that's the hexapod code let me just get back into the slides and then let me just show you how it all works together now with the code and the simulator this is how it works edit in pry so that you can control the simulator directly you can see here now I get into the simulator I just say walk and the robot walks and then if I say I issue it a command another command say all the legs I want to calibrate them so it will calibrate the legs to moving to 90 degrees each and then say something else I want it to tiptoe so it will just stand up like so now we can control the simulator using the bot's library so this is it and actually that's where we just stopped because the whole duration so we spent I think close to 90% of the time on the hardware we went through a lot of iterations and a lot of problems and the software we spent just really not as much time so it really just begun and we will be continuing after this there are other things that we actually want to do so previously we were sending commands from the laptop to the robot to control it but we're not giving up on the rest of the pry because I think it's not autonomous until it can actually think on its own and move somewhere else it requires better servos we bought the cheap servos 6 bucks each but there is a reason why some of the other servos cost 40 bucks because they are better servos and we wanted to put in sensors once it's autonomous you can put in sensors then you can detect the surroundings and it wouldn't walk smash into a wall can maybe detect its environment and walk towards the light or even do what Jim did as to make it follow a particular sensor or something we want to try other different types of things we want to try for bipads and we want to try for different kinds of materials as well so as you were doing the hardware and waiting for the new servos to come and so on try different types of things so this is what I call strider the cardboard quadruped so I built this with cardboard using a slightly different servo also I built cardboard and this is bipad robot so this is a lot simpler it's quite fun to build so basically what I did was I took some recycled cardboard and I cut it up and I built the foot and the tie string them together attach it to a body this is the lower body and then doing the same principle basically stick the servo controller on top and on the legs and it's a video of cardboard so it's stumbling on each other because my cardboard cutting skills are not exactly the best in the world but it works and so far I think that's that's what we have today there are other robot libraries such as Argus this is the one that Jim did and R2 as well which is actually an excellent library to control robots and this is something that I've tried as well but before I go I just wanted to show the real life demo if you can just turn on the lights please I hope this works I hit live demo almost never works on me it's too fast oops sorry it's still showing date sorry I need to change the code a bit so this guy as using the simulator I just need to make sure it goes to this guy so let me run it again it's connecting with the robot hopefully it works hopefully it doesn't fall off the edge thank you