OmgItsHeaven
Member
I needed to a code a robot which can collide to its obstacle. I am using the SRF005 Ultrasonic Sensor to measure the distance. However in my code down below, my pauses in parallel task are horribly off, like pause 500 is 4-5 second long. Could anyone please explain this. Also if my range goes above 40 cm, then during debug I can see the range going 0 then 45, 0 then 46 and so on. I think that this is related to the pause statement being too short for long range, but still I want your help.
#SIMTASK ALL
symbol trig = B.1
symbol echo = C.4
symbol range = w1
symbol currentsense = w0
#define BuzzerPin = C.0
start0:
pulsout trig,2
pulsin echo,1,range
pause 20
let range = range * 10 / 58
debug
readadc10 3,currentsense
goto start0
start1:
pwm B.2,255,1
pwm B.4,255,1
pause 250
low B.2
pause 250
goto start1
start2:
do while range <25
suspend 1
high B.2
high B.4
loop while range <25
resume 1
goto start2
start3:
if currentsense > 180 then
pause 10
if currentsense > 180 then
suspend 1
suspend 2
low B.2
low B.4
high C.1
high C.2
pause 100
low C.1
pause 10
low C.2
resume 1
resume 2
else
goto start3
endif
endif
#SIMTASK ALL
symbol trig = B.1
symbol echo = C.4
symbol range = w1
symbol currentsense = w0
#define BuzzerPin = C.0
start0:
pulsout trig,2
pulsin echo,1,range
pause 20
let range = range * 10 / 58
debug
readadc10 3,currentsense
goto start0
start1:
pwm B.2,255,1
pwm B.4,255,1
pause 250
low B.2
pause 250
goto start1
start2:
do while range <25
suspend 1
high B.2
high B.4
loop while range <25
resume 1
goto start2
start3:
if currentsense > 180 then
pause 10
if currentsense > 180 then
suspend 1
suspend 2
low B.2
low B.4
high C.1
high C.2
pause 100
low C.1
pause 10
low C.2
resume 1
resume 2
else
goto start3
endif
endif