Monthly Archives: August 2012

A Clojure REPL Driven Roomba


One of the things that I love about Clojure is that it can go anywhere that Java can.  That is why, when I found out that the Roomba already had a Java library written for it – I was excited to be able to hook it up to my Emacs / Swank and be able to control it from my editor.

It is great fun! If you have a Roomba at home and you want to play along…

  1. Read Setting up and Configuring Bluetooth and Roomba part from this post.

  2. Checkout the sample project clj-roomba from github.

Have fun doing this like this:

(def roomba (RoombaCommSerial. ))
 
;;Find your port for your Roomba
(map println (.listPorts roomba))
(def portname "/dev/cu.FireFly-943A-SPP")
(.connect roomba portname)
(.startup roomba)  ;;puts Roomba in safe Mode
;; What mode is Roomba in?
(.modeAsString roomba)
(.control roomba)
(.updateSensors roomba) ; returns true if you are connected
 
 
(.pause roomba 30)
(.playNote roomba 72 40)
(.playNote roomba 79 40)
(.spinLeft roomba)
(.spinRight roomba)
(.goBackward roomba)
(.goForward roomba)
(.turnLeft roomba)
(.turnRight roomba)
 
(.stop roomba)
(.reset roomba)
(.vacuum roomba true)
(.vacuum roomba false)
(.clean roomba)
 
;; Get the sensor data
(.updateSensors roomba) 
(.bumpLeft roomba)
(.bumpRight roomba)
(.wheelDropLeft roomba)
(.wheelDropRight roomba)
(.wheelDropCenter roomba)
(.sensorsAsString roomba)
 
 
(defn bark [r]
  (doto r
    (.vacuum true)
    (.playNote 50 5)
    (.pause 150)
    (.vacuum false)))
 
(bark roomba)

A quick video of hacking Roomba in action

Next up – Getting more roombas to implement Rich Hickey’s ant colony demo

Talking to your Roomba via Bluetooth and RoombaComm

I love Roomba. It cleans our floors and it can be hacked to help teach my kids programming. Win!

Here are the setup steps that I used to get going talking to Roomba:

  • Ordered a Rootooth bluetooth connection for Roomba.  I could have build one from scratch, but I am a busy mom and hacker.
  • Removed the cover from Roomba to expose the ROI port (Video).
  • Setup the Bluetooth adapter on my Mac
    • Start Bluetooth network assistant
    • Have the firefly adapter deteted
    • Enter the passkey: 1234
    • Click edit serial ports to see what port it assigned.  Mine was FireFly-943A-SPP.  Alternatively, you can look at /dev directory
    • Next, you need to configure the baud rate for your Roomba. I found these instructions helpful
    • Install zterm on your mac  - set the serial port to your roomba and the baud rate to the correct baud rate
    • On zterm you now should be able to echo any key you type
  • Download RoombaComm java package
  • Look at the README.  You will need to run makeit.sh to build and ./rxtxlib/macosx_setup.command (for Macs)
  • Finally run RoombaCommTest.sh to connect up and control your Roomba!