Shop OBEX P1 Docs P2 Docs Learn Events
need to be able to use 2 irsensors to detect if theres any objects a certain wa — Parallax Forums

need to be able to use 2 irsensors to detect if theres any objects a certain wa

AshleyAshley Posts: 9
edited 2007-10-12 15:11 in BASIC Stamp
hey im ashley,
trying really hard to program but not work. so okay i hooked up 2 photoresistos to a boe bot and i want to make them point towards the ground and be able to follow a black line that has curves...but i also need to be able to use 2 irsensors to detect if theres any objects a certain ways away...oh and there will be serveral boe bots following me...also needa stop when the track ends..and it needs to know when to stop...i was thinking of having like a counter to determine when it stops and when it gets to a certain number it does but i dunno...anways heres what i got for the photos:

DO

IF (IN6 > 670 AND IN6 < 690) AND (IN3 > 670 AND IN3 < 700) THEN
PULSOUT 15,850
PULSOUT 14,650
PAUSE 100
ENDIF

LOOP

i was trying to make them stay within the black (so have a range which they can only go between) and when it got to white it'd change and keep on black...but when i go to run it doesnt move at all... and i know i need more code...lol...anyways help would be great [noparse]:)[/noparse] tyty

oh and also my friend is having troubles just programing irsensors...heres her code...

REQOUT 4,2000,3000
DEBUG "start"
DO

FREQOUT 9,1,38500
irdetectleft = IN8
DEBUG HOME, "irdetectleft =" ,BIN1 irdetectleft
PAUSE 100

FREQOUT 8,1, 38500
irdetectleft = IN9

FREQOUT 2,1, 38500
irdetectleft = IN0
DEBUG "start1"

IF (irdetectleft = 0) AND (irdetectright = 0) THEN
DEBUG "startend"
GOSUB back_up
GOSUB turn_left
GOSUB turn_left
ELSEIF (irdetectleft = 0) THEN
DEBUG "startend1"
GOSUB back_up
GOSUB turn_right
ELSEIF (irdetectright = 0) THEN
DEBUG "startend2"
GOSUB back_up
GOSUB turn_left
ELSE
GOSUB forward_pulse
ENDIF
LOOP

forward_pulse:
DEBUG "start2"
PULSOUT 15,850
PULSOUT 14,650
PAUSE 20
RETURN

turn_left:
FOR pulsecount = 0 TO 20
DEBUG "start3"
PULSOUT 15,650
PULSOUT 14,650
PAUSE 20
NEXT
RETURN

turn_right:

FOR pulsecount = 0 TO 20
DEBUG "start4"
PULSOUT 15,850
PULS
PULSOUT 14,850
PAUSE 20
NEXT
RETURN

back_up:
DEBUG "start5"
FOR pulsecount = 0 TO 40
PULSOUT 15,650
PULSOUT 14,850
PAUSE 20
NEXT
RETURN

she doesnt get it why its not working...shes just trying to get them turning for right, left, and straight turns...someone told me to use DEC but it wasnt working either...so help needed...

tyty please respond soon? <3 Ash

Post Edited By Moderator (Chris Savage (Parallax)) : 10/12/2007 2:49:18 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-12 04:21
    Two thoughts ...
    1) INn are all single bits so to say IN0 > 670 doesn't make any sense. Read the section in the Robotics with the BoeBot tutorial on using photoresistors with a Stamp and just get the Stamp to reliably read the light values. Later you can add code to move the BoeBot.

    2) Your friend's code is just too big and has too many different pieces to tackle here as a whole. The crucial part is to get each functional piece working and to understand how it works, then begin to combine functions. You need to reliably read distances using the IR sensors or at least reliably detect obstacles. You need to have bits of code that move the BoeBot the way you expect them to work. It looks like you have the pieces, but what works? What doesn't work and how does it not work?
  • AlleciaAllecia Posts: 1
    edited 2007-10-12 04:28
    Ok, im the "friend" My boe bot is fine with the code but the simple things like getting my Irs to work isn't working out so great i've re wired it ive cheaked all my codes and stuff so far i have only been able to get one to work.
  • AshleyAshley Posts: 9
    edited 2007-10-12 04:31
    but if im try to go on a black line and theres white on both opposite side of the line and i dont wanna touch the white..i wanna stay on the black throughout the "maze"....wouldnt i need to have some sort of range in the code?
  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-12 04:55
    You could mount two white/non-white adjusted photoresistors on either side of the black line. When either sensor showed non-white, it must be reading the black stripe. There's a whole chapter in the Robotics tutorial on using the photoresistors. You could use a single photoresistor with the RCTIME statement to actually read the light level (and check a range of levels).
  • AshleyAshley Posts: 9
    edited 2007-10-12 13:03
    okay so the testblackwhitelogic code on page 232 should help me test my photoresistors....

    code:



    ' {$STAMP BS2} ' Stamp directive
    ' {$PBASIC 2.5} ' PBASIC directive.
    '
    [noparse][[/noparse] Constants ]
    LeftWhite CON 16
    RightWhite CON 33
    LeftBlack CON 26
    RightBlack CON 45
    LeftAvg CON LeftWhite + LeftBlack / 2
    RightAvg CON RightWhite + RightBlack / 2
    '
    [noparse][[/noparse] Variables ]
    timeLeft VAR Word ' Left photoresistor reading
    timeRight VAR Word ' Right photoresistor reading
    '
    [noparse][[/noparse] Main Routine ]
    DO
    GOSUB Test_Photoresistors
    IF (timeLeft > LeftAvg) THEN
    DEBUG CRSRXY, 0, 0, "Left Black "
    ELSE
    DEBUG CRSRXY, 0, 0, "Left White "
    ENDIF
    IF (timeRight > RightAvg) THEN
    DEBUG CRSRXY, 13, 0, "Right Black", CR
    ELSE
    DEBUG CRSRXY, 13, 0, "Right White", CR
    ENDIF
    LOOP
    '
    [noparse][[/noparse] Subroutine - Test_Photoresistors ]
    Test_Photoresistors:
    HIGH 6 ' Left RC time Measurement.
    PAUSE 3
    RCTIME 6,1,timeLeft
    HIGH 3 ' Right RC time measurement.
    PAUSE 3
    RCTIME 3,1,timeRight
    RETURN


    and would the avoidblackspots code work if i change it to avoid the white spots instead...? its on page 233-234...

    code:



    ' {$STAMP BS2} ' Stamp directive
    ' {$PBASIC 2.5} ' PBASIC directive.
    '
    [noparse][[/noparse] Constants ]
    LeftWhite CON 16
    RightWhite CON 33
    LeftBlack CON 26
    RightBlack CON 45
    LeftAvg CON LeftWhite + LeftBlack / 2
    RightAvg CON RightWhite + RightBlack / 2
    '
    [noparse][[/noparse] Variables ]
    timeLeft VAR Word ' Left photoresistor
    reading
    timeRight VAR Word ' Right photoresistor
    reading
    '
    [noparse][[/noparse] Initialization ]
    FREQOUT 4, 2000, 3000
    '
    [noparse][[/noparse] Main Routine ]
    DO
    GOSUB Test_Photoresistors
    GOSUB Navigate
    LOOP
    '
    [noparse][[/noparse] Subroutines
    Test_Photoresistors:
    HIGH 6 ' Left RC time
    Measurement.
    PAUSE 3
    RCTIME 6,1,timeLeft
    HIGH 3 ' Right RC time
    measurement.
    PAUSE 3
    RCTIME 3,1,timeRight
    RETURN
    Navigate:
    ' Both detect black paper, back up and make a noise
    IF (timeLeft > LeftAvg) AND (timeRight > RightAvg) THEN
    PULSOUT 13, 650
    PULSOUT 12, 850
    FREQOUT 4, 20, 4400 ' Beep instead of pause
    ' Left detects black paper, turn away to right, make a noise
    ELSEIF (timeLeft > LeftAvg) THEN
    PULSOUT 13, 850
    PULSOUT 12, 850
    FREQOUT 4, 20, 2200
    ' Right detects black paper, turn away to left, make a noise
    ELSEIF (timeRight > RightAvg) THEN
    PULSOUT 13, 650
    PULSOUT 12, 650
    FREQOUT 4, 20, 3300
    ' Neither detects black paper, go forward one pulse.
    ELSE
    PULSOUT 13,850
    PULSOUT 12,650
    PAUSE 20
    ENDIF
    RETURN



    this might be the wrong code but i think it should help....any suggestions?
  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-12 14:31
    These are the correct ideas, but the direction of movement is backward from what you need. If your right sensor goes from white to black, you want to turn to the right to keep the sensor on the white. If your left sensor goes from white to black, you want to turn to the left to keep the sensor on the white. If they both detect white, you want to go forward a short distance. If neither detect white, something is wrong and you want to stop.
  • AshleyAshley Posts: 9
    edited 2007-10-12 15:01
    okay so if i change the PULSOUT to the opposites then it will work properly?
  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-12 15:11
    What do you think? ... and why? What happens when you try it?
Sign In or Register to comment.