Saturday, September 6, 2014

IR Shot Detection Details

I haven't provided much detail on the beam-breaker shot detection setup in the AVI-TAR prototype so this post will be dedicated to that. What I started out with is a bit of a kludge but I'm working on alternatives that I'll explain at the end.

The Prototype

In order to quickly put the prototype together I had to come up with a shot detector that didn't require a lot of fabrication or special parts. I needed to put an IR emitter/detector pair somewhere in the path of the BB as it traveled past the hop-up and down the barrel. BB movement detection in the feed tube from the magazine, before the air-nozzle, is pretty difficult since the BBs are stacked in the tube "shoulder to shoulder". There are hop-up assemblies available that use that detection method, but only to signal an empty magazine condition.

So...where to put the detector. My first attempt, used in the working prototype, is this:

About 6" down from the hop-up I machined two slots into the outer barrel and cross-drilled so that I can see the inner barrel. If you'll note the notch at the top of the barrel closer to the hop-up, that's where a mounting plate notches into the barrel and fastens down into the lower barrel bed in the body of the AEG. I have to allow clearance for that.

The IR detector is hot-glued to the outer barrel and I fortified it with a little tape wrap (removed here for the picture).

The inner barrel is cross-drilled and a very thin clear tape is applied over the holes once the barrel is de-burred inside and out:

After the drilling and performed and the barrel assembly is back together, I can use the AVI-TAR system to verify its alignment via a testing tool I wrote into the main menu. It simply tells me if the IR detector is "on" or "off". A cleaning rod shoved down the barrel helps verify proper operation. Overall, a pretty simple operation.


Obviously, hot-glue and tape are not a good solution for mounting the IR detector. I also am not fond of machining the barrels. The problem is that there are only a few places to properly put positive shot detection sensors:
  • In the hop-up chamber. It can be very difficult since the interior of the hop-up chamber contains the rubber bucking and the barrel, neither of which are transparent to light. There are clear buckings available so it may be that a new hop-up chamber could be engineered to meet my needs. It's pretty complex part and would need to be the same size as the current hop-up chamber to fit a stock TAR.
  • In a mock-suppressor. There is actually a new system out there that does just this (and uses 2 detectors to give you a chrono feature). My problem with such an assembly is that it needs to be connected to the controller for power and signal. Any kind of cabling harness would not look good, would be a weak spot on the gun and would be a pain to work with when you did maintenance.  The alternative is a wireless system. This requires more complex electronics and a separate power source for the detector assembly. Oh, no...more batteries to manage.
  • Outer-barrel extension. This is a decent possibility if engineered properly. Unlike a suppressor, this would allow users to put whatever barrel-end on their TAR, be it the standard flash hider or any suppressor they prefer.
  • In the existing barrel assembly. This requires machining of parts but results in a clean look since it would be inside the gun body. The machining isn't a lot of work but it would not be "parts swap" operation unless one could obtain pre-worked barrel assemblies. The detector would be mounted in a "clamp-on" assembly that fits into the machined outer barrel. This would stand up to the rigors of use and would be easy to maintain.

That wraps up this post. See you on the field, maybe.

Tuesday, July 22, 2014

AVI-TAR System Design Part 4:Plastic Prototyping

This post will dive into the design of the plastics used in the prototype. For someone without any real experience in the process of plastics fabrication I found the process to be pretty painless. The introduction of simple CAD tools and the revolution in 3D printing made this project possible.

Concept Comes First

This can be the hardest part of the process. Sometimes the design concept just falls into your lap, other times you try to force something and still other times you just feel lost. Since I'm starting with a base design (the TAR AEG) the conceptual process is exploratory: how does this look? How does that work? How do the two relate and can it be made cleaner, less complex, more robust?

In the end, I used some paper to scribble out ideas until I came up with this:

Aside: Yes, I keep a paper project binder. It's so much less structured than a computer and usually more available to capture quick bits of info. Eventually everything makes its way into files but I can always find that one measurement, coding tidbit or just my original train of thought in that binder. Your results may vary...

Now that I have new parts identified, time for measurements. I simple slide caliper did the job, giving me critical dimensions for replacement parts:

Design Comes Next

I've got to take that pile of numbers and turn into something that I can touch. I'd already decided that 3D printing was the way to go for quick prototyping so it's just a matter of creating .STL files (stereo lithography file format...used by a lot of printing systems).

I've dabbled with various 3D modeling software, mostly for animations (Lightwave, Blender and some stuff that doesn't exist anymore) but I needed something that was geared towards solid modeling for CAM. I didn't want to deal with procedural or parametric modeling; I write enough code already. I ended up using Autodesk's 123D Design. It's free, pretty basic and spits out STL files. Since it's pretty simple the learning curve isn't too bad. With about 12 hours of fiddling, watching tutorials online and letting a few cuss words leak out I started ending up with complete objects like this:

Once I'm happy with the dimensions and look it gets exported to an STL file for printing.
Time to Make the Doughnuts

I've been following the advances in 3D printing via MAKE and similar places. I'd seen some of the first commercial UV-laser/liquid polymer stereo lithography systems in the early '90s and was excited for the future. 

I have access to an Affina H-series printer. It's got a fairly small 6" x 6" x 6" print volume but that's more than I need for the parts I'm interested in. The printer is pretty easy to set up and operate. The only gotcha I've seen so far is in the feed system. Your filament spool sits on a hanger off to the side of the printer and I've found that some spools don't rotate properly, causing knots or snags during printing.

So, as I designed parts, I'd run them on the printer for try-fitting:

If you've not had the chance to use a 3D printer like the Affina, there are some kinks to be aware of:

  • The parts are layered so there is a grain to the printed parts. If you're going to have parts that need to bend, like mounting tabs, print the bending component "with the grain". That is, print so the bending component can be represented in one layer. Otherwise, the first time you bend it you'll snap the part at a layer interface.
  • Unless you set the printer properly, solids aren't really solid. Most STL slicers build hollow shells with internal webbing to save time and materials. If you need something to be thick and solid, be aware of the printer's settings.
  • Be aware of rafting and support requirements for more complex shapes. Sometimes you can print a part that seems to be mostly support material. Cutting that stuff out from the part is a pain.

Parts In Hand...Do They Work?

It's always nice to compare your replacements against the original parts just to see if you got the basic form correct:

In the above photo, the original top scope mount/rear sight assembly is at the bottom. The new display mount and housing (with the LCD display) is at the top. Looks like we're close to proper fitment. The only thing to do is try it:

In this case, it took 3 iterations to make a display mount that fit the existing top rail assembly. If you look at the original part you'll see a small bolt; the new part uses the same mounting nut and a longer bolt to secure itself to the top rail.

Parts Inventory

To complete the prototype I printed the following:
  • Bottom grip cap (holds the selection switch). You can see it in other posts.
  • Top-rear rail, which is the base for...
  • Display housing (the big curved thing that holds the display)
  • Display Bezel (locks the display in place)
  • Magazine switch mount. This holds the microswitch used to detect magazine state. It's glued inside, just below the gearbox, where there's a little room.

What's Next

More field testing is underway. Time constraints have kept the prototype off the field but I should have some field videos soon. Until then, keep winding those mags.

Friday, June 20, 2014

AVI-TAR System Design Part 3: Parallel Tasks

See the Intro Video for a quick demo of the prototype

In the last post I talked about the "bench test" system. This post is about the process behind building an integrated prototype.

After the Bench Test...

So I have a functional hardware and software system literally duct-taped to my AEG. The next step has to be mechanical integration, right? (Yes, that's rhetorical.)

I broke it down into these parts:

  • logic board location and internal wiring
  • display location and housing
  • scroll switch location and housing
  • Magazine switch mounting
I'd already kludged the IR detector and will be revisiting that subsystem later on. Each of these parts stand alone and so I worked on them in parallel. We'll start with the heart of the system here.

Logic Board

From the start I'd had the idea of mounting the logic on the underside of the top rail assembly of the TAR-21. It's a long plastic part that slides out of the main body and it has a lot of dead space. The original board I'd designed was the approximate shape but not quite right. Also, since it used .1" headers for most connections it was not field-ready. Those headers are big and do not lock the connectors in place. Great for tinkering, not so much for real world use.

So, back to Eagle Lite for some tweaks to the schematic and board layout. The schematic needed some cleanup, inserting the IR detector connections and deleting some now unneeded parts. Here's the REV B schematic:

As you can see from this version, I'm learning a little more about schematic-building.

A not so quick trip through the board layout and I get this, which went off to OSH PARK for manufacture:

You'll notice that I'm using through-hole components for everything but the half-bridge power device. It's easier for me to build and troubleshoot and I don't need to shrink the board down any further.

Here's the board stuffed and mounted into the top rail. It's a friction fit but there are provisions for fasteners.

I'm using Hirose connectors for the low-power connections. I'm here to tell you that terminating the wires into those without the specific crimping tool is a good way to determine how motivated you are in your work. It's tough, fiddly work.

Next time...the display housing.

Intro Video Posted

I finally found a few hours to shoot and edit a short introductory video on the AVI-TAR prototype:

It shows the basic operator interface and what it looks like as it burns through a small  50-round simulated magazine. I'm using a 300-round flash mag to supply the gun but set the mag capacity low to show a complete magazine cycle when firing in burst mode.

I've almost got the next post in the design saga done, just need to shoot a few more photos.

Stay upwind from the guys who pack menu 01 MREs with them...

Saturday, June 14, 2014

AVI-TAR System Design Part 2: Prototyping

Last post I talked more about the design path behind the current incarnation of the AVI-TAR project. Time for nuts and volts.

Phase I: Component Selection

Last post, I talked about what parts I thought I'd need. I'd settled on the Sparkfun Pro Micro Arduino board for my initial prototype since I expected that it'd have the horsepower to run the system I wanted to develop. It's small and easy to both breadboard and integrate. That just left everything else...

I knew that I wanted to mount the display behind the top rail of the TAR, where the MARS sight would normally attach. I figured on printing up plastics for that so I had a good idea of dimensions: about 45mm x 45mm. That helps greatly with the display selection. There are a number of LCD and OLED modules out there and they're all pretty cheap. After a good deal of research I decided that I'd try a Nokia 5110-style display. I picked up the SparkFun version as well as a few from Deal Extreme, which were half the price of SparkFun's part but are also not made as well.

Input switches for the user interface was purely a product design choice. I started out with a 4 button membrane switch part that I had laying around but quickly realized that there's no good place to put that on the TAR. After some unfocused staring at my partly disassembled TAR I came up with the "navigation inputs in the grip tail" idea. SparkFun came to the rescue with a scrolling switch on a PCB:

By now I must sound like a SparkFun employee. The reality is that I hit a lot of sites looking at stuff; SparkFun just seems to keep coming up with the right part at a decent price. Digikey filled most of the rest of my BOM (bill of materials).

Phase 2: Breadboarding

WIth parts in hand, I tossed the Arduino, nav switch and LCD onto a protoboard and started writing code to bootstrap myself. It only took a few hours spread across a week or two.

Once I got "Hello World!" working and could read the switch inputs it was time to build a PCB test platform since the motor controller is a surface mount job.

Phase 3: Test Platform

The last time I designed a PCB I used an etch-resist pen. This time around I used Eagle Light. Whip up a schematic with the schematic editor and it'll help greatly with the board layout. Here's the schematic (click to enlarge):

I eventually ended up with this 2-layer board from the OSH Park PCB service:

This board uses .1" headers for connections. It allowed me to quickly swap things around. The Pro Micro (which I soldered headers onto as well) sits in a regular DIP socket on the board so I can swap it out as well. The only things soldered in are the passives and power electronics.

From that and the schematic I got to my test platform:

(Yes, the board it powered up and on the main screen)

With this board I was able to try out a number of shot detection methods: dV, dI (the motor driver has a current sense output), even a piezo element attached to the gearbox:

(The gearbox is from a SIG 552, one of our first AEGs in the house)

Interestingly, for my hardware choices I found that the piezo detection method was very good at determining when a shot occurred. My software wasn't quick enough to detect the current changes in the freewheeling part of the gearbox cycle. Voltage detection was also a non-starter with a LiPo and the motor driver running the show. When I first played with voltage detection, I saw distinct spike in voltage when the motor freewheeled via a Fluke scopemeter across the battery leads of my stock microswitch-operated gun. With the half-H bridge driver and a LiPo running the gearbox, all I saw was a dip in voltage when the gearbox was operating.

That left me with a choice: try to use the piezo detector and filter out rough handling (bumps, drops, etc.) or go with a true BB detector. 

I ended up gritting my teeth and drilling a perfectly good 6.03 barrel to mount one of these:

It's a Sharp 10mm photo interrupter on a breakout board. I'll bet you can't guess where I got it from...

Putting that across the path of the BB as it went down the barrel was the surest way to detect a shot. At 500 fps (154.2 m/sec - more than most fields allow anywhere) a 6mm BB travels about 25,700 BB-widths per second. That means that as that BB passes the photo interrupter it will deliver a signal change that lasts about 39 microseconds. As long as the photo detector's edge time is 1/4 of this or less and the Arduino can detect and act on the signal change we're all good.

As it turns out, Arduino interrupt servicing is much faster than 39 microseconds so we have a working shot detector. The rest is just coding. Or is it?

More about that next post, as well as the "production prototype" board build. Time to bend an elbow...

Thursday, June 12, 2014

AVI-TAR System Design Part 1

When I started this project over a year ago I knew very little about AEG (airsoft electric gun) operation. That was a blessing because it forced me to try different things in ignorance of the "system" I was working with. You learn more from your failures.

With that in mind, time for some technical stuff.

Theory of Operation

This is a toy, after all, so I didn't try to get too fancy. In order to meet my design goals (in my first post) I figured that I needed the following elements:
  • A "shot sensor" to detect when a round was shot. There are a few ways to do this:
    • Timer - Once gearbox timing is determined, you can time the shots if you have a fast enough timer system and fine control of the motor so that you can be sure of where the gearbox is when you stop the motor.
    • dV or dI detection - The motor that drives the gearbox tends to draw more current as it pulls back the spring and then freewheels as the sector gear releases the spring for a shot.
    • Hard gearbox timing - Uses some method to determine where the gearbox is. There are a few systems out there that seem to monitor the sector gear. I assume that they look at the disconnector assembly to determine when the system has run through a cycle.
    • BB detection - Uses some method to detect a BB fed through the barrel.
    • Other - Vibration detecion via a piezo element on the gearbox? Tried that...
  • A magazine position sensor to tell when there's a mag inserted in the mag well.
  • A user interface; display and user controls that would fit into the gun's design.
  • Power electronics to control the motor.
  • A micro controller to tie it all together.
From that comes the system diagram:

Of course, this is primarily a software-driven design since the feature set I'm aiming for is complex.

With these subsystems, the operational theory is:

  • State-driven software that reacts to user inputs as well as environmental inputs,
  • Environmental inputs include shot detection, battery voltage and magazine state.
  • User inputs include trigger state and some sort of menu/selection switch inputs.
  • Software runs in a continuous loop, checking inputs; some inputs may generate interrupts to trigger state changes mid-loop.
  • Inputs result in state changes, which cause subroutines to execute, based on state.

So Many Choices:
A good scientist is a person with original ideas. A good engineer is a person who makes a design that works with as few original ideas as possible.
With that quote I profess to be more engineer than scientist. Why hurt yourself while trying to unscrew the inscrutable? I tackled components in this order:

  1. Motor control. I wanted a half H-bridge design but didn't want to have to festoon my board with multiple MOSFETS and their attendant components that'd be needed to interface to logic-level I/O. Fortunately, there's a lot of need for this type of logic-driven real-world interface so you can find everything you need to control a DC motor prepackaged onto a chip for not much money. I looked at a number of high power half bridge drivers before settling on the Infineon BTN7960B, which I found can be sourced cheaply. It's an older product and Infineon has since moved on to the BTN7971 and BTN89xx family. A good discussion of how to use these neat little devices is here.
  2. Processor. There are plenty of decent uCs out there and plenty of good tool chains supporting them. I didn't want to waste time in circuit design so I looked into breadboard type devices. It boiled down to PIC and AVR devices. I've used both before but the AVR-based Arduino culture seemed more adept at rapid prototyping so that's where I went. The SparkFun Pro Micro (5V) is what I settled on. I'd helped my son build a game with one for a school project and he got to learn C and state-driven programming while I got to check out the product.
  3. Everything else. I knew that I didn't have a full-formed idea for the user interface, nor did I understand how to detect shots from the AEG. I figured that I'd dope those out through trial and error. And boy, was there a lot of error to experience...

The "everything else" category was where the scientist came in. Experimentation was the only way to determine how to solve the puzzles of shot detection and the little gotchas that revealed themselves during design integration (making all the parts work as expected). Research is important to the scientific process as well. For example, I found that the micro switch used in the S&T gearbox has a lot of bounce when running in full-auto mode due to the extreme vibrations caused by the gearbox. I spent hours figuring out why the gun would randomly stop firing in burst mode; this was the cause. As it turns out, someone else wrote up the phenomenon. A little time on Google would've saved me hours of hair-pulling and I ain't got much hair to begin with. Of course, you have to know what you don't know before you can research.

I figured that I'd be breadboarding the bench test, throwing support electronics around the core as needed. In reality, once I decided on the display to use and got that working on a breadboard I saw that I needed to get onto a PCB. The motor control IC I wanted to use is a surface-mount device and I needed to run it full power in the early stages of development. No way to do that on your usual white protoboard.

These days, you can do PCB design and get a batch of boards made pretty quickly. I've been using OSH Park for PCBs. They take Eagle board files and turn them into reality for not a lot of money.

I'll continue on with the PCB design and schematic in the next post. Until then, "if you can hear it, it wasn't meant for you".

Wednesday, May 28, 2014

Intro to the AVI-TAR User interface, Mk 1

In the last post I showed a profile shot of the AVI-TAR. I'll fill in some of the details in this post.

Visual Interface:

I tinkered with a few different display types before settling on a PCD8544 type screen. It's an 84x48 pixel LCD with LED backlighting. For now, I have it in a basic angled housing that sits on a replacement rail. Here's an operator's view:

(Don't mind the rough edges...prototype 3D printed plastics FTW!)

When powered up with no magazine inserted, you'll see this home screen:

The parts are:
  • Upper left corner: battery voltage/status
  • Middle left (purple outline): burst setting - right now in "safe" mode
  • Lower left (green outline): round counter
  • Center (red outline): magazine bar graph (empty right now - no mag inserted)
  • Upper right (no outline): status messages
  • Middle right (blue outline): rounds remaining in magazine
  • Lower right (inverted text): selected magazine capacity

With a new magazine inserted:

I'm in 3-round burst mode with a full 100 round mag, ready to engage.

In addition to the home screen there are menus, some simple, some more complex, for setting modes, magazine sizes, viewing counters, etc. etc. More on that later. The settings are all controlled through a navigation rocker on the bottom of the hand grip:

If you've ever seen an S&T TAR-21, you'll wonder why that bottom cap is removable. I did, anyway. You really can't store anything in the hand grip since it's hollow all the way up into the main body cavity and you need a screwdriver to remove it in any case so it's not very practical in the field. I printed up this part as a replacement. Note the spherical depression that the switch sits in...keeps it from getting manipulated or damaged when the bottom of the grip drags or drops. 

The switch is a 3-position rocker (up, down and push-to-click) so you can have both hands on the gun and tucked in while you change burst settings, for example. My original idea was to put membrane switches on the side of the top rail. That's a no-go because you have to take your hand off the grip to push buttons AND which ever side you pick you're going to piss off opposite-handers. 

That was a fun bit of CAD work that took 5 versions to get right. I'm brand new to 3D printing, BTW, and if you've got any mechanical talent it's pretty simple to pick up. There's plenty of good free 3D CAD programs out there to play with. Dive in and make a mess the first few times...nobody will care and you'll learn quickly what works.

Next post I'll dive into the electronics. They're pretty simple and modern half-bridge motor driver ICs make the power side almost child's play.