Go to Post Hi. My name is Rick and I am a Roboholic. - Rick TYler [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 17-02-2012, 09:39
guoruiwu1994 guoruiwu1994 is offline
Registered User
FRC #1815
 
Join Date: Feb 2010
Location: Toronto
Posts: 15
guoruiwu1994 is an unknown quantity at this point
What is the point of timer.delay?

It delays the code by the specified amount of time, but I'm not sure what the benefits of that are.
Reply With Quote
  #2   Spotlight this post!  
Unread 17-02-2012, 11:55
NS_Radication's Avatar
NS_Radication NS_Radication is offline
Student
AKA: Marco Schoener
FRC #1369 (Minotaur)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2009
Location: Tampa
Posts: 88
NS_Radication is an unknown quantity at this point
Re: What is the point of timer.delay?

The Timer.delay(); function allows the robot to activate a value and reset.

For example:

driveTrain.tankDrive(motor1, motor2);
Timer.delay(0.005);

This allows the drivetrain to refresh the motors at 5 ms(aka stop on a dime!)

OR

if(joy1.getRawButton(1))
{
move_motor = true;
}
Timer.delay(0.5);

if(move_motor == true)
{
motor.set(1.0);
}
Timer.delay(0.005);

This allows button 1 to change position only after every half second if the code changes. So the button held will not change if the button is hit again for 0.5 seconds.

Hope this helped.

P.S. The placement of the Timer.delay() is very important because having a drive train after a time greater than, for example, .15 seconds, will start to see a very small twitch in activating the motors and cause it to slow down and start up at intervals. It can get weird!

Happy Competition!
__________________
Team 1369
Senior
Head Programmer (Java)
Head Electrician
Reply With Quote
  #3   Spotlight this post!  
Unread 18-02-2012, 11:06
Lalaland1125 Lalaland1125 is offline
Registered User
AKA: Ethan Steinberg
FRC #2429
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2011
Location: La Canada
Posts: 29
Lalaland1125 is an unknown quantity at this point
Re: What is the point of timer.delay?

Just double checking, won't timer.delay also pretty much freeze the thread that the robot is running under, so if you are running a single threaded robot the robot will completely freeze for that amount of time?
Reply With Quote
  #4   Spotlight this post!  
Unread 18-02-2012, 11:12
EricVanWyk EricVanWyk is offline
Registered User
no team
 
Join Date: Jan 2007
Rookie Year: 2000
Location: Boston
Posts: 1,597
EricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond repute
Send a message via AIM to EricVanWyk
Re: What is the point of timer.delay?

Quote:
Originally Posted by Lalaland1125 View Post
Just double checking, won't timer.delay also pretty much freeze the thread that the robot is running under, so if you are running a single threaded robot the robot will completely freeze for that amount of time?
Almost. It will pause the thread it is called from, allowing your other threads to take that time to do stuff. Think of it as a way of saying "I'm good for the next N milliseconds, its someone else's turn."
Reply With Quote
  #5   Spotlight this post!  
Unread 18-02-2012, 11:25
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: What is the point of timer.delay?

Quote:
Originally Posted by Lalaland1125 View Post
Just double checking, won't timer.delay also pretty much freeze the thread that the robot is running under,
Yes, if by "freeze the thread" you mean "nothing else in that thread will execute until the delay expires".

Quote:
so if you are running a single threaded robot the robot will completely freeze for that amount of time?
Nothing else in that single thread will execute until the delay expires. So if that's what you mean by "the robot will completely freeze for that amount of time", then yes.



Last edited by Ether : 18-02-2012 at 11:38. Reason: edited for clarity
Reply With Quote
  #6   Spotlight this post!  
Unread 18-02-2012, 12:36
Herbblood's Avatar
Herbblood Herbblood is offline
Knowledgeable
AKA: Ally
FRC #3044 (OxBE4)
Team Role: Programmer
 
Join Date: Oct 2011
Rookie Year: 2008
Location: Ballston Spa
Posts: 247
Herbblood is an unknown quantity at this point
Re: What is the point of timer.delay?

Yeah, with the delay the entire program stops until the delay is over.
__________________
Off to WPI!
Go OxBE4
Reply With Quote
  #7   Spotlight this post!  
Unread 18-02-2012, 12:57
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: What is the point of timer.delay?

Quote:
Originally Posted by Herbblood View Post
Yeah, with the delay the entire program stops until the delay is over.
For the benefit of students reading this thread, as a blanket statement without qualifiers, that is untrue.

If the delay is implemented as blocked waiting (rather than busy waiting) it halts only the thread in which it is located. Other threads continue to execute. Even if the delay is implemented as busy waiting, other threads will execute IF they are of greater priority, or if they are of equal priority AND time-slicing is enabled.



Reply With Quote
  #8   Spotlight this post!  
Unread 18-02-2012, 15:06
wireties's Avatar
wireties wireties is offline
Principal Engineer
AKA: Keith Buchanan
FRC #1296 (Full Metal Jackets)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Rockwall, TX
Posts: 1,170
wireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond repute
Send a message via AIM to wireties
Quote:
Originally Posted by Ether View Post
If the delay is implemented as blocked waiting (rather than busy waiting) it halts only the thread in which it is located. Other threads continue to execute. Even if the delay is implemented as busy waiting, other threads will execute IF they are of greater priority, or if they are of equal priority AND time-slicing is enabled.
That is really close. VxWorks has the following task states: executing, ready, blocked, delayed or any of these things in combination with suspended or stopped. I suspect the delay method simply puts the task into a delayed state. The "busy waiting" thing is not done by the OS. I think ether is referring to something commonly called a spinlock - that could be the case with this delay method but it is nothing to do with the OS.
__________________
Fast, cheap or working - pick any two!
Reply With Quote
  #9   Spotlight this post!  
Unread 18-02-2012, 16:21
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: What is the point of timer.delay?

Quote:
Originally Posted by wireties View Post
That is really close. VxWorks has the following task states: executing, ready, blocked, delayed or any of these things in combination with suspended or stopped. I suspect the delay method simply puts the task into a delayed state. The "busy waiting" thing is not done by the OS. I think ether is referring to something commonly called a spinlock - that could be the case with this delay method but it is nothing to do with the OS.
I guess I could have been clearer. None of my comments were referring to the OS. Here's an expanded clumsy-reading version of my post, with nothing left to the reader's imagination:

If the delay is implemented as blocked waiting (used generically here to include blocked waiting for a timer) (rather than busy waiting aka "spinning", either by the programmer or by a call to an intrinsic function of the language that the programmer is using or by a library routine that the programmer calls either directly or indirectly) it halts only the thread in which it is located. Other threads continue to execute. Even if the delay is implemented (see previous exansion of "implemented") as busy waiting (aka "spinning"), other threads will execute IF they are of greater priority, or if they are of equal priority AND time-slicing is enabled.



Last edited by Ether : 18-02-2012 at 16:26.
Reply With Quote
  #10   Spotlight this post!  
Unread 19-02-2012, 00:42
Sunstroke Sunstroke is offline
Programmer
AKA: Joe Grinstead
FRC #3504 (Girls of Steel)
Team Role: Mentor
 
Join Date: Apr 2009
Rookie Year: 2009
Location: New England
Posts: 49
Sunstroke is an unknown quantity at this point
Re: What is the point of timer.delay?

I believe that in Squawk (the Java VM on the cRIO), all threads are artificial constructs in the VM.

I mean that in the sense that the Squawk system will not use the cRIO's built in threading capabilities, it just kind of pretends to use them.

Also, Timer.delay() is implemented with Thread.sleep() and so it will NOT prevent other threads from running while it is asleep. However, the thread that calls Timer.delay(...) will wait until that time has passed.
Reply With Quote
  #11   Spotlight this post!  
Unread 19-02-2012, 00:47
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: What is the point of timer.delay?

Quote:
Originally Posted by Sunstroke View Post
the Squawk system will not use the cRIO's built in threading capabilities
Just a point of clarification: the cRIO doesn't have a "built-in" threading capability. It uses a third-party RTOS, vxWorks.


Reply With Quote
  #12   Spotlight this post!  
Unread 19-02-2012, 14:29
gixxy's Avatar
gixxy gixxy is offline
Programming and Arduino Mentor
AKA: Gustave Michel III
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Nov 2011
Rookie Year: 2012
Location: Ruston, LA
Posts: 207
gixxy is on a distinguished road
Re: What is the point of timer.delay?

I know that if you put in a Timer.delay() it will delay EVERYTHING. I put in a 4 second delay on a command to stop it from being called too often, but during that 4 seconds I couldn't do anything, the DriveTrain,our BallFeed belt. everything was frozen.
Reply With Quote
  #13   Spotlight this post!  
Unread 19-02-2012, 14:36
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: What is the point of timer.delay?

Quote:
Originally Posted by gixxy View Post
I know that if you put in a Timer.delay() it will delay EVERYTHING. I put in a 4 second delay on a command to stop it from being called too often, but during that 4 seconds I couldn't do anything, the DriveTrain,our BallFeed belt. everything was frozen.
Did you read posts 4, 5, 7, 8, 9, and 10 about threads ?


Reply With Quote
  #14   Spotlight this post!  
Unread 19-02-2012, 22:35
gixxy's Avatar
gixxy gixxy is offline
Programming and Arduino Mentor
AKA: Gustave Michel III
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Nov 2011
Rookie Year: 2012
Location: Ruston, LA
Posts: 207
gixxy is on a distinguished road
Re: What is the point of timer.delay?

Quote:
Originally Posted by Ether View Post
Did you read posts 4, 5, 7, 8, 9, and 10 about threads ?


We are multithreaded. Which is why this is confusing me.

Last edited by gixxy : 19-02-2012 at 22:38.
Reply With Quote
  #15   Spotlight this post!  
Unread 19-02-2012, 22:40
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: What is the point of timer.delay?

Quote:
Originally Posted by gixxy View Post
We are multithreaded.
Quote:
Originally Posted by gixxy View Post
I know that if you put in a Timer.delay() it will delay EVERYTHING. I put in a 4 second delay on a command to stop it from being called too often, but during that 4 seconds I couldn't do anything, the DriveTrain,our BallFeed belt. everything was frozen.
Are you saying that if you add a Timer.delay() to one thread (let's call it "Thread A") it will stop execution of all other threads?

Is Thread A higher priority than the other threads?

or

Is Thread A the same priority as the other threads, and you have time-slicing disabled?


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


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

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