Sie sind auf Seite 1von 22

Food Living Outside Play Technology Workshop

Nerf Vulcan Sentry Gun


by BrittLiv on March 2, 2013

Table of Contents

Nerf Vulcan Sentry Gun . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

Intro: Nerf Vulcan Sentry Gun . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Step 1: Stuff you need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

Step 2: Take the Vulcan apart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Step 3: Take the Vulcan apart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

Step 4: Optional: Replace the spring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

Step 5: Rewiring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

Step 6: Turn axis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

Step 7: Turn axis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

Step 8: Tilt axis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

Step 9: Tilt axis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

Step 10: Electronics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

Step 11: Processing IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

File Downloads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

http://www.instructables.com/id/Nerf-Vulcan-Sentry-Gun/
Author:BrittLiv Find out more about me
I'm a Chemical and Biological Engineering student especially interested in Computational Fluid Dynamics. To balance all the theoretical work I like to make
stuff in my free time.

Intro: Nerf Vulcan Sentry Gun


In this instructable, I will show you how to modify a Nerf Vulcan to automatically aim and fire at targets. As an added bonus, this gun won't fire at anyone wearing a shirt
with the instructables robot on it. I had this project in mind for a long time and finally managed to find the time to bring it to life.

If you've been browsing through my other instructables, you might have noticed that I am obsessed with Nerf guns. So far, Ive managed to infect just about everyone
around me with the Nerf virus. It is really fun to see how these plastic toys turn grown men into small boys!

My main aim was for it to look awesome; which was difficult to achieve without removing the front part of the gun. But, I managed to accomplish this without removing the
barrel, and Im really happy with how it turned out!

A big thanks goes to Bob who authored an awesome write up on how to build a sentry gun .

Please do not attempt this mod unless you are convinced that you will be able to do it; otherwise you might destroy your gun.

Please follow this link: (embedding a video doesn't seem to be working at the moment)
http://www.youtube.com/watch?v=C70R7oo4jMc

Image Notes
1. not wearing an instructables shirt, being detected and shot
2. wearing an instructables shirt, being safe.
3. A bit hard to see instructables robot.

http://www.instructables.com/id/Nerf-Vulcan-Sentry-Gun/
Step 1: Stuff you need
Stuff you need

To build the base:

Wood: 5 mm, 9 mm, 15 mm plywood


20 x 40 x 45 mm and 20 x 40 x 128 mm rectangular block of wood (you can also use the 1.5 mm plywood)
Junior drum throne
2 x ball-bearing (12 x 28 x 8 mm)
Axial ball bearing (80 x 105 x 19 mm)
12 mm wooden pole
Wood glue
Sand paper
Wood filler
Paint/paint brush
15 x spax/wood screws M4 x 40 mm; 4 x screws M4 x 16 mm
4 x wing nuts: M5
4 x machine screws: M5 x 16 mm
4 x brackets
Two component glue

Electronics

Servo for the turn axis: BMS-660DMG+HS


Servo for the tilt axis: Hitec HS-805BB
Wire
Arduino Uno
TIP120 transistor
1N4004 diode
1k resistor
Pin header

Other

Nerf Vulcan
6 Volt battery pack
5 kg replacement spring for the Vulcan
Optional: Paint and plastic primer for the gun
3 mm lead pearls or something similar as a counter weight
6V 3700mAh battery pack
9.6V 2000mAh battery pack

Tools

Drill (3, 5, 12, 28 (to fit the bearing) mm drill bits)


Sander
Scroll saw
Soldering iron
Claw hammer
Phillips Head screw driver
Hot glue gun

Things like a scroll saw and a powerful drill are useful, but not a 100% necessary. I finished the whole tilt axis with just a fret saw and a cordless drill which was far too
weak to drill the 28mm hole (I used the fret saw instead).

http://www.instructables.com/id/Nerf-Vulcan-Sentry-Gun/
Step 2: Take the Vulcan apart
Taking the Vulcan apart is certainly not an easy task, so be careful and try not to snap any plastic pieces.

Start by taking the handle off. You won't have to loosen any screws. Just hold the gun down and pull it to the side, as shown in the first picture.
Remove the screws from the belt retainer and take out the plastic inserts. Afterwards you can just pull it off.

http://www.instructables.com/id/Nerf-Vulcan-Sentry-Gun/
Step 3: Take the Vulcan apart
Use a claw hammer, to pry off the bolt head.
Remove the battery tray cover, as well as the battery tray.
Depending on the age of your Vulcan, there might be a sticker.
If there is a sticker, you will then have to cut it in half.
Now remove all the screws from the main part of the blaster.
You dont need to take the screws off which hold the barrel together unless you plan on painting the blaster.
Carefully pry the pieces apart.
Be careful that you dont damage the wires.

Image Notes
1. take all these screws out

http://www.instructables.com/id/Nerf-Vulcan-Sentry-Gun/
Step 4: Optional: Replace the spring
I recommend changing the spring at this point, but that decision is up to you. When you use battery packs with higher voltage, it will increase the firing rate, but not the
strength of the shot.
In my opinion, a 5 kg spring works best (the original one is a two kilo spring). I tried a 7 kilo spring in one, and although it was strong, it resulted in a lot of mis-firing.

To replace the spring, follow these steps:

Start by removing the orange plastic piece on the plunger.


Remove the 10 screws marked in the first picture of this step.
Then take off the casing.
Unhook the spring.
Remove the collar and spring from the plunger (as shown in the third picture).
Carefully remove the plunger.
Pull the plunger out of its casing.
After unscrewing the screw which is holding the plunger head you will be able to change the spring.

In the last picture you can see how the firing speed improved. To give you an idea of the guns speed after the replacement - it is about as fast as an unmodified Nerf
Maverick.

I tried to remove the air restrictor, too but noticed no difference in the firing speed, so I just left it where it was originally

Image Notes Image Notes


1. remove 1. be careful not to loose this pin
2. remove
3. remove
4. remove
5. remove
6. remove
7. remove
8. remove
9. remove
10. remove
11. remove
12. be careful not to loose the cap

http://www.instructables.com/id/Nerf-Vulcan-Sentry-Gun/
Step 5: Rewiring
A big advantage of the Nerf Vulcan is that no extra servo is needed to fire it. The Arduino can directly be wired to the motor of the gun.

To wire the Arduino to the Motor:

First solder one wire to the positive side of the motor - as shown in the first picture.
Then solder a second wire to the switch - as shown in the second picture.

Either unscrew the mechanism, or use pliers to place the wire underneath it, as shown in the third picture. Now all that is left to do is to secure the wires with hot glue, as
shown in the fourth picture of this step. I simply connected the two wires; But you can also add a switch, to also enable firing by pulling the trigger.

If you are planning on painting the gun, be sure to avoid painting the plunger head and the internal parts. The paint will only disturb the function and be scraped off after a
time.

I've uploaded a picture to help you reassemble the Nerf gun. Be cautious so you dont snap or break any pieces.

http://www.instructables.com/id/Nerf-Vulcan-Sentry-Gun/
Step 6: Turn axis
I originally wanted to use the base plate of the chair, but noticed that it was quite shabby. So after cutting off the cushion I replaced it with a 20x20x1.5 cm plywood plate,
as shown in the pictures.

Cut a slot into the other 20x20x1.5 cm plywood plate, to fit the servo. Make sure that the axis is perfectly centered!

Now you will have to cut a hole into each of the 0.5 cm plywood or MDF plates, in order to fit the axial ball bearing (take a look at step 1 for the measurements). Glue one
to plate holding the servo and the other one to the third plate. Drill a hole into the center of the third plat, which has to be big enough to allow you to screw the servo arm
to the servo.

http://www.instructables.com/id/Nerf-Vulcan-Sentry-Gun/
Step 7: Turn axis
Glue the sides to the bottom plate of the box, as shown in the first picture. The piece in the front was supposed to hold the webcam. But after using the gun for the first
time, I noticed that even though the base is really sturdy it moves a bit when the gun stops, which results in false detections. So I just decided to place the camera on the
floor in front of the gun until I'll be able to find the time to build a tripod for the camera.

Before you paint the pieces, you should fill the holes and prime them. Next. , make sure that everything fits and screw the servo in place. In my experience the best way
to position the servo arm is to screw it to the servo and to use two component glue to attach it to the top piece. Before you do so, make sure that the angle the servo can
turn in both directions is the same. After the glue is set, unscrew the arm from the servo and take the plate off. Now you can screw the servo arm to the plate, to give the
connection better strength.

http://www.instructables.com/id/Nerf-Vulcan-Sentry-Gun/
Step 8: Tilt axis
Before attaching the pole as shown in this step, I wanted build a platform. The platform should make attaching and removing the Vulcan as easy as possible; but I noticed
that it didn't work. The main reason for this was that even though the center of gravity of the back and the front was pretty well balanced, the top and bottom really wasn't.
So the servo didnt have enough power to move the gun.

I decided that the best way to attach the wooden pole would be through an existing screw hole. Since the gun should be attached in its center of gravity, I had to use
counterweights later on (I didn't want to take the front of the gun off, since I thought it looked good). Otherwise the center of gravity interferes with the ammo belt.

Drill a hole to fit the wooden pole through the screw hole marked in the first picture. Cut a disc with a 6 cm diameter from the 1.5 cm plywood and drill a 12 mm hole into
its center. Paint the disc and place the pole through the hole. Secure it with a screw, as shown in the pictures. I suggest that you paint the pole after you've placed it in the
bearings, otherwise it might not fit. Place the pole through the Nerf gun and glue the wooden disc to the plastic. Use two more screws to secure it.

http://www.instructables.com/id/Nerf-Vulcan-Sentry-Gun/
Step 9: Tilt axis
Cut a wooden disc to fit the arm of the Hitec HS805BB servo. Secure it with the provided screws and screw it to the servo. Cut all the pieces from the 9 mm plywood that
are shown in the second step. Be sure to round the top edges of one side, as shown in the last picture. If you dont, your ammo belt might get stuck. Place the two ball
bearings into the two identical side pieces and paint them after filling and priming. Cut a hole into the third piece to fit the servo. Its very important that the axis is
perfectly centered. You should really spend some time on this step, since it will greatly affect how well your gun will work.

Place the wooden pole holding the Nerf Vulcan between the two pieces with the bearings. Now use the 128 mm rectangular block of wood as a spacer (the lower end of
the plates has to face the back of the gun). At first I tried to secure the spacer with glue, but the connection was just not strong enough. So I used M4 x 40mm wood
screws, to secure it in place. It also makes it easier to take the gun apart later should it be necessary.

Glue the 45 mm rectangular block of wood to the bottom of one of the panels and cut the wooden pole to the correct length in order for it to perfectly fit into the wooden
disc which you've build before. Attach the servo and screw the wooden disc to the pole, as well as the servo plate to the spacer.

Then use the brackets, screws and wing nuts to attach the base, as shown in the pictures. Using the wing nuts allows an easy disassembly of the gun and therefore
assures easy transportation.

Use the lead pearls or something similar as a counter weight, until the gun is perfectly in balance. Hot glue works great to hold the pearls in place.

Image Notes Image Notes


1. counter weights 1. I shortened the pole later.

http://www.instructables.com/id/Nerf-Vulcan-Sentry-Gun/
Step 10: Electronics
Connecting the two servos and the electronic trigger to the Arduino is relatively simple. The wiring is shown in the first picture. The 1k resistor protects the Ardunio from
electric shorts and the diode prevents stray electricity and sparks. You can of course leave your circuit on the breadboard, but I decided to use a perfboard.
The voltage of the battery pack connected to your gun motor controls the firing rate. If you want your gun to shoot faster feel free to use a second battery pack, or one
with a higher voltage rate.

Thanks a lot lo Bob Rudolph for writing the awesome code for the sentry gun (you can also download it here ). Just upload the files to your Arduino. Make sure to adjust
the servo positions to your gun!

PSG Arduino code:

/*
-------------------- Project Sentry Gun --------------------
============================================================
----- An Open-Source Project, initiated by Bob Rudolph -----
*/

// Set your controller type here


// type options: "Arduino_bare", "Shield_v4", "Shield_v6", "Shield_v7", "Standalone_v3", "Standalone_v5", "Standalone_v7", "Standalone_v8"
#define type "Arduino_bare"

/* Help & Reference: http://projectsentrygun.rudolphlabs.com/make-your-own


Forum: http://projectsentrygun.rudolphlabs.com/forum

ATTACHMENT INSTRUCTIONS: (for using an Arduino board)


attach x-axis (pan) standard servo to digital I/O pin 8
attach y-axis (tilt) standard servo to digital I/O pin 9
attach trigger standard servo to digital I/O pin 10
attach USB indicator LED to digital pin 11
attach firing indicator LED to digital I/O pin 12
attach mode indicator LED to digital I/O pin 13
attach reloading switch to digital I/O pin 3 (low-active: when on, connects pin to GND)
attach diable plate momentary button to digital I/O pin 2 (low-active: when on, connects pin to GND)
attach electric trigger MOSFET circuit to digital I/O pin 7

adjust the values below to the values that work for your gun:

*/
// <=========================================================================>
// Begin custom values - change these servo positions to work with your turret
// <=========================================================================>

// servo positions:
#define panServo_scanningMin 60 // how far side to side you want the
#define panServo_scanningMax 120 // gun to turn while 'scanning'
#define scanningSpeed 3000 // total time for 1 sweep (in milliseconds)

#define panServo_HomePosition 90 // 'centered' gun position


#define tiltServo_HomePosition 90 //

#define panServo_ReloadPosition 90 // convenient position for reloading gun


#define tiltServo_ReloadPosition 85 //

//#define triggerServo_HomePosition 120 // trigger servo not-firing position


//#define triggerServo_SqueezedPosition 90 // trigger servo firing position

// more trigger settings:


#define triggerTravelMillis 1500 // how often should trigger be squeezed (in semi-auto firing)
// higher value = slower firing, lower value = faster firing

// disable plate settings:


#define disablePlateDelay 5000 // how long to disable sentry when plate is pressed (in milliseconds)

// ammunition magazine/clip settings:


boolean useAmmoCounter = false; // if you want to use the shot counter / clip size feature, set this to true
int clipSize = 100; // how many shots before the gun will be empty and the gun will be disabled (reload switch resets the ammo count

// <=========================================================================>
// End custom values
// <=========================================================================>
http://www.instructables.com/id/Nerf-Vulcan-Sentry-Gun/
int panServoPin; // Arduino pin for pan servo
int tiltServoPin; // Arduino pin for tilt servo
//int triggerServoPin; // Arduino pin for trigger servo, or output to trigger MOSFET
int firingIndicatorLEDPin; // Arduino pin for firing indicator LED
int USBIndicatorLEDPin; // Arduino pin for USB indicator LED
int modeIndicatorLEDPin; // Arduino pin for Mode indicator LED
int reloadSwitchPin; // Arduino pin for input from RELOAD switch
int disablePlatePin; // Arduino pin for input from disable plate
int electricTriggerPin; // Arduino pin for output to trigger MOSFET
boolean invertInputs; // TRUE turns on internal pull-ups, use if closed switch connects arduino pin to ground
// pin assignments for each hardware setup are set in the function assignPins() at bottom of code

typedef struct config_t


{
// Booleans but int
int controlMode;
int safety;
int firingMode;
int scanWhenIdle;
int trackingMotion;
int trackingColor;
int leadTarget;
int safeColor;
int showRestrictedZones;
int showDifferentPixels;
int showTargetBox;
int showCameraView;
int mirrorCam;
int soundEffects;

// Integers
int camWidth;
int camHeight;
int nbDot;
int antSens;
int minBlobArea;
int tolerance;
int effect;
int trackColorTolerance;
int trackColorRed;
int trackColorGreen;
int trackColorBlue;
int safeColorMinSize;
int safeColorTolerance;
int safeColorRed;
int safeColorGreen;
int safeColorBlue;
int idleTime;

// Floats
double propX;
double propY;
double xRatio;
double yRatio;
double xMin;
double xMax;
double yMin;
double yMax;

}
configuration;
configuration configuration1;

#include <Servo.h>

Servo pan; // x axis servo


Servo tilt; // y axis servo
Servo trigger; // trigger servo

int xPosition; // pan position


int yPosition; // tilt position
int fire = 0; // if 1, fire; else, don't fire

int fireTimer = 0;
int fireSelector = 1; // 1 - semi-automatic firing, auto/semi-auto gun

// 3 - full automatic firing, full-auto gun

int idleCounter = 0;
int watchdog = 0;
int watchdogTimeout = 2000;
boolean idle = true;
boolean scanning = false;
boolean scanDirection = true;
boolean disabled = false;
unsigned long int disableEndTime;
int scanXPosition = panServo_scanningMin;

int shotCounter = 0; // number of shots fires since last reload


boolean clipEmpty = false; // is the ammo magazine empty?

byte indicator; // if 'a', continue, if 'z', idle


byte x100byte; // some bytes used during serial communication
byte x010byte;
byte x001byte;
byte y100byte;
byte y010byte;
http://www.instructables.com/id/Nerf-Vulcan-Sentry-Gun/
byte y001byte;
byte fireByte;
byte fireSelectorByte;
byte scanningByte;

void setup(){
assignPins();

pan.attach(panServoPin); // set up the x axis servo


pan.write(panServo_HomePosition);
tilt.attach(tiltServoPin); // set up the y axis servo
tilt.write(tiltServo_HomePosition);
pinMode(electricTriggerPin, OUTPUT); // electric trigger, set as output
digitalWrite(electricTriggerPin, LOW);
// trigger.attach(triggerServoPin); // servo for trigger, set that servo up
// trigger.write(triggerServo_HomePosition);

pinMode(USBIndicatorLEDPin, OUTPUT); // set up USB indicator LED


pinMode(modeIndicatorLEDPin, OUTPUT); // set up Mode indicator LED
pinMode(firingIndicatorLEDPin, OUTPUT); // set up firing indicator LED
pinMode(reloadSwitchPin, INPUT); // set up reload switch input
pinMode(disablePlatePin, INPUT); // set up disable plate input
if(invertInputs) {
digitalWrite(reloadSwitchPin, HIGH); // turn on internal pull-up
digitalWrite(disablePlatePin, HIGH); // turn on internal pull-up
}
Serial.begin(4800); // start communication with computer

void loop() {
if (Serial.available() >= 10) { // check to see if a new set of commands is available
watchdog = 0;
indicator = Serial.read(); // read first byte in buffer
if(indicator == 'a') { // check for 'a' (indicates start of message)
idle = false;
idleCounter = 0;
digitalWrite(USBIndicatorLEDPin, HIGH); // light up the USB indicator LED
x100byte = Serial.read(); // read the message, byte by byte
x010byte = Serial.read(); //
x001byte = Serial.read(); //
y100byte = Serial.read(); //
y010byte = Serial.read(); //
y001byte = Serial.read(); //
fireByte = Serial.read(); //
fireSelectorByte = Serial.read(); //
fireSelector = int(fireSelectorByte) - 48; // convert byte to integer
scanningByte = Serial.read();
if((int(scanningByte) - 48) == 1) {
scanning = true;
}
else{
scanning = false;
}
}
else if(indicator == 'z'){ // check for command to go idle (sent by computer when program is ended)
idle = true;
}
else if(indicator == 'b'){ // start backup

backup();

}
else if(indicator == 'r'){ // start restore

restore();

}
}
else{
watchdog++;
if(watchdog > watchdogTimeout) {
idle = true;
}
}
if(idle) { // when Arduino is not getting commands from computer...
Serial.write('T'); // tell the computer that Arduino is here
idleCounter++; // periodically blink the USB indicator LED
if(idleCounter > 1000) { //
sequenceLEDs(1, 100);
delay(10);

// digitalWrite(USBIndicatorLEDPin, HIGH); //
// delay(250); //
// digitalWrite(USBIndicatorLEDPin, LOW); //
idleCounter = 0; //
} //
else{ //
digitalWrite(USBIndicatorLEDPin, LOW); //
} //
xPosition = panServo_HomePosition; // keep x axis servo in its home position
yPosition = tiltServo_HomePosition; // keep y axis servo in its home position
fire = 0; // don't fire
}
else{ // when Arduino is getting commands from the computer...
xPosition = (100*(int(x100byte)-48)) + (10*(int(x010byte)-48)) + (int(x001byte)-48); // decode those message bytes into two 3-digit numbers
yPosition = (100*(int(y100byte)-48)) + (10*(int(y010byte)-48)) + (int(y001byte)-48); //
fire = int(fireByte) - 48; // convert byte to integer
}
http://www.instructables.com/id/Nerf-Vulcan-Sentry-Gun/
if(scanning) {
digitalWrite(modeIndicatorLEDPin, HIGH);
if(scanDirection) {
scanXPosition += 1;
if(scanXPosition > panServo_scanningMax) {
scanDirection = false;
scanXPosition = panServo_scanningMax;
}
}
else{
scanXPosition -= 1;
if(scanXPosition < panServo_scanningMin) {
scanDirection = true;
scanXPosition = panServo_scanningMin;
}
}
xPosition = scanXPosition;
yPosition = tiltServo_HomePosition;
fire = 0;
delay(scanningSpeed/abs(panServo_scanningMax-panServo_scanningMin));
}
else{
digitalWrite(modeIndicatorLEDPin, LOW);
}

if((digitalRead(disablePlatePin) == HIGH && !invertInputs) || (digitalRead(disablePlatePin) == LOW && invertInputs)) { // check the disable plate to see
disabled = true;
disableEndTime = millis() + disablePlateDelay;
}
if(millis() > disableEndTime) {
disabled = false;
}

if((digitalRead(reloadSwitchPin) == HIGH && !invertInputs) || (digitalRead(reloadSwitchPin) == LOW && invertInputs)) { // check the reload switch to see
shotCounter = 0;
xPosition = panServo_ReloadPosition; // if it is flipped, override computer commands,
yPosition = tiltServo_ReloadPosition; // and send the servos to their reload positions
fire = 0; // don't fire while reloading
digitalWrite(modeIndicatorLEDPin, HIGH);
delay(100);
digitalWrite(modeIndicatorLEDPin, LOW);
delay(100);
}

if(disabled) {
xPosition = panServo_ReloadPosition; // if it is flipped, override computer commands,
yPosition = tiltServo_ReloadPosition; // and send the servos to their reload positions
fire = 0; // don't fire while reloading
digitalWrite(modeIndicatorLEDPin, HIGH);
delay(50);
digitalWrite(modeIndicatorLEDPin, LOW);
delay(50);
}

pan.write(xPosition); // send the servos to whatever position has been commanded


tilt.write(yPosition); //

if(useAmmoCounter & shotCounter >= clipSize) {


clipEmpty = true;
}
else{
clipEmpty = false;
}

if(fire == 1 && !clipEmpty) { // if firing...


Fire(fireSelector); // fire the gun in whatever firing mode is selected
}
else{ // if not firing...
ceaseFire(fireSelector); // stop firing the gun
}
}

void Fire(int selector) { // function to fire the gun, based on what firing mode is selected
if(selector == 1) {
fireTimer++;
if(fireTimer >=0 & fireTimer <= triggerTravelMillis) {
digitalWrite(electricTriggerPin, HIGH);
// trigger.write(triggerServo_SqueezedPosition);
digitalWrite(firingIndicatorLEDPin, HIGH);
}
if(fireTimer > triggerTravelMillis & fireTimer < 1.5*triggerTravelMillis) {
digitalWrite(electricTriggerPin, LOW);
// trigger.write(triggerServo_HomePosition);
digitalWrite(firingIndicatorLEDPin, LOW);
}
if(fireTimer >= 1.5*triggerTravelMillis) {
fireTimer = 0;
if(useAmmoCounter) {
shotCounter++; // increment the shot counter
}
}
}
if(selector == 3) {
digitalWrite(electricTriggerPin, HIGH);
// trigger.write(triggerServo_SqueezedPosition);
digitalWrite(firingIndicatorLEDPin, HIGH);
}
http://www.instructables.com/id/Nerf-Vulcan-Sentry-Gun/
}

void ceaseFire(int selector) { // function to stop firing the gun, based on what firing mode is selected
if(selector == 1) {
fireTimer = 0;
digitalWrite(electricTriggerPin, LOW);
// trigger.write(triggerServo_HomePosition);
digitalWrite(firingIndicatorLEDPin, LOW);
}
if(selector == 3) { // for my gun, both firing modes cease firing by simply shutting off.
digitalWrite(electricTriggerPin, LOW);
// trigger.write(triggerServo_HomePosition);
digitalWrite(firingIndicatorLEDPin, LOW);
}
}

void sequenceLEDs(int repeats, int delayTime) {


int startDelay;
for(int i = 0; i < repeats; i++) {

digitalWrite(USBIndicatorLEDPin, LOW);
digitalWrite(modeIndicatorLEDPin, LOW);

startDelay = millis();
while(millis()-startDelay < delayTime) {
digitalWrite(firingIndicatorLEDPin, HIGH);
}
digitalWrite(firingIndicatorLEDPin, LOW);

startDelay = millis();
while(millis()-startDelay < delayTime) {
digitalWrite(USBIndicatorLEDPin, HIGH);
}
digitalWrite(USBIndicatorLEDPin, LOW);

startDelay = millis();
while(millis()-startDelay < delayTime) {
digitalWrite(modeIndicatorLEDPin, HIGH);
}
digitalWrite(modeIndicatorLEDPin, LOW);

startDelay = millis();
while(millis()-startDelay < delayTime) {
// chill
}
}
}

void assignPins() {
if(type == "Arduino_bare" || type == "Arduino_Bare") {
// pin attachments:
panServoPin = 8; // Arduino pin for pan servo
tiltServoPin = 9; // Arduino pin for tilt servo
// triggerServoPin = 7; // Arduino pin for trigger servo, or output to trigger MOSFET
firingIndicatorLEDPin = 12; // Arduino pin for firing indicator LED
USBIndicatorLEDPin = 11; // Arduino pin for USB indicator LED
modeIndicatorLEDPin = 13; // Arduino pin for Mode indicator LED
reloadSwitchPin = 3; // Arduino pin for input from RELOAD switch
disablePlatePin = 2; // Arduino pin for input from disable plate
electricTriggerPin = 10; // Arduino pin for output to trigger MOSFET
invertInputs = true; // TRUE turns on internal pull-ups, use if closed switch connects arduino pin to ground
}
else if(type == "Shield_v4" || type == "Shield_v6") {
// pin attachments:
panServoPin = 9; // Arduino pin for pan servo
tiltServoPin = 8; // Arduino pin for tilt servo
// triggerServoPin = 7; // Arduino pin for trigger servo, or output to trigger MOSFET
electricTriggerPin = 6; // Arduino pin for output to trigger MOSFET
firingIndicatorLEDPin = 11; // Arduino pin for firing indicator LED
USBIndicatorLEDPin = 12; // Arduino pin for USB indicator LED
modeIndicatorLEDPin = 13; // Arduino pin for Mode indicator LED
reloadSwitchPin = 10; // Arduino pin for input from RELOAD switch
disablePlatePin = 2; // Arduino pin for input from disable plate
invertInputs = true; // TRUE turns on internal pull-ups, use if closed switch connects arduino pin to ground
}
else if(type == "Shield_v7") {
// pin attachments:
panServoPin = 8; // Arduino pin for pan servo
tiltServoPin = 9; // Arduino pin for tilt servo
// triggerServoPin = 10; // Arduino pin for trigger servo, or output to trigger MOSFET
electricTriggerPin = 7; // Arduino pin for output to trigger MOSFET
firingIndicatorLEDPin = 12; // Arduino pin for firing indicator LED
USBIndicatorLEDPin = 6; // Arduino pin for USB indicator LED
modeIndicatorLEDPin = 13; // Arduino pin for Mode indicator LED
reloadSwitchPin = 11; // Arduino pin for input from RELOAD switch
disablePlatePin = 2; // Arduino pin for input from disable plate
invertInputs = true; // TRUE turns on internal pull-ups, use if closed switch connects arduino pin to ground
}
else if(type == "Standalone_v3") {
// pin attachments:
panServoPin = 8; // Arduino pin for pan servo
tiltServoPin = 9; // Arduino pin for tilt servo
// triggerServoPin = 10; // Arduino pin for trigger servo, or output to trigger MOSFET
electricTriggerPin = 7; // Arduino pin for output to trigger MOSFET
firingIndicatorLEDPin = 12; // Arduino pin for firing indicator LED
USBIndicatorLEDPin = 14; // Arduino pin for USB indicator LED
modeIndicatorLEDPin = 13; // Arduino pin for Mode indicator LED
reloadSwitchPin = 11; // Arduino pin for input from RELOAD switch
disablePlatePin = 2; // Arduino pin for input from disable plate
http://www.instructables.com/id/Nerf-Vulcan-Sentry-Gun/
invertInputs = true; // TRUE turns on internal pull-ups, use if closed switch connects arduino pin to ground
}
else if(type == "Standalone_v5") {
// pin attachments:
panServoPin = 8; // Arduino pin for pan servo
tiltServoPin = 9; // Arduino pin for tilt servo
// triggerServoPin = 10; // Arduino pin for trigger servo, or output to trigger MOSFET
electricTriggerPin = 7; // Arduino pin for output to trigger MOSFET
firingIndicatorLEDPin = 12; // Arduino pin for firing indicator LED
USBIndicatorLEDPin = 14; // Arduino pin for USB indicator LED
modeIndicatorLEDPin = 13; // Arduino pin for Mode indicator LED
reloadSwitchPin = 11; // Arduino pin for input from RELOAD switch
disablePlatePin = 2; // Arduino pin for input from disable plate
invertInputs = true; // TRUE turns on internal pull-ups, use if closed switch connects arduino pin to ground
}
else if(type == "Standalone_v7") {
// pin attachments:
panServoPin = 8; // Arduino pin for pan servo
tiltServoPin = 9; // Arduino pin for tilt servo
// triggerServoPin = 10; // Arduino pin for trigger servo, or output to trigger MOSFET
electricTriggerPin = 7; // Arduino pin for output to trigger MOSFET
firingIndicatorLEDPin = 12; // Arduino pin for firing indicator LED
USBIndicatorLEDPin = 14; // Arduino pin for USB indicator LED
modeIndicatorLEDPin = 13; // Arduino pin for Mode indicator LED
reloadSwitchPin = 11; // Arduino pin for input from RELOAD switch
disablePlatePin = 2; // Arduino pin for input from disable plate
invertInputs = true; // TRUE turns on internal pull-ups, use if closed switch connects arduino pin to ground
}
else if(type == "Standalone_v8") {
// pin attachments:
panServoPin = 8; // Arduino pin for pan servo
tiltServoPin = 9; // Arduino pin for tilt servo
// triggerServoPin = 10; // Arduino pin for trigger servo, or output to trigger MOSFET
electricTriggerPin = 7; // Arduino pin for output to trigger MOSFET
firingIndicatorLEDPin = 12; // Arduino pin for firing indicator LED
USBIndicatorLEDPin = 14; // Arduino pin for USB indicator LED
modeIndicatorLEDPin = 13; // Arduino pin for Mode indicator LED
reloadSwitchPin = 11; // Arduino pin for input from RELOAD switch
disablePlatePin = 2; // Arduino pin for input from disable plate
invertInputs = true; // TRUE turns on internal pull-ups, use if closed switch connects arduino pin to ground
}
}

Backup:

// contributed by Hugo K.

#include <EEPROM.h>
#include "EEPROMAnything.h"

/*
// Booleans but int
int controlMode;
int safety;
int firingMode;
int scanWhenIdle;
int trackingMotion;
int trackingColor;
int leadTarget;
int safeColor;
int showRestrictedZones;
int showDifferentPixels;
int showTargetBox;
int showCameraView;
int mirrorCam;
int soundEffects;

// Integers
int camWidth;
int camHeight;
int nbDot;
int antSens;
int minBlobArea;
int tolerance;
int effect;
int trackColorTolerance;
int trackColorRed;
int trackColorGreen;
int trackColorBlue;
int safeColorMinSize;
int safeColorTolerance;
int safeColorRed;
int safeColorGreen;
int safeColorBlue;
int idleTime;

// Floats
double propX;
double propY;
double xRatio;
double yRatio;
double xMin;
double xMax;
double yMin;
double yMax;
*/
http://www.instructables.com/id/Nerf-Vulcan-Sentry-Gun/
void backup(){

char* Parameter;
char* i;

char BufferSerie[200];
for (int z=0;z<=200;z++) BufferSerie[z]='\0';

// Save the String Send

byte bufferPos=0;
char ch;
boolean endOfString = false;

while( !endOfString){
if(Serial.available()){
ch = Serial.read();

if(ch != '!'){

BufferSerie[bufferPos++] = ch;

}else{

endOfString = true;
}
}
}

// Split the received String and update the struct configuration."Value"

// Booleans
Parameter = strtok_r(BufferSerie, ";", &);
configuration1.controlMode = atoi(Parameter);

Parameter = strtok_r(NULL, ";", &);


configuration1.safety = atoi(Parameter);

Parameter = strtok_r(NULL, ";", &);


configuration1.firingMode = atoi(Parameter);

Parameter = strtok_r(NULL, ";", &);


configuration1.scanWhenIdle = atoi(Parameter);

Parameter = strtok_r(NULL, ";", &);


configuration1.trackingMotion = atoi(Parameter);

Parameter = strtok_r(NULL, ";", &);


configuration1.trackingColor = atoi(Parameter);

Parameter = strtok_r(NULL, ";", &);


configuration1.leadTarget = atoi(Parameter);

Parameter = strtok_r(NULL, ";", &);


configuration1.safeColor = atoi(Parameter);

Parameter = strtok_r(NULL, ";", &);


configuration1.showRestrictedZones = atoi(Parameter);

Parameter = strtok_r(NULL, ";", &);


configuration1.showDifferentPixels = atoi(Parameter);

Parameter = strtok_r(NULL, ";", &);


configuration1.showTargetBox = atoi(Parameter);

Parameter = strtok_r(NULL, ";", &);


configuration1.showCameraView = atoi(Parameter);

Parameter = strtok_r(NULL, ";", &);


configuration1.mirrorCam = atoi(Parameter);

Parameter = strtok_r(NULL, ";", &);


configuration1.soundEffects = atoi(Parameter);

// Integers
Parameter = strtok_r(NULL, ";", &);
configuration1.camWidth = atoi(Parameter);

Parameter = strtok_r(NULL, ";", &);


configuration1.camHeight = atoi(Parameter);

Parameter = strtok_r(NULL, ";", &);


configuration1.nbDot = atoi(Parameter);

Parameter = strtok_r(NULL, ";", &);


configuration1.antSens = atoi(Parameter);

Parameter = strtok_r(NULL, ";", &);


configuration1.minBlobArea = atoi(Parameter);

Parameter = strtok_r(NULL, ";", &);


configuration1.tolerance = atoi(Parameter);

Parameter = strtok_r(NULL, ";", &);


configuration1.effect = atoi(Parameter);

Parameter = strtok_r(NULL, ";", &);


configuration1.trackColorTolerance = atoi(Parameter);

Parameter = strtok_r(NULL, ";", &);


configuration1.trackColorRed = atoi(Parameter);

http://www.instructables.com/id/Nerf-Vulcan-Sentry-Gun/
Parameter = strtok_r(NULL, ";", &);
configuration1.trackColorGreen = atoi(Parameter);

Parameter = strtok_r(NULL, ";", &);


configuration1.trackColorBlue = atoi(Parameter);

Parameter = strtok_r(NULL, ";", &);


configuration1.safeColorMinSize = atoi(Parameter);

Parameter = strtok_r(NULL, ";", &);


configuration1.safeColorTolerance = atoi(Parameter);

Parameter = strtok_r(NULL, ";", &);


configuration1.safeColorRed = atoi(Parameter);

Parameter = strtok_r(NULL, ";", &);


configuration1.safeColorGreen = atoi(Parameter);

Parameter = strtok_r(NULL, ";", &);


configuration1.safeColorBlue = atoi(Parameter);

Parameter = strtok_r(NULL, ";", &);


configuration1.idleTime = atoi(Parameter);

// floats
Parameter = strtok_r(NULL, ";", &);
configuration1.propX = strtod(Parameter,NULL);

Parameter = strtok_r(NULL, ";", &);


configuration1.propY = strtod(Parameter,NULL);

Parameter = strtok_r(NULL, ";", &);


configuration1.xRatio = strtod(Parameter,NULL);

Parameter = strtok_r(NULL, ";", &);


configuration1.yRatio = strtod(Parameter,NULL);

Parameter = strtok_r(NULL, ";", &);


configuration1.xMin = strtod(Parameter,NULL);

Parameter = strtok_r(NULL, ";", &);


configuration1.xMax = strtod(Parameter,NULL);

Parameter = strtok_r(NULL, ";", &);


configuration1.yMin = strtod(Parameter,NULL);

Parameter = strtok_r(NULL, ";", &);


configuration1.yMax = strtod(Parameter,NULL);

delay(20);

// Backup on EEPROM 92 bytes, Start on 0


EEPROM_writeAnything(0, configuration1); //take more than 92*3.3ms

void restore(){

EEPROM_readAnything(0, configuration1); // Relode Struct configuration from EEPROM

delay(20);

Serial.println('R'); // Tel Processing Arduino Ready for Sending Values

//Booleans
Serial.print(configuration1.controlMode);
Serial.print(";");

Serial.print(configuration1.safety);
Serial.print(";");

Serial.print(configuration1.firingMode);
Serial.print(";");

Serial.print(configuration1.scanWhenIdle);
Serial.print(";");

Serial.print(configuration1.trackingMotion);
Serial.print(";");

Serial.print(configuration1.trackingColor);
Serial.print(";");

Serial.print(configuration1.leadTarget);
Serial.print(";");

Serial.print(configuration1.safeColor);
Serial.print(";");

Serial.print(configuration1.showRestrictedZones);
Serial.print(";");

Serial.print(configuration1.showDifferentPixels);
Serial.print(";");

Serial.print(configuration1.showTargetBox);
Serial.print(";");

Serial.print(configuration1.showCameraView);
Serial.print(";");

Serial.print(configuration1.mirrorCam);
Serial.print(";");

http://www.instructables.com/id/Nerf-Vulcan-Sentry-Gun/
Serial.print(configuration1.soundEffects);
Serial.print(";");

//Integers
Serial.print(configuration1.camWidth);
Serial.print(";");

Serial.print(configuration1.camHeight);
Serial.print(";");

Serial.print(configuration1.nbDot);
Serial.print(";");

Serial.print(configuration1.antSens);
Serial.print(";");

Serial.print(configuration1.minBlobArea);
Serial.print(";");

Serial.print(configuration1.tolerance);
Serial.print(";");

Serial.print(configuration1.effect);
Serial.print(";");

Serial.print(configuration1.trackColorTolerance);
Serial.print(";");

Serial.print(configuration1.trackColorRed);
Serial.print(";");

Serial.print(configuration1.trackColorGreen);
Serial.print(";");

Serial.print(configuration1.trackColorBlue);
Serial.print(";");

Serial.print(configuration1.safeColorMinSize);
Serial.print(";");

Serial.print(configuration1.safeColorTolerance);
Serial.print(";");

Serial.print(configuration1.safeColorRed);
Serial.print(";");

Serial.print(configuration1.safeColorGreen);
Serial.print(";");

Serial.print(configuration1.safeColorBlue);
Serial.print(";");

Serial.print(configuration1.idleTime);
Serial.print(";");

//Floats
Serial.print(configuration1.propX);
Serial.print(";");

Serial.print(configuration1.propY);
Serial.print(";");

Serial.print(configuration1.xRatio);
Serial.print(";");

Serial.print(configuration1.yRatio);
Serial.print(";");

Serial.print(configuration1.xMin);
Serial.print(";");

Serial.print(configuration1.xMax);
Serial.print(";");

Serial.print(configuration1.yMin);
Serial.print(";");

Serial.print(configuration1.yMax);
Serial.print("!");

EEPROMAnything.h

#include <EEPROM.h>
#include <Arduino.h> // for type definitions

template <class T> int EEPROM_writeAnything(int ee, const T& value)


{
const byte* p = (const byte*)(const void*)&alue;
int i;
for (i = 0; i < sizeof(value); i++)
EEPROM.write(ee++, *p++);
return i;
}

template <class T> int EEPROM_readAnything(int ee, T& value)


{
byte* p = (byte*)(void*)&alue;
int i;

http://www.instructables.com/id/Nerf-Vulcan-Sentry-Gun/
for (i = 0; i < sizeof(value); i++)
*p++ = EEPROM.read(ee++);
return i;
}

Step 11: Processing IDE


In order to run the sentry gun processing code, you will need to install the 32 bit version of the Processing ID environment first. You can download it here .

Create a folder named "Processing" and copy the files provided with this step into it. Furthermore you will have to copy the files in the "copy these into processing root or
system32" folder to your root system.

You can find a detailed description on how the software works on the project sentry gun page here . The only major new thing is the surf classifier to detect the
instructables robot. It can be controlled with these lines:

public boolean use_surf = true;


public int surf_sensivity = 3;
public String surfRefFile = "D:/Sentry/robot_live2.jpg";

http://www.instructables.com/id/Nerf-Vulcan-Sentry-Gun/
File Downloads

Processing.zip (21 MB)


[NOTE: When saving, if you see .tmp as the file ext, rename it to 'Processing.zip']

Related Instructables

Nerf Vulcan Nerf Vulcan AC


Modification Arduino nerf vulcan mod extended vulcan how to mod a
Controlled Nerf by kidengineer power mod by clip by vulcan belt by
Project by
Vulcan by bogott timeshifter1 crazyboy007
Zinventor
alecnotalex

Advertisements

Comments
1 comments Add Comment

HollyMann says: Jun 29, 2013. 3:31 PM REPLY


Great job Britt - you put a lot of time into this and it is awesome!!!

http://www.instructables.com/id/Nerf-Vulcan-Sentry-Gun/

Das könnte Ihnen auch gefallen