Step 1: Placing the Despensers
Step 2: Load 'em Up
Step 3: Making the Mechanics
Put 2 powered rails then 1 detector rail for the length of the defence system, next, put 1 powered rail at each end with a block behond it
(this makes the cart go back and forth).
Then, put redstone wire down to the despensers (each powers 3)
Put a redstone torch down for each 2 powered rails.
Step 4: Start It Up
Put a minecart down and push it to get it going.
Now it works.
Step 5: Other Ideas
Then, make a circular track with the same functions.
Smaller model shown below.