Program (if then) (do loop) (timer) problem urgent!!!!
Hi everyone
I'm now makeing a car which can detect infrared and move toward to it.
And i am now writting my program
There are two sensors of my car which using PORTD
IF THE LEFT ONE DETECT INFRARED SIGNAL THEN IT WILL TURN LEFT
IF THE RIGHT ONE DETECT INFRARED SIGNAL THEN IT WILL TURN LEFT
IF BOTH DETECT INFRARED SIGNEL THEN IT WILL MOVE TOWARD
IF NO SIGNAL DETECT, IT WILL TURN AROUND UNTILL·IT FIND THE SIGNAL··AND AFTER 30 SECONDS, IT WILL STOP
THE PROBLEM IS THAT I SET THAT IF NOT SIGNAL DETECT, IT WILL MOVE AROUND
BUT WHEN IT RUN,IT WILL NON STOP TURN AROUND.
SO HOW CAN I FIX IT?
ALSO,HOW CAN I SET THAT AFTER 30 SECONDS IT WILL STOP?
Program:
IF IN12=0 AND IN14=0 THEN<
BOTH SENSOR DETECT SIGNAL
OUTC=15
PAUSE 500
OUTC=0
PAUSE 200
ELSEIF IN12=0 AND IN14=1 THEN<
LEFT SENSOR DETECT SIGNAL
OUTC=12
PAUSE 500
OUTC=0
PAUSE 200
ELSEIF IN12=1 AND IN14=0 THEN<
RIGHT SENSOR DETECT SIGNAL
OUTC=12
PAUSE 500
OUTC=0
PAUSE 200
ELSEIF IN12=1 AND IN14=1 THEN<
BOTH SENSOR NO SIGNAL
OUTC=12
PAUSE 500
ENDIF
MILLION THANKS
Post Edited (philip88822) : 5/20/2009 7:42:40 PM GMT
I'm now makeing a car which can detect infrared and move toward to it.
And i am now writting my program
There are two sensors of my car which using PORTD
IF THE LEFT ONE DETECT INFRARED SIGNAL THEN IT WILL TURN LEFT
IF THE RIGHT ONE DETECT INFRARED SIGNAL THEN IT WILL TURN LEFT
IF BOTH DETECT INFRARED SIGNEL THEN IT WILL MOVE TOWARD
IF NO SIGNAL DETECT, IT WILL TURN AROUND UNTILL·IT FIND THE SIGNAL··AND AFTER 30 SECONDS, IT WILL STOP
THE PROBLEM IS THAT I SET THAT IF NOT SIGNAL DETECT, IT WILL MOVE AROUND
BUT WHEN IT RUN,IT WILL NON STOP TURN AROUND.
SO HOW CAN I FIX IT?
ALSO,HOW CAN I SET THAT AFTER 30 SECONDS IT WILL STOP?
Program:
IF IN12=0 AND IN14=0 THEN<
BOTH SENSOR DETECT SIGNAL
OUTC=15
PAUSE 500
OUTC=0
PAUSE 200
ELSEIF IN12=0 AND IN14=1 THEN<
LEFT SENSOR DETECT SIGNAL
OUTC=12
PAUSE 500
OUTC=0
PAUSE 200
ELSEIF IN12=1 AND IN14=0 THEN<
RIGHT SENSOR DETECT SIGNAL
OUTC=12
PAUSE 500
OUTC=0
PAUSE 200
ELSEIF IN12=1 AND IN14=1 THEN<
BOTH SENSOR NO SIGNAL
OUTC=12
PAUSE 500
ENDIF
MILLION THANKS
Post Edited (philip88822) : 5/20/2009 7:42:40 PM GMT
Comments
As per the forum guidelines it is recommended that you use a descriptive subject line for your message. This will allow others who may be able to help you to know what your message is about. Currently the subject line does not convey anything useful to those that may be able to help you. You can edit your message/subject using the pencil icon to the top right of the message.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
Do you have your IF...THEN statements in a DO...LOOP? If not, your program is probably just running through the IF...THEN statements once and will never check the sensors again. So when you tell your bot to rotate if nothing is detected until something is detected, then if you never tell it to check the sensors again, it will keep rotating because those values will remain the same indefinitely.
Hope that helps!
Jessica
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jessica Uelmen
Education Department
Parallax, Inc.
I'VE TRY DO LOOP ALSO
BUT THE PROBLEM IS SAME
I DUNNO WHAT'S THE PROBLEM
MAIN:
DO WHILE IN12=0 AND· IN14=0
OUTC=15
PAUSE 500
OUTC=0
PAUSE 200
LOOP
DO WHILE IN14=0 AND IN12=1
OUTC=12
PAUSE 500
OUTC=0
PAUSE 200
LOOP
DO WHILE IN14=1 AND IN12=0
OUTC=3
PAUSE 500
OUTC=0
PAUSE 200
LOOP
DO
IF IN12=1 AND IN14=1 THEN
OUTC=12
PAUSE 200
OUTC=0
PAUSE 200
OUTC=3
PAUSE 200
OUTC=0
PAUSE 200
ENDIF
LOOP UNTIL IN12<>1 OR IN14<>1
GOTO MAIN
THE OTHER PARTS ARE ALL FINE
BUT THE NO SIGNAL PART IS STILL NON-STOP
PLEASE HELP!!!
Post Edited (philip88822) : 5/20/2009 7:41:47 PM GMT
Try putting the whole code in a DO...LOOP.· In the loops you just listed, you'll run into the same problem of the loops only executing once.· Here's some psuedocode:
Hope this helps!
Jessica
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jessica Uelmen
Education Department
Parallax, Inc.
It's work now.
Thanks a lot
But there are some little problem,
can i set if 5 seconds cannot detect signal then it will turn around
cause the code have some time problem
About the 30 seconds stop
Do you have any information about this??
There a few way to this , this is just one of them
The order of red routine being first or the blue routine being First is up to you in how you want to work
' {$STAMP BS2}
' {$PBASIC 2.5}
laps··· VAR·· Byte
MAIN:
laps = 00
DO
laps = laps + 1····························
IF IN12=0 AND· IN14=0 THEN
IF laps = 20 THEN EXIT················ ' Set LAPS for ever long you want this routine to run
OUTC=15······························· ' "LONG = how many time you want the routine to repeat it self
PAUSE 500
OUTC=0
PAUSE 200
ENDIF
LOOP
'=================================================================================
DO
IF IN12=1 OR IN14=1 THEN EXIT··········· ' This is a DO Nothing Loop Until one of the IR see something
LOOP
laps = 00
DO
laps = laps + 1···································· ·' Or you loop this so many time then exit and go to something else
IF IN12=1 OR IN14=1 OR laps =·5 THEN EXIT·······················
PAUSE 1000
·
·LOOP
'=================================================================================
·
··························································· DO
DO WHILE IN14=0 AND IN12=1·····················IF IN14=0 AND IN12=1·THEN
OUTC=12·················································GOSUB· SubRoutine1
PAUSE 500··············································· ELSE
OUTC=0·················································· IF IN14=1 AND IN12=0 THEM
PAUSE 200··············································· GOSUB SubRoutine2
LOOP························································ELSE
·······························································IN12=1 AND IN14=1 THEN
DO WHILE IN14=1 AND IN12=0······················ GOSUB· SubRoutine3
OUTC=3···················································· ENDIF
PAUSE 500················································· ENDIF
OUTC=0····················································· ·ENDIF
PAUSE 200·················································· LOOP
LOOP
································································· SubRoutine1:
································································ DO
DO····························································· OUTC=12
IF IN12=1 AND IN14=1 THEN·····························PAUSE 500·········
OUTC=12····················································· OUTC=0
PAUSE 200···················································· PAUSE 200···············································
OUTC=0······················································· LOOP UNTIL IN4 = 1 AND 12 = 0
PAUSE 200··················································· RETURN
OUTC=3
PAUSE 200··················································· SubRoutine2:
·································································· DO
OUTC=0······················································ OUTC=3
PAUSE 200····················································PAUSE 500
ENDIF························································· OUTC=0
LOOP UNTIL IN12<>1 OR IN14<>1···················· PAUSE 200
GOTO MAIN·················································· LOOP UNTIL IN4 =·0 AND 12 = 1
··································································RETURN
'===========================================================================
can i set if 5 seconds
laps = 00
DO
laps = laps + 1··················· ·' This is a Counting Routine
IF laps =·5 THEN EXIT···········
PAUSE 1000
·
·LOOP
can i set if 5 seconds cannot detect signal then it will turn around
laps = 00
DO
laps = laps + 1····················
IF IN12=0 AND· IN14=0 THEN
IF laps =·5 THEN EXIT·········· ' Just change how many laps you want to do
PAUSE 1000
·LOOP
·Turn Around Routine here···········
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 5/21/2009 2:45:14 AM GMT
This is some more pseudo or generic code. I wasn't sure what Stamp You where using, But I think You get the idea.CON values
vary from one Stamp to another so You may have to adjust the values Accordingly
Time1 CON 5000 ' 5 sec delay This method lets You change All the PAUSE times in 1 place for "Time1"
Time2 CON 2000 ' 2 sec delay Instead Of every place PAUSE 5000 is used. same for the other 2 PAUSE Times
Time3 CON 1000 ' 1 sec delay
X VAR NIB ' can be NIB, BYTE, or WORD
X=1
Main:
DO
INPUT 12 'input left IR sensor
INPUT 14 'input right IR
X=X+1 'X starts off with a value of 1 (see above),Then adds 1 to it on every LOOP. This is Your counter
IF IN12=0 AND IN14=1 THEN GOSUB LefTurn
IF IN12=1 AND IN14=0 THEN GOSUB RiTurn
IF IN12=0 AND IN14=0 THEN GOSUB Forward
IF X=30 THEN GOTO Stop 'If the DO-LOOP,loops 30 times with out meeting any of the IF statements We END the program
PAUSE Time3 'Time3 is 1 sec. So 30 passes = 30 sec
LOOP
GOTO Main
Forward:
OUTC = 15
PAUSE Time1
OUTC = 0
PAUSE Time2
X=1 'reset counter because You got a Signal from Left and right IR sensor
RETURN
LefTurn:
OUTC = 12
PAUSE Time1 ' time1 set to 5 Seconds in above CON
OUTC = 0
PAUSE Time2
X=1 'reset counter because You got a Signal from LeftTurn IR sensor
RETURN
RiTurn:
OUTC = 12
PAUSE Time1
OUTC = 0
PAUSE Time2
X=1
RETURN
Stop: 'Instead of END, Some human interface could be used here to help get the Car back on track
OUTC = 0
END 'This will stop the program-You'll have to reset most Stamps to start the program up again after END "hit RESET button" or cycle power.
Hope This helps with out being to confusing.
_________$WMc%_______
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Truth is out there············································ BoogerWoods, FL. USA