Help writing a code
ur5pointos2slo
Posts: 19
Ok so in my last post I was trying to hook up infrared headlights and use QTI line follower sensors. I finally have them all hooked up but now I need to write a code to make it work properly and need a little help. I need the robot to follow a given line(the line travels all the way to the wall). So I need to get the·bot to stop short of the wall using the headlights. Then after it does that I need it to pause for about 10-20 seconds Make a 180 degree turn and follow the line back down to the other end and repeat the process. If anyone could help me write a code to make it do this that would be greatttly appreciated.
Comments
Main:
Loop until done
gosub folow line
if wall is ahead done = true
End loop
pause number of seconds
Turn 180 degrees
GOTO main
Now, I'm assuming here that the line is between two walls and your bot is bouncing (sort of) between the two. As for your code, some suggestions. Always use proper indentation. Notice that on line 18 you have a DO, and the next line is not indented. Wrong. Second, make sure that you close out anything that you open. With that same DO, you should have a loop close by (not like you have it; on line 84). Keep things in small, logical blocks. You should only have one GOTO command in your code: to loop back to main. Everything else, you should have a GOSUB that runs until a RETURN. Make sure that you have all the returns you need in your code.
Next, replace all pin numbers with a pin variable declared at the begining. This will help you do two things: easily change what I/O pin that particular component uses, and make your code more self documenting. Next, notice that you have two blocks of code that deal with the servos (lines 31 and 89). Delete one, then if neccessary, you can call the appropriate subroutine to do the work.