Shop OBEX P1 Docs P2 Docs Learn Events
4 pings in a robin fashion — Parallax Forums

4 pings in a robin fashion

RobeRobe Posts: 13
edited 2005-07-29 04:27 in BASIC Stamp
GOOD MORNING EVERYONE,· I HAVE WRITTEN THIS CODE TO TRIGGER FOUR PINGS IN A RUBBING FASION BUT I HAVE TRIED A FEW DIFFERENT WAYS AND I CAN'T GET IT TO WORK. I AM NOT SURE WETHER OR NOT MY SUB ROUTINE IS WRIGHT OR IF I NEED 1 FOR EACH PING, OR IF SOMETHING IS MISSING. COULD·ANYONE HELP ME WITH REVIEWING THIS·CODE. I WOULD APPRECIATE THE HELP.confused.gif

{$STANP BS2}
{$PBASIC 2.5}
ping1·· PIN 5
ping2·· PIN· 2
Ping3· ·PIN 15
Ping4 · PIN 4

trigger com 5
trigger· com 6
trigger· com 7
trigger· com 8

scale1· com $200
scale2· com $200
scale3· com $200
scale4· com $200

rawtoin· com 889
rawtoin· com 889
rawtoin· com 889
rawtoin· com 889

ishigh1· com 1
ishigh2· com 1
ishigh3· com 1
ishigh4· com 1

islow1· com 0
islow2· com 0
islow3· com 0
islow4· com0

rawdist1· var· word
rawdist2· var· word
rawdist3· var· word
rawdist4· var· word

inches1· var· word
inches2· var· word
inches3··var· word
inches4· var· word

pingnum· var bit

pulsecount· var byte
counter····· var·byte
pulseleft···· var word
pulseright·· var word

theping····· var byte
pingbase····var byte

ishigh······· var bit
rawdist····· var bit
scale········ var bit

DO

pingnum· = pingnum + 1 // 2

gosub get_sonar

inches1 = rawdist1**rawtion1
inches2 = rawdist2**rawtoin2
inches3 = rawdist3**rawtoin3
inches4 = rawdist4**rawtoin4

if (inches1·= 5 ) then
pulsout 13, 650
pulsout 12, 850

····· '· more navegation code goes here for ping #2 to #3

elseif ( inches4 = 5 )then
for counter 1 to 50
pulsout 13, 850
pulsout 12,· 850
next
pause 50

else
pulseleft··· = 850
pulseright· = 650

pulsout 13, pulseleft
pulsout 12, pulseright

loop

get_sonar:
theping = pingbase + pingnum
low theping
pulsout ·theping, trigger
pulsing·· theping, ishigh,rawdist (pingnum)
rawdist (pingnum ) = rawdist(pingnum)*/scasle1
rawdist (pingnum ) = rawdist(pingnum) / 2

RETURN







·

Comments

  • kb2hapkb2hap Posts: 218
    edited 2005-07-26 17:26
    Well for one the "islow1 COM 0" (that goes for all COM->CON) the coms you put in I belive should be CON instead also your pingnum is only a bit but it looks like it could easily return values other than 0 or 1
    thats just a quick glance.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    DTQ
  • Buck RogersBuck Rogers Posts: 2,175
    edited 2005-07-26 22:30
    Hello from Buck Rogers
    Good code, however, NO SHOUTING! It is very annoying to do that.
    nono.gif

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

    www.gregg.levine.name
  • MacGeek117MacGeek117 Posts: 747
    edited 2005-07-26 22:36
    Also, (this is a tip for everyone) please post your code in a attachment.
    bugg

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Boe-bot: $229


    Toddler: $249

    Learning Google is your friend: priceless
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-27 14:06
    Your program seems to me a mish-mash of SRF-04 code and Ping code, and not organized as well as I think you want.· If you are indeed using Parallax Ping sensors (that have just one wire for trigger and echo), and those are connected to the pins you label "Trigger" then the attached program should get you going.· Note that I removed other definitions to focus on the Ping sensors.· Once the sensors are working as required you can add back the other items -- slowly, and carefully testing as you go.


    Note on my attachment: I've attached the program as a .TXT file so that it can be viewed online without downloading.· After downloading, simply remove the added .TXT extension to open in the BASIC Stamp IDE.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Philip GamblinPhilip Gamblin Posts: 202
    edited 2005-07-29 04:27
    I didn't look at the logic in your code but I did correct a bunch of typos. I think·it would be a good idea to start with a much smaller program. Get one Ping working properly before trying to get all four working. Here's a suggestion, create a loop that does the following 1) trigger the ping· 2) get the time· 3) store the value in a variable 4) scale it·· 5) debug it .

    Let the loop run continuously while you check the operation of the sensor. I corrected some of the· syntax errors, but i did not check /alter any of the program logic.
Sign In or Register to comment.