View Single Post
  #7   Spotlight this post!  
Unread 09-03-2007, 09:42
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: autonomous timing

There are two good ways to keep track of time. Using interrupts is precise and reliable, but it requires specific knowledge of how to do it. Counting communication packets is easy and usually good enough, and it's trivial to explain.

The middle section of User_Autonomous_Code() executes only when there's new data from the radio link. It's where the default code has the comment "/* Add your own autonomous code here. */" If you increment an integer at that point, you will have a rudimentary timer that you can read and compare against. The radio communication occurs every 26.2 milliseconds, so you can use that to figure out how long to wait.

If you add 26 to the counter each time, you can measure time in milliseconds, which might be easier for the programmer to keep track of. You'll be running a little slow, but by less than one percent -- the timer should read 14872 ms after 15 real seconds.

The one real thing to worry about is lost communication packets. The timer will fail to increment if no radio data is received. Since the robot will end up being disabled anyway if that happens too often, it probably isn't worth compensating for, but you can do so if you want by reading the packet number.