Code for using Ping as 0 1 High Low: Ultrasonic BS2
We are firing a ping pong ball through a series of vertical targets. I want to use the PING sensor as a simple 0 or 1, high or low edge finder. The idea being to rotate our bot until the edge of our target is found, then continue until the single is lost, thus finding the beginning of the hole cut in out target. I am really just hoping to find a basic code sample that I can begin to modify. We are not using any type of roaming function and the sensor if not mounted on the servo turret.
Thanks
Thanks

Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
Code to calibrate:
'Get the values for the line repeat until ina == 1 repeat i from 0 to rcount line[noparse][[/noparse] i] := adc.in(i) if(linemin[noparse][[/noparse] i] > line[noparse][[/noparse] i] or linemin[noparse][[/noparse] i] == 0) linemin[noparse][[/noparse] i] := line[noparse][[/noparse] i] if(linemax[noparse][[/noparse] i] < line[noparse][[/noparse] i]) linemax[noparse][[/noparse] i] := line[noparse][[/noparse] i] 'com.str(string("Calculating Line Thresholds")) 'com.tx(13) repeat i from 0 to rcount t1 := (linemin[noparse][[/noparse] i] + linemax[noparse][[/noparse] i])/2 t2 := 0'||(linemin[noparse][[/noparse] i] - linemax[noparse][[/noparse] i])/64 linemin[noparse][[/noparse] i] := t1-t2 linemax[noparse][[/noparse] i] := t1+t2Code to execute when you get a reading:
repeat i from rcount to 0 line[noparse][[/noparse] i] := adc.in(i) if(line[noparse][[/noparse] i] > linemax[noparse][[/noparse] i]) binout[noparse][[/noparse] i] := 1 if(line[noparse][[/noparse] i] < linemin[noparse][[/noparse] i]) binout[noparse][[/noparse] i] := 0 image := image + (binout[noparse][[/noparse] i] << i)I used arrays since I have eight sensors that I want to get the input of (from an ADC). You would only need single variables. BTW, the code is for a line following robot.
Post Edited (SRLM) : 11/22/2009 10:37:24 PM GMT
http://forums.parallax.com/showthread.php?p=590119
-Phil