|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Using TimerTasks
Is it a good idea to create TimerTasks to take care of updating certain portions of the robot, such as the drive train or the ball handling system? For instance, if there is something that needs to be called regularly (like setting the Jaguars for motors or checking limit switches, etc.) just set a TimerTask to call it at a 20ms period so that we don't have to worry about updating.
I have them working, but I'm wondering if there are any disadvantages that I'm missing, and also hoping to help anyone who wants to try. |
|
#2
|
||||
|
||||
|
Re: Using TimerTasks
It sounds to me like you're redoing what IterativeRobot does. Maybe I missed something but you're saying you want certain things to only happen periodically? I would just use IterativeRobot and change the update period or use counters to call your functions every X cycles, since the teleopPeriodic frequency is known.
|
|
#3
|
|||
|
|||
|
Re: Using TimerTasks
Well, we're already doing that, but I set up a TimerTask because it's just cleaner, because you don't need to make sure your update functions are at the end of your iterative loop or whatever. Are there any downsides to using a TimerTask?
|
|
#4
|
||||
|
||||
|
Re: Using TimerTasks
Eh, I don't know of any, but you should probably hold out for someone with more know-how...
|
|
#5
|
|||||
|
|||||
|
Re: Using TimerTasks
We use TimerTasks extensively in our code this year. Every mechanism that has any "background" tasks like filters or PID controllers gets one. In my opinion it helps to keep your robot's "main loop" uncluttered.
|
|
#6
|
|||
|
|||
|
Re: Using TimerTasks
Thanks for the reassurance.
Here's another question... If I use Timer.delay() from the WPILibJ in a TimerTask, does that still pause ALL of your code? I wouldn't think so, because it only sleeps the current thread (as I understand it... I'm not sure). Here's the delay() function in the Timer Class: Code:
public static void delay(final double seconds) {
try {
Thread.sleep((long) (seconds * 1e3));
} catch (final InterruptedException e) {
}
}
|
|
#7
|
|||
|
|||
|
Re: Using TimerTasks
It only pauses the calling Thread. Although you do need to keep in mind that this type of delay does not mean that something will occurr every seconds of time. It means that the something will occur AFTER seconds of time has gone by. This means that if your code runs for a long time, you may not get the period you might be expecting.
|
|
#8
|
|||
|
|||
|
Re: Using TimerTasks
Quote:
Timer.schedule will run something at a fixed delay instead. Check out the javadocs for more info: http://www.wbrobotics.com/javadoc/java/util/Timer.html -Jason |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Using Magnets | 1jbinder | Rules/Strategy | 6 | 23-01-2008 19:42 |
| using tangent | LightWaves1636 | Math and Science | 2 | 13-02-2006 08:06 |
| Using Potentiometers | arpus maximus | Electrical | 5 | 20-11-2004 16:45 |
| Using Linux? | Raven_Writer | IT / Communications | 41 | 05-07-2004 16:53 |
| Using Flash | Keys | Website Design/Showcase | 8 | 12-03-2003 18:31 |