Introduction: First-person View Roomba Driving
It's fun to drive a Roomba around by remote control. It's even more fun to have a first-person view while doing so. This particular project for me was almost all software development because I already had all the hardware. Here's what you need on the hardware side:
- Roomba 500+ (if you have an older Roomba, you'll have to tweak the code)
- Two Android devices (e.g., a phone and a tablet)
- Bluetooth Roomba adapter (I used a Brainlink set up according to this Instructable)
- A stand for putting an Android device on a Roomba (this can be just a couple of pieces of wood and some rubber bands; Velcro on the stand and the Roomba makes things more convenient).
The idea is that one Android device stands on the Roomba and streams video which is displayed by the other. You can do this with Skype or Google Hangouts, or with a webcam app.
The only problem was how to control the Roomba from the device that was displaying the video. I tried using an xposed module that let me run two windows on the tablet, one with a Roomba remote control app and the other showing the video, but that was a clunky way to do it. So instead I wrote Roodrive (source code here), a simple Roomba Bluetooth remote app that is controlled by swiping in a semi-transparent square on the screen that shows up on top of an app displaying video.
Step 1: Hardware
Assemble some sort of stand for your device that you can attach to the Roomba. You can make one from a couple of pieces of wood or from some Legos. You can attach it to the Roomba with rubber bands or with a bit of Velcro. Velcro (or some other hook-and-loop fastener) is a bit more convenient. I just attach a phone to it with a rubber band.
Attach a Bluetooth adapter to the Roomba. I used a Brainlink device. You could probably also make a very cheap adapter from an HC-06, a voltage regulator and a miniDIN-8 plug. For convenience, I had drilled a hole through the Roomba's faceplate to attach to the Roomba's UART port. You could also just take off the faceplate.
Step 2: Video Software
One option is to use IP Webcam or similar app on the device attached to the Roomba and a webcam viewer app like tinyCam Monitor on the other device. I suggest turning down the resolution and the frame-rate for maximum responsiveness. A nice thing about the IP Webcam / tinyCam setup is that you can remotely trigger the flash on the device on the Roomba, which creates a nice headlight for going in the dark.
The other option is to run Google Hangouts or Skype on the two devices, with different accounts. This lets you drive the Roomba up to people and talk with them, making a rudimentary telepresence robot (severely limited by Bluetooth--but one could rewrite my Roodrive software to work via tcp/ip and use a WiFi adapter on the Roomba).
Make sure you can see the video from the Roomba.
Step 3: Bluetooth Control
Pair your Roomba's Bluetooth adapter with the device you're using as your remote control.
Turn on your Roomba
Download and run Roodrive.
Select your Bluetooth adapter in Roodrive.
Press "Connect". If all goes well, you get a little semitransparent square (which you can move by touching and move the upper left corner, and resize by using two fingers one of which is on the upper left corner) which you can use to control the Roomba. That square will show on top of other apps. Make sure you can control the Roomba by swiping on the square.
Go back to the app showing the video from the other device. You can now drive with first-person view.
Step 4: Software Development Notes
If you want to write your own software for controlling the Roomba 500+, the crucial documentation is here.
To connect, send a 128 byte to the Bluetooth device that is connected to the Roomba. This puts the Roomba in passive mode. To accept movement commands send 131, which puts the Roomba in safe mode (so it won't drive off stairs, or drive away while plugged in, etc.)
Then you drive the Roomba with the high-level 137 command, where you specify speed and turning radius, or the somewhat lower level 145 command, where you specify individual wheel velocities. See the documentation for details or look at Roodrive.java in my source code. In Roodrive, I use 137 for straight driving (swiping up or down) and for straight turning (swiping left or right) and 145 if the user wants to drive and turn at the same time. It's all pretty straightforward.
Here's a note you might find useful if developing your own software: As you drive your Roomba around, there is a good chance you'll drive over something which will activate the cliff sensors. If it's in safe mode, the Roomba will immediately exit safe mode and go to passive mode, and ignore all movement commands. So in Roodrive, each time the user touched the control area to make a movement, at the beginning of the touch I started off by sending the 128, 131 bytes to put the Roomba in safe mode again before sending any of the actual drive commands. Thus, if you run the Roomba to a dangerous location with you finger on the control area, it'll stop moving. But it'll wake up again when you take your finger off and touch the control area again.
As a bonus, if you turn off the Roomba while you're connected to it and then turn it back on, this will mean you don't need to disconnect and reconnect, as long as your Bluetooth adapter stays connected to the device you're using as your remote.