00:00:19.359
everyone can you hear me can you hear me at the back is that good great thank you
00:00:25.920
so hi um it's still morning 10 minutes to noon so still good morning and uh
00:00:33.000
welcome to Singapore for our visitors and welcome to the talk I'm going to talk about uh me and shipping we are
00:00:39.480
going to talk about ruby and robots
00:00:45.480
today so can I begin it's okay so let me start by talking a little
00:00:52.359
bit about myself um I work for company called
00:00:57.399
PayPal uh we do payments before this I used to work for HP uh
00:01:03.600
doing some research for HP Labs also work for Yahoo and of course obviously the the
00:01:09.439
reason why I'm here today is because I love Ruby uh I've been doing Ruby about 10 years now so did some recollection I
00:01:16.080
think I started off in 2005 and just so quick is just 10 years now uh I like
00:01:23.119
Ruby so much that I've actually written a few books on Ruby and uh my last book
00:01:29.159
was actually not not exactly about Ruby but it was close enough but uh it was translated into multiple languages so
00:01:35.640
that was pretty cool um so I spoke in this conference since 2011 the first
00:01:44.360
conference uh together with M so I'm glad to be here again and then I've been speaking in 2012 2013 I skipped last
00:01:52.320
year and I'm back this year but I'm back and I brought a a friend with me so let me introduce chip
00:02:03.039
hello can you hear me uh hi there I'm shiping um I'm a
00:02:09.560
software engineer at PayPal as well uh and I uh did my intership at uh Intel
00:02:14.680
before and here are some open source projects I've been working on uh this is
00:02:20.239
uh miniq it is open source Cote copyright design uh and here is Jack duno it is it
00:02:27.959
is a device that you can plug into your mobile phone that uh do data
00:02:33.480
transmission from your audio jack uh and here is cashu uh it is a 3D sketching
00:02:42.280
software okay sorry it's a big award that we have
00:02:48.000
switched back and forth so let me tell you a little bit about um how we came up with the idea in two years ago two years
00:02:56.280
ago uh Jim where was here and he spoke exactly on this stage uh I think it's
00:03:03.040
two weeks exactly will be exactly two years as before the night before we had
00:03:08.560
the uh um conference we had speakers dinner and I sat next to JY during the
00:03:14.040
speakers dinner and we chatted about many different things and one of the things that he showed me and something I
00:03:20.120
want to show you now is this you can't really hear it and it's a
00:03:27.280
bit slow but uh when I first saw this it sort of totally blew me away it was like wow you
00:03:35.200
can actually do that U and of course light bulb started to flash in my mind
00:03:40.799
and said 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
00:03:47.519
um I couldn't make it last year and at the beginning of this year we was thinking what should I do for Ruby com
00:03:54.959
this year. Ruby com this year and then I thought hey you know this is what I saw
00:04:00.200
two years ago with Jim uh while Jim is no longer with us I want to continue the spirit and talk about Hardware uh and
00:04:07.079
talk about robots and this is how we arrive to this talk and this is why I'm
00:04:12.239
here today okay so um in this talk I'm actually going to just go through the
00:04:18.359
Journey about how um we came out with the robot how we EV actually develop the
00:04:24.759
robot and unlike um I think I've seen some robot talks and I think some people talk to me about hey you're not going to
00:04:30.680
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
00:04:35.720
lot of stuff but I'm going to show you how we actually went from almost nothing
00:04:40.960
to actually building the robot and actually um running it right making it work using Ruby so let me start off with
00:04:47.759
the hardware when we came first when I first came up with the idea about doing a
00:04:53.680
robot um I didn't actually want to do a drone because Jim did a drone and uh I
00:04:59.160
know should is actually good in drones right you saw his open source project but I wanted to do something slightly
00:05:04.479
different so we went scouring around the internet to see you know what could we do and um lo and behold I saw on eBay
00:05:12.759
right something like hey this looks cool what can I do with this so as it turns
00:05:18.280
out this is actually a robot frame called to robot is by a Chinese hardware
00:05:24.720
company that specializes in building robot frames so that was pretty nice
00:05:29.800
it's not that expensive as well so wanted to give it a try um as we dug a little bit deeper I saw that actually
00:05:36.240
was a clone of uh another robot company called links motion uh so the specific
00:05:41.560
model is called ly motion Phoenix of course um the Phoenix was actually a
00:05:46.919
little bit more expensive than the torot so the toot is about 133 and the uh
00:05:52.319
Phoenix was close to $800 uh this means that this is the the body as well as the servos the servos are basically the
00:05:58.520
motors that runs the the robots it has no electronics of course but that could come later so I guess there's no
00:06:05.199
question on which one we should actually go for right so uh so we bought the
00:06:10.240
tooot frame and then we went shopping like uh and we went shopping on all
00:06:16.560
kinds of places we went to Du extreme we went to Q10 which is a local uh uh
00:06:22.240
company here eBay RS online selling electronics and we bought a lot of stuff
00:06:27.360
so instead of the U the ones that came with the Phenix we bought the tower Pro mg 995 mg here is the meta gear Servo uh
00:06:35.440
we bought 18 of them because it needs 18 servos to power the uh the the hexapod
00:06:42.120
which is the robot you saw just now it's pretty cheap here $6 whereas the other ones that we bought from links will be
00:06:48.000
about $40 each so we got this um pretty nice and popular
00:06:55.360
Servo to power it we got the 32 Channel servo controller again from tooot it's
00:07:02.160
reasonable PR price um the servo controller has power for the servo
00:07:07.800
controller itself so it actually requires two kinds of Power uh one kind of power for the controller and another
00:07:14.360
type another power for the servo so it needs two power sources then that's the
00:07:20.919
input and output for the controller and of course that's the Jacks for the servos themselves so the
00:07:27.960
power the Sero controller um I got a so occasionally we shop you
00:07:34.120
get premiums right so this is one of the free be I got uh so this Powers the server controller to power the servers
00:07:41.520
themselves um got a battery pack of four
00:07:46.639
double A SI alkaline batteries this cost about $2 is about a dollar for the pack
00:07:52.560
itself and uh $2 two Singapore dollars uh in Daiso we got it the alkaline
00:07:59.520
batteries so this C about $2 we thought okay that's 1,500 milliamp hour is it
00:08:07.080
enough maybe not enough but hey it's just two bucks so let's get three of them right so we got three of
00:08:14.080
them 450 that that should be pretty good so let's start building the the laks now
00:08:22.240
um each Lake actually has three degrees of freedom which means really three
00:08:27.599
servos per L and we model it well this is actually modeled against the legs of
00:08:33.120
an insect which has the Koka the femur and the tbia so we model against the
00:08:40.080
insect leg of and this is how we actually built the legs with the coxa and a
00:08:46.240
femur servos then this is the actual femur and this is the the tiia so we
00:08:53.680
built all these things separately then we put them together so this is the coxa femur and tibia so that's one leg you
00:09:01.519
see each of these leg uh has a Servo with the wires coming out so it sticks
00:09:06.560
out the red and black is for the power and the ground and the Orange is a signal cable that goes
00:09:11.880
in and this is how the leg and the silver controller works together we have
00:09:18.040
the wires sticking into the server controller so now we got the mechanical part of it we have the legs we have the
00:09:24.560
controller able to control the uh the legs we need the brains so what kind of
00:09:29.880
brains we use we use the Raspberry Pi right so at that point in time the Raspberry Pi came out with version two
00:09:35.800
and say hey that's perfect so we got one uh and we attached the Raspberry Pi to
00:09:42.079
the server controller using the GP output so how do we control the how do
00:09:48.480
we control the Raspberry Pi how do we actually communicate the Raspberry Pi um we use the USB Wi-Fi adapter and stuck
00:09:55.560
it on the Rasberry Pi so this is how it works now so we have the raspberry P we have the Sero controller and we have the
00:10:02.720
legs we have everything now so we put it together and more pictures you can see
00:10:10.079
like resembling the the robot and finally we have it it's a little bit
00:10:15.360
messy but hey that's not too bad fully assembled hexapod version one and here you go let me just show you
00:10:22.480
a quick video of it it's coming it's coming coming
00:10:29.839
there you go it it moves that's
00:10:34.920
good next we wanted to make it move more right so it should move more so it needs
00:10:40.079
to move otherwise it can't be a robot so let's make it
00:10:45.360
move okay sort of moving but it's not really
00:10:50.680
going anywhere right so okay what's wrong um it's basically there's not
00:10:56.880
enough power like so we went back we p through the specifications and say hey what's wrong uh we look at the servos
00:11:05.560
themselves it's 400 m Ms when there's no load and one to 2 amps when there's under normal load so we have 12 servos
00:11:13.240
that powers the lake when it's standing up um and six servos that are just not doing anything when it's standing up
00:11:20.040
that comes out to be about 21 amps and the power required for that uh
00:11:26.680
to drive it is 126 Wat right um let's look at what we actually
00:11:33.720
need what we actually have in the double air battery P packs so we have each one of them uh we tested the current and the
00:11:41.120
voltage so we got about seven wats per pack so we have 21 WS so of course it
00:11:48.000
wouldn't work right so yeah screwed up okay that's what it is so we went ahead
00:11:56.079
and and bought another battery uh we went less chipo this time around right so that was two bucks each so we bought
00:12:01.720
this Lio battery Lio is a Lithium Polymer uh battery this is actually used
00:12:07.760
to Power Radio Control Helicopters we bought this about $2 over that's pretty
00:12:13.120
okay not too expensive uh and we calculated we did our calculations again 160 milliamp
00:12:19.560
hours time 20c it's 32 amps and the power we get is 237 wats that's a lot
00:12:26.079
more than 126 wats so yep should work so great let's get it moving so we did
00:12:33.120
some fancy soldering um this is actually me I have not sold it for 22 years so
00:12:39.519
that was my first attempt it actually felt miserably so I got shun to help me to sold it after that so um and then we
00:12:46.399
went ahead and it blew up right so what
00:12:51.839
happened was I connected it there was a Sizzle there's a snap and then smoke started rising from the servos
00:13:00.880
uh so I made a a really really terrible mistake so I thought it was 7.4 amps 7.4
00:13:08.000
volts because it says 7.4 volts of course I did not rtfm because the next
00:13:13.399
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
00:13:21.600
more than the 7.2 Max operating range of the servo I thought 7.4 a little bit more than 7.2 should be okay but it's
00:13:28.120
actually a lot more so um yeah smoke came out the whole thing burned and I
00:13:33.920
lost eight servos like it's just totally demolished like
00:13:41.880
uh screw up that's uh rookie mistake right so went back again did more
00:13:48.880
research and we found a voltage regulator so what a voltage regulator does is it converts a u a power source
00:13:56.639
of higher voltage and converted into a low voltage um we did some more fancy soldering like
00:14:02.680
did some stuff and then went ahead so what else could go wrong right so uh as
00:14:08.920
it turns out the raspberry pie that we got either is because it's just too many tries or it's just lazy handling or
00:14:15.279
didn't not put in whatever it is hardware braks and that was unstable we could not communicate with the Raspberry
00:14:21.759
Pi it um killed the SD card we put in whatever it is it just did not work so
00:14:29.800
yeah that was that was really terrible um but we persisted and thought of a
00:14:37.160
different way of communicating with the the robot now so instead of putting the raspberry pie the brain directly on the
00:14:43.519
robot so what if we actually put the brain somewhere else and communicate
00:14:48.839
with the robot remotely so uh we bought the JY MCU bluo adapter and stuck it to
00:14:55.600
the servo controller instead of having it uh into the Raspberry Pi and then we
00:15:02.519
send signals from the computer through Bluetooth into the server controller like and
00:15:07.759
then here we go let's see how that
00:15:15.639
works so this this is it stands up
00:15:20.759
good and hey it starts moving
00:15:31.120
so flush with this success what we did was uh we went ahead and did some
00:15:36.160
tweaking uh it was actually quite noisy I I did not have the sound here but you know it was
00:15:42.240
like hot metal heating the uh floor it made a huge sound like woke up all the
00:15:48.399
neighbors and everything so paded feet so I plug out some uh rubber padding
00:15:54.480
from your pants and then stuck it as the legs um use some cardboard and build a
00:16:01.319
case and then we have the version three that's the version three stretching his legs there your verion
00:16:07.399
tree ready to go and uh here you go right standing
00:16:14.399
up then slowly strutting his way towards me
00:16:21.120
slowly slowly and no it moves it's pretty good it's not too bad it didn't make the Ruckers it didn't wake up the
00:16:27.279
the neighbors uh my wife wasn't complaining which is good
00:16:41.040
works so that was the hardware so how do we actually control the software let let's see how that works
00:16:48.240
um so as I said earlier on we actually use a computer to send the signals
00:16:53.600
through Bluetooth to the the legs but how does it actually do it um we send it
00:16:59.800
through serial and we send text commands really so the text commands have things
00:17:04.839
like this so uh hash one one is a Servo channel so it has a 32 channels so Servo
00:17:11.120
Channel means that the first channel is SS to um how much to rotate the servo so
00:17:17.039
a Servo is basically a a motor that can only move to a certain degrees given the particular signal sense here is 100 uh
00:17:25.240
100 1,500 uh whatever it is is and there's a rotation between 500 to
00:17:31.880
2,500 uh and then the command after T is the speed from 100 to 9 99,999 so that's
00:17:40.280
controlling one Servo uh to control three servos basically you just string them together and you can string as many as you want
00:17:46.440
to the server controller and the server controller would then trigger off the the ls it's not that complicated so this
00:17:52.240
here is server one server two server three now that's pretty simple enough so
00:17:57.880
to make it even simpler right U built something called Bots it's a simple library for controlling robots U and
00:18:04.679
it's it's pretty simple I'll show it to you later uh so time for some Ruby code so basically we just model the
00:18:11.679
servo initializing it with a number which is a Servo Channel and then we do a rotation the rotation does nothing
00:18:18.440
else but return a string that indicates like the number the servo and how much
00:18:24.120
rotation it should actually do given the degrees and if we Model A Leg as well so
00:18:29.280
each leg is a three degree of Freedom leg initializing with the COA the femur and the tibia which is a Servo each and
00:18:36.000
then we actuate we convert the uh uh the side of the the robot so if it's the
00:18:41.919
left side and the right side it's actually 100 degree difference are 80° difference so we need to convert it and
00:18:47.159
then it just Returns the three strings together that the single string containing the three Sero controls
00:18:53.240
together and that's more code so we have this now but testing the
00:19:01.039
robot was kind of a dicey matter so uh we decided to build a uh physics
00:19:06.960
simulator and uh let me pass it on to shiping now to talk about the
00:19:12.520
simulator hello okay it's working now uh yeah so one of the problems uh we we had
00:19:19.000
when we are developing the hex board was it's not really convenient to test and
00:19:25.600
develop on the real device because hex SP itself is kind of heavy and it's not
00:19:31.720
easy to carry it around and the battery gets drained pretty fast so uh we want
00:19:37.120
to build a physics simulator so that we don't really need the rear device so we
00:19:42.880
can uh just run the simulator on our laptop and uh we can do development on
00:19:49.559
the hexbot on it so we created this uh hex spot same project it is a physics
00:19:56.200
Simulator for hex spots uh you can find the source code and instructions on how to run it uh in this uh giab repo uh so
00:20:04.440
first uh let me do a show a demo video of how this uh simulator Works
00:20:18.120
oops uh so you can send commands uh through TCP Port 5555 so I just do a
00:20:24.799
taet so we can send commands to it uh so the commands we send to the simulator is
00:20:32.559
uh server controller commands uh like the- one p something so once you send
00:20:38.280
the command the uh hexb will move as the command
00:20:45.600
says so now we combine two commands together so you can see both of the legs
00:20:51.039
are moving and also you can drag the robot around to uh see if anything is
00:20:57.200
wrong uh so here is a demo video for hexart same uh and I quickly go through how the
00:21:05.039
simulator is built so first uh we send commands uh like this uh through the TCP
00:21:12.000
port and then uh we will use this command to update the bullet phys uh
00:21:18.360
physics engine and then we uh update the positions and rotations of all the
00:21:24.279
objects we have uh in the uh same uh and it with openg GL so we can visualize the
00:21:33.480
moments uh sorry the simulator is written in C++ uh so here uh is there are four
00:21:40.240
items we need to uh Define for creating a new simulator a first you need to define a world so you can add different
00:21:47.279
objects in it to uh create physics simulation and then you need to Define
00:21:53.159
shapes for each body part and then you you can bind these shapes with uh rigid
00:21:59.799
bodies uh and because uh each servos we have on the hexbot is like a joint so
00:22:07.720
you need to create this uh constraints uh so you need to create a constraint
00:22:13.320
for each joint so the necks are moving uh correctly uh here's the code for how to
00:22:20.320
creating the shapes basically the uh it's the the body part is just a box and
00:22:26.400
the next part is uh capture shapes and here is the code to bind the
00:22:33.559
shapes with uh rigid bodies and next is to add the
00:22:39.720
constraints so uh this is uh a lag of hex sport so it has three axis so what
00:22:47.400
we can do is uh we can add hinge constraints here uh basically you just
00:22:52.799
need to Define uh the uh transformation matrix for the two bodies and then you
00:22:58.840
can add this kind of constraint uh this is uh code for adding
00:23:04.720
the henge constraint and uh now I'll pass it back to Sol for all
00:23:12.559
together so now we have the U we are able to control each one of the servos
00:23:18.640
individually we also able to control the each leg but how do we actually make the
00:23:23.679
robot walk and work properly so we modeled the um hexapod
00:23:30.520
against that of an insect um specifically of an of an ant so we wanted to see how an ant actually walks
00:23:37.120
so um by the way I did not actually take this video of an anend walking like I
00:23:42.960
got it somewhere from YouTube so you notice this is how the ants walks and this is what is known as a tripod gate
00:23:50.080
so it has three legs moving at a time and then it will say three LS first and then the next three LS and then next
00:23:56.360
three LS and next three LS so this this is how it works this is a six Leed
00:24:01.559
tripod gate so a tripod gate for an end is really not a running gate it's actually just a walking gate and that's
00:24:07.720
good enough I suppose for for what we wanted to do so um using this particular diagram we built that uh walking gate
00:24:17.679
and let me just show you the code uh let me just show the actual code here
00:24:30.840
including the include the port um initialize the legs set the
00:24:38.240
channels and then as we move it we set the tripod step one tripod step two Tri
00:24:44.720
step three step four this is a little bit primitive there are other mechanisms of actually moving the robot licks and
00:24:50.399
their algorithms like the inverse kinematics so we actually uh use the simplest way possible that's the most
00:24:56.399
primitive way but it works pretty okay um not as smooth as it it could have
00:25:01.799
been but it Mo it works pretty okay so so that's the hexa port code let me just
00:25:09.880
get back into the
00:25:16.840
slides and then let me just show you how it all works together now with have the code and the simulator this is how it
00:25:24.360
works
00:25:30.799
added in pry so that you can control the simulator directly um you can see here now I get
00:25:37.640
into the simulator I just say walk and the robot
00:25:44.960
walks right uh and then if I say issue
00:25:50.200
it a command another command say all the
00:25:56.159
legs I want to calibrate them so it will calibrate the licks to moving to 90
00:26:01.679
deges each and then say something else I want it to uh tiptoe so it would just stand up
00:26:10.120
right so um now you can control the the simulator using the uh uh the
00:26:18.520
B's Library so this is this is it and actually that's where we just
00:26:24.880
stopped um because the whole duration we spend I think close to 90% of the time
00:26:31.240
on the hardware like we went through a lot of iterations a lot of problems and the software we spent actually not as
00:26:37.159
much time so this really just begun uh and we will be continuing after this there are other things that we
00:26:44.000
actually want to do so previously we're sending commands from the laptop to the robot to control it but we're not giving
00:26:50.799
up on the rest very Pi because I think it's not autonomous until it can actually think on its own and move
00:26:56.279
somewhere else um it requires better servos we bought the cheap servos six
00:27:01.799
bucks each but there is a reason why some of the other servos cost 40 bucks
00:27:07.039
right because they are better servos and we wanted to put in sensors once it's
00:27:12.559
autonomous you can put in sensors then it detect surroundings and uh it wouldn't walk smash into a wall can
00:27:19.279
maybe detect its environment and and walk towards the light or even do what Jim did as to make it follow a
00:27:25.559
particular U sensor or something we want to try other different types of things
00:27:31.159
uh we want to try for bads and we want to try for different kinds of materials as well so as you were doing the
00:27:37.679
hardware and waiting for the new servos to come and so on um try different types of things right so um this is one I call
00:27:46.159
Strider the cardboard quadropad so I built this with cardboard using a
00:27:52.480
slightly different servo
00:27:59.480
and also I built card ball this is bipad robot so this is a lot simpler it's
00:28:05.799
quite fun to build so basically what I did was I took some recycled cardboard and uh I cut it up and I built the foot
00:28:15.039
and the tie string them together attach it to a body uh this is the lower body and then
00:28:22.760
using the same principle basically stick the Sero controller on top and on the legs and it's a video of
00:28:36.360
cardboard so it's stumbling on on uh each other because my cardboard cutting
00:28:42.240
skills are not exactly the best in the world um but it works and uh so far I
00:28:47.600
think that's that's that's what we have today um there are other robot libraries
00:28:54.519
and such as AUST this is the one that Jim did and and R2 as well um which is
00:29:00.440
actually an excellent library to control robots and this is something that I've tried as well but before I go I just
00:29:08.039
wanted to show the real life demo if you can just turn on the liks
00:29:19.480
please I hope this works I hit live demo it's like almost
00:29:25.679
never works for me
00:29:35.320
okay it's too fast okay oops sorry it's still showing the sorry
00:29:44.399
sorry uh I need to change the code a
00:29:50.039
bit so this guy is using the simulator I just need to make sure it goes to this
00:29:58.399
guy so let me run it
00:30:05.159
again my controller
00:30:10.600
okay it's connecting with the robot hopefully it's Works hopefully it doesn't fall off the
00:30:16.679
age