|while loops and timers issue
|Page 1 of 1|
|Author:||jgarrett [ Mon Jul 08, 2013 12:57 pm ]|
|Post subject:||while loops and timers issue|
I am teaching a class on RobotC basics and Vex and am new to robotc. Students and I are trying to write code for a simple program that has use a timer for 10 to 20 seconds to control the robot. While under the timer loop (while statement) the robot needs to go forward until it senses an object turn left or right then go forward turn left or right then go straight. After 10 seconds gives the user control of the robot through joystick controller. So far we can either get it to sense the object or go straight for 10 seconds then give up control but not both. Example code below. Thoughts?
|Author:||rcahoon [ Wed Jul 10, 2013 7:27 pm ]|
|Post subject:||Re: while loops and timers issue|
Let me make a couple of suggestions, and if you still can't figure it out, let me know:
1. In ROBOTC, select all your code, then select Edit>>Code Formatting>>Format Selection from the menu. This will properly indent your code so that it's easier to see which bits of code are grouped together within while and if statements. I suspect your code isn't doing what you think it is or want it to.
2. Remember that a while loop will cause only its code to be run until it's condition is false. If you want your program to do two things at once, such as go straight and detect objects, they will both need to be inside the same while loop.
|Page 1 of 1||All times are UTC - 5 hours [ DST ]|
|Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group