Go to Post know what else would be great? with each new rep point you get 10 airline miles on your Visa or MasterCard - KenWittlief [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 18-02-2010, 08:21
Geek 2.0 Geek 2.0 is offline
Registered User
FRC #0107
Team Role: Programmer
 
Join Date: Sep 2009
Rookie Year: 2008
Location: Holland, MI
Posts: 120
Geek 2.0 will become famous soon enough
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.
Reply With Quote
  #2   Spotlight this post!  
Unread 18-02-2010, 22:31
Lord_Jeremy's Avatar
Lord_Jeremy Lord_Jeremy is offline
Lord_Jeremy the Procrastinator
AKA: Jeremy Agostino
FRC #1546 (Chaos Inc.)
Team Role: Electrical
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Baldwin, New York
Posts: 45
Lord_Jeremy is an unknown quantity at this point
Send a message via ICQ to Lord_Jeremy Send a message via AIM to Lord_Jeremy Send a message via MSN to Lord_Jeremy Send a message via Yahoo to Lord_Jeremy
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.
__________________
Compiling...
Compiling...
Reply With Quote
  #3   Spotlight this post!  
Unread 18-02-2010, 23:16
Geek 2.0 Geek 2.0 is offline
Registered User
FRC #0107
Team Role: Programmer
 
Join Date: Sep 2009
Rookie Year: 2008
Location: Holland, MI
Posts: 120
Geek 2.0 will become famous soon enough
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?
Reply With Quote
  #4   Spotlight this post!  
Unread 19-02-2010, 00:19
Lord_Jeremy's Avatar
Lord_Jeremy Lord_Jeremy is offline
Lord_Jeremy the Procrastinator
AKA: Jeremy Agostino
FRC #1546 (Chaos Inc.)
Team Role: Electrical
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Baldwin, New York
Posts: 45
Lord_Jeremy is an unknown quantity at this point
Send a message via ICQ to Lord_Jeremy Send a message via AIM to Lord_Jeremy Send a message via MSN to Lord_Jeremy Send a message via Yahoo to Lord_Jeremy
Re: Using TimerTasks

Eh, I don't know of any, but you should probably hold out for someone with more know-how...
__________________
Compiling...
Compiling...
Reply With Quote
  #5   Spotlight this post!  
Unread 19-02-2010, 08:16
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,080
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
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.
Reply With Quote
  #6   Spotlight this post!  
Unread 20-02-2010, 11:04
Geek 2.0 Geek 2.0 is offline
Registered User
FRC #0107
Team Role: Programmer
 
Join Date: Sep 2009
Rookie Year: 2008
Location: Holland, MI
Posts: 120
Geek 2.0 will become famous soon enough
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) {
        }
    }
Thanks!
Reply With Quote
  #7   Spotlight this post!  
Unread 22-02-2010, 17:03
ericarseneau ericarseneau is offline
Registered User
no team
 
Join Date: Jan 2010
Location: San Diego
Posts: 30
ericarseneau is an unknown quantity at this point
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.
Reply With Quote
  #8   Spotlight this post!  
Unread 23-02-2010, 10:39
Happy Birthday! JasonStern JasonStern is offline
Mentor
FRC #1123 (AIM Robotics)
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2003
Location: Arlington, VA
Posts: 65
JasonStern is on a distinguished road
Re: Using TimerTasks

Quote:
Originally Posted by ericarseneau View Post
... does not mean that something will occurr every seconds of time.
You can call Timer.scheduleAtFixedRate if you want something to be run at a fixed period.

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
__________________
Que será será
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT -5. The time now is 12:40.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi