Shop OBEX P1 Docs P2 Docs Learn Events
Help with Program Please — Parallax Forums

Help with Program Please

Bill KennyBill Kenny Posts: 15
edited 2005-11-24 06:05 in BASIC Stamp
Hello All,
·
I was wondering if someone could help me try to figure out some programming I am having trouble with.
·
I have the Boe-Bot kit and am trying to put it in a toy tank like vehicle. I have done that and it works great except the feature I want to add are stumping me.
·
This is what I am trying to do;
·
I am using the whiskers program (tweaked a little) I will post below. It is hunting for a path to avoid objects. When it encounters one, I would like a red LED in the barrel to flash once and then activate a separate sound board I have, and then turn as usual to avoid the object. Each time it needs to reverse to avoid the objects is when I need the led flash and the sound to go off. The sound board is from radio shack that is capable of 20 seconds of your recorded sound. I have a 3 second explosion with the led light up to simulate firing the tank. Basically the purple exposed wires are just for a switch.
·
Any help?
·
Here's the code;

' Robotics with the Boe-Bot - RoamingWithWhiskersModIRwLED.bs2
' Adapt RoamingWithWhiskers.bs2 for use with IR pairs.

' {$STAMP BS2}·················· ' Stamp directive.
' {$PBASIC 2.5}················· ' PBASIC directive.

DEBUG "Program Running!"

'
( Variables )

· irDetectLeft······ VAR· Bit
· irDetectRight····· VAR· Bit
· pulseCount········ VAR· Byte······· ' FOR...NEXT loop counter.

'
( Initialization )

FREQOUT 4, 2000, 3000················ ' Signal program start/reset

'
( Main Routine )

DO
· FREQOUT 8, 1, 38500················ ' Store IR detection values in
· irDetectLeft = IN9················· ' Bit variable
· FREQOUT 2, 1, 38500
· irDetectRight = IN0


· IF (irDetectLeft =0) AND (irDetectRight = 0) THEN
··· HIGH 10·························· ' LED
··· HIGH 1··························· ' LED
··· GOSUB Back_Up···················· ' Both IR pairs detect obsticle
··· GOSUB Turn_Left·················· ' Back up & U-turn (left twice)
··· GOSUB Turn_Left
· ELSEIF (irDetectLeft = 0) THEN····· ' Left IR pair detects
··· HIGH 10·························· ' LED
··· GOSUB Back_Up···················· ' Back up and turn right
··· GOSUB Turn_Right
· ELSEIF (irDetectRight = 0) THEN···· ' Right IR pair detects
··· HIGH 1··························· ' LED
··· GOSUB Back_Up···················· ' Back up & turn left
··· GOSUB Turn_Left
· ELSE······························· ' Both IR pairs 1, no detects
··· GOSUB Forward_Pulse·············· ' Apply a forward pulse
· ENDIF······························ ' and check again
LOOP

'
( Subroutines )

Forward_Pulse:······················· ' Send a single forward pulse.
··· PULSOUT 13, 850
··· PULSOUT 12, 650
··· PAUSE· 20
· RETURN
Turn_Left:··························· ' Left turn, about 90-degrees.
· FOR pulseCount = 0 TO 20
··· PULSOUT 13, 650
··· PULSOUT 12, 650
··· PAUSE 20
· NEXT
· RETURN
Turn_Right:
· FOR pulseCount = 0 TO 20··········· ' Right turn, about 90-degrees.
··· PULSOUT 13, 850
··· PULSOUT 12, 850
··· PAUSE 20
· NEXT
· RETURN
Back_Up:····························· ' Back up.
· FOR pulseCount = 0 TO 40
··· PULSOUT 13, 650
··· PULSOUT 12, 850
··· PAUSE 20
· NEXT
· RETURN



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Thanks

Bill
640 x 480 - 39K
640 x 480 - 48K
640 x 480 - 59K
640 x 480 - 30K

Comments

  • SN96SN96 Posts: 318
    edited 2005-11-22 19:45
    What results does your current code provide other than the LEDs never turning off?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Mike

    ·
  • Bill KennyBill Kenny Posts: 15
    edited 2005-11-22 19:57
    Hi Mike;

    Thanks for your reply and you are right once the LED lights·it never goes off! confused.gif· Otherwise the movment of the vehicle is fine.

    I have not yet tried to connect the sound board up, Hmm dont know were and I am very new to this. Any hints?

    Thanks

    Bill

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Thanks

    Bill

    Post Edited (Bill Kenny) : 11/22/2005 8:00:09 PM GMT
  • SN96SN96 Posts: 318
    edited 2005-11-22 20:22
    Bill,
    The reason the led lights never go off is because you set them to HIGH but never set them to LOW. What is missing is this:

    IF (irDetectLeft =0) AND (irDetectRight = 0) THEN
        HIGH 10                           ' LED On
        PAUSE 100                         ' Change this value to to the desired time delay
        LOW 10                            ' Turn off LED
        HIGH 1                            ' LED On
        PAUSE 100                         ' Delay value
        LOW 1                             ' Turn off LED
        GOSUB Back_Up                     ' Both IR pairs detect obsticle
        GOSUB Turn_Left                   ' Back up & U-turn (left twice)
    
     
    



    As for the sound device, I can't help you with that.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Mike

    ·
  • Bill KennyBill Kenny Posts: 15
    edited 2005-11-22 21:50
    Mike,
    THANKS!!!!!· ·
    ·
    The LED now works. I just ran it off the 10 I/O and split the neg. to the center IR detector pins #2's.
    ·
    Who can help me with the sound board? Like I said, all I need to do is basically find a way to have something act as a switch like touching the two purple wires together for a split second to set off the sound board.
    ·
    Any input will be most appreciated
    ·
    Thanks
    Bill

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Thanks

    Bill
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-22 22:47
    A lot of sound board use an active-low input for triggering. If this is the case then you could use a simple transistor circuit to pull the line to ground.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Bill KennyBill Kenny Posts: 15
    edited 2005-11-23 00:48
    Well I am trying to know avail, can someone post a scematic for me, like I said I am new to this. Someone posted one earlier but I think they removed it as it was not working, I tried it.

    I have these parts if they will work I dont know. NTE 54, NTE 25, NTE 13

    ·Thanks
    ·Bill

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Thanks

    Bill

    Post Edited (Bill Kenny) : 11/23/2005 5:07:50 PM GMT
  • Bill KennyBill Kenny Posts: 15
    edited 2005-11-23 22:52
    Ok well I didn't get any answers to the soundboard activation question, so I used an NTE relay R56-1D .5-60 SPST that I saw at FRY's and am activating it from I/O #10 along with the led. Everything works GREAT!

    Here is the final program;

    Thanks Anyhow
    Bill

    ' Robotics with the Boe-Bot - RoamingWithWhiskersModIRwLEDwSound.bs2
    ' Adapt RoamingWithWhiskers.bs2 for use with IR pairs and LED
    ' gun barrel with seperate sound board.

    ' {$STAMP BS2}·················· ' Stamp directive.
    ' {$PBASIC 2.5}················· ' PBASIC directive.

    DEBUG "Program Running!"

    '
    ( Variables )

    · irDetectLeft······ VAR· Bit
    · irDetectRight····· VAR· Bit
    · pulseCount········ VAR· Byte······· ' FOR...NEXT loop counter.

    '
    ( Initialization )

    FREQOUT 4, 2000, 3000················ ' Signal program start/reset

    '
    ( Main Routine )

    DO

    · FREQOUT 8, 1, 38500················ ' Store IR detection values in
    · irDetectLeft = IN9················· ' Bit variable

    · FREQOUT 2, 1, 38500
    · irDetectRight = IN0


    · IF (irDetectLeft =0) AND (irDetectRight = 0) THEN
    ··· HIGH 10·························· ' LED
    ··· PAUSE 500
    ··· LOW 10
    ··· GOSUB Back_Up···················· ' Both IR pairs detect obsticle
    ··· GOSUB Turn_Left·················· ' Back up & U-turn (left twice)
    ··· GOSUB Turn_Left
    · ELSEIF (irDetectLeft = 0) THEN····· ' Left IR pair detects
    ··· HIGH 10·························· ' LED
    ··· PAUSE 500
    ··· LOW 10
    ··· GOSUB Back_Up···················· ' Back up and turn right
    ··· GOSUB Turn_Right
    · ELSEIF (irDetectRight = 0) THEN···· ' Right IR pair detects
    ··· HIGH 10·························· ' LED
    ··· PAUSE 500
    ··· LOW 10
    ··· GOSUB Back_Up···················· ' Back up & turn left
    ··· GOSUB Turn_Left
    · ELSE······························· ' Both IR pairs 1, no detects
    ··· GOSUB Forward_Pulse·············· ' Apply a forward pulse
    · ENDIF······························ ' and check again
    LOOP

    '
    ( Subroutines )

    Forward_Pulse:······················· ' Send a single forward pulse.
    ··· PULSOUT 13, 850
    ··· PULSOUT 12, 650
    ··· PAUSE· 20
    · RETURN

    Turn_Left:··························· ' Left turn, about 90-degrees.
    · FOR pulseCount = 0 TO 20
    ··· PULSOUT 13, 650
    ··· PULSOUT 12, 650
    ··· PAUSE 20
    · NEXT
    · RETURN

    Turn_Right:
    · FOR pulseCount = 0 TO 20··········· ' Right turn, about 90-degrees.
    ··· PULSOUT 13, 850
    ··· PULSOUT 12, 850
    ··· PAUSE 20
    · NEXT
    · RETURN

    Back_Up:····························· ' Back up.
    · FOR pulseCount = 0 TO 40
    ··· PULSOUT 13, 650
    ··· PULSOUT 12, 850
    ··· PAUSE 20
    · NEXT
    · RETURN



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Thanks

    Bill

    Post Edited (Bill Kenny) : 11/23/2005 10:57:45 PM GMT
  • MMISCOOLMMISCOOL Posts: 36
    edited 2005-11-24 04:40
    Hey. If you need to hook up the sound board just ge a reley. Conect the reley to an i/o pin and hook the swich side up to your sound board.
  • Buck RogersBuck Rogers Posts: 2,175
    edited 2005-11-24 05:01
    Hello from Buck Rogers
    A suggestion. Please cease and desist from using the classic All Caps mode. It's more appropriate to the days when the computer systems didn't realize we humans spoke in upper and lower case characters. I grok that some of us do. And I'm even inclined to make allowances, but not now. Also please try to spellcheck.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Buck Rogers

    www.gregg.levine.name
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-11-24 06:01
    Bill,

    ·· Without more information on the sound board it would be hard to make guesses, but at the very worst a small reed relay could be used to simulate a switch.· There are tons of circuits for connecting a relay to a Stamp pin, especially in Matt Gilliland's Cookbooks...The code would be much the same as your LED, except with a different pin.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com


    Post Edited (Chris Savage (Parallax)) : 11/24/2005 6:05:06 AM GMT
  • ejdarlingejdarling Posts: 24
    edited 2005-11-24 06:05
    Sometimes you should use a reley. Really.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -Eric
Sign In or Register to comment.