Shop OBEX P1 Docs P2 Docs Learn Events
Multiple PING)) Code Logic Suggestions — Parallax Forums

Multiple PING)) Code Logic Suggestions

Bill ChennaultBill Chennault Posts: 1,198
edited 2010-02-05 20:42 in Accessories
All--

I would like to upgrade my robot with multiple pings. It is my thought that if I had 8 PING)) units, I could easily cover the machine's entire "sight distance" out as far as necessary (36" is fine.) However, I can't get a handle on the logic to implement the code which will let me determine the sensor reporting the most distance ("most distance"·would be·a clear path: there are combinations of clear paths, ie; left-front, right-front, etc., but that makes it worse).

Other than a bunch of IF/THEN statements, how would you do it? Maybe it is simple and I am not seeing the forest through the trees.

Thanks!

--Bill

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-02-05 20:12
    If you use sequential I/O pins for the PING)))s, you could set up a simple loop to fill an array with the values from each of the PING)))s. You'd then have another loop that would look for the highest value (and its index). That would represent the clear path. You could construct your loop to either save the first "highest" value seen or the last "highest" value seen, whichever behavior you want.

    If you want to change the search order, you could just rearrange the PING))) connections so they're scanned in the order you want.

    If you have 8 PING)))s, that would take about 160ms to make a pass through all of them.
  • ZootZoot Posts: 2,227
    edited 2010-02-05 20:27
    e.g.

    
    PingsPins PIN 0 ' as an implied array, using pins 0-7
    maxDist VAR Word
    minDist VAR Word
    pingDist VAR Word(8)
    maxPing VAR Nib ' saved idx of ping
    minPing VAR Nib
    i VAR Nib
    
    
    LoopMe:
    maxDist = $0000
    minDist = $FFFF
    FOR i = 0 TO 7
       PULSOUT PingsPins(i), 2
       PULSIN PingsPins(i), pingDist(i)
       IF pingDist(i) < minDist THEN
          minDist = pingDist(i)
          minPing = i
       ENDIF
       IF pingDist(i) > maxDist THEN
          maxDist = pingDist(i)
          maxPing = i
       ENDIF
    NEXT
    
    DEBUG "max dist is Ping #", DEC1 maxPing,": ", DEC5 maxPing, CR,
    DEBUG "min dist is Ping #", DEC1 minPing,": ", DEC5 minPing, CR
    PAUSE 2000
    GOTO LoopMe
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • Bill ChennaultBill Chennault Posts: 1,198
    edited 2010-02-05 20:42
    Mike and Zoot--

    Mike, thanks for the logic. I am glad I quit thinking about it. I am going to attempt to poll the PING))s in a timed interrupt (SX/B) and return their distances to the main routine.

    Zoot! Ha! Thanks for the code!

    --Bill

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You are what you write.

    Post Edited (Bill Chennault) : 2/5/2010 8:48:04 PM GMT
Sign In or Register to comment.