Help! How to detect obstacles using ping))), and making the servos turn for avoidance
kolai
Posts: 9
Hello everyone, I'm a newbie on obstacle sensing using the ping))) sensor. I'm trying to make obstacle sensing boe - bot w/ 3 sensors, namely 2 - IR emitter & Receiver and the ping))) sensor. I didn't attach the ping sensor to the servo because the purpose of the ping sensor is only to detect forward obstacles and the IRs for the left and right obstacles. I really just can't get it to work, I've used the 2 IRs and it went well. What I want next is to add a middle sensor('ping)))') to detect forward obstacles, but as I try to study the codes from 'Mini Projects', I get so confused on how to use it, and even the 'RoamingWithPing.bs2' gave me a headache.
Please Help. :blank:
Here is my code
' {$STAMP BS2}
' {$PBASIC 2.5}
'Maze Traversal
DEBUG " Program Running! "
irDetectLeft VAR Bit
irDetectRight VAR Bit
cmConstant CON 2260
pulseLeft VAR Word
pulseRight VAR Word
distance VAR Byte
cmFinal VAR Byte
FREQOUT 4, 30, 5000
GOSUB Read_Ping
GOSUB Calc_Distance
DO
IF (cmFinal < 3) THEN
pulseLeft = 650
pulseRight = 850
FREQOUT 8, 1, 38500
irDetectRight = IN0
FREQOUT 9, 1, 38500
irDetectLeft = IN10
ELSEIF (irDetectRight = 0) AND (irDetectLeft = 1)THEN
pulseLeft = 650
pulseRight = 650
HIGH 1
ELSEIF (irDetectRight = 1) AND (irDetectLeft = 0)THEN
pulseLeft = 850
pulseRight = 850
HIGH 15
ELSE
pulseLeft = 850
pulseRight = 650
LOW 1
LOW 15
ENDIF
Read_Ping:
PULSOUT 3, 5 ' Start Ping)))
PULSIN 3, 1, distance ' Read echo time
RETURN
Calc_Distance:
cmFinal = cmConstant ** distance ' These are the whole measurements
PULSOUT 13, pulseLeft
PULSOUT 12, pulseRight
PAUSE 20
LOOP
Thanks
Please Help. :blank:
Here is my code
' {$STAMP BS2}
' {$PBASIC 2.5}
'Maze Traversal
DEBUG " Program Running! "
irDetectLeft VAR Bit
irDetectRight VAR Bit
cmConstant CON 2260
pulseLeft VAR Word
pulseRight VAR Word
distance VAR Byte
cmFinal VAR Byte
FREQOUT 4, 30, 5000
GOSUB Read_Ping
GOSUB Calc_Distance
DO
IF (cmFinal < 3) THEN
pulseLeft = 650
pulseRight = 850
FREQOUT 8, 1, 38500
irDetectRight = IN0
FREQOUT 9, 1, 38500
irDetectLeft = IN10
ELSEIF (irDetectRight = 0) AND (irDetectLeft = 1)THEN
pulseLeft = 650
pulseRight = 650
HIGH 1
ELSEIF (irDetectRight = 1) AND (irDetectLeft = 0)THEN
pulseLeft = 850
pulseRight = 850
HIGH 15
ELSE
pulseLeft = 850
pulseRight = 650
LOW 1
LOW 15
ENDIF
Read_Ping:
PULSOUT 3, 5 ' Start Ping)))
PULSIN 3, 1, distance ' Read echo time
RETURN
Calc_Distance:
cmFinal = cmConstant ** distance ' These are the whole measurements
PULSOUT 13, pulseLeft
PULSOUT 12, pulseRight
PAUSE 20
LOOP
Thanks
Comments
There are only a few conditions possible. The right IR detector can detect something (or not). The left IR detector can detect something (or not). The PING can detect something (or not). That's only 8 possibilities. First you have to define what you want your robot to do under those 8 combinations of conditions. It's simpler than that because some of the 8 possibilities are mirror images of each other (left vs. right) and, in some cases, there are "don't care" conditions. Work out those 8 combinations and the robot's actions associated with each one and let us know what you come up with.
Plwase Help
and finally i got it.
Its a prototype but it works;
Code: