This is my first year as a programmer for my FRC Team, but I have a Java background to work off of.
I am using Netbeans 7.1 with a default program with IterativeRobot and SimpleRobot subclasses. Both are default programs that I have used for testing verbatim and the results, after I have fixed electrical and network on the Classmate (2009) issues, is the Timer.delay() function.
Following examples are from the SimpleRobot program, the IterativeRobot program is the BuiltInDefaultCode code.
In Tele-Op, the motor will respond to the joystick and, by default, has a the delay set to 0.005 seconds:
In Autonomous, it has a 2 second value with a movement at half speed.
for (int i; i < 4; i++)
{
driveTrain.drive(0.5, 0.0);
Timer.delay(2.0);
}
The issue is that instead of holding the motor value until the seconds expire, the Jaguar and motor will move for a split second and wait the entire 2 seconds until repeat.
If anyone has any solution, question, comment, advice, anti-Murphy’s Law Orbital cannon, or other pieces of help, it would be GREATLY appreciated!
Get the current time from the timer. If the clock is running it is derived from the current system clock the start time stored in the timer class. If the clock is not running, then return the time when it was last stopped.
Returns:
Current time value for this timer in microseconds (uSeconds)
Will the new timer implemented within the method auto-start at 0 or will it have some other start area. And if it was started, would I subtract a <desired time> + old time] - old time or what?
Any suggestions or comments would be very helpful and greatly appreciated.
I disabled watchdog (this was two years ago) when I was doing autonomous for programming. Try doing the same with motorsafety.
Just make sure you start it again during teleop
Nonono you dont need the for loop or the while loop… All you do is do a simple drive function and then put Timer.delay(8); and then after that set the motors to 0 speed. You dont really want a while loop in autonomous because then you will be doin the same thing over again and I dont think you would want that…
SimpleRobot only has one thread. If you look at the Timer.delay() method, you’ll see that it calls Thread.sleep(). You aren’t able to do anything until the Thread wakes up again.
Well the issue is that whether there is a loop or not, it still stops for a split second and uses the delay() as the “do nothing” time. Can you be more specific, a simple code example perhaps?
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:
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.