View Single Post
  #10   Spotlight this post!  
Unread 05-02-2012, 00:49
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
Re: Autonomous Motor Problems

One of the (sometimes) more annoying aspects of programming a robot is that everything has to be "refreshed" periodically. Certain sensors have to be sampled at a high rate to get good results, speed controllers will stop if you leave them on for too long without setting them, etc. This means that programming a robot actually lends itself fairly well to the IterativeRobot setup: you write your Continuous() and Periodic() methods in a way that won't actually stop the robot from running.

In your case, the best idea is probably to do something like this:
Code:
Timer t = new Timer();
t.start();
while(t.get() < TIME_LIMIT*1000000)
    doStuff();
where TIME_LIMIT is your desired length of time in seconds, and doStuff() does stuff (in this case sets motor speed).

If you look at the source of WPILibJ's Timer class, there are a few interesting features: a method reset(), which resets the Timer's value to 0; a constructor which actually calls reset(), meaning that a new Timer always starts at 0; and stop(), which, although it may seem counter-intuitive, does not actually reset it, just prevents it from counting any further. Basically, it does what you want and keeps all the "old time" stuff behind the scenes, so you don't have to worry about it.
Reply With Quote