3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.


Autonomous Paintball Sentry Gun

Step 7Using the Software

Using the Software

When you run the code, two windows should pop up. One is the Webcam View and the other is the Control Panel.

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 reloading position, change these lines :
    if(digitalRead(7) == HIGH) {
        xPosition = 110 ;
        yPosition = 135 ;
        fire = 0;
    }


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);
            }
            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);
        }
    }

« Previous StepDownload PDFView All StepsNext Step »
6 comments
Mar 22, 2012. 2:10 PMAJMansfield says:
What would be cool is if you then got an IR camera, so it can track body heat, and then some sort of marker (UV led vest? Tracking dots?) you can use to distinguish between your own team and others.
Sep 24, 2011. 6:22 AMLTM-Pedro says:
Hi, I'm from spain and i'll build a turret using your tutorial, but y would like to add some extras, such as a airsoft grenade launcher remotely controled, some tactical lasers and lights and other camera controled by a servo (wich is controlled by a joystick). I would want to know if i could use a joystick to control the airsft gun using your software.

Thaks and sorry for the grammar

Aug 6, 2011. 3:08 PMvruiz3 says:
i dont get it...how do you run the code.i got Hex editor
Feb 21, 2011. 1:08 PMVick Jr says:
I have a problem with the sounds.

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?
Feb 22, 2011. 5:21 AMVick Jr says:
Windows XP
processing 1.2.1
turret_05_03

Thanks you. If you can fix this it would be great! I'l also look into it when I have time.
Feb 22, 2011. 8:33 AMVick Jr says:
I made a quick fix. I'll post it later. Basically I changed your code to use an audioSnippet array, then before playing a sound, I pause whatever sound was last played, in case it's still playing. I also pause whatever sound I'm about to play.
Feb 22, 2011. 4:29 PMVick Jr says:
Never mind. It doesn't work. I've noticed that it only seems to lag if you move the turret (or it moves itself in auto mode) while a sounds is playing. Maybe the sound playing isn't running on a separate thread so when the main program slows down, the sounds do too. We should try another audio library. That Or I'll use my waveshield.

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.
Feb 23, 2011. 1:38 AMljfa321 says:
Hm, since like your problem are different with my Windows7 one.
Mine just keep repeat the last word of the second sound track.
However, the tracking works perfectly even the sound if screwed up.
Feb 22, 2011. 4:05 AMlug big lug says:
You should have some of those sounds in a really deep voice like when it says sentry mode activated..... that would be cool.....

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
15
Followers
2
Author:sentryGun53