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…
- Read Setting up and Configuring Bluetooth and Roomba part from this post.
- 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)
Next up – Getting more roombas to implement Rich Hickey’s ant colony demo…