SlideShare una empresa de Scribd logo
1 de 107
Descargar para leer sin conexión
RoRoRoomba
                         Roomba on Ruby on Rails




Friday, April 27, 2012
Thanks!


                         • Nancy Dussault-Smith
                         • Joshua Lifton
                         • and iRobot for the Roombas!




Friday, April 27, 2012
Thanks!




Friday, April 27, 2012
Introductions




Friday, April 27, 2012
My Roomba




Friday, April 27, 2012
konnichiwa

                         • Charles Abbott
                         •
                         • Life in Japan www.forthecode.org
                         • “The greatest obstacle...



Friday, April 27, 2012
“Greatest obstacle...



                         “The greatest obstacle to discovery




Friday, April 27, 2012
“Greatest obstacle...


                         “The greatest obstacle to discovery is not
                         ignorance




Friday, April 27, 2012
“Greatest obstacle...


                         “The greatest obstacle to discovery is not
                         ignorance, but




Friday, April 27, 2012
“Greatest obstacle...


                         “The greatest obstacle to discovery is not
                         ignorance, but the illusion of
                         knowledge” - Daniel J. Boorstin




Friday, April 27, 2012
“Hack Me”




Friday, April 27, 2012
3 R’s


                         tokyorails.org
Friday, April 27, 2012
Ruby




Friday, April 27, 2012
Rails




Friday, April 27, 2012
Roomba




Friday, April 27, 2012
Roomba on Ruby on Rails

                         • SerialPort + Ruby controls Roomba
                         • Rails site that routes remote requests
                         • ???
                         • Profit!



Friday, April 27, 2012
Resources
                         • http://hackingroomba.com/ (Open
                           source Java package)
                         • http://www.dprg.org/projects/
                           2009-07a/
                         • http://roombahacking.com/
                           roombahacks/roombacmd/
                         • http://www.arduino.cc/

Friday, April 27, 2012
Getting Started




Friday, April 27, 2012
Getting Supplies




Friday, April 27, 2012
and then...




Friday, April 27, 2012
my firstborn




Friday, April 27, 2012
Back on Track




Friday, April 27, 2012
Arduino Layout
                                          RX = receive
                                          TX = transmit




Friday, April 27, 2012
iRobot OI or SCI?




Friday, April 27, 2012
ROI? API?




Friday, April 27, 2012
Wired Up




Friday, April 27, 2012
Roomba + Arduino
                              What’s next?




Friday, April 27, 2012
Arduino Sandwich




Friday, April 27, 2012
Arduino Sketches

           void setup(){}



             void loop(){}




Friday, April 27, 2012
RAD?




Friday, April 27, 2012
Example Roomba Sketch




Friday, April 27, 2012
Debugging Arduino




Friday, April 27, 2012
Debugging Pains

                           [137] [255] [56] [1] [244]

                         Disconnect, Connect, Disconnect

                                    Headless

                              Documentation woes



Friday, April 27, 2012
Past First Base




Friday, April 27, 2012
Arduino




Friday, April 27, 2012
Arduino Wireless XBEE




Friday, April 27, 2012
Bluetooth




Friday, April 27, 2012
USB to Serial




Friday, April 27, 2012
Wifi




Friday, April 27, 2012
Where to Start?




Friday, April 27, 2012
Simple Serial




Friday, April 27, 2012
Writing Code

         def initialize(port, baud=115200)

               @serial = SerialPort.new(port, baud, 8, 1, SerialPort::NONE)

               sleep 0.2
               api_setup_start
               sleep 0.1
               api_setup_control

         end




Friday, April 27, 2012
Writing Opcodes
              # Must call this first to start the serial command interface
              def api_setup_start
                write(128)
              end

              # Enables user control of Roomba, puts SCI in safe mode
              def api_setup_control
                write(130)
              end

              # Starts a normal cleaning cycle.
              def api_clean
                write(135)
              end




Friday, April 27, 2012
Modeling the ROI
     # api_drive(255, 0, 0, 0) //go backward
     # api_drive(0, 255, 0, 0) //go forward
     # api_drive(0, 0, 0, 0) // stop
     def api_drive(velocity_high, velocity_low, radius_high, radius_low)
       write(137, velocity_high, velocity_low, radius_high, radius_low)
     end




Friday, April 27, 2012
Complex Write and Read
                  def api_querylist(*bytes)
                    write(149, bytes.length, *bytes)
                    wait_for_rx
                    read
                  end




Friday, April 27, 2012
The Bottom of the Barrel

                         def write(*args)
                           args.each do |a|
                             @serial.write a.chr
                           end
                         end



Friday, April 27, 2012
The Bottom of the Barrel

             def read(timeout=50)
               @serial.read_timeout= timeout
               bytes = []
               until (x = @serial.getbyte).nil?
                 bytes.push(x)
               end
               bytes
             end
Friday, April 27, 2012
Pulling it Together

                                   ls /dev/tty.*
                               find your serial device
                            then jump into rails console

              roo = Roomba.new(“/dev/tty.usbserial-xxx”)
              => #<Roomba:0x00000103e5bec0 @serial=#<SerialPort:fd 9>>




Friday, April 27, 2012
“Hello Roomba” Demo


                         “Don’t Assume It--Prove It”
                                      - Tip, The Pragmatic Programmer




Friday, April 27, 2012
Pitfall #1

          Forgetting to say “when”




Friday, April 27, 2012
Status Reports




Friday, April 27, 2012
down the rabbit hole

                         Flash Your Sign




Friday, April 27, 2012
down the rabbit hole

   Binary and Signed Integers




Friday, April 27, 2012
down the rabbit hole

                          Dealing With Binary

           def signed_integer(bytes)
             case bytes.size
             when 1
               return (bytes[0] & ~(1 << 7)) - (bytes[0] & (1 << 7))
             when 2
               sixteenbit = bytes[0] << 8 | bytes[1]
               return (sixteenbit & ~(1 << 15)) - (sixteenbit & (1 << 15))
             end
           end




                         learn more: http://en.wikipedia.org/wiki/Two%27s_complement#Calculating_two.27s_complement




Friday, April 27, 2012
down the rabbit hole

                         A Hex Digression




Friday, April 27, 2012
Better Abstraction




Friday, April 27, 2012
Distance & Time
        # distance is in mm
        # velocity is in mm/s (-500 to 500)
        def move(distance, degree=0, velocity=200)

              distance = distance.to_i.abs #distance can never be negative

              if distance == 0 #not moving, just spinning on axis
                # time = wheelbase * PI / 360degrees * degrees / velocity ABS
                time_in_seconds = calculate_spin_time(velocity, degree)
              else
                time_in_seconds = (distance.to_f / velocity.to_f).abs
              end




Friday, April 27, 2012
High Byte, Low Byte
                         # distance is in mm
                         # velocity is in mm/s (-500 to 500)
                         def move(distance, degree=0, velocity=200)
                           distance = distance.to_i.abs #distance can never be negative
                           if distance == 0 #not moving, just spinning on axis
                             # time = wheelbase * PI / 360degrees * degrees / velocity ABS
                             # wheelbase might be different for different roombas
                             time_in_seconds = calculate_spin_time(velocity, degree)
                             # now that we know how long to spin, set degree to 1 so it will spin roomba instead of put it on an arc
                             degree = 1
                           else
                             time_in_seconds = (distance.to_f / velocity.to_f).abs
                           end




                                    set_velocity(velocity)
                                    set_degree(degree)




Friday, April 27, 2012
Move!

       api_drive(@velocity_high, @velocity_low, @radius_high, @radius_low)

       start_moving = Time.now

       until (start_moving - Time.now).abs >= time_in_seconds
         sensors = get_readings(:bumps_and_drops, :wall)
         break if sensors[:bumps_and_drops][:formatted].to_i(2) > 0
       end

       api_drive(0,0,0,0)
       sensors




Friday, April 27, 2012
‘Move’ Demo




Friday, April 27, 2012
Pitfall #2

                               L...a...te..n....c..y
                                          ...


                                         no!


                                         no!


                                        yes!

                         ...             no!
Friday, April 27, 2012
Cut out the Middle Men




                         *Arduino is still awesome, and I encourage you to try it.

Friday, April 27, 2012
What Freedom Looks Like




Friday, April 27, 2012
Logic Level Converter


       http://www.sparkfun.com
                                           http://www.sparkfun.com




Friday, April 27, 2012
Prototyping!




Friday, April 27, 2012
SerialPort || TCPSocket




                         All we need is an IP address and a Port!

Friday, April 27, 2012
Connected and then...


                ............................never ending silence..........




Friday, April 27, 2012
UART

                Universal
                Asynchronous
                Receiver (RX)
                Transmitter (TX)




Friday, April 27, 2012
UART an Angel




Friday, April 27, 2012
Pitfall #3

                         All you get is #$@#!
                                                                    .0....T.
                                                                    ./....Y.
                                                         .:....T.
                                                                    .*....Y.
                                                         ./....L.
                                      ......+.                      .*.....
                           .4....U.                      .7....M.
                                      .`....N.                      .'....T.
                           ......V.                      .6....Q.
                                      .=......                      ./....W.
                           .-....L.                      .2....L.
                                      ........                      .,....U.
                           .7....T.                      .7....U.
                                      ......H.                      ......Q.
                           ./....S.                      ......P.
                                      .B......                      .2....L.
                           .0....O.                      .3....O.
                                      ........                      .7....T.
                           .4....V.                      .4....W.
                                      ........                      ./....[.
                           .-....S.                      .,....L.
                                      ......e.                      .(....V.
                           .0....Y.                      .7....U.
                                      .!......                      .-....N.
                           .*....V.                      ......V.
                                      ........                      .5....Q.
                           .-....U.                      .-....Z.
                                      .l....,.                      .2....U.
                           ......R.                      .)....Q.
                                      .W....V.                      ......N.
                           .1....W.                      .2....V.
                                      .-....R.                      .5....V.
                           .,....R.                      .-....^.
                                      .1....M.                      .-....Q.
                           .1....V.                      .%....Q.
                                      .6....B.                      .2....T.
                           .-....S.                      .2....O.
                                      .A....V.                      ./....O.
                           .0....N.                      .4....M.
                                      .-....V.                      .4....U.
                           .5....[.                      .6....Q.
                                      .-....N.                      ......Q.
                           .(....M.                      .2....T.
                                      .5....H.                      .2....O.
                           .6....R.                      ./....M.
                                      .;....T.                      .4....W.
                           .1....Q.                      .6....X.
                                      ./....L.                      .,....N.
                           .2....V.                      .+....N.
                                      .7....M.                      .5....W.
                           .-....P.                      .5....N.
                                      .6....H.                      .,....S.
                           .3....Y.                      .5....U.
                                      .;....K.                      .0....X.
                           .*....S.                      ......R.
                                      .8....S.                      .+....S.
                           .0....U.                      .1....`.
                                      .0....U.                      .0....Q.
                           ......L.                      .#....Q.
                                      ......O.                      .2....T.
                           .7....T.                      .2....U.
                                      .4....U.                      ./....L.
                           ./....R.                      ......R.
                                      ......Q.                      .7....T.
                           .1......                      .1....J.
                                      .2....P.                      ./....V.
                                                         .9....P.
                                      .3....R.                      .-....N.
                                                         .3....O.
                                      .1....W.                      .5....S.
                                                         .4....[.
                                      .,....U.                      .0....O.
                                                         .(....R.
                                      ......I.                      .4....N.
                                                         .1....X.
                                                                    .5....N.
                                                         .+....Y.
                                                                    .5....P.
                                                         .*....S.
                                                                    .3....O.

Friday, April 27, 2012
Pitfall #3

                         All you get is #$@#!



                              Solution #1: RTFM




Friday, April 27, 2012
Pitfall #3

                         All you get is #$@#!
                           Solution #2: Factory Defaults




Friday, April 27, 2012
Pitfall #3

                         All you get is #$@#!



                            Solution #3: RTFM, again...




Friday, April 27, 2012
Pitfall #3

                         All you get is #$@#!
                            Solution #3: RTFM, again...




Friday, April 27, 2012
Wifly Configuration
                         P195:~ charles$ telnet 169.254.1.1 2000
                         Trying 169.254.1.1...
                         Connected to 169.254.1.1.
                         Escape character is '^]'.
                         *HELLO*
                         $$$
                         CMD
                         set comm close 0
                         AOK
                         <2.23>set comm open 0
                         <2.23>set sys printlvl 0
                         <2.23> save
                         Storing in config
                         <2.23> reboot
Friday, April 27, 2012
Pretty Prototype...




Friday, April 27, 2012
Roomba Wifi




Friday, April 27, 2012
Roomba Wifi




Friday, April 27, 2012
3 Final Hurdles




                  nope         nope        huh?



Friday, April 27, 2012
Hurdle 1

                         Wifly Option (a)




Friday, April 27, 2012
Hurdle 1

                         “Hold, hold,...




Friday, April 27, 2012
Hurdle 1

                         Wifly Option (b)




Friday, April 27, 2012
Hurdle 2

                   The Stateless Web Tax



                         def initialize(port, baud=115200)
                           sleep 0.2
                           api_setup_start
                           sleep 0.1
                           api_setup_control




Friday, April 27, 2012
Hurdle 3

                         Device Busy
                              CONCURRENT
                               REQUESTS




                         OK          Errno::EBUSY: Resource busy




Friday, April 27, 2012
Hurdle 2 & 3

                             Socket Server

                                                             Pseudocode
                                               server = TCPServer.open(port) # Socket to listen on
                start Roomba Socket Server     roomba = Roomba.new(location)

                                               Thread.abort_on_exception = true
                                               loop do
                                                 puts "Roomba Socket Server Running! (15 second timeout)"
                                                 Thread.start(server.accept) do |client|
                                                   # => Read the incoming TCP Socket request
                                                   # => Pass the command to the roomba
                                                   client.close # Disconnect from the client
                                                 end
                                               end




Friday, April 27, 2012
Extended Demo


                         “Coding Ain’t Done ‘Til All The Tests Run”
                                            - Tip 63, The Pragmatic Programmer




Friday, April 27, 2012
Looking Forward




Friday, April 27, 2012
Testing Drones


                         • How do you run software tests on
                           something in the physical world?




Friday, April 27, 2012
Roomba Simulator




Friday, April 27, 2012
Test the Simulation




Friday, April 27, 2012
Compare with Live Test



                                  Bring it!




Friday, April 27, 2012
Simulator Scenarios




Friday, April 27, 2012
Challenges

                         If i tape a marker on Roomba...
                                 Map out a room...




Friday, April 27, 2012
Physical Computing?
                         Why you should care.




                           Jeremiah Palecek http://nerdkore.com

Friday, April 27, 2012
By 2020




                               Ericsson White Paper
                         284 23-3149 Uen | February 2011

Friday, April 27, 2012
Already




                            “By 2016, there will be 1.4 mobile devices per capita. That year, there will be over 10 billion mobile-
                            connected devices, including machine-to-machine (M2M) modules.”




                         http://techcrunch.com/2012/02/14/the-number-of-mobile-devices-will-exceed-worlds-
                                             population-by-2012-other-shocking-figures/
Friday, April 27, 2012
People then Things




                                    Ericsson White Paper
                              284 23-3149 Uen | February 2011
Friday, April 27, 2012
People and Things




                           https://trandi.wordpress.com/2011/09/26/vfd-clock-connects-to-the-internet/




Friday, April 27, 2012
People and Things




                           http://lifeboat.co.nz/the-finished-wireless-water-sensor/
Friday, April 27, 2012
Just Getting Started




Friday, April 27, 2012
“A Pragmatic Philosophy”

                         Invest Regularly in Your
                           Knowledge Portfolio
                            - Tip 8, The Pragmatic Programmer




                          “Simon Stevin!”


Friday, April 27, 2012
An Eccentric




Friday, April 27, 2012
Who is Simon Stevin?
  •waterway, spillways, sluices
  •navigation, steering
  •interest rate tables
  •The Art of Fortification •Copernican system
                             •treatise on perspective
                             •musical tuning
    •Trigonometry            •civil unrest handbook
    •hydrostatic paradox
    •optics, geography, philosophy
    •and more...
Friday, April 27, 2012
1585, De Thiende


                           “The Tenths”
                               35pg




Friday, April 27, 2012
Changes the World


                            “What seems a wonder, is not
                              really a wonder.” - Simon Stevin




Friday, April 27, 2012
Fork it!



                         github.com/tokyorails



                                Charles Abbott
                                  www.forthecode.org




Friday, April 27, 2012
RoRoRoomba



Friday, April 27, 2012

Más contenido relacionado

Similar a RoRoRoomba - Ruby on Rails on Roomba Railsconf 2012

PuppetCamp NYC - Building Scalable Modules
PuppetCamp NYC - Building Scalable ModulesPuppetCamp NYC - Building Scalable Modules
PuppetCamp NYC - Building Scalable ModulesPuppet
 
鱼与熊掌 - 软件质量和交付速度
鱼与熊掌 - 软件质量和交付速度鱼与熊掌 - 软件质量和交付速度
鱼与熊掌 - 软件质量和交付速度andyhu1007
 
Ruby para-programadores-php
Ruby para-programadores-phpRuby para-programadores-php
Ruby para-programadores-phpJuan Maiz
 
Engines Lightning Talk
Engines Lightning TalkEngines Lightning Talk
Engines Lightning TalkDan Pickett
 
An Analytics Toolkit Tour
An Analytics Toolkit TourAn Analytics Toolkit Tour
An Analytics Toolkit TourRory Winston
 
Symfony - Introduction
Symfony - IntroductionSymfony - Introduction
Symfony - IntroductionPiers Warmers
 
Games for the Masses - Wie DevOps die Entwicklung von Architektur verändert (...
Games for the Masses - Wie DevOps die Entwicklung von Architektur verändert (...Games for the Masses - Wie DevOps die Entwicklung von Architektur verändert (...
Games for the Masses - Wie DevOps die Entwicklung von Architektur verändert (...Wooga
 
Cypher Query Language
Cypher Query Language Cypher Query Language
Cypher Query Language graphdevroom
 

Similar a RoRoRoomba - Ruby on Rails on Roomba Railsconf 2012 (10)

PuppetCamp NYC - Building Scalable Modules
PuppetCamp NYC - Building Scalable ModulesPuppetCamp NYC - Building Scalable Modules
PuppetCamp NYC - Building Scalable Modules
 
鱼与熊掌 - 软件质量和交付速度
鱼与熊掌 - 软件质量和交付速度鱼与熊掌 - 软件质量和交付速度
鱼与熊掌 - 软件质量和交付速度
 
Ruby para-programadores-php
Ruby para-programadores-phpRuby para-programadores-php
Ruby para-programadores-php
 
Engines Lightning Talk
Engines Lightning TalkEngines Lightning Talk
Engines Lightning Talk
 
An Analytics Toolkit Tour
An Analytics Toolkit TourAn Analytics Toolkit Tour
An Analytics Toolkit Tour
 
Symfony - Introduction
Symfony - IntroductionSymfony - Introduction
Symfony - Introduction
 
Games for the Masses - Wie DevOps die Entwicklung von Architektur verändert (...
Games for the Masses - Wie DevOps die Entwicklung von Architektur verändert (...Games for the Masses - Wie DevOps die Entwicklung von Architektur verändert (...
Games for the Masses - Wie DevOps die Entwicklung von Architektur verändert (...
 
Cypher Query Language
Cypher Query Language Cypher Query Language
Cypher Query Language
 
RoR app for dummies
RoR app for dummiesRoR app for dummies
RoR app for dummies
 
JRuby at Square
JRuby at SquareJRuby at Square
JRuby at Square
 

Último

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 

Último (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

RoRoRoomba - Ruby on Rails on Roomba Railsconf 2012

  • 1. RoRoRoomba Roomba on Ruby on Rails Friday, April 27, 2012
  • 2. Thanks! • Nancy Dussault-Smith • Joshua Lifton • and iRobot for the Roombas! Friday, April 27, 2012
  • 6. konnichiwa • Charles Abbott • • Life in Japan www.forthecode.org • “The greatest obstacle... Friday, April 27, 2012
  • 7. “Greatest obstacle... “The greatest obstacle to discovery Friday, April 27, 2012
  • 8. “Greatest obstacle... “The greatest obstacle to discovery is not ignorance Friday, April 27, 2012
  • 9. “Greatest obstacle... “The greatest obstacle to discovery is not ignorance, but Friday, April 27, 2012
  • 10. “Greatest obstacle... “The greatest obstacle to discovery is not ignorance, but the illusion of knowledge” - Daniel J. Boorstin Friday, April 27, 2012
  • 12. 3 R’s tokyorails.org Friday, April 27, 2012
  • 16. Roomba on Ruby on Rails • SerialPort + Ruby controls Roomba • Rails site that routes remote requests • ??? • Profit! Friday, April 27, 2012
  • 17. Resources • http://hackingroomba.com/ (Open source Java package) • http://www.dprg.org/projects/ 2009-07a/ • http://roombahacking.com/ roombahacks/roombacmd/ • http://www.arduino.cc/ Friday, April 27, 2012
  • 22. Back on Track Friday, April 27, 2012
  • 23. Arduino Layout RX = receive TX = transmit Friday, April 27, 2012
  • 24. iRobot OI or SCI? Friday, April 27, 2012
  • 27. Roomba + Arduino What’s next? Friday, April 27, 2012
  • 29. Arduino Sketches void setup(){} void loop(){} Friday, April 27, 2012
  • 33. Debugging Pains [137] [255] [56] [1] [244] Disconnect, Connect, Disconnect Headless Documentation woes Friday, April 27, 2012
  • 34. Past First Base Friday, April 27, 2012
  • 38. USB to Serial Friday, April 27, 2012
  • 40. Where to Start? Friday, April 27, 2012
  • 42. Writing Code def initialize(port, baud=115200) @serial = SerialPort.new(port, baud, 8, 1, SerialPort::NONE) sleep 0.2 api_setup_start sleep 0.1 api_setup_control end Friday, April 27, 2012
  • 43. Writing Opcodes # Must call this first to start the serial command interface def api_setup_start write(128) end # Enables user control of Roomba, puts SCI in safe mode def api_setup_control write(130) end # Starts a normal cleaning cycle. def api_clean write(135) end Friday, April 27, 2012
  • 44. Modeling the ROI # api_drive(255, 0, 0, 0) //go backward # api_drive(0, 255, 0, 0) //go forward # api_drive(0, 0, 0, 0) // stop def api_drive(velocity_high, velocity_low, radius_high, radius_low) write(137, velocity_high, velocity_low, radius_high, radius_low) end Friday, April 27, 2012
  • 45. Complex Write and Read def api_querylist(*bytes) write(149, bytes.length, *bytes) wait_for_rx read end Friday, April 27, 2012
  • 46. The Bottom of the Barrel def write(*args) args.each do |a| @serial.write a.chr end end Friday, April 27, 2012
  • 47. The Bottom of the Barrel def read(timeout=50) @serial.read_timeout= timeout bytes = [] until (x = @serial.getbyte).nil? bytes.push(x) end bytes end Friday, April 27, 2012
  • 48. Pulling it Together ls /dev/tty.* find your serial device then jump into rails console roo = Roomba.new(“/dev/tty.usbserial-xxx”) => #<Roomba:0x00000103e5bec0 @serial=#<SerialPort:fd 9>> Friday, April 27, 2012
  • 49. “Hello Roomba” Demo “Don’t Assume It--Prove It” - Tip, The Pragmatic Programmer Friday, April 27, 2012
  • 50. Pitfall #1 Forgetting to say “when” Friday, April 27, 2012
  • 52. down the rabbit hole Flash Your Sign Friday, April 27, 2012
  • 53. down the rabbit hole Binary and Signed Integers Friday, April 27, 2012
  • 54. down the rabbit hole Dealing With Binary def signed_integer(bytes) case bytes.size when 1 return (bytes[0] & ~(1 << 7)) - (bytes[0] & (1 << 7)) when 2 sixteenbit = bytes[0] << 8 | bytes[1] return (sixteenbit & ~(1 << 15)) - (sixteenbit & (1 << 15)) end end learn more: http://en.wikipedia.org/wiki/Two%27s_complement#Calculating_two.27s_complement Friday, April 27, 2012
  • 55. down the rabbit hole A Hex Digression Friday, April 27, 2012
  • 57. Distance & Time # distance is in mm # velocity is in mm/s (-500 to 500) def move(distance, degree=0, velocity=200) distance = distance.to_i.abs #distance can never be negative if distance == 0 #not moving, just spinning on axis # time = wheelbase * PI / 360degrees * degrees / velocity ABS time_in_seconds = calculate_spin_time(velocity, degree) else time_in_seconds = (distance.to_f / velocity.to_f).abs end Friday, April 27, 2012
  • 58. High Byte, Low Byte # distance is in mm # velocity is in mm/s (-500 to 500) def move(distance, degree=0, velocity=200) distance = distance.to_i.abs #distance can never be negative if distance == 0 #not moving, just spinning on axis # time = wheelbase * PI / 360degrees * degrees / velocity ABS # wheelbase might be different for different roombas time_in_seconds = calculate_spin_time(velocity, degree) # now that we know how long to spin, set degree to 1 so it will spin roomba instead of put it on an arc degree = 1 else time_in_seconds = (distance.to_f / velocity.to_f).abs end set_velocity(velocity) set_degree(degree) Friday, April 27, 2012
  • 59. Move! api_drive(@velocity_high, @velocity_low, @radius_high, @radius_low) start_moving = Time.now until (start_moving - Time.now).abs >= time_in_seconds sensors = get_readings(:bumps_and_drops, :wall) break if sensors[:bumps_and_drops][:formatted].to_i(2) > 0 end api_drive(0,0,0,0) sensors Friday, April 27, 2012
  • 61. Pitfall #2 L...a...te..n....c..y ... no! no! yes! ... no! Friday, April 27, 2012
  • 62. Cut out the Middle Men *Arduino is still awesome, and I encourage you to try it. Friday, April 27, 2012
  • 63. What Freedom Looks Like Friday, April 27, 2012
  • 64. Logic Level Converter http://www.sparkfun.com http://www.sparkfun.com Friday, April 27, 2012
  • 66. SerialPort || TCPSocket All we need is an IP address and a Port! Friday, April 27, 2012
  • 67. Connected and then... ............................never ending silence.......... Friday, April 27, 2012
  • 68. UART Universal Asynchronous Receiver (RX) Transmitter (TX) Friday, April 27, 2012
  • 69. UART an Angel Friday, April 27, 2012
  • 70. Pitfall #3 All you get is #$@#! .0....T. ./....Y. .:....T. .*....Y. ./....L. ......+. .*..... .4....U. .7....M. .`....N. .'....T. ......V. .6....Q. .=...... ./....W. .-....L. .2....L. ........ .,....U. .7....T. .7....U. ......H. ......Q. ./....S. ......P. .B...... .2....L. .0....O. .3....O. ........ .7....T. .4....V. .4....W. ........ ./....[. .-....S. .,....L. ......e. .(....V. .0....Y. .7....U. .!...... .-....N. .*....V. ......V. ........ .5....Q. .-....U. .-....Z. .l....,. .2....U. ......R. .)....Q. .W....V. ......N. .1....W. .2....V. .-....R. .5....V. .,....R. .-....^. .1....M. .-....Q. .1....V. .%....Q. .6....B. .2....T. .-....S. .2....O. .A....V. ./....O. .0....N. .4....M. .-....V. .4....U. .5....[. .6....Q. .-....N. ......Q. .(....M. .2....T. .5....H. .2....O. .6....R. ./....M. .;....T. .4....W. .1....Q. .6....X. ./....L. .,....N. .2....V. .+....N. .7....M. .5....W. .-....P. .5....N. .6....H. .,....S. .3....Y. .5....U. .;....K. .0....X. .*....S. ......R. .8....S. .+....S. .0....U. .1....`. .0....U. .0....Q. ......L. .#....Q. ......O. .2....T. .7....T. .2....U. .4....U. ./....L. ./....R. ......R. ......Q. .7....T. .1...... .1....J. .2....P. ./....V. .9....P. .3....R. .-....N. .3....O. .1....W. .5....S. .4....[. .,....U. .0....O. .(....R. ......I. .4....N. .1....X. .5....N. .+....Y. .5....P. .*....S. .3....O. Friday, April 27, 2012
  • 71. Pitfall #3 All you get is #$@#! Solution #1: RTFM Friday, April 27, 2012
  • 72. Pitfall #3 All you get is #$@#! Solution #2: Factory Defaults Friday, April 27, 2012
  • 73. Pitfall #3 All you get is #$@#! Solution #3: RTFM, again... Friday, April 27, 2012
  • 74. Pitfall #3 All you get is #$@#! Solution #3: RTFM, again... Friday, April 27, 2012
  • 75. Wifly Configuration P195:~ charles$ telnet 169.254.1.1 2000 Trying 169.254.1.1... Connected to 169.254.1.1. Escape character is '^]'. *HELLO* $$$ CMD set comm close 0 AOK <2.23>set comm open 0 <2.23>set sys printlvl 0 <2.23> save Storing in config <2.23> reboot Friday, April 27, 2012
  • 79. 3 Final Hurdles nope nope huh? Friday, April 27, 2012
  • 80. Hurdle 1 Wifly Option (a) Friday, April 27, 2012
  • 81. Hurdle 1 “Hold, hold,... Friday, April 27, 2012
  • 82. Hurdle 1 Wifly Option (b) Friday, April 27, 2012
  • 83. Hurdle 2 The Stateless Web Tax def initialize(port, baud=115200) sleep 0.2 api_setup_start sleep 0.1 api_setup_control Friday, April 27, 2012
  • 84. Hurdle 3 Device Busy CONCURRENT REQUESTS OK Errno::EBUSY: Resource busy Friday, April 27, 2012
  • 85. Hurdle 2 & 3 Socket Server Pseudocode server = TCPServer.open(port) # Socket to listen on start Roomba Socket Server roomba = Roomba.new(location) Thread.abort_on_exception = true loop do puts "Roomba Socket Server Running! (15 second timeout)" Thread.start(server.accept) do |client| # => Read the incoming TCP Socket request # => Pass the command to the roomba client.close # Disconnect from the client end end Friday, April 27, 2012
  • 86. Extended Demo “Coding Ain’t Done ‘Til All The Tests Run” - Tip 63, The Pragmatic Programmer Friday, April 27, 2012
  • 88. Testing Drones • How do you run software tests on something in the physical world? Friday, April 27, 2012
  • 90. Test the Simulation Friday, April 27, 2012
  • 91. Compare with Live Test Bring it! Friday, April 27, 2012
  • 93. Challenges If i tape a marker on Roomba... Map out a room... Friday, April 27, 2012
  • 94. Physical Computing? Why you should care. Jeremiah Palecek http://nerdkore.com Friday, April 27, 2012
  • 95. By 2020 Ericsson White Paper 284 23-3149 Uen | February 2011 Friday, April 27, 2012
  • 96. Already “By 2016, there will be 1.4 mobile devices per capita. That year, there will be over 10 billion mobile- connected devices, including machine-to-machine (M2M) modules.” http://techcrunch.com/2012/02/14/the-number-of-mobile-devices-will-exceed-worlds- population-by-2012-other-shocking-figures/ Friday, April 27, 2012
  • 97. People then Things Ericsson White Paper 284 23-3149 Uen | February 2011 Friday, April 27, 2012
  • 98. People and Things https://trandi.wordpress.com/2011/09/26/vfd-clock-connects-to-the-internet/ Friday, April 27, 2012
  • 99. People and Things http://lifeboat.co.nz/the-finished-wireless-water-sensor/ Friday, April 27, 2012
  • 100. Just Getting Started Friday, April 27, 2012
  • 101. “A Pragmatic Philosophy” Invest Regularly in Your Knowledge Portfolio - Tip 8, The Pragmatic Programmer “Simon Stevin!” Friday, April 27, 2012
  • 103. Who is Simon Stevin? •waterway, spillways, sluices •navigation, steering •interest rate tables •The Art of Fortification •Copernican system •treatise on perspective •musical tuning •Trigonometry •civil unrest handbook •hydrostatic paradox •optics, geography, philosophy •and more... Friday, April 27, 2012
  • 104. 1585, De Thiende “The Tenths” 35pg Friday, April 27, 2012
  • 105. Changes the World “What seems a wonder, is not really a wonder.” - Simon Stevin Friday, April 27, 2012
  • 106. Fork it! github.com/tokyorails Charles Abbott www.forthecode.org Friday, April 27, 2012