Parallax Forums
  HomeLog InRegisterCommunity CalendarSearch the ForumHelp
   
Parallax Forums > Public Forums > Completed Projects > My Very First Basic Stamp project. Ping activated turret gun!  Forum Quick Jump
 
New Topic Post Reply Printable Version
[ << Previous Thread | Next Thread >> ] | Show Newest Post First ]

wabbit
Registered Member

Email Address Not AvailablePersonal Homepage Not AvailablePrivate Messaging Not AvailableAIM Not AvailableICQ Not AvailableY! Not AvailableMSN Not Available
Date Joined Mar 2008
Total Posts : 16
 
   Posted 3/16/2008 3:26 PM (GMT -8)    Quote This PostAlert An Admin About This Post.
Hi all,
 
I bough the boebot kit and went through the book.
 
This is my first project using a basic stamp and programming.
 
I have a Ping sensor mounted on top of a servo. It scans back and forth looking for any object closer than 30 in. When it locates and object the toy disc shooter which is also mounted on a servo swings to the same position and fires.
 
The major challenge I had was with the toy gun. I thought since the gun took battery that it would be all electric and therefore easy for the basic stamp to fire. It turns out the gun has an electric motor that spins up to speed when you turn the toy on. Then it has a mechanical linkage that pushes a foam disk into the motor when the trigger is pressed. I had to use another servo to activate the trigger.
 
 
 
 
 
Here is a video of it working:
 
To turn on the motor in the toy I am using a 5v reed relay. I soldered a diode across it to protect the stamp.
 
I made this mainly to annoy my coworkers as they walk past my cubicle.
 
Here is the program: This is my first ever program. Please let me know if anything could be streamlined or enhanced in the code.
 
' {$STAMP BS2}
' {$PBASIC 2.5}
'----------------------------pin locations for each component----------------------------------------------------------
'p6 = ping sensor
'p8 = relay to activate dc motor
'p10 = piezo speaker
'p12 (servo plug) = sweeping servo that ping sensor is attached to
'p13 (servo plug) = servo that gun is attached to
'p14 (servo plug) = servo that activates mechanical trigger on toy gun
'----------------------------constants and variables--------------------------------------------------------------------
inconstant CON 890                               'constant to divide raw ping data to convert to inches. Room Temp
counterstep CON 150                              'this is the amount of steps the sweep will go through.
'-----------------change this constant to change the trigger range- This number is in inches----------------------------
trigger CON 30                                  'trigger distance
'-----------------------------------------------------------------------------------------------------------------------
direction VAR Word
ammo VAR Word
counter VAR Word                                 'this counter is for the servo sweep
sweep VAR Word
gunsweep VAR Word                                'this counter repeats the sweep until servo is in position
indistance VAR Word
time VAR Word
beeper VAR Word
'---------------------sets trigger servo to neutral start position and motor relay to off----------------------------
LOW 8                                               'sets fire relay to off
FOR counter = 1 TO 20                               'sets trigger servo to neutral
    PULSOUT 14,750
    PAUSE 20
  NEXT
'---------------------beeps 5 times then slowly scans ping servo right to left (just for show!)----------------------
FOR counter = 1 TO 5                                'beep at start
  FREQOUT 10, 250, 3500
  PAUSE 100
NEXT
                                                    'sweep to start position - just for show
FOR counter = 1000 TO 500 STEP 3
      PULSOUT 12, counter
      PAUSE 10
NEXT
'---------------------------------------starts scanning/firing sequence-----------------------------------------------
DO                                                   'start scanning
    FOR direction = 500 TO 1050 STEP counterstep
    FOR sweep = 1 TO 6
      PULSOUT 12, direction
      PAUSE 10
    NEXT
      PULSOUT 6,5                                    'ping
      PULSIN 6,1,time
      indistance = inconstant ** time                ' convert ping input to inches
      DEBUG HOME, DEC5 time, " ping raw data", CR,   'displays raw ping data
      DEC3 indistance, " in", CR,                         'displays ping results in inches
      DEC2 ammo, " ammo count"                 'displays the amount of ammo left
      PAUSE 10
    IF indistance = <trigger THEN
      GOSUB fire
      ELSE
    ENDIF
  NEXT
 
  FOR direction = 900 TO 550 STEP counterstep
    FOR sweep = 1 TO 6
      PULSOUT 12, direction
      PAUSE 10
    NEXT
      PULSOUT 6,5                                    'ping
      PULSIN 6,1,time
      indistance = inconstant ** time                ' convert ping input to inches
      DEBUG HOME, DEC5 time, " ping raw data", CR,   'displays raw ping data
      DEC3 indistance, " in"                         'displays ping results in inches
      PAUSE 10
    IF indistance = <trigger THEN                    'triggers firing sequence
      GOSUB fire
      ELSE
    ENDIF
  NEXT
LOOP

fire:                                                'activates firing relay
ammo = ammo + 1
HIGH 8
FOR gunsweep = 1 TO 10                               'move to fire position of ping servo
  PULSOUT 13, direction
  PAUSE 20
NEXT

PAUSE 300                                            'pause long enough for dc motor to spin up to speed
  FOR counter = 1 TO 20                              'servo to activate mechanical trigger
    PULSOUT 14,600
    PAUSE 20
  NEXT
LOW 8
  FOR counter = 1 TO 20                              'return trigger servo to neutral
    PULSOUT 14,750
    PAUSE 20
  NEXT
 
FOR gunsweep = 1 TO 10                               'return to center after fire
  PULSOUT 13, 750
  PAUSE 20
NEXT
IF ammo = 10 THEN                                    'check how much ammo is left
  GOSUB ammoout
  ELSE
ENDIF
RETURN
'------------------------if ammo out return servos to neutral and beep 10 times then shutdown---------------------------
ammoout:
FOR gunsweep = 1 TO 10                               'return to center after ammo out
  PULSOUT 13, 750
  PULSOUT 12, 750
  PAUSE 20
NEXT
FOR beeper = 1 TO 10
  FREQOUT 10, 250,3500
  PAUSE 100
  NEXT
END
Back to Top
 

James Long
Lil Brother SMT Assembly Services



Email Address Not AvailablePersonal Homepage Not AvailablePrivate Messaging Not AvailableAIM Not AvailableICQ Not AvailableY! Not AvailableMSN Not Available
Date Joined Aug 2004
Total Posts : 1181
 
   Posted 3/16/2008 3:51 PM (GMT -8)    Quote This PostAlert An Admin About This Post.

I'm sorry....but that is classic. A very good first project, and it looks as if you are pretty satisfied with the result.

You didn't say if the gun was auto repeat. (it keeps shooting if the target doesn't move).

Sitll a very nice first project.....

James L


James L
Partner/Designer
Back to Top
 

wabbit
Registered Member

Email Address Not AvailablePersonal Homepage Not AvailablePrivate Messaging Not AvailableAIM Not AvailableICQ Not AvailableY! Not AvailableMSN Not Available
Date Joined Mar 2008
Total Posts : 16
 
   Posted 3/16/2008 4:09 PM (GMT -8)    Quote This PostAlert An Admin About This Post.

Its not auto repeat. But that would be nice wouldnt it?!

I guess I'll get started on it.

I did program it to keep track of how many discs it fires so that it will shut down when it is finished.

 

I am also thinking of adding a "doomsday button" (big red button that says "do not push") When pushed the gun will sweep back and forth firing every disc as fast as possible.

 

I need to get a big red button! 

Back to Top
 

wabbit
Registered Member

Email Address Not AvailablePersonal Homepage Not AvailablePrivate Messaging Not AvailableAIM Not AvailableICQ Not AvailableY! Not AvailableMSN Not Available
Date Joined Mar 2008
Total Posts : 16
 
   Posted 3/16/2008 5:21 PM (GMT -8)    Quote This PostAlert An Admin About This Post.
adjusted the subroutine code so that after the gun turns to position and the dc motor has come up to speed it will pings again to see if the target is still there.
 
Also after each trigger pull it pings to see if the target is still there. If yes it keeps firing (pinging between each fire) until the target leaves or it runs out of ammo.
 
Heres the revised code
 
 
' {$STAMP BS2}
' {$PBASIC 2.5}
'----------------------------pin locations for each component----------------------------------------------------------
'p6 = ping sensor
'p8 = relay to activate dc motor
'p10 = piezo speaker
'p12 (servo plug) = sweeping servo that ping sensor is attached to
'p13 (servo plug) = servo that gun is attached to
'p14 (servo plug) = servo that activates mechanical trigger on toy gun
'----------------------------constants and variables--------------------------------------------------------------------
inconstant CON 890                               'constant to divide raw ping data to convert to inches. Room Temp
counterstep CON 150                              'this is the amount of steps the sweep will go through.
'-----------------change this constant to change the trigger range- This number is in inches----------------------------
trigger CON 15                                  'trigger distance
'-----------------------------------------------------------------------------------------------------------------------
direction VAR Word
ammo VAR Word
counter VAR Word                                 'this counter is for the servo sweep
sweep VAR Word
gunsweep VAR Word                                'this counter repeats the sweep until servo is in position
indistance VAR Word
time VAR Word
beeper VAR Word
'---------------------sets trigger servo to neutral start position and motor relay to off----------------------------
LOW 8                                               'sets fire relay to off
FOR counter = 1 TO 20                               'sets trigger servo to neutral
    PULSOUT 14,750
    PAUSE 20
  NEXT

'---------------------beeps 5 times then slowly scans ping servo right to left (just for show!)----------------------
FOR counter = 1 TO 5                                'beep at start
  FREQOUT 10, 250, 3500
  PAUSE 100
NEXT
                                                    'sweep to start position - just for show
FOR counter = 1000 TO 500 STEP 3
      PULSOUT 12, counter
      PULSOUT 13, counter
      PAUSE 10
    NEXT
FOR counter = 1 TO 20                               'sets gun to neutral
    PULSOUT 13,750
    PAUSE 20
NEXT
 
'---------------------------------------starts scanning/firing sequence-----------------------------------------------
DO                                                   'start scanning
    FOR direction = 500 TO 1050 STEP counterstep
    FOR sweep = 1 TO 6
      PULSOUT 12, direction
      PAUSE 10
    NEXT
      PULSOUT 6,5                                    'ping
      PULSIN 6,1,time
      indistance = inconstant ** time                ' convert ping input to inches
      DEBUG HOME, DEC5 time, " ping raw data", CR,   'displays raw ping data
      DEC3 indistance, " in", CR,                         'displays ping results in inches
      DEC2 ammo, " ammo count"                 'displays the amount of ammo left
      PAUSE 10
    IF indistance = <trigger THEN
      GOSUB fire
      ELSE
    ENDIF
  NEXT
 
  FOR direction = 900 TO 550 STEP counterstep
    FOR sweep = 1 TO 6
      PULSOUT 12, direction
      PAUSE 10
    NEXT
      PULSOUT 6,5                                    'ping
      PULSIN 6,1,time
      indistance = inconstant ** time                ' convert ping input to inches
      DEBUG HOME, DEC5 time, " ping raw data", CR,   'displays raw ping data
      DEC3 indistance, " in"                         'displays ping results in inches
      PAUSE 10
    IF indistance = <trigger THEN                    'triggers firing sequence
      GOSUB fire
      ELSE
    ENDIF
  NEXT
LOOP

fire:                                                'activates firing relay
HIGH 8
FOR gunsweep = 1 TO 10                               'move to fire position of ping servo
  PULSOUT 13, direction
  PAUSE 20
NEXT

PAUSE 250                                            'pause long enough for dc motor to spin up to speed
PULSOUT 6,5                                          'ping to check if target is still in location
      PULSIN 6,1,time
      indistance = inconstant ** time                ' convert ping input to inches
      IF indistance = <trigger THEN
        GOSUB triggerpull
        ELSE
        LOW 8
        FOR gunsweep = 1 TO 10                       'return to center after fire
          PULSOUT 13, 750
          PAUSE 20
        NEXT
      ENDIF
RETURN
triggerpull:        ammo = ammo + 1
          IF ammo = 11 THEN                                    'check how much ammo is left
          GOSUB ammoout
          ELSE
          ENDIF
          FOR counter = 1 TO 20                              'servo to activate mechanical trigger
            PULSOUT 14,600
            PAUSE 20
          NEXT
          FOR counter = 1 TO 20                              'return trigger servo to neutral
              PULSOUT 14,750
              PAUSE 20
          NEXT
                    PULSOUT 6,5                                    'ping to check if target is still in location
                    PULSIN 6,1,time
                    indistance = inconstant ** time                'convert ping input to inches
                    IF indistance = <trigger THEN
                       GOSUB triggerpull
                    ELSE                                           'turn off relay
                    LOW 8
                        FOR gunsweep = 1 TO 10                     'return to center after fire
                        PULSOUT 13, 750
                        PAUSE 20
                        NEXT
                    ENDIF
          RETURN
 
'------------------------if ammo out return servos to neutral and beep 10 times then shutdown---------------------------
ammoout:
FOR gunsweep = 1 TO 10                               'return to center after ammo out
  PULSOUT 13, 750
  PULSOUT 12, 750
  PAUSE 20
NEXT
FOR beeper = 1 TO 10
  FREQOUT 10, 250,3500
  PAUSE 100
  NEXT
END
Back to Top
 

Ugha
Registered Member



Email Address Not AvailablePersonal Homepage Not AvailablePrivate Messaging Not AvailableAIM Not AvailableICQ Not AvailableY! Not AvailableMSN Not Available
Date Joined Jul 2007
Total Posts : 547
 
   Posted 3/17/2008 6:24 AM (GMT -8)    Quote This PostAlert An Admin About This Post.
That's awesome wabbit.

A couple suggestions...
Can you somehow mount the Ping on top of the gun's turrent and use that to scan so there's less of a delay in firing?

You need to add wheels! A mobile foam disc killing machine!

Another thing to consider is a target... a simple robot that moves randomly in the gun's field of view with a giant target
sitting on it... maybe put an impact switch on it so it knows when its been hit and sits still (plays dead).
 
Edit: What's that white plastic mount you have the Ping attached to? It looks like a perfect fit.
Back to Top
 

Whit
Registered Member



Email Address Not AvailablePersonal Homepage Not AvailablePrivate Messaging Not AvailableAIM Not AvailableICQ Not AvailableY! Not AvailableMSN Not Available
Date Joined Mar 2007
Total Posts : 1249
 
   Posted 3/17/2008 6:52 AM (GMT -8)    Quote This PostAlert An Admin About This Post.
Great project wabbit! My only suggestion is a giant tube of foam disks to feed the disk shooter! ;-)

Coworkers be warned.


Whit+
 
"We keep moving forward, opening new doors, and doing new things, because we're curious and curiosity keeps leading us down new paths." - Walt Disney

Post Edited (Whit) : 3/17/2008 2:59:37 PM GMT

Back to Top
 

wabbit
Registered Member

Email Address Not AvailablePersonal Homepage Not AvailablePrivate Messaging Not AvailableAIM Not AvailableICQ Not AvailableY! Not AvailableMSN Not Available
Date Joined Mar 2008
Total Posts : 16
 
   Posted 3/17/2008 8:13 AM (GMT -8)    Quote This PostAlert An Admin About This Post.
Nice suggestions.
 
Yes I could mount the ping directly on the gun, but I am a little worried about the gun mount right now. The gun is just epoxied to the servo horn. I dont want to put too much weight on it. I think I might mount this on the boebot and chase my dogs with it.
 
The little plastic thing on the ping sensor is a perfect fit!  I modelled it in Solidworks and printed it out at work on our Dimension 3D rapid prototyping machine.  
 
Here are the ideas for my next 2 projects:
 
Hack this toy parrot I have that says insults and flaps its wings- Make it say different more specific things to my coworkers.
 
Built a LED clock of some type. I am thinking of the design ideas now.
 
 
 
 
Back to Top
 

Whit
Registered Member



Email Address Not AvailablePersonal Homepage Not AvailablePrivate Messaging Not AvailableAIM Not AvailableICQ Not AvailableY! Not AvailableMSN Not Available
Date Joined Mar 2007
Total Posts : 1249
 
   Posted 3/17/2008 10:25 AM (GMT -8)    Quote This PostAlert An Admin About This Post.
Check out Chris Savage's Binary Digital Clock here - http://forums.parallax.com/forums/default.aspx?f=21&m=90943


Whit+
 
"We keep moving forward, opening new doors, and doing new things, because we're curious and curiosity keeps leading us down new paths." - Walt Disney

Back to Top
 

jslil
Registered Member

Email Address Not AvailablePersonal Homepage Not AvailablePrivate Messaging Not AvailableAIM Not AvailableICQ Not AvailableY! Not AvailableMSN Not Available
Date Joined Jan 2008
Total Posts : 11
 
   Posted 3/26/2008 11:20 AM (GMT -8)    Quote This PostAlert An Admin About This Post.
Sweet Machine. I am totally jealous, rapid prototyping is an unfair advantage.
Keep it up
Back to Top
 

Larry Sutherland
Registered Member



Email Address Not AvailablePersonal Homepage Not AvailablePrivate Messaging Not AvailableAIM Not AvailableICQ Not AvailableY! Not AvailableMSN Not Available
Date Joined Jun 2007
Total Posts : 64
 
   Posted 3/26/2008 5:53 PM (GMT -8)    Quote This PostAlert An Admin About This Post.
Whit-
new avatar?


 
 
 
 
 
"Understand a grain of rice through and through and you will understand the nature of the universe."
 - Hsueh-feng,  Blue Cliff Record

Back to Top
 
[ << Previous Thread | Next Thread >> ]
New Topic Post Reply Printable Version
 
Forum Information
Currently it is Tuesday, February 09, 2010 3:17 AM (GMT -8)
There are a total of 415,988 posts in 57,637 threads.
In the last 3 days there were 78 new threads and 885 reply posts. View Active Threads
Who's Online
This forum has 18517 registered members. Please welcome our newest member, try388.
51 Guest(s), 7 Registered Member(s) are currently online.  Details
Graham Stabler, humanoido, Bob Lawrence (VE1RLL), computer guy, Rick Brooks, JohnandElspeth, mikestefoy