Multiple PING)) Code Logic Suggestions
Bill Chennault
Posts: 1,198
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.
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
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.
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
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