• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
A survey of robotics in Ruby
 

A survey of robotics in Ruby

on

  • 1,545 views

Basics of Ruby and Robitcs

Basics of Ruby and Robitcs

Statistics

Views

Total Views
1,545
Views on SlideShare
1,450
Embed Views
95

Actions

Likes
1
Downloads
0
Comments
0

3 Embeds 95

https://twitter.com 52
http://eventifier.co 42
http://www.conferize.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution-ShareAlike LicenseCC Attribution-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    A survey of robotics in Ruby A survey of robotics in Ruby Presentation Transcript

    • A Survey of Roboticsin RubyJosh Adams | @knewterAdam Dill | @adamdillSaturday, June 15, 13AThis is Josh Adam from Isotope 11I am Adam DIll from Inside.comAnd how can it not be fun, were talking about robots!
    • This talk has two parts• Survey / knowledge dump• Project narrativeSaturday, June 15, 13J:This talk has a couple of parts. The first one is really just a braindump - lots of good information on the library landscape.After that, we’ll dig into building a project together
    • Part the firstA Survey of Robotics with RubySaturday, June 15, 13ASo lets dive into the survey so you guys can see what is out there
    • Robots?• A machine capable of carrying out a complex series of actionsautomatically.• (esp. in science fiction) A machine resembling a human beingand able to replicate certain human movements andfunctions.• Robotics: The branch of technology that deals with thedesign, construction, operation, and application of robots.Saturday, June 15, 13A:What is a robot?a robot is a force multiplier, it lets you take a simple action and cause a cascade of more complex decisions and actionsJOSH
    • Robots?• A machine capable of carrying out a complex series of actionsautomatically.• (esp. in science fiction) A machine resembling a human beingand able to replicate certain human movements andfunctions.• Robotics: The branch of technology that deals with thedesign, construction, operation, and application of robots.LAMESaturday, June 15, 13
    • ROBOTS!!!1!!!one!http://www.flickr.com/photos/torek/3788181603/Saturday, June 15, 13JWe all know what robots are, right? They’re awesome
    • State of Hobby Robotics• Growing rapidly• lots of good mags• My 3 favorites =>• Costs have fallen• Getting really approachableSaturday, June 15, 13Amass production of sensors for phones has made this affordablewhile the maker movement has made this approachable approachablegreat references are available, make first among them
    • State of Hobby Roboticswith Ruby• http://artoo.io/ - Sinatra for Robots• https://github.com/hparra/ruby-serialport/• http://www.rock-robotics.org - heavily c based, wiredtogether with Ruby• right now, Python is better, and certainly more active, andmore mature• long term, Ruby is a great choiceSaturday, June 15, 13AArtoo is like sinatra for Robotics. It’s definitely leading the pack right now.Serialport is an easy way to use serial devices, but there are some baud rate issues.Rock robotics is mostly C-based, but wired together with RubyPython’s presently outpacing us in robots, but Ruby is the future.JWhy is Ruby such a good choice, Adam?
    • Why is Ruby a great choice?• All the normal reasons Ruby is great• DSLs• Metaprogramming• Developer happinessSaturday, June 15, 13AAll the normal reasons:DSLs, Metaprogramming, and you can have fun *writing* your robots, not just playing with them.
    • Artoo.io ExampleSaturday, June 15, 13JSo we aren’t going to dig into artoo too much, but it’s definitely worth checking out.Artoo’s awesome and provides a common interface for variousdevices. It’s really made for controlling toys, which is fun andan easy way to start.It also gives you an easy way to roll a web API interface for your system.(It also uses Celluloid, which is easily my favorite Ruby library)
    • Where to start?• Get easy wins early:• Sphero - about $130• Parrot ARDrone - about $150 refurbSaturday, June 15, 13ADon’t start with a giant projectIt’s very easy to get bogged down in a small hardware problem (resistor values, etc)JWhen should I learn Ohm’s Law, etc?ARight. So make sure to get some easy wins up front to help keep yourself motivated.I suggest you buy either a sphero or a Parrot ARDrone and just play with it.
    • Sphero• http://www.gosphero.com/• Bluetooth enabled ball• drives itself around• best dog toy ever• waterproofSaturday, June 15, 13AThis is a sphero. It’s basically just a ball with a motor inside of it.It’s bluetooth-controlled (via serialport), it’s a lot of fun and really simple.These are great for someone just learning to program to see real-world results of the code they’re typing, so it’d be good forteaching kids and keeping them engaged.There are some great KidsRuby Artoo resources for the Sphero
    • Sphero with RubySaturday, June 15, 13ACool Sphero gems, and artoo supports it.You can see we’re just giving it a speed and a direction. It doesn’t get much simpler than this.(DEMO)
    • Saturday, June 15, 13AHere’s an example of using Artoo to control an armada (fleet?) of spherosWhat’s cool here is you can see how multitasking works with this evented architecture.
    • Parrot ARDrone• http://ardrone2.parrot.com/• Acts as its own wifi AP• Connect to it over wifi, it’sjust a device with an IP• Send UDP packets to it• Stream video from 2camerasSaturday, June 15, 13JSo the other easy toy is the Parrot ARDrone. This guy creates his own WiFi access point that you connect to, then you can justsend him UDP packets to control him. He’s also got a couple of video cameras.Like we said, it’s $150 for a refurb and you can get a new one for around $250
    • Parrot ARDroneSaturday, June 15, 13JJim Weirich wrote the `argus` gem to control it via RubyArtoo supports it(DEMO)
    • Rolling your own• What if you don’t want a ball or a quadcopter? What if youwant to be master of your own fate?Saturday, June 15, 13JSo now you’ve got your easy wins and you’re still interested. What’s next?
    • MicrocontrollersA microcontroller is a small computer ona single IC containing a processor,memory, and programmable I/O. -wikipediaSaturday, June 15, 13AMicrocontrollers are essentially tiny computers. The real keys are they are on a single board, and have I/O.
    • Microcontrollers!!!!!11!!!wtfbbqhaxSaturday, June 15, 13JThe arduino showed up right around the same time Make magazine did, and they had a huge impact on hobbyists (though peoplethat were doing microcontrollers before that will hate me for saying that). Still, it’s only a 16MHz device with virtually no storage,no networking, and it had to be programmed in C. Now we have a whole range of options, from the Beaglebone Black to thePCDuino, which offers a 1GHz chip, 1GB of RAM, a Mali 400 GPU, and an Arduino-compatible pinout (so you can take advantageof existing shields). Those are both far more expensive and power hungry than the almighty Raspberry Pi, though. With a RasPi,you get 700MHz, 512MB RAM, and networking for $35, as well as lots of GPIO to hook into. It just really hits a sweet spot.
    • Microcontrollers!!!!!11!!!wtfbbqhaxArduinoSaturday, June 15, 13JThe arduino showed up right around the same time Make magazine did, and they had a huge impact on hobbyists (though peoplethat were doing microcontrollers before that will hate me for saying that). Still, it’s only a 16MHz device with virtually no storage,no networking, and it had to be programmed in C. Now we have a whole range of options, from the Beaglebone Black to thePCDuino, which offers a 1GHz chip, 1GB of RAM, a Mali 400 GPU, and an Arduino-compatible pinout (so you can take advantageof existing shields). Those are both far more expensive and power hungry than the almighty Raspberry Pi, though. With a RasPi,you get 700MHz, 512MB RAM, and networking for $35, as well as lots of GPIO to hook into. It just really hits a sweet spot.
    • Microcontrollers!!!!!11!!!wtfbbqhaxBeagleboneBlackArduinoSaturday, June 15, 13JThe arduino showed up right around the same time Make magazine did, and they had a huge impact on hobbyists (though peoplethat were doing microcontrollers before that will hate me for saying that). Still, it’s only a 16MHz device with virtually no storage,no networking, and it had to be programmed in C. Now we have a whole range of options, from the Beaglebone Black to thePCDuino, which offers a 1GHz chip, 1GB of RAM, a Mali 400 GPU, and an Arduino-compatible pinout (so you can take advantageof existing shields). Those are both far more expensive and power hungry than the almighty Raspberry Pi, though. With a RasPi,you get 700MHz, 512MB RAM, and networking for $35, as well as lots of GPIO to hook into. It just really hits a sweet spot.
    • Microcontrollers!!!!!11!!!wtfbbqhaxBeagleboneBlackArduinoPCDuinoSaturday, June 15, 13JThe arduino showed up right around the same time Make magazine did, and they had a huge impact on hobbyists (though peoplethat were doing microcontrollers before that will hate me for saying that). Still, it’s only a 16MHz device with virtually no storage,no networking, and it had to be programmed in C. Now we have a whole range of options, from the Beaglebone Black to thePCDuino, which offers a 1GHz chip, 1GB of RAM, a Mali 400 GPU, and an Arduino-compatible pinout (so you can take advantageof existing shields). Those are both far more expensive and power hungry than the almighty Raspberry Pi, though. With a RasPi,you get 700MHz, 512MB RAM, and networking for $35, as well as lots of GPIO to hook into. It just really hits a sweet spot.
    • Microcontrollers!!!!!11!!!wtfbbqhaxBeagleboneBlackArduinoPCDuinoRaspberry PiSaturday, June 15, 13JThe arduino showed up right around the same time Make magazine did, and they had a huge impact on hobbyists (though peoplethat were doing microcontrollers before that will hate me for saying that). Still, it’s only a 16MHz device with virtually no storage,no networking, and it had to be programmed in C. Now we have a whole range of options, from the Beaglebone Black to thePCDuino, which offers a 1GHz chip, 1GB of RAM, a Mali 400 GPU, and an Arduino-compatible pinout (so you can take advantageof existing shields). Those are both far more expensive and power hungry than the almighty Raspberry Pi, though. With a RasPi,you get 700MHz, 512MB RAM, and networking for $35, as well as lots of GPIO to hook into. It just really hits a sweet spot.
    • Raspberry PiThe Raspberry Pi is a credit-card sized computer that plugsinto your TV and a keyboard.It’s a capable little PC whichcan be used for many of thethings that your desktop PCdoes, like spreadsheets, word-processing and games. It alsoplays high-definition video.Saturday, June 15, 13AJosh will go ahead and pass around the Pi[run through ports]
    • RaspberryPi Setup• dd image to memory card• plug it all up (power last)• about a dozen setup questions• Debian LXDE setup (lightweight x11)• can also run Arch• straight console if thats all you wantSaturday, June 15, 13Asetup is really easy, dd takes about 30 min, but other than that your running in under 15 min
    • RaspberryPi:Running Ruby• install RVM normally• install  ruby via rvm• takes a long time to compile• 1.9.3 seems to work better, mostly due to compile times andgem compatibility• expect this to change in the coming monthsSaturday, June 15, 13((Josh setup RC car))AGetting ruby running is about as easy, I used RVM, compile takes a few hours1.9.3 seems to be the best right now, I expect this will change soon
    • RaspberryPi GPIO and Tips• be careful with the Pi, need buffering, grab some transistorsor a ULN2003 to protect it.• limited hardware PWM out of the box (1, shared with audio).  We’ll get you around that limitation a little later.• You need at least a 1-amp power supply, and you probablywant a powered USB hub if you want more than kb/mouse.Saturday, June 15, 13A
    • RaspberryPi Tips (cont)• Get a Pi Cobbler breakout board to make your life easier• Cirago wifi/bluetooth dongle for $11, works great• Buy a nice case (or 3d print one :D :D :D)• Use a class 10 SD card if you can. dd is *slooooow* on a badcard.• There’s a camera module for $25.Saturday, June 15, 13Aexplain pi cobbler is the ribbon cable attached to the one going around, it makes breadboarding easiercirago wifi/bluetooth seems to work great for basic IO and is low poweredcases keep you from shorting it out, i put some heatsinks so i can overclock mine a bitclass 10 sd cards are great, makes dd faster, and UX faster
    • GPIO Examplesusing pi_piper gem, see: https://github.com/jwhitehorn/pi_piperEvent driven Raspberry Pi GPIO programming in RubySaturday, June 15, 13J
    • InputSaturday, June 15, 13J
    • OutputSaturday, June 15, 13J
    • Control schemes• Serial Ports• Connection Types• Bluetooth• USB• GPIO• Or my favorite, straight DRb over the networkSaturday, June 15, 13Alots of ways to control hardware, serial ports you ust write too like appending to a text file, can attach over bluetooth usb or gpio(J interupts)DRB
    • Part the secondBuilding something neatSaturday, June 15, 13J
    • Rubotnik(This slide intentionallyleft dumb)Saturday, June 15, 13J
    • So you have a RasPi• We made it blink earlier with `pi_piper`• What’s the next quick win we can get?• (note: most of the upcoming code is super quick-n-dirty)• Our goal is just to demystify this stuff - none of this code isbeyond a Ruby Nuby.Saturday, June 15, 13ASo we got some easy wins with the toys earlier, and we took a microcontroller and made an LED blinkWhat is our next steps?Going forward we have a lot of quick code, goal isn’t to provide code examples but to demystify how this works. No magic here.
    • Twitter-powered blinkenlightsSaturday, June 15, 13J
    • Saturday, June 15, 13J
    • That was cool. Now what?• How’s about some more direct control?• Android -> JRuby <- DRb -> MRI -> RasPi -> BlinkenlightSaturday, June 15, 13ASo all this is cool, but how can we get into some more direct control of robots?talk through adding android and DRBJSomething about how awful writing custom protocols iscompared to DRb
    • Saturday, June 15, 13JThis is the pickaxe example of DRb objects basically, completely standard...talk through class briefly
    • So now android?• Eww, java• Not the worst thing in the world• Tiny codeSaturday, June 15, 13JYou came to this conference looking for Java code and we know it.
    • Saturday, June 15, 13JThis interface is literally just a button
    • Saturday, June 15, 13JI don’t think this is scary Java code, but it has lots of things I learned about jruby that will be helpful
    • Use JRuby jars from ruboto projectSaturday, June 15, 13J
    • ...or JRuby asplodeSaturday, June 15, 13J
    • if you don’t add stdlib to loadpathyou spend three days cryingSaturday, June 15, 13J
    • AsyncTask because no networkon main thread (also, you needthe INTERNET permission for DRb)Saturday, June 15, 13J
    • Cat’ing ruby strings together.With globals for control flow.Nothing unusual here.Move along.Saturday, June 15, 13J
    • Saturday, June 15, 13
    • RGB LEDSaturday, June 15, 13AWhat’s the next obvious step past a single red led?A single RGB LED. Let’s make it happen
    • RGB LED• So now we have an LED, so what’s the next simplest way toratchet up?Saturday, June 15, 13AWhat’s the next obvious step past a single red led?A single RGB LED. Let’s make it happen
    • RGB LED• So now we have an LED, so what’s the next simplest way toratchet up?• RGB LED, controlled by a color picker on the android device,that changes color in realtime.Saturday, June 15, 13AWhat’s the next obvious step past a single red led?A single RGB LED. Let’s make it happen
    • RGB LED• So now we have an LED, so what’s the next simplest way toratchet up?• RGB LED, controlled by a color picker on the android device,that changes color in realtime.• Problem: RGB LED requires analog levels, but we only havedigital with pi_piper.Saturday, June 15, 13AWhat’s the next obvious step past a single red led?A single RGB LED. Let’s make it happen
    • Pulse Width ModulationSaturday, June 15, 13ASo you can use PWM to simulate analog levels, but you’re really just switching them on and off. If an output is switched on 10% ofthe time, evenly distributed, then it makes an LED look like it’s been sent a 10% max output signal.Later we’ll use them for logic level stuff, but for now we’ll just treat PWM like fake-analog.
    • Pulse Width Modulation• RasPi only has one hardware PWM pin, and it’s shared withthe audio output (so you can’t use PWM and play sound at thesame time)• So you can run pi-blaster to get 8 PWM outputs. It’s auserland driver that hooks into the true PWM pin’s interruptand uses it to drive any GPIO pin like it’s PWM• https://github.com/sarfata/pi-blaster/Saturday, June 15, 13Jpi-blaster, up to 8 PWM
    • Pulse Width Modulation• To completely turn off pin1:echo "1=0" > /dev/pi-blaster• To completely turn on pin1:echo "1=1" > /dev/pi-blaster• To set pin1 to a PWM of 20%echo "1=0.2" > /dev/pi-blasterSaturday, June 15, 13AHere’s how you use pi-blaster - everything’s just a file, and you write commands to it
    • Saturday, June 15, 13JHere’s a really basic class representing our rgb led. I’m just showing the red channel code here.
    • This class is actuallylike 200 lines long :-Saturday, June 15, 13JIf we’d used any metaprogramming at all here, it’d have been much smaller. I promised quick-n-dirty code right?
    • Buuuuut• Turns out that most RGB LEDs expect the common leg to behigh, and the channel-specific legs to be a modulated ground(our code assumed the common leg would be ground)• Luckily, Ruby’s awesome so when I ran into this when testingit took all of three seconds to fix it up. NOTE: I also had torun the 3.3V line to the common leg, then you’re justmodulating the difference (so 100% duty cycle for a given legmeans no voltage potential difference, or ‘off’)Saturday, June 15, 13J
    • ZOMGSaturday, June 15, 13JHey hey, object oriented programming is awesome.Anyway, let’s go ahead and see what the android interface for this project looks like
    • Saturday, June 15, 13AJust a basic color picker, nothing fancy here. As you change the slider, we want the led updating in real time
    • Saturday, June 15, 13JMore java code. Last time we ran code each time you hit a button, but now we have a slider. At first I ran code on each changeevent from the slider, but it turns out DRb can’t handle 200 messages/second and it would get laggy.
    • Timer Task that fires 20 timesper second. That seems to bea sweet spot.Saturday, June 15, 13JSo my solution to this is to sample the UI 20x/second and send a message over DRb each time
    • If you’re going this route, have a singlemethod that accepts the state of theUser Interface. Then handle it onthe server side (rather than multiplemessages, one per user interfacecomponent)Saturday, June 15, 13JI found out later that apparently that’s what RC Controllers in the real world do anyway, so that was serendipitous. So there’sbasically all the code, how well does it work?
    • Saturday, June 15, 13JPretty darn well....
    • So what’s next?• Let’s finish this project up with somethingfun.• You go to the thrift store, and you buy oneof these bad boys for $2. This is the wayto go for this stuff by the way - there’s aTON of old toys waiting to be awesomeagain.• Tank steering R/C base - this is the RAD2.Saturday, June 15, 13AAlright, so we’ve got PWM control of a ruby process from android now. What next?Let’s finish up by building an RC Tank steering thingie...bullet points...
    • Speed Construction• Take a Sabertooth 2x12RC ($65)• Add a RasPi• Add a 12V battery• Add a cirago wifi/bt stick• Mutilate a usb micro cableSaturday, June 15, 13JPut all this stuff together aaaand
    • Saturday, June 15, 13JThis is what you end up with
    • PWM and the Sabertooth• So to control the Sabertooth,you send a PWM signal per-motor.• 2000us pulse width: 100%forward• 1500us pulse width: idle• 1000us pulse width: 100%reverseMappedto 0..1values forpi-blasterSaturday, June 15, 13JExplain sabertooth logic levels, and show how we’re mapping them to pi-blaster levels
    • -1.01.0Saturday, June 15, 13AHere’s the interface. Just two sliders, mapped from -1 to 1. Your standard tank steering controls
    • Map those values from the lastslide into our pwm output valuesfor pi-blasterSaturday, June 15, 13J
    • This all looksfamiliar by nowSaturday, June 15, 13J
    • This isfamiliartooSaturday, June 15, 13J
    • DemoSaturday, June 15, 13Advance to the next slide if the demo fails...
    • Thank you for comingSaturday, June 15, 13JThanks for being so attentive. As a rather generous thanks for attending our talk, we’ve provided free iPads under everyone’sseats.OMG THAT GUY ACTUALLY LOOKED of course we didn’t do thatAOnce again, thanks for coming. Any questions?
    • Saturday, June 15, 13JThanks for being so attentive. As a rather generous thanks for attending our talk, we’ve provided free iPads under everyone’sseats.OMG THAT GUY ACTUALLY LOOKED of course we didn’t do that