Shop OBEX P1 Docs P2 Docs Learn Events
Trying to use 2 PING))) units at once without success - help? — Parallax Forums

Trying to use 2 PING))) units at once without success - help?

scifiguy30scifiguy30 Posts: 8
edited 2006-05-22 02:04 in BASIC Stamp
·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.

Comments

  • SSteveSSteve Posts: 808
    edited 2006-05-15 07:01
    Does the Ping_Demo.BS2 program have a PAUSE statement in the loop? The code you posted doesn't so I imagine each PING))) will be triggered very frequently.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows
  • scifiguy30scifiguy30 Posts: 8
    edited 2006-05-15 13:59
    No, I thought of that after I posted this. I'll try that next. Thanks!
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-05-15 14:10
    Also post it (attached) with your display code...Maybe there was something wrong with that.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • scifiguy30scifiguy30 Posts: 8
    edited 2006-05-16 01:04
    Putting the Pauses in seemed to work. I'm now trying to figure out why if I add one more operation to the main program it cycles only once and won't loop. This is a program to move a large robot that uses 2 Ping sensors and 1 Lynx IRPD to detect obstacles. If anyhting is detected by any of the sensors it is directed to stop, and if none are detected it is directed to move. The subroutines to move and stop are for controlling standard servos that are being used as throttles for motor controllers. Here is the entire program:

    ' =========================================================================
    '
    ' 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!
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-05-16 03:17
    Scifiguy30 -

    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 -->
  • scifiguy30scifiguy30 Posts: 8
    edited 2006-05-16 05:44
    Thanks very much, Bruce! I'll put it in and give it a try.
  • scifiguy30scifiguy30 Posts: 8
    edited 2006-05-20 22:27
    Thanks to everyone·for their help with this. I'm down to one last problem. I can get both the Ping))) sensors to work or the IRPD to work, but not both at once. 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. If I comment out the ELSEIF statement to defeat the IRPD then the sonar units work fine. Any ideas? Thanks in advance!

    ' =========================================================================
    '
    '·· 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
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-05-20 23:10
    Scifiguy -

    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 -->
  • scifiguy30scifiguy30 Posts: 8
    edited 2006-05-21 00:02
    Thank you, Bruce. Your suggested code is more efficient than what I had, but it operates the same way mine does. If the IRPD subroutine is included that is the only part that works. If it is excluded the sonar units will start working again. Any other thoughts?
  • SSteveSSteve Posts: 808
    edited 2006-05-21 01:05
    Maybe you need some DEBUG statements to get a better idea of what's happening. I don't see anything in Detect_IRPD that should keep Get_Sonar_Front or Get_Sonar_Side from working.

    I know you didn't ask for optimization tips, but if you changed
    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
    


    to this:
    Detect_IRPD:
     IRPD_Detect = 0                                ' Reset detection status as nothing detected
    
     HIGH 3 : PAUSE 1                              ' Turn on left LED by connecting to Vdd
     IF IN5 = 1 THEN IRPD_Detect = 1              'If left sensor detects anything, stop the ATC
     LOW 3                                          ' Turn LED off to conserve power
    
     HIGH 4 : PAUSE 1                              ' Turn on right LED by connecting to Vdd
     IF IN5 = 1 THEN IRPD_Detect = 1              'If right sensor detects anything, stop the ATC
     LOW 4                                          ' Turn LED off to conserve power
    
     RETURN
    


    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
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-05-21 03:40
    Scifiguy -

    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 -->
  • scifiguy30scifiguy30 Posts: 8
    edited 2006-05-21 06:04
    To Baritone - code efficiency tips are always appreciated, thank you for your suggestion. I've incorporated it into my program.

    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!
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-05-21 06:49
    Scifiguy -

    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 -->
  • SSteveSSteve Posts: 808
    edited 2006-05-21 06:50
    So are you saying that when inches_S is less than 36 or inches_F is less than 36 that Stop_ATC is not being called? Try putting a DEBUG statement in Move_ATC_Forward and Stop_ATC to see if the subroutines are being called but are maybe not doing what you expect.

    IN5 simply reads the input status of pin 5.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows
  • scifiguy30scifiguy30 Posts: 8
    edited 2006-05-21 18:05
    OK, I've implemented your suggestions and made a change that looks like it works, but I don't know why it works. I put a debug statement at the beginning of the program per Bruce's suggestion and the program only executes once. I put debug commends into the servo subroutines and found that the program was continuously running the stop subroutine. The main program code looked like this:

    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.
  • SSteveSSteve Posts: 808
    edited 2006-05-22 02:04
    Does your IR detector output a 0 (active low) or 1 (active high) when it detects IR?

    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
Sign In or Register to comment.