|
How We Built the Quintessential Sentry Gun (Updated Oct 27th)
It's still alive
There will be a Mark II version. Okay, "quintessential" might be going a little far, but it's enough to frighten me. The idea of this project was to create a fully-automated sentry gun, capable of picking out a human target and accurately tracking and shooting him or her in the heart. Really, the idea was to find a cool robotics project for the summer while I was working at an advertising agency, and I'd only ever seen sentry guns in movies (like Congo) and video games (Half-Life 1, Half-Life 2, Team Fortress Classic). I couldn't find any record of anyone building one, even the military, although it seems likely I just didn't look hard enough. It's a pretty simple technology. One of my friends did mention the Phalanx anti-missile gun, which is of similar design, but uses radar for tracking instead of an optical method. The Phalanx has been around since the early 80's. He was also quick to add that there are some pretty good reasons for not building an optical sentry gun, a big one being that it's generally a good idea to shoot down any missile headed in your direction, but that same philosophy may not be the best when applied to humans. If you're here just to see my little brother get shot with it, scroll to the bottom. :) I'm sorry this webpage sucks, it will get better with time. First of all: Thank you everyone who has emailed me for your encouragement and support in this. You are really the ones who have convinced me to move forward with this project. About the new video: -------------- Test2 actually has the first test we ever did as the last cut. Notice that we hadn't messed with many of the settings for outdoors. Ezra was also standing too close to the gun, because we weren't aware that it would track at such long distances. It's also a bit more painful up close...sorry about that, Ez. Basically, I just put that shot up there because it's funny. The middle shot is when we're recalibrating the gun because the recoil and turret motion had misaligned our camera. You'll also notice that he's able to duck under the motion range of the gun. This was because it was still set up for a smaller tripod. No more ducking for Ez. ---------------- Construction The first part of this fun little summer project was to write all of the necessary computer code to control the turret. I started by learning Microsoft's DirectShow technology and utilizing the OpenCV library according to the tutorial by R. Laganiere to access the pixels being sent by my web cam. I used simple algorithms from a Machine Vision course I took at Boston University to develop the aiming program. A couple of servos from Craigslist and a Mini SSC II servo controller later, I was ready to start. The Mini SSC II didn't come with any code for C++, so I had to write my own control code that worked through serial. I set up a small test turret that just rotated a laser pointer so I could work out the proper methods for calibrating the turret to the camera view area and aiming data. My little brother, Ezra, helped me assemble the full turret. The gun on the turret is a cheap automatic Airsoft replica of an FN P90 that shoots .2 gram 6mm BB's. The gun was an obvious choice because it was light and has an unusual horizontal magazine that made it easier to mount. We used plywood and the extent of my middle school wood shop experience to assemble all of the major components. My uncle helped with some of the trickier woodworking techniques.
The thumb hole in the P90 made a nice place through which to put a bolt that tightened the two pieces of plywood together. The hole in the middle is for the wooden dowel that we used for an axle between two bearings from Ace Hardware. The mount consists of three major pieces, the gun attachment (above), the tilt head, and the pan base (below).
We used a lazy susan bearing that had an annoying amount of play in it for the main support of the gun weight. Notice the dowel in the center of the bearing. On top is the nylon gear that connects to the servo which will turn the tilt head.
This is the underside of the tilt head. The part in the middle is the drive shaft of the servo. Those circles are concentric, but the larger circle wasn't evenly drilled. We didn't have a drill press and usually resorted to repeatedly using a square to make sure the drill was perpendicular to the wood. That didn't work particularly well on this occasion.
This is the assembled, unpainted turret without the trigger mechanism.
These are the pan and tilt control servos (on the painted turret). The one on the right is a direct drive servo that connects to the dowel in the middle of the lazy susan bearing. The servo on the left uses RC airplane elevator linkage to connect to the tilt head. The control software for the latter was more difficult to program because it's actually a four-bar linkage, and I am not a mechanical engineer. This was the simplest explanation of how to calculate input and output angles in a four-bar linkage, if you're interested.
You can see where the tilt servo connects to the tilt head. Also, note that the trigger mechanism has been attached.
From this angle you can see the trigger control micro servo towards the rear of the gun. You can also see the cheap digital camera attached to the underside of the turret base. On the side facing us is the laser site I used for calibrating the gun, on top is a red dot scope that is horribly inaccurate (but looks cool), and on the far sid is the tactical LED flashlight. I hope to replace the white LED's with infrared ones at some point.
This is the back of the turret. The Mini SSC II is on the left, next to it is its power, a 9-volt battery. There are three cables that leave the turret, the USB from the camera, the serial control cable from the Mini SSC II, and the servo power (a 6v, 1amp external power supply). The blue wires are from the servos. We had a problem with the pan servo dumping power back through its PWM control line into the Mini SSC II when it was operating outside its torque range. This caused all the servos to jump and jitter, which in turn led to a horrible harmonic motion in the entire gun. We put diodes on all of the PWM lines, which helped a lot, but we think that there's still some bleed happening through the servo power lines because there's still a little twitchiness when the pan servo gets overworked.
Ezra (right) and I proudly standing with the finished turret. Contrary to common belief, we're wearing beige shirts. I have no idea why they came out as pink in the picture. Notice the tactical LED flashlight is glowing on the left side of the turret. There is absolutely no practical reason for that.
Testing Most of my software had been tested in my room with the small turret. To test outside, we had to drag my huge (and ancient) 1.5ghz, 512meg RDRAM computer to the backyard. Most of the testing involved me directing my little brother in front of the turret, him getting shot, and then running away. Polo shirts, not surprisingly, offer very little protection from BB's that are prone to leaving little welts. When I originally wrote the software, I added code so it would use the Microsoft speech API to say "Freeze" and offer various instructions to a target that it had acquired. The speech synthesizer was too much for my computer and it would stutter, entirely missing (rather important) commands and freezing the computer up. I'm sure multithreading will help with this particular problem, but for testing we turned off the speech synthesizer and left on the delayed firing that waited until the target moved.
This is from the sentry gun's camera. Although the crosshairs are on Ezra's stomach, there is a smaller set of crosshairs right on his sternum (where the gun was pointed). The problem is, I made those crosshairs white. The large crosshairs are pointing to his center of mass. The tiny ones in the upper right and lower left point to the bounds of the detected region. Once I determined that the gun was properly refraining from firing, I told Ezra to move. The blobby light areas, like Ezra's pants, are what the software is considering a non-background object.
I just had the program draw crosshairs on the bounds when it was firing. Ezra is on the verge of running at this point.
This is a frame very close to the one above, but from a camcorder we set up next to the turret. Here is the link to a video of this particular test (Quicktime). The first clip is the scene from the camcorder's perspective, the second is from the turret's. The last scene is the turret tracking Ezra in the dark as he vainly attempts to shoot the turret using a pistol.
Notes -------------------------------- There is still a large amount of work left to do on the software for the turret, however much of it will be completed in time for USM's first prototype in late December. I left all of these "I would like" things in the notes, because they're amusing. USM is currently engineering a high-precision version of the turret. --------------------------------------------- As for the hardware, I'd love to put more than $50 into the control head than I already have. There is more give in the system than I like because the pan bearing is a lazy susan bearing. This means that the gun has about a 4-inch horizontal hit area at 30 feet. Vertically, it is a bit more accurate--to around an inch. Another problem with the hardware is that the pan servo is operating at the absolute maximum torque it can handle. I simply need a bigger, more expensive one. That way it will stop overshooting its stopping position when it has to move quickly. I would like to get a more stable tripod. This one wobbled so much the camera shook past what my algorithm could handle, as you can see by the periodic huge white areas in the AVI. I would love to add a laser range finder to the mix, preferably on an independently aimable gimbal. Range finding would allow the gun to be accurate at long range and compensate for ballistics. It would also help a lot when I continue the multiple target identification and tracking system. There are a number of applications for a sentry gun like this that don't involve putting holes in people. For example, I could put a camera on top and use it for wildlife photography. A squirt gun could be attached, and it could be used to discipline your cat when it tries to jump on the couch...simultaneously watering your couch. It lends itself nicely to a vortex gun platform, and that could be used to keep crows off of cornfields. I would like to pursue some of these ideas when I have the time. I hope you enjoyed it! We certainly did. Hopefully, I'll be able to update this site later this semester as the software improves. I also may post more videos of our somewhat-painful test runs.
Don't Die Disclaimer: Don't use these plans, derivations of the gun, or anything to hurt people. In fact, don't hurt people. |
Any questions or comments can be directed to Aaron Rasmussen, ai.rasmussen@gmail.com.