Slide 1

Slide 1 text

RoRoRoomba Roomba on Ruby on Rails Friday, April 27, 2012

Slide 2

Slide 2 text

Thanks! • Nancy Dussault-Smith • Joshua Lifton • and iRobot for the Roombas! Friday, April 27, 2012

Slide 3

Slide 3 text

Thanks! Friday, April 27, 2012

Slide 4

Slide 4 text

Introductions Friday, April 27, 2012

Slide 5

Slide 5 text

My Roomba Friday, April 27, 2012

Slide 6

Slide 6 text

• Charles Abbott • • Life in Japan www.forthecode.org • “The greatest obstacle... konnichiwa Friday, April 27, 2012

Slide 7

Slide 7 text

“The greatest obstacle to discovery “Greatest obstacle... Friday, April 27, 2012

Slide 8

Slide 8 text

“The greatest obstacle to discovery is not ignorance “Greatest obstacle... Friday, April 27, 2012

Slide 9

Slide 9 text

“The greatest obstacle to discovery is not ignorance, but “Greatest obstacle... Friday, April 27, 2012

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

“Hack Me” Friday, April 27, 2012

Slide 12

Slide 12 text

3 R’s tokyorails.org Friday, April 27, 2012

Slide 13

Slide 13 text

Ruby Friday, April 27, 2012

Slide 14

Slide 14 text

Rails Friday, April 27, 2012

Slide 15

Slide 15 text

Roomba Friday, April 27, 2012

Slide 16

Slide 16 text

Roomba on Ruby on Rails • SerialPort + Ruby controls Roomba • Rails site that routes remote requests • ??? • Profit! Friday, April 27, 2012

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

Getting Started Friday, April 27, 2012

Slide 19

Slide 19 text

Getting Supplies Friday, April 27, 2012

Slide 20

Slide 20 text

and then... Friday, April 27, 2012

Slide 21

Slide 21 text

my firstborn Friday, April 27, 2012

Slide 22

Slide 22 text

Back on Track Friday, April 27, 2012

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

iRobot OI or SCI? Friday, April 27, 2012

Slide 25

Slide 25 text

ROI? API? Friday, April 27, 2012

Slide 26

Slide 26 text

Wired Up Friday, April 27, 2012

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

Arduino Sandwich Friday, April 27, 2012

Slide 29

Slide 29 text

Arduino Sketches void setup(){} void loop(){} Friday, April 27, 2012

Slide 30

Slide 30 text

RAD? Friday, April 27, 2012

Slide 31

Slide 31 text

Example Roomba Sketch Friday, April 27, 2012

Slide 32

Slide 32 text

Debugging Arduino Friday, April 27, 2012

Slide 33

Slide 33 text

Debugging Pains [137] [255] [56] [1] [244] Disconnect, Connect, Disconnect Headless Documentation woes Friday, April 27, 2012

Slide 34

Slide 34 text

Past First Base Friday, April 27, 2012

Slide 35

Slide 35 text

Arduino Friday, April 27, 2012

Slide 36

Slide 36 text

Arduino Wireless XBEE Friday, April 27, 2012

Slide 37

Slide 37 text

Bluetooth Friday, April 27, 2012

Slide 38

Slide 38 text

USB to Serial Friday, April 27, 2012

Slide 39

Slide 39 text

Wifi Friday, April 27, 2012

Slide 40

Slide 40 text

Where to Start? Friday, April 27, 2012

Slide 41

Slide 41 text

Simple Serial Friday, April 27, 2012

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

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

Slide 44

Slide 44 text

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

Slide 45

Slide 45 text

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

Slide 46

Slide 46 text

The Bottom of the Barrel def write(*args) args.each do |a| @serial.write a.chr end end Friday, April 27, 2012

Slide 47

Slide 47 text

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

Slide 48

Slide 48 text

Pulling it Together ls /dev/tty.* find your serial device then jump into rails console roo = Roomba.new(“/dev/tty.usbserial-xxx”) => #> Friday, April 27, 2012

Slide 49

Slide 49 text

“Hello Roomba” Demo “Don’t Assume It--Prove It” - Tip, The Pragmatic Programmer Friday, April 27, 2012

Slide 50

Slide 50 text

Forgetting to say “when” Pitfall #1 Friday, April 27, 2012

Slide 51

Slide 51 text

Status Reports Friday, April 27, 2012

Slide 52

Slide 52 text

Flash Your Sign down the rabbit hole Friday, April 27, 2012

Slide 53

Slide 53 text

Binary and Signed Integers down the rabbit hole Friday, April 27, 2012

Slide 54

Slide 54 text

Dealing With Binary down the rabbit hole 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

Slide 55

Slide 55 text

A Hex Digression down the rabbit hole Friday, April 27, 2012

Slide 56

Slide 56 text

Better Abstraction Friday, April 27, 2012

Slide 57

Slide 57 text

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

Slide 58

Slide 58 text

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

Slide 59

Slide 59 text

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

Slide 60

Slide 60 text

‘Move’ Demo Friday, April 27, 2012

Slide 61

Slide 61 text

L...a...te..n....c..y Pitfall #2 ... no! no! yes! no! ... Friday, April 27, 2012

Slide 62

Slide 62 text

Cut out the Middle Men *Arduino is still awesome, and I encourage you to try it. Friday, April 27, 2012

Slide 63

Slide 63 text

What Freedom Looks Like Friday, April 27, 2012

Slide 64

Slide 64 text

Logic Level Converter http://www.sparkfun.com http://www.sparkfun.com Friday, April 27, 2012

Slide 65

Slide 65 text

Prototyping! Friday, April 27, 2012

Slide 66

Slide 66 text

SerialPort || TCPSocket All we need is an IP address and a Port! Friday, April 27, 2012

Slide 67

Slide 67 text

Connected and then... ............................never ending silence.......... Friday, April 27, 2012

Slide 68

Slide 68 text

UART Universal Asynchronous Receiver (RX) Transmitter (TX) Friday, April 27, 2012

Slide 69

Slide 69 text

UART an Angel Friday, April 27, 2012

Slide 70

Slide 70 text

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

Slide 71

Slide 71 text

All you get is #$@#! Pitfall #3 Solution #1: RTFM Friday, April 27, 2012

Slide 72

Slide 72 text

All you get is #$@#! Pitfall #3 Solution #2: Factory Defaults Friday, April 27, 2012

Slide 73

Slide 73 text

All you get is #$@#! Pitfall #3 Solution #3: RTFM, again... Friday, April 27, 2012

Slide 74

Slide 74 text

All you get is #$@#! Pitfall #3 Solution #3: RTFM, again... Friday, April 27, 2012

Slide 75

Slide 75 text

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

Slide 76

Slide 76 text

Pretty Prototype... Friday, April 27, 2012

Slide 77

Slide 77 text

Roomba Wifi Friday, April 27, 2012

Slide 78

Slide 78 text

Roomba Wifi Friday, April 27, 2012

Slide 79

Slide 79 text

3 Final Hurdles nope nope huh? Friday, April 27, 2012

Slide 80

Slide 80 text

Wifly Option (a) Hurdle 1 Friday, April 27, 2012

Slide 81

Slide 81 text

“Hold, hold,... Hurdle 1 Friday, April 27, 2012

Slide 82

Slide 82 text

Wifly Option (b) Hurdle 1 Friday, April 27, 2012

Slide 83

Slide 83 text

The Stateless Web Tax def initialize(port, baud=115200) sleep 0.2 api_setup_start sleep 0.1 api_setup_control Hurdle 2 Friday, April 27, 2012

Slide 84

Slide 84 text

Device Busy OK Errno::EBUSY: Resource busy CONCURRENT REQUESTS Hurdle 3 Friday, April 27, 2012

Slide 85

Slide 85 text

Socket Server Roomba Socket Server start server = TCPServer.open(port) # Socket to listen on 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 Pseudocode Hurdle 2 & 3 Friday, April 27, 2012

Slide 86

Slide 86 text

Extended Demo “Coding Ain’t Done ‘Til All The Tests Run” - Tip 63, The Pragmatic Programmer Friday, April 27, 2012

Slide 87

Slide 87 text

Looking Forward Friday, April 27, 2012

Slide 88

Slide 88 text

Testing Drones • How do you run software tests on something in the physical world? Friday, April 27, 2012

Slide 89

Slide 89 text

Roomba Simulator Friday, April 27, 2012

Slide 90

Slide 90 text

Test the Simulation Friday, April 27, 2012

Slide 91

Slide 91 text

Compare with Live Test Bring it! Friday, April 27, 2012

Slide 92

Slide 92 text

Simulator Scenarios Friday, April 27, 2012

Slide 93

Slide 93 text

Challenges If i tape a marker on Roomba... Map out a room... Friday, April 27, 2012

Slide 94

Slide 94 text

Physical Computing? Jeremiah Palecek http://nerdkore.com Why you should care. Friday, April 27, 2012

Slide 95

Slide 95 text

By 2020 Ericsson White Paper 284 23-3149 Uen | February 2011 Friday, April 27, 2012

Slide 96

Slide 96 text

Already http://techcrunch.com/2012/02/14/the-number-of-mobile-devices-will-exceed-worlds- population-by-2012-other-shocking-figures/ “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.” Friday, April 27, 2012

Slide 97

Slide 97 text

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

Slide 98

Slide 98 text

People and Things https://trandi.wordpress.com/2011/09/26/vfd-clock-connects-to-the-internet/ Friday, April 27, 2012

Slide 99

Slide 99 text

People and Things http://lifeboat.co.nz/the-finished-wireless-water-sensor/ Friday, April 27, 2012

Slide 100

Slide 100 text

Just Getting Started Friday, April 27, 2012

Slide 101

Slide 101 text

“A Pragmatic Philosophy” Invest Regularly in Your Knowledge Portfolio - Tip 8, The Pragmatic Programmer “Simon Stevin!” Friday, April 27, 2012

Slide 102

Slide 102 text

An Eccentric Friday, April 27, 2012

Slide 103

Slide 103 text

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

Slide 104

Slide 104 text

1585, De Thiende “The Tenths” 35pg Friday, April 27, 2012

Slide 105

Slide 105 text

Changes the World “What seems a wonder, is not really a wonder.” - Simon Stevin Friday, April 27, 2012

Slide 106

Slide 106 text

Fork it! github.com/tokyorails Charles Abbott www.forthecode.org Friday, April 27, 2012

Slide 107

Slide 107 text

RoRoRoomba Friday, April 27, 2012