Build a Simple Internet Controlled Webcam Robot
The prerequisites for this build are basic understanding of Linux, script and HTML programming and some soldering experience.
Hardware
- Raspberry Pi Model A (~$30) - I got mine from Adafruit. In hindsight I might have chosen model B, to have the possibility of cabled internet connection. It would have saved me some trouble in the beginning.
- SSD card (Minimum 8GB), cables, breadboard, and USB power supply (with USB micro connector) (~$50) - Use the stuff that you already have lying around and buy only the things you really need. The breadboard will only be used for testing.
- Edimax EW-7811UN (~$11) - A simple USB wifi adapter. It worth buying this brand, since Occidentalis (the Debian Linux based OS for Raspberry Pi) comes with the necessary drives installed.
- Logitech C270 (~$23) - An affordable webcam from Logitech. You can of course use any webcam you already have, but newer ones will support MJPEG, which makes the live feed much faster.
- 4 RC servos (~$30total) - I used the ones that came with my old RC radio, but you can get any kind. With my Hitec HS-325 servos I was able to easily modify two of them to spin 360 degrees in order to use them to drive to wheels of the robot. I suggest servos that provide 3-4 kg of torque for the wheels, smaller for the pan and tilt camera setup.
- LiPo battery (~$30) - Any 2-4 cell LiPo battery will do. Choose it based on how much battery time you want your robot to have. I'm currently using a Polyquest 4 cell 4350 mAh battery, because I already had it from a previous project, but I would recommend something cheaper like a Zippy Flightmax 5000 mAh. I haven't checked the battery life while using it on the robot, but it should probably give approximately 12 hours of standby time. You will of course also need a LiPo battery charger.
- UBEC (~$5) - The Raspberry Pi and servos run on 5V DC, so we need this to to reduce the LiPo battery's 10+ voltage. Hobbyking has UBECs for less than 5 USD.
- 2 hobby wheels (~$5) - Hobbyking sells these cheap wheels for use on RC planes. There's a trade off to be made between power and speed of your robot, depending on the diameter you choose for your wheels. You will also need a swivel wheel from some old furniture.
- 10-15mm (~$30) plywood, nuts, bolts, wires, micro switch, pipe hanger strap, double sided tape.
- Fish-eye lens (~25) - Most webcameras have a narrow field of view. This makes navigating the robot like driving while looking through telescope. I've modified my webcam simply by putting a cheap fish-eye lens in front of it.
Software
- Occidentalis - Debian based Linux distro derived from Raspbian Wheezy, created by Adafruit.
- Apache 2 - Web server
- PiBits Servoblaster - This is software for the Raspberry Pi, which provides an interface to drive multiple servos via the GPIO pins. You control the servo postions by sending commands to the driver saying what pulse width a particular servo output should use.
- MJPG-streamer - MJPG-streamer takes JPGs from Linux-UVC compatible webcams, filesystem or other input plugins and streams them as M-JPEG via HTTP to webbrowsers, VLC and other software.
- HTML page - Shows the controls and streaming video (MJPEG), and sends controls to the Python CGI script.
- Python CGI script - Sends values to Servoblaster, and executes OS commans to start/stop MJPG-streaming and shut down the Raspberry Pi.
Setting up the Raspberry Pi
- Setup the Occidentalis OS on the SSD
- Setup WiFi on the Raspberry Pi - If you bought a Model A without cabled internet, like I did, you'll need to connect your Raspberry Pi to a USB keyboard and a screen using HDMI to set this up.
- Update/upgrade Linux, setup SSH and install Apache2 - Perform only the steps you see necessary.
- Optional: Test out controlling your servos from the Raspberry Pi - This process does not use the Servoblaster, and only supports one servo, but it's the fastest way to see some physical movement.
- Install servoblaster - Make sure you have updated/upgraded before trying this, or you will get errors!
- Install MJPG-streamer - This not actually an installation since, but we will set MJPG-streamer to be started at boot later.
- Give web-server user rights to run sudo commands without password (this is obviously a security risk, but if you're not using the Raspberry Pi for other sensitive stuff, it shouldn't be a problem):
- sudo nano /etc/sudoers
- Add line: www-data ALL=(ALL) NOPASSWD: ALL
- Secure the web page - If you're going to expose the web page on the Internet I suggest you at least activate username/password authentication on your web server.
Writing the web page and Python CGI script
Assembling the robot
- Open two of the servos and modify them to run 360 degrees
- Mount wheels on the two servos
- Cut out a piece of plywood
- Mount swivel wheel to the plywood board
- Mount the wheel servos to the plywood board using double sided tape and pipe hanger strap
- Create a pan and tilt setup for the camera and mount it on the plywood board
- Split the signal calge (yellow) from the power cables of all the servos and plug them into the GPIO pins on the Rasberry Pi as indicated in the instructions from Servoblaster
- Create the power setup described in the next section