Autonomous Paintball Sentry Gun
Autonomous Paintball Sentry Gun
Table of Contents
Step 2: Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Step 5: Wiring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Step 6: Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
http://www.instructables.com/id/Autonomous-Paintball-Sentry-Gun/
Intro: Autonomous Paintball Sentry Gun
Make your own, custom AUTONOMOUS SENTRY GUN!
This sentry gun autonomously tracks, aims, and shoots at targets, using:
-An airsoft or paintball gun
-A webcam to find targets
-A computer to process the video feed and aim the gun
-Servo motors to physically aim the gun and squeeze the trigger
-A sturdy tripod base
-A microcontroller to interface between the computer and the servo motors
-Lots of camo paint
The end result is a paintball/airsoft spewing robot, that can turn the tides of any match.
P.S. take pictures during the project, and when you are finished, send me a picture, and a description of your project, and I will feature it on the Successful Projects page
of my website. Thanks!
Image Notes
1. Airsoft M4 machine gun
2. Webcam
3. Arduino and custom PCB (inside waterproof compartment)
4. Servo motors to pan and tilt the gun
5. USB cords go to computer
6. Sturdy tripod base
7. Control switches: -Reload -Servo Power -Safety (gun power)
Also, you will need a laptop or computer to run the sentry gun program. $250 for a cheap netbook, if you don't have anything else...
http://www.instructables.com/id/Autonomous-Paintball-Sentry-Gun/
Step 2: Arduino
What's an Arduino? ...and how do you pronounce that, anyway?
An Arduino is a microcontroller. It plugs into a computer with a USB cord. On the Arduino board, shown below, there is an ATMega328 microchip, as well as 14 digital
input/outputs, 6 analog inputs, and a USB port.
That's not all, but it's everything that you will need to know about, to build a sentry gun. For complete details on the Arduino board, go to
http://arduino.cc/en/Main/ArduinoBoardUno.
You will use the Arduino board to take commands from the computer, and drive the servo motors as the commands dictate. Also, it will provide you with hookups for
expanding your own ciruit easily afterwards.
Image Notes
1. An Arduino Uno, the latest Arduino board. There are many different styles and models of Arduino board, and almost any of them will work in this project, as long
as they have digital input/outputs, and UBS/serial communication
Your remaining servo motor will be used to squeeze the trigger of your gun.
For heavy guns, such as the paintball gun shown below, you might want to get some stronger servo's.
http://www.instructables.com/id/Autonomous-Paintball-Sentry-Gun/
Image Notes
1. A standard servo. These will work fine for light-weight guns, but larger guns
such as paintball guns will require heavy-duty servo motors.
Image Notes
1. Tilt servo - controls the up-down (y-axis) movement of the gun
2. Pan servo - controls the side to side (x-axis) movement of the gun
3. Trigger servo - pulls the trigger of the gun
4. Semi-automatic paintball gun
http://www.instructables.com/id/Autonomous-Paintball-Sentry-Gun/
Image Notes
1. Tilt servo - controls the up-down (y-axis) movement of the gun
2. Pan servo - controls the side to side (x-axis) movement of the gun
3. Trigger servo - pulls the trigger of the gun
4. Semi-automatic paintball gun
The gun should be balanced on the tilt servo. Find the gun's center of gravity, and mount it at that point. This is so the servo dosn't have to waste energy trying to
keep the gun level. IMPORTANT: when the servo has no power supplied to it, the gun should tilt freely, and when you move it with your hand it should not return to level -
rather it should stay right where you let go. Spend a lot of time getting this balance just right, it is a major factor in the effectiveness of your finished sentry.
Stability is key. You want a strong, solid sentry. Vibration will cause a lot of issues with the camera later, if you don't suppress it now. I'm not going to teach you how to
build well, but keep in mind that screws and bolts are better than nails, nails are better than zip ties, zip ties are better than staples, and even staples are better than duct
tape.
The webcam must be solidly mounted to the base. You want it close to the gun, but the gun barrel can't ever move into the camera's view - it will see that as a target.
Also, the webcam should be as solid as possible - vibration from the servo's and gun firing will mess it up.
Depending on the expected use for the sentry (airsoft? paintball? water jet? laser?), you may need to add a durable compartment to hold the electronics.
Finally: tripods are cool, but they can be prone to a lot of shaking if built badly, or if you use a flimsy camera tripod. Surveyor's tripods are great for sentry guns - they are
heavy, stable, and often adjustable too.
http://www.instructables.com/id/Autonomous-Paintball-Sentry-Gun/
Image Notes
1. webcam is screwed onto base - very stable
2. switches and LED's
3. Gun is balanced on tilt servo
4. Compartment for electronics - made from durable lock-n-lock box
5. Stable base - made from 2 sheets of 3/4 inch plywood, and 2 sheets of 1/4 inch aluminum. The tripod legs slide into holes drilled for the purpose, and are fixed in
by bolts.
6. Copper pipe for legs
Step 5: Wiring
Arduino :
The Arduino connects to the computer through the USB A to B cord. This also powers the Arduino. Various other things wire to the Arduino:
Servos :
You will need a seperate power source for your servo's. I reccomend 4 C-cell or D-cell batteries, wired in series to make 6V. Check the data sheet to find the power
consumption for your servo's!
Servo motors have three wires: power, ground, and signal. Each servo's power wire is typically red, and should be connected to the (+) wire from your servo power
source. The ground wire is typically black or brown and should be connected to a ground pin on the Arduino board, and to the (-) wire of your power source. The signal
wire is typically yellow, orange or white and should be connected as follows: The x-axis servo's signal wire goes to the Arduino's digital I/O pin 3, the y-axis servo to pin 4,
and the trigger servo to pin 6.
You can also add some optional switches and LED's , but they are not necessary:
-USB status indicator LED to digital I/O pin 6
-firing indicator LED to digital I/O pin 2
-a "power switch" between the (+) from the servo power source and the servo's, to turn off the servo's and save battery power
-a "safety switch" between the (+) from the servo power source, and the trigger servo, (but after the 'power switch'), to turn off the firing functionality easily and quickly (in
an emergency)
-a 'reload' switch, wired between +5V from the Arduino and digital I/O pin 7, to set the gun in a programmable position convenient for reloading
Solder everything if you can. If you want, make your own arduino 'shield' with all the conections. This allows you to "plug in" the Arduino, and "unplug" it when it is needed
elsewhere, without losing track of which wires go to which pins.
http://www.instructables.com/id/Autonomous-Paintball-Sentry-Gun/
Image Notes Image Notes
1. Wire your "power switch" in here 1. Custom shield - solder pin headers to some perf-board, in the right places for
2. Wire your "safety switch" in here the Arduino pins. You don't need headers for the Analog In set of sockets on te
3. You may also want to add a resistor in series with each LED too, for Arduino, or for the digital I/O pins 8-13 and AREF. Don't use the solder on this
protection. The value depends on your LED, but 5K should work fine for most. perf-board as a reference - I was messing around with an h-bridge IC to control
4. These are the pin labels seen on the Arduino board - if they are difficult to the airsoft gun....
understand, refer to the written directions above. 2. Servo power source - comes from the 4 D-cell batteries. I soldered this nice
5. These are NOT the correct pin numbers! (see box to left) power cord to the battery wires, and a matching jack to the 'shield' (on
6. remember to connect the ground of the servo power source to the Arduino underside).
ground 3. Arduino board - what else.
Step 6: Software
Now you have your sentry gun built, the wiring finished, and no doubt you want it to do something!
Before you plug your Arduino into your computer, go download the Arduino IDE .
If you have a Diecimila or older board, set the Power Jumber to USB.
Now, plug your Arduino in - the green Power LED on the Arduino should light up, and the orange LED might flash a few times. Good job!
The Arduino IDE is what you will use to load the Arduino program onto your board. However, you will need the seperate, Processing IDE to run the computer side of the
code. This does the camera tracking, and sends commands to the Arduino.
Go download the Processing IDE .
Open both Processing IDE and Arduino IDE. They should look very similar.
With a little bit of trial-and-error on the code, you should have a working sentry in no time! So get started typing!
The next thing you need to do is download the JMyron, blobDetection, and controlP5 libraries from processing.org. Find the link to each library on that page. The
instructions for downloading each one can be found by clicking on it's link.
You are ready to go get the code! Download the latest version it from my website . After you have saved it to your computer, unzip the folder, and follow the directions in
the strategically placed README.txt files.
Open the Arduino code in the Arduino IDE. Make sure you have selected the proper board and serial port from the Tools menu. Next, click 'Verify', wait for it to say "done
compiling", then click 'Upload'. The RX and TX LED's on the Arduino board should pulse a little, then stop.
Now, open the Processing code in the Processing IDE. Click 'Run', and watch the magic happen!
Of course, for many of you this will not work on the first try. Don't get upset, it's normal. Pop me an email with any problems, or leave a comment below.
If you are getting this error when you try to run: processing.app.debug.RunnerException: UnsatisfiedLinkError: D:\Software\processing-
1.2.1\libraries\JMyron\library\JMyron.dll: Can't find dependent libraries:
http://www.instructables.com/id/Autonomous-Paintball-Sentry-Gun/
"Reason : Windows 7 doesn't come with MicroSoft C libraries, which were normally include in the other (older) Windoes system.
This means there are two files missing in the Windows 7 system: MSVCP71.DLL and Msvcr71.dll
Solution : Download these two files from here:
http://www.addictivetips.com/?attachment_id=38105
AND!
For Windows 7 32-bit OS: put both dll files inside Windows/System32 folder
For Windows 7 64-bit OS: put both dll files inside Windows/SysWOW64 folder."
Image Notes
1. This is what you want...
In Manual Mode, you can aim and fire by pointing and clicking on the webcam view. In Autonomous Mode, the software takes over, and your gun gains a life of it's own!
Give it a little time to adjust to the background, and then it will shoot at anything that enters its view.
Play around with the other functions as well - Auto/Semi-auto, hide camera view, etc.
Calibrating - your servo and camera arrangement is probably unique, so you will need to calibrate it the first time.
You can do this by adjusting the values of xMin, xMax, yMin, and yMax, at the beginning of the code. Play around with them untill you have the gun aiming where you
point the mouse on the webcam view. A useful tool to do this is to watch the numbers scrolling by at the bottom of the Processing IDE while you run the code.
You may also need to calibrate the servo positions set in the Arduino code:
To set the home position (no USB communication), change these lines :
if(idle) {
idleCounter++;
if(idleCounter > 10000) {
analogWrite(5, 50);
delay(250);
digitalWrite(5, LOW);
idleCounter = 0;
}
else{
digitalWrite(5, LOW);
}
xPosition = 110 ;
yPosition = 100 ;
fire = 0;
}
To set the 'squeezed' and 'not squeezed' positions for the trigger servo, change these lines :
void Fire(int selector) {
if(selector == 1) {
fireTimer++;
if(fireTimer >=0 && fireTimer <= triggerTravelMillis) {
trigger.write( 90 );
digitalWrite(2, HIGH);
http://www.instructables.com/id/Autonomous-Paintball-Sentry-Gun/
}
if(fireTimer > triggerTravelMillis && fireTimer < 1.5*triggerTravelMillis) {
trigger.write( 140 );
digitalWrite(2, LOW);
}
if(fireTimer >= 1.5*triggerTravelMillis) {
fireTimer = 0;
}
}
if(selector == 3) {
trigger.write( 90 );
digitalWrite(2, HIGH);
}
}
void ceaseFire(int selector) {
if(selector == 1) {
fireTimer = 0;
trigger.write( 140 );
digitalWrite(2, LOW);
}
if(selector == 3) {
trigger.write( 140 );
digitalWrite(2, LOW);
}
}
Image Notes
1. Open Camera Settings
2. Set current frame as background (in autonomous mode)
3. Toggle between autonomous and manual modes
4. Fire your gun with automatic fire (holds trigger) or with semi-automoatic fire (squeezes trigger repeatedly)
5. Show the view from the camera
6. The live feed from the webcam
7. aiming crosshairs - used in manual mode
Related Instructables
Comments
50 comments Add Comment view all 55 comments
I have installed jmyron as instructed in the file but i still get this error :(
Your help would be greatly appreciated :)
Copy the "JMyron" folder found in this directory into the Processing/libraries directory.
NO! Put that folder instead at C:\Users\ USERNAME \Documents\processing-1.1\processing-1.1\libraries
Copy the "JMyron Examples" folder into your Processing Examples folder.
IMPORTANT FOR WINDOWS USERS: there is a folder called "Extra DLLs" - those are DLLs that JMyron depends on so make sure they're copied into
your system's DLL search path - such as the Processing root directory, or even C:\windows\System32.
"IMPORTANT FOR WINDOWS USERS: there is a folder called "Extra DLLs" - those are DLLs that JMyron depends on so make sure they're copied
into your system's DLL search path - such as the Processing root directory, or even C:\windows\System32."
Place "Extra DLLs" to system's DLL search path" I don't understand this.
BTW, do you know what kind of souce I will be able to find a air solenoid?
http://www.instructables.com/id/Autonomous-Paintball-Sentry-Gun/
I event try to copy the entire working folder from VISTA to 7, but still no luck, and I do put the DLLs in to both process root and
C:\Windows\System32.
BTW, my windows 7 machine is completly clean, I only install the new version of JAVA since the one come with the installing CD
is old I think.
Also, I try to put the two dll files all over the place, but still got no luck so far.
Reason: Windows 7 doesn't come with MicroSoft C libraries, which were normally include in the other (older)
Windoes system.
This means there are two files missing in the Windows 7 system: MSVCP71.DLL and Msvcr71.dll
AND!
For Windows 7 32-bit OS: put both dll files inside Windows/System32 folder
For Windows 7 64-bit OS: put both dll files inside Windows/SysWOW64 folder
==========================================
New problem occurs now, but not a very big deal to me though.
Still, in Windows 7 machine, the behavior of the portal sound track is weired.
When start the program, the first sound track (deploying~) plays no problem, but whatever the sound track comes
after that, tent to lag forever at the end of it.
Example: press RUN > First sound: "Deplaying" > Second sound: "Will you come over
herererererererererererererererererererer................"
The tracking still works fine and smooth while the sound is lagging, it just really creeped me out when I first heard
this at 1:30am by myself XD"
1. http://luckylarry.co.uk/arduino-projects/arduino-sonic-range-finder-with-srf05/
Problem: limited distance(about 10m max), and almost imposible to focus on small object.
2.http://hackedgadgets.com/2010/11/24/laser-range-finder-build/
homemade laser range finder, should be a very good one for sentry
Problem: it's not easy, almost like another full profect, and the camera unit are damn expansive......
3: http://sites.google.com/site/todddanko/home/webcam_laser_ranger
another laser range finder, but instead using chip and camera unit like the above one, this one use webcam and computer Software to do the job.
http://www.instructables.com/id/Autonomous-Paintball-Sentry-Gun/
Problem: now we really need to mount an second webcam on the gun berrel.
=====================================================
************************************************************************************
4: http://hackedgadgets.com/2008/09/03/webcam-rangefinder-2/
-Jason
Thanks.
Jason
I don't know of a way to choose the video input. That is not a part of the code, it is handled inside the JMyron library. A quick search on processing
forums yields one person with the same question , but nobody answered them.
Perhaps you can choose 'default' video source on your computer's Control Panel? Let me know if you find anything. Sorry i cant help any more than that!
Cheers
-Bob
I'm still working on ways to change the video input, but GraphEdit might be a solution. I just start learning how to use it.
Thanks
-Jason
http://www.instructables.com/id/Autonomous-Paintball-Sentry-Gun/
ljfa321 says: Feb 18, 2011. 4:16 PM REPLY
I was doing some research on the ways to connect 2 or more webcam video steam into one while waiting for my new servol to come. (I burned one of my
heavy duty servol by supply 7.5V to the 6V servol :P )
Don't have any luck yet for a reliable way to connect 2 webcam, but I cam across something interesting.
http://www.aroundvision.com/purchase.htm
Basically, its a cheap device using mirror to make a webcam views 360-degree, and he have a software to adjust the video stream so it won't looks too odd.
It looks like a fun thing to try, but it will be extreamly hard to adjust the video into a non-curly one, though It will be hard for the sentry software to aim properly
since a straight line in real world won't be that staight in the video stream.
Its seems like most computer will have no problam getting video from 2 webcam at the same time; its the software came with the webcam that will cause
problem.
Simply put, two webcams using the same software to run will have problem running at the same time due to the problem occur while running 2 same
software at the same time.
It will be much easier to use 2 webcams from different brand which have two different softwares.
But than the different views (as for contract, size, zoom, colour, etc) of the webcam may cause problem when merge two videws into one...........
Basically, this is a device that takes input from four cameras, and combines them into one output. The output signal is a standard video signal, so the
computer reads it as one camera.
However, this output signal is divided into quarters, each quarter showing one of the original camera views. The code could easily be worked to split
these 4 views apart, and re-join them in a horizontal configuration, giving you a wide-range view, from 4 seperate cameras.
If anybody has a multiplexer like this, or knows where to get one, let us know!
Stereoscopic Multiplexer
http://www.3dtv.at/Downloads/Index_en.aspx
A software that works like a hardware multiplexer. Even better, I take two USB webcam as imput and put the video stream side by side!!!
I'm still waiting my second webcam to come, and haven't succesfully run the software with 1 webcam, but this looks promissing.
If so, will it be possible to set a different trigger (in my thought, battle switch), which will be activate when a orange target that is smaller than a size be seen?
And the battle switch ( the second trigger) can disconect the trigger servo when seen a orange target.
http://www.instructables.com/id/Autonomous-Paintball-Sentry-Gun/
ljfa321 says: Feb 23, 2011. 9:32 PM REPLY
Thats sweet!!! you already finished the hardest part!
The rest is just telling it what to do when see the specific colour.
BTW: the ability to decide the tracked target size on the new version of the software is awsom! Now my sentry won't track its own BB's :P
(That happened probebly because I slowed my airsoft gun's voltage to the slowest when I was testing at home)
They seem to repeat and they are laggy. I can hear parts of one sound playing while others play at the same time. Some play fine but others get stuck. Any
ideas? Is there a way to stop previous sounds playing before telling a new one to play?
Thanks you. If you can fix this it would be great! I'l also look into it when I have time.
In either case. I successfully tested my turret today and aside from frequent jamming and glitchy sounds, it worked well and was very
impressive. Thank you for this instructable!
I will continue to improve the design and code and will submit my turret to your "featured successful projects" page.
http://www.instructables.com/id/Autonomous-Paintball-Sentry-Gun/
ljfa321 says: Feb 21, 2011. 12:01 PM REPLY
Ok, everything is working for the new servo <3
Now I just have to wait until the university reading break is over and the shop open to build the body of the sentry. I will build a very simple base first to test
how the servo react to heavy load, and will go straight to the full scale of this
http://img4.imageshack.us/img4/7015/sentrygun1.jpg
While waiting, I will test different type of materials, since the end result will be really heavy If I go all metal or even all wood...........
http://www.instructables.com/id/Autonomous-Paintball-Sentry-Gun/