Charles Abbott's presentation slides about hacking Roombas using Ruby and a Rails app over serial cable, bluetooth, arduino, and a straight serial to wifi gateway (wifly). Given at RailsConf 2012, video available on Confreaks.com.
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
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
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
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
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
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
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