Robot for the Office
Tele-Presence (sort of) robot for the office. Work from home and yet attend the boring meetings. Scare vendors into telling the truth about their products. Chase tiny children when they come to the office for the Hallowe'en or Christmas parties.
Gather Tools and Materials
(1) [$3 - $70] RC truck with beefy motor; I used one of these: GT Cross Land Racer (NOTE: you can also find many RC trucks cheap at garbage sales, the Goodwill, and the ARC)
(1 ea) [$39] Raspberry Pi with ($9) 8G Class 10 memory card, ($0)Raspian Image, ($10) Edimax WiFi dongle, ($11) Sony Playstation Eye Camera
(1) [$1.25] 7293D motor controller chip ($1.25) (NOTE: get two because, well you know)
(1) [$8] Set of 22g wires (M/M, F/F, M/F)
(1) [$10 for 5] Lil' tiny breadboard
(1) [$9] Breadboard jumper kit (these are GREAT)
(1) [$0.26] 4AA Battery holder and 4AA batteries (for the L293D chip)
(1) [$25] 5v USB rechargeable battery (for the Raspberry Pi)
(1) [$19 optional] 9V rechargeable battery (for motors, if your truck didn't come with one)
(2) [$0.45 ea] On/Off switch (one for L293D battery power, and one for motor battery power)
(1) Shoebox
(1) Popcorn Tin (or high Tupperware bowl/w lid)
(3) Strips Velcro
(x) Lil' tiny screws
(1) Lipstick, chalk, paint
(1) Roll duct tape
(1) Drill, 1/16" drill bit
(1) Lil' tiny Phillips-head screw driver
(1) X-acto knife
(1) Scissors
(1) Wire cutter
(A Note About RC Vehicles)
Just FYI
- The bigger the better
- The bigger does not necessarily mean more power, though
- Truck varieties usually have better clearance
- Usually the bigger the $ the better (more powerful) (like above $25)
- The rock climbers are really powerful but don't make good robots because they twist and jostle too much, they just aren't stable enough for taller robots
Strip RC Vehicle
This will vary on your model, but there should be 4 or 5 lil' tiny screws that hold a plastic froo-froo truck-looking plastic blob on top of the base chassis.
Take this off and you'll wind up with something like this.
Locate Forward/back and Left/right Motors
95% of the RC trucks/cars I've dismantled have a beefy motor in the rear of the truck and a smaller motor in the front.
The beefy motor moves the car forward and back; while the front motor moves the front wheels left and right.
The beefy motor usually has a two wires (M+ [red or white] and M- [black]) and the front motor usually has two wires (M+ [orange] and M- [black]) and may have a bunch of skeery-looking wires of different colors. You just need the M+ and M- wires.
Remove Receiver Board
Clip out the electronic board from the guts of the truck. If your car was salvaged from a garbage sale and doesn't have a transmitter, then this should not be too traumatic.
If this IS to traumatic though, or you want to continue to be able to run the car with the RC remote, you can leave the board intact and, in the next step, splice/solder your access wires into/onto the board. This would allow you to still be able to run the robot from the remote control for the car (IF your car came with one). Most of my chassis have come from garbage sales and don't have a remote and the receiver board is broken anyway.
Lengthen Motor Wires
Here we just lengthen the motor wires so that they can be routed to the motor controller chip.
Add a 22g jumper wire to each of the four motor wires. In these photos, I just stripped the ends of the motor wires on the truck, stripped the end of a M/M jumper wire, twisted them together, and squashed 'em with duct tape.
NOTE
So if you had chosen in the previous step to NOT remove the receiver board in the truck, you can attempt to splice on some jumper wires to the motor or to the motor outputs on the board, the latter requiring soldering.
Extract and Wire Up Motor Battery
The truck will usually come with either a single big battery, or a series of AA batteries. Or possibly none if it came from a garbage sale.
In any case, you'll want to extricate the battery pack or battery holder and wire it up in series with a switch.
Why? You will find that this will make it easier to start up the robot and access the motor battery when recharging is needed. Most of the trucks come with the motor battery under the chassis, which is a hassle to get to once the robot is finished.
By moving the battery (as we'll do in a bit) and giving it a switch, you'll save some hassle when playing with the robot.
Wire Up Chip Battery and Holder
The motor chip will require 5-6 volts, so prepare a battery just for it. Again, wire in a switch so that you can turn it on and off easily.
NOTE:
I originally had tried to power the chip from the 5v pin on the Raspi, but that didn't provide enough power and eventually I cooked my Pi.
Find a Component Holder/box
Component Holder = box
Find a box of some sort that will fit well on top of the truck chassis.
Box: Mark Screw Holes on Truck
Remove the box, then look on the top of the truck for existing holes that you can use to affix the box to the truck. You might have to make your own, but in this example there were three existing good holes.
Use lipstick, chalk, or paint to mark the holes . . .
Box: Push Box Down on Hole Registration Marks
Put the box back down (be sure it's empty), and press down so as to transfer the lipstick/chalk/paint onto the back of the box as registration marks.
Box: Flip Over and Drill Holes Through Registration Marks
This doesn't always work as easily as it should, but eh. Try try again as needed.
Box: Add Some Access Holes
Cut a few holes in the back and/or sides of the box to allow you to access the insides easier.
Why? After running the robot, you'll want to sometimes remove parts, replace batteries, etc. An access hole or two will allow you to do this.
Box: Screw Box to Truck Chassis
Screw the box to the truck using the holes you just created.
Box: Thread Motor Wires Through Access Hole
Take the four elongated motor wires and route them through the access hole into the box.
L7239D Chip Info
The L7239D is a motor control chip. It has 16 pins. You basically give power to the chip itself, then hook up the output pins to the motors, then hook up the input pins to the F/B/L/R motor controls which will come from the Raspberry Pi's "GPIO" pins.
L7293D Close Up
The pins on the L7293D in the photo are reserved for this project as:
- VCC: 5-6v for the chip's power (goes to the separate chip battery)
- MLI: motor left input/control (will go to the Raspi GPIO pins)
- MLO: motor left output (will go to the motor left m- wire on the truck)
- GND: ground
- GND: ground
- MRO: motor right output (will go the motor right m+ wire on the truck)
- MRI: motor right input/control (will go to the Raspi GPIO pins)
- RLE: enable for the L/R motor
- FBE: enable for F/B motor
- MBI: motor back input/control (will go to the Raspi GPIP pins)
- MBO: motor back output (will go to the motor back m- wire on the truck)
- GND: ground
- GND: gound
- MFO: motor forward output (will go to the motor forward m+ wire on the truck)
- MFI: motor forward input/control (will go to the Raspi GPIO pins)
- BTP: motor/truck battery plus (goes to the truck's battery)
You'll want to jumper the pins together using nifty breadboard jumpers as in the picture to make it a little easier. Sort of.
Wire Motor Outputs
Place the breadboard containing the motor chip into the box.
Connect the four motor output wires to the motor output pins of the chip.
Wire Motor Battery
Place the motor battery into the box and hook it to the breadboard. Note that the motor battery's + end goes to the lower-right pin of the chip, and the - end (ground) is connected to one of the ground locations on the breadboard.
IMPORTANT
Ok, well not really that important, but when wiring in the motor battery, make sure you have easy access to the battery's switch.
Wire in the Chip Battery
Place the chip battery set into the box and hook it up to the VCC pin and another ground location.
IMPORTANT:
Again, be sure to make the battery switch will be easily accessible.
Wire in Raspi GND to Breadboard GND
Put the Raspberry Pi module in the box.
Connect a F/M from a GND on the Raspberry Pi to an available GND hole on the breadboard.
In this photo, the Raspberry Pi GND that is located on the far row and third pin in was used.
Wire Raspi Motor Fwd Control GPIO Pin to Breadboard
Connect a F/M from the GPIO control 1 pin on the Raspberry Pi to the motor fwd control pin on the breadboard.
GPIO control pin 1 is actually three pins down from the GND pin we are using.
Wire Raspi Motor Back Control GPIO Pin to Breadboard
Connect a F/M from the GPIO control 4 pin on the Raspberry Pi to the motor fwd control pin on the breadboard.
GPIO control pin 4 is actually two pins down from the GPIO control pin 1 that we are using for the forward control.
Wire Raspi Motor Left/Right Control GPIO Pins to Breadboard
Repeat the process for the Left/Right motor control: connect GPIO control pin 5 and GPIO control pin 6 to the breadboard's Left and Right Motor input control pins, respectively.
Add Raspi Rechargeable Battery
Connect the Raspberry Pi's rechargeable battery to the Pi.
Be sure to place the battery near one of the access holes so that you can turn the Pi on and off easily.
Remember you now have three different batteries to contend with:
- The battery for the motors
- The battery for the L293D chip
- The battery for the Raspberry Pi
Connect Camera and WiFi Dongle to Raspi Through Access Hole
Here I found it easier to place the Raspberry Pi toward the back of the truck and cut out another access hole for the camera and WiFi dongle. These both connect to the USB ports of the Pi.
Make Battery Switches Accessible
You can leave the switches inside the box and access them through one of the holes, or, preferably, screw them onto one of the sides of the box for easier access. Here I cut a few lil' tiny holes for the switches.
Close Lid, Add Velcro Strips
Add a couple of velcro strips to the top of the box
Add Popcorn Tin or Other Prop
I added a popcorn tin to give the final robot a few extra inches of height. Skip this step if you want a shorter robot. The velcro is just to help keep the tin on the roof of the box.
Attach Mascot Body
I used Egor, our office mascot for the final robot. In this photo, I used a cola bear, just as an example.
Use duct tape or velcro to attach the mascot to the popcorn tin or top of the box.
Create Shoulder Frame
Bend a hangar or stiff wire to give some shoulder shape.
Add Shoulder
Tape the shoulder frame to the back of the tin. This will help keep the robot's lab coat or rain coat up.
Add Some Arms
Use a pool noodle duct-taped around the shoulder/hangar and down the sides to create arms.
Use some stiff wire to bend the arm a little, then wrap the same said wire around the shoulder to the other side. This will allow you to give the arms a little bend and help keep them from splaying outward. You can see this in the second photo close up of Egor's right arm.
Add Camera
Tape the camera to the front of the robot, just like in Criminal Minds. Note: this photo doesn't show the pool noodle arms.
NOTE
A quick note about cameras. There are basically two types of cameras usable on the Raspi: A USB web-type camera, and the RaspiCam camera (shown in second photo). The USB cameras can be tricky. Some work. Some don't. The PlayStation camera (third photo) does work out of the three USB cameras that I tried. You can also opt for a camera built specifically for the Raspi. I also tried one of them (i.e. the RaspiCam). Here are the considerations:
- USB camera
- Advantage: Usually cheap ($3-$30)
- Advantage: Have a long cable
- Advantage: Lots of on-line tutorials on the various software that works
- Disadvantage: Can be tricky to find compatible camera
- Disadvantage: Can suck down power
- Raspi camera
- Advantage: Built specifically for Raspi so not a compatibility issue
- Advantage: Does not suck as much power
- Disadvantage: EXTREMELY short cable (making its cable longer is said to cause jitter in the final video)
- Disadvantage: pricey ($30)
Add Clothes
Now for the fun part, fashion show, here's the bear
Squirrel Robot
Don't ask.
But, by keeping the components modular, it's easy to swap out the 'bot body.
Mr. Fuzzy
This is our other office mascot.
Dog Robot.
Egor
Here's Egor's final outfit. Got him some shoes and a tie at the Goodwill.
Running Egor With Just Remote Control
That's most of the hardware. If you wanted to, you could quit now and just run Egor around the office with just the transmitter, like Bryan did here (provided you had spliced the motor wires in the first few steps and left the receiver board intact).
But for a tele-presence (sort of) capability, read on !
Add Walkie Talkie
Not a true tele-presence, but eh, allows Egor to ask for chocolate and to tell people to get out of the way.
Raspi Software
That's the hardware. To run Egor from the Internet or Intranet or private net, you can use the Raspberry Pi.
The Raspberry Pi computer needs to be set up with:
- WiFi access
- User interface to view the camera output
- User interface to control the GPIO pins and, ultimately the motors
Raspi WiFi Access
There are many ways to set up WiFi/remote control for Egor. Bottom line is that for Egor I had to set him up as an Access Point. (As shown sort of in second photo.) Your situation may be different, though.
Here is a great tutorial on setting up the Raspi as a WiFi Access Point.
And here is a tutorial for setting up the Raspi with standard WiFi on the Pi
Here are some things to consider when considering how to control your robot via WiFi:
- WiFi can come in several or more flavors, these are the ones I considered:
- DHCP (where Egor connects to your company's WiFi and assigns an IP)
- This is preferred for a company environment because your IT group will probably not appreciate you coming up with and stealing an IP
- The advantage is that you are using the office WiFI and Egor can run all over the building (provided your office's WiFi is extensible)
- The disadvantage may be that your office's WiFi is terrible and has crappy through-put
- The other disadvantage is that you don't know what IP Egor will be running on between turning him on and off; he could have a new IP each time. There are a couple of ways to mitigate this problem:
- Add an LCD display to display the IP that Egor was assigned
- Have the on-board Raspi LEDs blink in morse code his IP
- Add an SMTP mail client to email you his IP
- Static IP (where Egor connects to your office's WiFi but has his own IP)
- This is preferred when the IT group doesn't care if you hog an IP or are assigned an IP for Egor
- The disadvantage again, could be that your office's WiFi is crappy
- The advantage is you know the IP
- Access Point (where Egor becomes his own network with his own IP)
- This is preferred when you the company's WiFi is crappy; you can keep Egor's camera video stream and control signals on his own private network
- This is advantageous because you will know Egor's IP
- This is a big disadvantage in that you are limited to the range of the WiFi dongle's transmitting capability
- DHCP (where Egor connects to your company's WiFi and assigns an IP)
Other things to consider:
- Third-party apps such as Google Voice, Skype, Turn/Heroku Servers, or relying on "new" HTML5 capabilities
- I looked into these but didn't want to be weighed down with these technologies. Some work, some don't, and there were too many unknowns. Plus, the office WiFi where Egor works is lousy.
Camera Execution and Http Access
There are numerous libraries that can capture USB video. I recommend mjpeg-streamer for many reasons. Here is an example documenting the installation of mjpeg-streamer. When mjpg-streamer is installed and running, you simply point a browser to the Raspi's IP with the (default) port of 8080, as shown in the photo.
Mjpeg-Streamer Installation for USB camera
And here is an example using mjpeg-streamer for the raspi-cam:
Mjpeg-Streamer Installation for RaspiCam
Based on info from the first link (Mjpeg-Streamer for USB camera), here are the commands I ran to get the Playstation USB camera running: [disclaimer: yes of course it works the first time! after about a hundred attempts]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- - - - - - - - - -
sudo apt-get update
sudo apt-get upgrade
lsusb [should show list of USB devices,including your camera]
sudo apt-get install subversion
sudo apt-get install libv4l-dev
sudo apt-get install libjpeg8-dev sudo apt-get install imagemagick
cd
pwd [(should show /home/pi]
svn co https://svn.code.sf.net/p/mjpg-streamer/code/
[the above should place a directory called "code/mjpg-streamer" under your /home/pi directory, if you want to use my motor controller in the next step, be sure that your directory has the same set up]
cd code
pwd [should show /home/pi/code]
cd mjpg-streamer
pwd [should show /home/pi/code/mjpg-streamer]
make USE_LIBV4L2=true clean all
make DESTDIR=/usr install
[for the Playstation camera, I had to tell mjpg-streamer to use YUV format, not the default mjpeg format; to do this, follow these sub-steps]:
- nano start.sh [or vi start.sh]
- look for the string ./mjpg-streamer WITHOUT A PREFIXED pound/hashtag [which are comment lines]
- within the above string, look for the string "./input_uvc.so" [WITH the quotes!] and change it to read:
- "./input_uvc.so -yuv" [WITH the quotes]
- So the line should look like:
- ./mjpg_streamer -i "./input_uvc.so -yuv" -o "./output_http.so -w ./www"
- Save file
- Exit
./start.sh [mjpg-streamer should start and you may see error messages about not being able to control a non-existent tripod, these errors can be ignored]
On my Raspi, when starting mjpg-streamer via the ./start.h command, the output appears as follows:
- pi@raspberrypi ~/code/mjpg-streamer $ ./start.sh
- MJPG Streamer Version: svn rev: 3:172
- i: Using V4L2 device.: /dev/video0
- i: Desired Resolution: 640 x 480
- i: Frames Per Second.: 5
- i: Format............: YUV
- i: JPEG Quality......: 80
- Adding control for Pan (relative) UVCIOC_CTRL_ADD - Error: Inappropriate ioctl for device
- Adding control for Tilt (relative) UVCIOC_CTRL_ADD - Error: Inappropriate ioctl for device
- o: www-folder-path...: ./www/
- o: HTTP TCP port.....: 8080
- o: username:password.: disabled
- o: commands..........: enabled
Then, I pointed my browser from another computer on the same network to the Raspberry Pi with port 8080.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NOTE:
In an attempt to minimize the bandwidth used for Egor's camera, I also wrote a UDP snapshot transfer mechanism which I ended up not needing due to putting Egor on his own private network.
Motor Controller Software
This just sucks. There's a buzillion ways to do this, but long long long story short, here's my code (Java class files) to run a simple Java applet user interface and server to control the motors. Trust me, you do not want to know the whole story why this is an applet. Just use the code if you like.
Other Instructables showing GPIO control over network:
Simple and Intuitive Web Interface for GPIO
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
To use my server and client control applet, place the following files in the following directories on the Raspi [again, this assumes that you installed mjpg-streamer at /home/pi/code/mjpg-streamer]
- cmdsrv.sh: /home/pi/code/mjpg-srtreamer
- cmd.html: /home/pi/code/mjpg-streamer/www
- cmdsrv.jar: /home/pi/code/mjpg-streamer/www
- cmdtx.jar: /home/pi/code/mjpg-streamer/www
To start the motor server:
- on the Raspi, run:
- cd
- cd code/mjpg-streamer
- ./cmdsrv.sh
To run the motor user interface:
- on another computer on same network, set your browser to:
- http:// the RaspberryPi's IP here>:9000
- A pop up page will appear and attempt to draw the applet
- If the applet UI doesn't show up, it may mean that your browser cannot or is not allowed to run applets
NOTE: the client part is a Java applet so your browser will have to be set to allow Java applets or download the cmdtx.jar file to your browser computer and run it right from Java on that computer.