Trying to use 2 PING))) units at once without success - help?
scifiguy30
Posts: 8
·I'm trying to use 2 PING))) sonar sensors at the same time with a BS2. I have a feeling I'm missing something really basic here (pardon the pun). Here is the code I'm using:
'·· {$STAMP BS2}
'·· {$PBASIC 2.5}
Ping_Front··········· PIN···· 14·············· ' Assign pin 14 on the Stamp to front Ping)))
Ping_Side············ PIN···· 15·············· ' Assign pin 15 on the Stamp to side Ping)))
Trigger········ CON···· 5······················ ' trigger pulse = 10 uS
Scale·········· CON···· $200··················· ' raw x 2.00 = uS
RawToIn·······CON···· 889···················· ' 1 / 73.746 (with **)
IsHigh········· CON···· 1······················ ' for sonar PULSOUT
IsLow·········· CON···· 0······················ ' for sonar PULSOUT
rawDist_F············ VAR···· Word·············· ' raw measurement from front
rawDist_S············ VAR···· Word·············· ' raw measurement from side
inches_F············· VAR···· Word·············· ' conversion to inches front
inches_S············· VAR···· Word·············· ' conversion to inches side
· DO
··· GOSUB Get_Sonar_Front······················ ' get sensor value
··· GOSUB Get_Sonar_Side······················· ' get sensor value
· LOOP
· END
Get_Sonar_Front:
· Ping_Front = IsLow··························· ' make trigger 0-1-0
· PULSOUT Ping_Front, Trigger·················· ' activate sensor
· PULSIN· Ping_Front, IsHigh, rawDist_F········ ' measure echo pulse
· rawDist_F = rawDist_F */ Scale··············· ' convert to uS
· rawDist_F = rawDist_F / 2···················· ' remove return trip
· inches_F = rawDist_F ** RawToIn·············· ' convert to inches
· RETURN
Get_Sonar_Side:
· Ping_Side = IsLow···························· ' make trigger 0-1-0
· PULSOUT Ping_Side, Trigger··················· ' activate sensor
· PULSIN· Ping_Side, IsHigh, rawDist_S········· ' measure echo pulse
· rawDist_S = rawDist_S */ Scale··············· ' convert to uS
· rawDist_S = rawDist_S / 2···················· ' remove return trip
· inches_S = rawDist_S ** RawToIn·············· ' convert to inches
· RETURN
·This was part of a larger program, but I tried running this by itself and it doesn't work. It compiles and runs, each PING))) is showing a pulsing green light but it is pulsing much faster than the Ping_Demo.BS2 program. When I include code to display results none are shown. Any help
anyone could offer would be greatly appreciated.
'·· {$STAMP BS2}
'·· {$PBASIC 2.5}
Ping_Front··········· PIN···· 14·············· ' Assign pin 14 on the Stamp to front Ping)))
Ping_Side············ PIN···· 15·············· ' Assign pin 15 on the Stamp to side Ping)))
Trigger········ CON···· 5······················ ' trigger pulse = 10 uS
Scale·········· CON···· $200··················· ' raw x 2.00 = uS
RawToIn·······CON···· 889···················· ' 1 / 73.746 (with **)
IsHigh········· CON···· 1······················ ' for sonar PULSOUT
IsLow·········· CON···· 0······················ ' for sonar PULSOUT
rawDist_F············ VAR···· Word·············· ' raw measurement from front
rawDist_S············ VAR···· Word·············· ' raw measurement from side
inches_F············· VAR···· Word·············· ' conversion to inches front
inches_S············· VAR···· Word·············· ' conversion to inches side
· DO
··· GOSUB Get_Sonar_Front······················ ' get sensor value
··· GOSUB Get_Sonar_Side······················· ' get sensor value
· LOOP
· END
Get_Sonar_Front:
· Ping_Front = IsLow··························· ' make trigger 0-1-0
· PULSOUT Ping_Front, Trigger·················· ' activate sensor
· PULSIN· Ping_Front, IsHigh, rawDist_F········ ' measure echo pulse
· rawDist_F = rawDist_F */ Scale··············· ' convert to uS
· rawDist_F = rawDist_F / 2···················· ' remove return trip
· inches_F = rawDist_F ** RawToIn·············· ' convert to inches
· RETURN
Get_Sonar_Side:
· Ping_Side = IsLow···························· ' make trigger 0-1-0
· PULSOUT Ping_Side, Trigger··················· ' activate sensor
· PULSIN· Ping_Side, IsHigh, rawDist_S········· ' measure echo pulse
· rawDist_S = rawDist_S */ Scale··············· ' convert to uS
· rawDist_S = rawDist_S / 2···················· ' remove return trip
· inches_S = rawDist_S ** RawToIn·············· ' convert to inches
· RETURN
·This was part of a larger program, but I tried running this by itself and it doesn't work. It compiles and runs, each PING))) is showing a pulsing green light but it is pulsing much faster than the Ping_Demo.BS2 program. When I include code to display results none are shown. Any help
anyone could offer would be greatly appreciated.
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
' =========================================================================
'
' File....... ATC_Control.BS2
' Purpose.... Control system for ATC - Automatic Tool Carrier
' Author..... Clark Farrell
' Started.... 10 APR 2006
' Updated.... 15 May 2006
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' =========================================================================
'
[noparse][[/noparse] Program Description ]
'
' This program utilizes 2 PING))) sonar sensors and one Lynx IRPD to detect if
' there are objects or people in front of, near the left front, or near
' the right side of the ATC. It then uses 2 standard hobby servos to turn 5k
' variable rotary potentiometers, which in turn are wired as throttle controls
' for two motor controllers. Each motor controller drives a 24V gear motor which
' turns one of the drive wheels. The ATC is capable of turning by running the motors
' at different speeds but steering control is not needed for this application. If the
' ATC were programmed to follow a route or respond to different sensor inputs it does
' have the capability to turn, but it does not have the ability to back up.
' The ATC's main program scans with each of the Ping))) sensors and the Lynx IRPD to
' determine if there are people or objects less than 2 feet away from the Ping))) sensors
' (front and right side) or less than 6 inches away from the IRPD (left front
' corner). If something/someone is detected the subroutine to stop the ATC is triggered.
' If nothing is detected the subroutine to move the ATC is triggered. A 1 second delay is
' incorporated at the start of the program loop to allow time for moving from the front to
' the side of the ATC to get tools without it trying to take off again when you are between
' the sensors' detection zones.
'
' The ATC utilizes a PING))) sonar sensor on the front and another on the right side
' (side from which tools are accessed) to detect people or obstacles close by.
' Since a sonar sensor measures the time required for a sound wave to travel from the
' sensor and back, the result is divided by two to remove the return portion of the echo
' pulse. The final raw result is the duration from the front of the sensor to the target
' in microseconds. At sea level sound travels through air at 1130 feet per second. This
' equates to 1 inch in 73.746 uS. Calculations are performed in the program to deliver a
' distance result in inches
'
' The Lynx IRPD utilizes 2 IR LED emitters, one on the left side of the sensor circuit
' board and one on the right side, with an IR sensor mounted between them. The sensor is
' shielded to the sides with electrical tape. It will detect light from the IR LED's only
' if that light is reflected off of nearby objects. The distance sensitivity is set by
' adjusting potentiometers located on the Lynx IRPD circuit board. The distance they will
' trigger is set at approximately 6 inches on the ATC. This setting is for indoor use,
' sunlight may trigger the sensors and keep the ATC from moving outdoors unless ambient
' light is compensated for in the software.
'
[noparse][[/noparse] I/O Definitions ]
Ping_Front PIN 14 ' Assign pin 14 on the Stamp to front Ping)))
Ping_Side PIN 15 ' Assign pin 15 on the Stamp to side Ping)))
'
[noparse][[/noparse] Constants ]
Trigger CON 5 ' trigger pulse = 10 uS
Scale CON $200 ' raw x 2.00 = uS
RawToIn CON 889 ' 1 / 73.746 (with **)
IsHigh CON 1 ' for sonar PULSOUT, set TTL high
IsLow CON 0 ' for sonar PULSOUT, set TTL low
'
[noparse][[/noparse] Variables ]
rawDist_F VAR Word ' raw measurement from front
rawDist_S VAR Word ' raw measurement from side
inches_F VAR Word ' conversion to inches front
inches_S VAR Word ' conversion to inches side
templ VAR Bit ' IRPD detection left side
tempr VAR Bit ' IRPD detection right side
IRPD_Detect VAR Nib ' IRPD detection either side
Counter_S VAR Word ' Counter for servo ramping to stop
Counter_M VAR Word ' Counter for servo ramping to move
'
[noparse][[/noparse] Program Code ]
Main:
DO
PAUSE 1000 ' Let IR settle
GOSUB Get_Sonar_Front ' get sensor value
GOSUB Get_Sonar_Side ' get sensor value
GOSUB Detect_IRPD ' get IRPD detection status
IF (rawDist_F < 20) THEN
GOSUB Stop_ATC
ELSEIF (rawDist_S < 20) THEN
GOSUB Stop_ATC
ELSEIF (IRPD_Detect = 1) THEN
GOSUB Stop_ATC
ELSE
GOSUB Move_ATC_Forward
ENDIF
LOOP
END
'
[noparse][[/noparse] Subroutines ]
' These subroutines trigger the two Ping sonar sensors and measure
' the echo pulses. The raw values from the sensors are converted to
' microseconds. This value is divided by two to remove the return trip.
' The resulting value is the distance from the sensor to the target in
' microseconds.
Get_Sonar_Front:
Ping_Front = IsLow ' make trigger 0-1-0
PULSOUT Ping_Front, Trigger ' activate sensor
PULSIN Ping_Front, IsHigh, rawDist_F ' measure echo pulse
rawDist_F = rawDist_F */ Scale ' convert to uS
rawDist_F = rawDist_F / 2 ' remove return trip
inches_F = rawDist_F ** RawToIn ' convert to inches
PAUSE 50 ' slow pulse rate a bit
RETURN
Get_Sonar_Side:
Ping_Side = IsLow ' make trigger 0-1-0
PULSOUT Ping_Side, Trigger ' activate sensor
PULSIN Ping_Side, IsHigh, rawDist_S ' measure echo pulse
rawDist_S = rawDist_S */ Scale ' convert to uS
rawDist_S = rawDist_S / 2 ' remove return trip
inches_S = rawDist_S ** RawToIn ' convert to inches
PAUSE 50 ' slow pulse rate a bit
RETURN
' This subroutine turns on the left and right LED's and reads back input from the IR sensor
' in the center of the Lynx IRPD mounted on the left front corner of the ATC.
' IRPD stands for Infrared Proximity Detector. The IRPD uses pins 3, 4 and 5 on the microcontroller.
' Pin 3 is connected to the left LED, Pin 4 is connected to the right LED, Pin 5 is connected
' to the IR sensor mounted in the center of the Lynx IRPD sensor board between the LED's.
' The intensity of the IR LED's is controlled via pots on the Lynx itself. They have been tuned
' to detect objects about 6 inches away.
Detect_IRPD:
HIGH 3 : PAUSE 10 ' Turn on left LED by connecting to Vdd
tempr = IN5 ' Detect signal with sensor at pin 5
LOW 3 ' Turn LED off to conserve power
HIGH 4 : PAUSE 10 ' Turn on right LED by connecting to Vdd
templ = IN5 ' Detect signal with sensor at pin 5
LOW 4 ' Turn LED off to conserve power
IF IRPD_L=1 OR IRPD_R=1 THEN IRPD_Detect=1
' This subroutine moves the ATC forward by using a servo to actuate a 5k ohm rotational pot
' as a throttle control for each of the two 24V gear motors that drive the ATC's rear wheels.
' Pin 12 is connected to the servo throttle for the motor controller driving the left wheel
' and Pin 13 is connected to the servo throttle for the motor controller driving the right
' wheel.
Move_ATC_Forward:
FOR Counter_M = 1 TO 200 ' Send the pulse out commands to the servos 200 times
PULSOUT 12, 750 ' Sends PWM position signals to servos to turn the throttle
PULSOUT 13, 450 ' on for each side
PAUSE 50 ' Pause between pulses to control ramp timing
NEXT
' This subroutine stops the ATC by using the servos in the same way as the subroutine above.
' The servos are sent to the "throttled back" position so the ATC will come to a halt.
Stop_ATC:
FOR Counter_S = 1 TO 200 ' Send the pulse out commands to the servos 200 times
PULSOUT 12, 880 ' Sends PWM position signals to the servos to turn the
PULSOUT 13, 580 ' throttle off for each side
PAUSE 50 ' Pause between pulses to contro ramp timing
NEXT
If I comment out the IRPD and servo control subroutines the program cycles and runs the Ping sensors. If I add either the IRPD or the servo control subroutines everything stops. Any ideas?
Thanks!
The routine Detect_IRPD is missing a RETURN statement causing a drop through, first into Move_ATC, then later into Stop_ATC.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
' =========================================================================
'
'·· File....... ATC_Control.BS2
'·· Purpose.... Control system for ATC - Automatic Tool Carrier
'·· Author..... Clark Farrell
'·· Started.... 10 APR 2006
'·· Updated.... 20 May 2006
'
'·· {$STAMP BS2}
'·· {$PBASIC 2.5}
'
' =========================================================================
'
[noparse][[/noparse] Program Description ]
'
' This program utilizes 2 PING))) sonar sensors and one Lynx IRPD to detect if
' there are objects or people in front of, near the left front, or near
' the right side of the ATC. It then uses 2 standard hobby servos to turn 5k
' variable rotary potentiometers, which in turn are wired as throttle controls
' for two motor controllers. Each motor controller drives a 24V gear motor which
' turns one of the drive wheels. The ATC is capable of turning by running the motors
' at different speeds but steering control is not used in this application. If the
' ATC were programmed to follow a route or respond to different sensor inputs it does
' have the capability to turn, but it does not have the ability to back up.
' The ATC's main program scans with each of the Ping))) sensors and the Lynx IRPD to
' determine if there are people or objects less than 3 feet away from the Ping))) sensors
' (front and right side) or less than 6 inches away from the IRPD (left front
' corner). If something/someone is detected the subroutine to stop the ATC is triggered.
' If nothing is detected the subroutine to move the ATC is triggered.
'
' The ATC utilizes a PING))) sonar sensor on the front and another on the right side
' (side from which tools are accessed) to detect people or obstacles close by.
' Since a sonar sensor measures the time required for a sound wave to travel from the
' sensor and back, the result is divided by two to remove the return portion of the echo
' pulse. The final raw result is the duration from the front of the sensor to the target
' in microseconds. At sea level sound travels through air at 1130 feet per second. This
' equates to 1 inch in 73.746 uS. Calculations are performed in the program to deliver a
' distance result in inches.
'
' The Lynx IRPD utilizes 2 IR LED emitters, one on the left side of the sensor circuit
' board and one on the right side, with an IR sensor mounted between them. It will detect
' light from the IR LED's only if that light is reflected off of nearby objects. The distance
' sensitivity is set by adjusting potentiometers located on the Lynx IRPD circuit board.
' The distance they will trigger is set at approximately 6 inches on the ATC. This setting
' is for indoor use, sunlight may trigger the sensors and keep the ATC from moving outdoors
' unless ambient light is compensated for in the software.
'
[noparse][[/noparse] I/O Definitions ]
Ping_Front··········· PIN···· 14·············· ' Assign pin 14 on the Stamp to front Ping)))
Ping_Side············ PIN···· 15·············· ' Assign pin 15 on the Stamp to side Ping)))
'
[noparse][[/noparse] Constants ]
Trigger········ CON···· 5······················ ' trigger pulse = 10 uS for Ping))) units
Scale·········· CON···· $200··················· ' raw x 2.00 = uS
RawToIn········ CON···· 889···················· ' 1 / 73.746 (with **) for distance conversion
IsHigh········· CON···· 1······················ ' for sonar PULSOUT, set TTL high
IsLow·········· CON···· 0······················ ' for sonar PULSOUT, set TTL low
'
[noparse][[/noparse] Variables ]
rawDist_F············ VAR···· Word·············· ' raw measurement from front
rawDist_S············ VAR···· Word·············· ' raw measurement from side
inches_F············· VAR···· Word·············· ' conversion to inches front
inches_S············· VAR···· Word·············· ' conversion to inches side
templ················ VAR···· Bit··············· ' IRPD detection left side
tempr················ VAR···· Bit··············· ' IRPD detection right side
IRPD_Detect·········· VAR···· Nib··············· ' IRPD detection either side
Counter_S············ VAR···· Word·············· ' Counter for servo ramping to stop
Counter_M············ VAR···· Word·············· ' Counter for servo ramping to move
'
[noparse][[/noparse] Program Code ]
Main:
··· PAUSE 1000································· ' 1 second delay before program starts
· DO
··· GOSUB Get_Sonar_Front······················ ' get sensor value
··· GOSUB Get_Sonar_Side······················· ' get sensor value
··· GOSUB Detect_IRPD·························· ' get IRPD detection status
·· IF (inches_F < 36) THEN
······· GOSUB Stop_ATC
·· ELSEIF (inches_S < 36) THEN
······· GOSUB Stop_ATC
·· ELSEIF IRPD_Detect = 1 THEN
······· GOSUB Stop_ATC
·· ELSE
······· GOSUB Move_ATC_Forward
·· ENDIF
· LOOP
· END
'
[noparse][[/noparse] Subroutines ]
' These subroutines trigger the two Ping sonar sensors and measure
' the echo pulses.· The raw values from the sensors are converted to
' microseconds.· This value is divided by two to remove the return trip.
' The resulting value is the distance from the sensor to the target in
' microseconds.
Get_Sonar_Front:
· Ping_Front = IsLow··························· ' make trigger 0-1-0
· PULSOUT Ping_Front, Trigger·················· ' activate sensor
· PULSIN· Ping_Front, IsHigh, rawDist_F········ ' measure echo pulse
· rawDist_F = rawDist_F */ Scale··············· ' convert to uS
· rawDist_F = rawDist_F / 2···················· ' remove return trip
· inches_F = rawDist_F ** RawToIn·············· ' convert to inches
· PAUSE 15····································· ' slow pulse rate a bit
· RETURN
Get_Sonar_Side:
· Ping_Side = IsLow···························· ' make trigger 0-1-0
· PULSOUT Ping_Side, Trigger··················· ' activate sensor
· PULSIN· Ping_Side, IsHigh, rawDist_S········· ' measure echo pulse
· rawDist_S = rawDist_S */ Scale··············· ' convert to uS
· rawDist_S = rawDist_S / 2···················· ' remove return trip
· inches_S = rawDist_S ** RawToIn·············· ' convert to inches
· PAUSE 15····································· ' slow pulse rate a bit
· RETURN
· ' This subroutine turns on the left and right LED's and reads back input from the IR sensor
· ' in the center of the Lynx IRPD mounted on the left front corner of the ATC.
· ' IRPD stands for Infrared Proximity Detector. The IRPD uses pins 3, 4 and 5 on the microcontroller.
· ' Pin 3 is connected to the left LED, Pin 4 is connected to the right LED, Pin 5 is connected
· ' to the IR sensor mounted in the center of the Lynx IRPD sensor board between the LED's.
· ' The intensity of the IR LED's is controlled via pots on the Lynx itself. They have been tuned
· ' to detect objects about 6 inches away.
Detect_IRPD:
·IRPD_Detect = 0······························· ' Reset detection status as nothing detected
·HIGH 3 : PAUSE 1····························· ' Turn on left LED by connecting to Vdd
·tempr = IN5··································· ' Detect signal with sensor at pin 5
·LOW 3········································· ' Turn LED off to conserve power
·HIGH 4 : PAUSE 1····························· ' Turn on right LED by connecting to Vdd
·templ = IN5··································· ' Detect signal with sensor at pin 5
·LOW 4········································· ' Turn LED off to conserve power
·IF templ = 1 THEN IRPD_Detect = 1············· 'If left sensor detects anything, stop the ATC
·IF tempr = 1 THEN IRPD_Detect = 1············· 'If right sensor detects anything, stop the ATC
·RETURN
· ' This subroutine moves the ATC forward by using a servo to actuate a 5k ohm rotational pot
· ' as a throttle control for each of the two 24V gear motors that drive the ATC's rear wheels.
· ' Pin 12 is connected to the servo throttle for the motor controller driving the left wheel
· ' and Pin 13 is connected to the servo throttle for the motor controller driving the right
· ' wheel.
Move_ATC_Forward:
· FOR Counter_M = 1 TO 50·········· ' Send the pulse out commands to the servos 200 times
· PULSOUT 12, 730··················· ' Sends PWM position signals to servos to turn the throttle
· PULSOUT 13, 450··················· ' on for each side
· PAUSE 10·························· ' Pause between pulses
· NEXT
· RETURN
· ' This subroutine stops the ATC by using the servos in the same way as the subroutine above.
· ' The servos are sent to the "throttled back" position so the ATC will come to a halt.
Stop_ATC:
· FOR Counter_S = 1 TO 50··········· ' Send the pulse out commands to the servos 200 times
· PULSOUT 12, 880···················· ' Sends PWM position signals to the servos to turn the
· PULSOUT 13, 620···················· ' throttle off for each side
· PAUSE 10··························· ' Pause between pulses
· NEXT
· RETURN
This is what you presently have in your program:
IF (inches_F < 36) THEN
GOSUB Stop_ATC
ELSEIF (inches_S < 36) THEN
GOSUB Stop_ATC
ELSEIF IRPD_Detect = 1 THEN
GOSUB Stop_ATC
ELSE
GOSUB Move_ATC_Forward
ENDIF
I suspect what you want is this:
IF (inches_F < 36) or (inches_S < 36) or IRPD_Detect = 1 THEN GOSUB Stop_ATC
ELSE
GOSUB Move_ATC_Forward
ENDIF
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
I know you didn't ask for optimization tips, but if you changed
to this:
you would eliminate the need for the templ and tempr variables and you'd use a little less code space.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
Please explain what you mean by the following - what is it that brings you to make this conclusion? You said "If I run the program as shown here only the IRPD triggers the servos as I want them to work and there is no response to the Ping))) units. "
Are you expecting that some object or obstacle placed in the path of both the PING and the IR MUST be sensed by both? If so, that's an erroneous conclusion from a number of viewpoints, not the least of which is that the sensing distance of the sonar and the IR will NOT be the same. Another example is that a piece of glass or other transparent object WILL be sensed by the PING, but may well NOT be sensed by the IR. See what I mean?
Forty years of programming tells me the problem, whatever it is, either has someth9ing to do with IN5 or that there is a false conclusion afoot somewhere along the way! I AGREE with tossing a few DEBUG statements in there to check the program flow.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
To Bruce - what I meant was that the sonar units don't trigger the servos to move if they detect anything at any distance if the IRPD code is enabled. I didn't mean to imply that there was anything similar about the detection capabilities of the sonar units and the IR sensor, and I didn't mean to imply anything needed to be detected simultaneously. I put my hand in front of each of the sensors separately, each should detect my hand at a different distance and not be influenced by what the others see. I suspect In5 also, but only because it is one of the functions I understand least in this program.
I've put the following code into the second sonar subroutine to see what the sonar units are reading:
DEBUG CLS
DEBUG "Each sonar unit reads", CR, DEC inches_S, CLREOL, CR, DEC inches_F, CLREOL
This is displaying that the sonar units are reading distances correctly. The problem is that the servos aren't being triggered. I thought I might be trying to do too much at once in this program and have too much overhead for the processor. I have scant experience with programming, which is probably obvious judging by my previous questions, so I'm looking for some expert advice on what my options are.
Thanks very much for your time, gentlemen, I greatly appreciate the feedback!
Something just occurred to me. Place this at the very beginning of the program, and let us know if appears more than once during any single execution of the program:
DEBUG "Begin Execution"
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
IN5 simply reads the input status of pin 5.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
IF (inches_F < 36) OR (inches_S < 20) OR IRPD_Detect = 1 THEN
GOSUB Stop_ATC
ELSE
GOSUB Move_ATC_Forward
ENDIF
I just reversed the status of the IRPD_Detect subroutine so it now looks like this:
IF (inches_F < 36) OR (inches_S < 20) OR IRPD_Detect = 0 THEN
GOSUB Stop_ATC
ELSE
GOSUB Move_ATC_Forward
ENDIF
Now it seems to be working properly. Any idea why? Thanks again for your suggestions, it REALLY helped me out.
If the IR detector is active-high your current code will set IRPD_Detect to 0 if no IR is detected. If the IR detector is active-low your current code will set IRPD_Detect to 0 if IR is detected from both the left LED and the right LED.
If your detector is active-low, you should change the "IF IN5" lines to "IF IN5 = 0 THEN IRPD_Detect = 1" and change the IRPD_Detect subroutine back to" IF (inches_F < 36) OR (inches_S < 20) OR IRPD_Detect = 1 THEN". That way IRPD_Detect will be set to 1 if either side detects IR.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows