Saturday, November 28, 2015

Web Controlled Dart Gun

I've had this 99% done for quite some time, the last 1% has taken quite a few months (I've unfortunately had to put it on the back burner due to other things).  Without further delay, here's a short Youtube video demo'ing my web controlled Dart Gun (construction details follow after the jump):


NOTE:  This project writeup is written for someone with an intermediate level of experience.  While I will tell you what to do (i.e., start something as a cron job), I won't tell you how to do it.  Google should be able to assist in those areas where the directions don't get you 100% there.


Bill of Materials

    For this project, I roped together the following items (note that the Gun itself and Mac Mini web server are discontinued items and would need to be substituted for other builds):

How the Dart Gun Works


    In order to modify this weapon, it's helpful to understand how it works (it's also useful to understand what's conceptually going on in order to evaluate the suitability of other dart guns to this modification).  This dart gun is a fully automatic model, one trigger press will cycle through and expend all of the rounds.  This is accomplished via two electrical circuits within the weapon.  One powers a set of wheels that work like a pitching machine.  The wheels grip the side of the dart and accelerate it out of the front of the weapon.  The second circuit powers the drum and pushing mechanism.  When it is energized, the drum rotates and, one by one, pushes the darts into the spinning wheels.  In order to successfully fire the weapon, the wheels must be spun up for some period of time (so they get to peak speed), and then the drum mechanism is engaged to push the darts into the spinning wheels.


Electrical Modifications to the Gun


    In order to convert the dart gun to enable remote control, three wires have to be soldered onto the battery box (NOTE:  Do not put batteries into the weapon after this modification, as the unit will be externally powered from here on out and the batteries will cause problems).  After this modification is complete, the gun will not function as it was sold (e.g., it can only be controlled remotely or via buttons added to the breadboard).  First, carefully remove the dozen or so screws that hold the gun together.  In order to fully disassemble, you'll also have to take apart the joint holding the front portion of the weapon on.  Keep careful track of how you took everything apart; you'll need to put everything back where it was once the modifications have been made.
    Remove the screws holding on the battery box and flip it over to access the solder points.  The three wires you need to solder on are the voltage wires going to the wheel mechanism (orange in the photo below), drum mechanism (yellow), and the common ground (blue).  Here's a photo of where the solder points are (solder points are specific to this dart gun.  If you use another gun, your solder points will vary):

Drill a hole in the outer case to route the wires through to the rest of the electronics.  Carefully reassemble the weapon (except for the front section), routing the wires through the hole to the outside of the weapon.


Physical Modifications to the Gun


    At this point, you've drilled a hole in the top of the case in order to route the wires to the outside of the gun.  In order to integrate this project, a number of changes also need to be made to the weapon.

    Modification #1:  Nose cone removal.  In my experience, the orange nose cone on the front of the fun provides no function, but it does serve to occasionally stop the rounds from leaving the weapon, requiring manual intervention to remove the stuck round.  Remove it.

    Modification #2:  Remove material protecting wheels.  The material behind the wheels does serve an important safety function, it keeps fingers from interacting with the wheels inappropriately.  It also limits the number of dart gun rounds that are usable with this gun (longer NERF brand rounds won't fit into the limited space between the drum and wheels on this weapon when unmodified).  I prefer to use NERF N-Strike Whistler Rounds with this weapon, so the excess material has to go.  Using a dremel, I carefully removed the protective cover from the wheels, creating the extra space needed for the longer rounds.  Here's a side-by-side before and after of the modification:



    Modification #3:  Zip-tie the trigger.  In order for the drum rotation mechanism to push the round forward into the wheels, the trigger has to be depressed (there's a lever inside that moves the push rod in and out of position).  As we can only interact with the weapon through its electronics, the lever has to alway in position.  Zip-tie the trigger in the rear position and trim the excess tie material.



    Modification #4:  Tripod mount. In order to mount your gun to a tripod, you have to have somewhere to screw the tripod into.  I experimented with a variety of positions with little luck.  In most positions, there was insufficient room to mount the tripod plate.  Depending on your tripod, YMMV.  I eventually settled on attaching the tripod to the bottom of the drum (see photo below).  To do so, drill a 3/8" hole and thread with a 1/4"-20 tap.




    Modification #5:  Mount the camera.  Without video, you'll only be able to fire the weapon blindly (maybe that's what you want, but probably not).  Attach the camera base to the side of the weapon, position the camera so it faces in the same direction as the weapon (you'll have to adjust this later).





The Remaining Electronics


    The simple aspect of this project is that everything runs off of 5 volts.  The complication lies with the gun motors themselves.  While they run on 5 volts, at peak draw, they pull 1.4 amps, way beyond what an Arduino is capable of providing (0.05 A being the maximum draw from any given Arduino pin).  As a result, the design has to incorporate relays and a separate power source to handle the additional current.  Here is the circuit diagram for the remaining electronics:



    To create the 2A@5V power source, take a spare USB cable and cut off the end that doesn't go into the USB charger (the end that doesn't have the Type-A connector).  5 volts is carried on the red wire, the black wire is the ground (they should be on opposite sides of the USB cable).  Strip the wires and solder them onto connectors, trim the data wires off.
    Given that the above diagram may be challenging to read, here are the connections required (diagram above is logical, a small breadboard will be required for the buttons and to split power and ground from the 5V power source):

  • Power source ground (solid black):  Route to common ground coming from gun (one of the three wires leaving the chasis).
  • Power source 5V line (solid green/blue):  Route to the center connector of each relay, and to the input of both buttons.
  • Wheel 5V line (solid blue):  From unconnected (top) terminal on relay #1 and output of button #1 to the wheel mechanism line coming from the gun's chasis.
  • Drum 5V line (solid green):  From unconnected (top) terminal on relay #2 and output of button #2 to the wheel mechanism coming from the gun's chasis.
  • Relay power line (dashed red):  From 5V on the Arduino to VCC on the relay board.
  • Relay ground line (dashed black):  From GND on the Arduino to GND on the relay board.
  • Wheel control line (dashed blue):  From Pin 10 on the Arduino to IN1 on the relay board.
  • Drum control line (dashed green):  From Pin 11 on the Arduino to IN2 on the relay board.
  • USB cable (thick black line):  From computer to Arduino.

    Once everything is connected, hot glue the breadboard, relay board, and Arduino to the side of the weapon.


Programming the Arduino


    The Arduino Sketch for this project is pretty simple.  Using the serialEvent interrupt, the Arduino listens for commands coming over the serial bus.  Depending on the command, the weapon's motors are turned either on or off.  The four commands understood are:
  • arm - Spins up the wheels.
  • shot - Turns on the drum circuit for 324ms, causing one round to cycle into position and be pushed into the wheel (i.e., shot from the weapon).  After several tests, 324ms was measured to be the average time between shots on my setup.  You may want to calibrate this value to your own system.  If the weapon wasn't armed, the wheels will spin up for two seconds prior to expending the round and turn off afterwards.
  • salvo - Turns on the drum circuit, causing the weapon to fire in full automatic mode.  Drum will not stop until a "stop" command is received.  If the weapon wasn't armed, the wheels will spin up for two seconds prior to starting the drum.
  • stop - Turns off all circuits (effectively stops firing the weapon).
The Arduino sketch can be found here.  Upload to the Arduino.  To test, use the serial monitor function of Arduino IDE to issue the four commands above.  At this point, you should be able to remotely turn the weapon off and on from the serial command line.  



Setting up the Web Server


    The web server has a couple of different parts.  The first part is a daemon (fifo_weapon_control.sh) that holds the serial connection to the Arduino open (if it doesn't stay open, the Arduino will reset every time it's talked to).  It then monitors a fifo for commands that it passes to the Arduino.  To configure, put the script in a directory of your choosing and create a fifo in that same directory (make sure that your web server will be able to write to the fifo).  Change the variables in the script to point to the Arduino's serial device and the fifo you created.  Start the daemon (as root), test by echoing the commands above into the fifo you created and monitoring the proper actions are occurring.  To start permanently, either place it in the startup init scripts or via cron job (cron job provides the benefit of automatic restart should the program terminate).

    The second part of the web server content is the static web page -- fire_control.html.  It uses a couple of layers to put a target reticle over the video coming from the camera and the image of barrel rifling in the background.  Along the top, four form buttons are provided to access the weapon's functionality (Arm, Single Shot, Full Auto, Stop).  In the background, a little javascript ties the button presses to the appropriate cgi-bin dynamic web page calls.


To configure, drop fire_control.html into the root directory your web server.  Modify the IFRAME within the web page to point at the video stream coming from your web camera.  place the rifling image (rifling.jpg) and target reticle (target.png) in the images directory of your web server.  To test, fire up your web browser and point it at fire_control.html.  You should see a web page similar to above.

    The last part of the web server content is the cgi-bin script (command).  It's purpose is to take the command generated by pressing a button on the web page and write it to the fifo (where fifo_weapon_control.sh passes it on to the Arduino for action).  To configure, drop command into your cgi-bin directory and make sure it is executable.  Configure the script to ensure it points at the fifo that you configured when setting up fifo_weapon_control.sh.



    At this point, if you have everything connected correctly, you should be able to remotely control your dart gun.  Have fun!  Questions/comments, feel free to leave them in the comments below.

No comments:

Post a Comment