need to be able to use 2 irsensors to detect if theres any objects a certain wa
Ashley
Posts: 9
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? Ash
Post Edited By Moderator (Chris Savage (Parallax)) : 10/12/2007 2:49:18 PM GMT
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? Ash
Post Edited By Moderator (Chris Savage (Parallax)) : 10/12/2007 2:49:18 PM GMT
Comments
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?
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?