![]() |
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.
|
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! |
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?
|
Re: What is the point of timer.delay?
Quote:
|
Re: What is the point of timer.delay?
Quote:
Quote:
|
Re: What is the point of timer.delay?
Yeah, with the delay the entire program stops until the delay is over.
|
Re: What is the point of timer.delay?
Quote:
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. |
Quote:
|
Re: What is the point of timer.delay?
Quote:
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. |
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. |
Re: What is the point of timer.delay?
Quote:
|
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.
|
Re: What is the point of timer.delay?
Quote:
|
Re: What is the point of timer.delay?
Quote:
|
Re: What is the point of timer.delay?
Quote:
Quote:
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? |
| All times are GMT -5. The time now is 12:49. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi