|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Re: Java wait Function
Timer.delay() is supposed to leave outputs set where they are as well, but I've had more success using Timer.getFPGATimestamp() in conjunction with a loop.
|
|
#2
|
||||
|
||||
|
Re: Java wait Function
Quote:
Our team had similar requirements surrounding our catapult (do X, wait half a second, then do Y). Originally the programmers implemented this using Timer.delay(). The result was that when the drivers tried to perform the action while moving, but then stopped moving or changed directions during the action, the robot would keep moving. Though .5 seconds doesn't sound like much, it is plenty of time for your robot to go just a little too far and injure someone, break something, or get you a penalty for going too far outside the arena. Use Timer.delay() with caution. |
|
#3
|
||||
|
||||
|
Re: Java wait Function
^This.
Year in and year out I see programmers bumping up against this concept. I think it's probably fair to say that some (many?) of them receive advice on how to fix the problem, but never really understand why there was a problem and why the fix fixed it. Does anyone have a link to a clear, simple, well-written tutorial on concurrent processing for FRC that covers threads, state machines, and interrupts? Last edited by Ether : 01-03-2014 at 13:18. |
|
#4
|
|||
|
|||
|
Re: Java wait Function
This is what I have done.
Inside op control: Code:
if(INSERT SOMETHING HERE) {
new Thread() {
public void run() {
//Code to run here:
Thread.sleep(time in ms);
//More code
}.start()
}
}
This has worked well for me. Hope this helps! Matt |
|
#5
|
||||
|
||||
|
Re: Java wait Function
how does the thread get killed?
|
|
#6
|
|||
|
|||
|
Re: Java wait Function
My understanding is that the JVM handles it. From here, it seems like letting the JVM handle could introduce race conditions if you access the same data from multiple threads like that...
Alex Brinister |
|
#7
|
||||
|
||||
|
Re: Java wait Function
ah. looked at it too fast. The thread completes normally when run() returns.
|
|
#8
|
|||
|
|||
|
Re: Java wait Function
Is safety configured for the drive base? I'd hope that the Java implementation would halt the drive motors when wait() or breakpoints delay for more than 100ms.
Greg McKaskle |
|
#9
|
|||
|
|||
|
Re: Java wait Function
I think this is only enforced if you have the Motor Safety Helper enabled. This feature is optional in both the C++ and Java libraries and can be disabled by the programmer. It is generally better to keep it enabled but to extend the timeout period using the SetTimeout() function in whatever motor controller class you choose to use (Talon, Victor, CANJaguar, Jaguar, etc).
Alex Brinister |
|
#10
|
|||
|
|||
|
Re: Java wait Function
What I intended to ask was whether the Motor Safety Helper was enabled when the robot motors ran for several seconds during the sleep() call.
Greg McKaskle |
|
#11
|
|||
|
|||
|
Re: Java wait Function
I have not turned motor safety helper on or off. So what ever it defaults to is what it is set to and it still works for me.
|
|
#12
|
|||
|
|||
|
Re: Java wait Function
Does the default result in zombie robots? I'd hope not. It should take effort to produce a zombie robot.
Also, if you are turning off the safety config, please ensure that everyone running the robot knows how to disable or estop the robot. Personally, I'd only turn it off when the robot is on blocks and I want the motors to keep running while I'm at a breakpoint. Greg McKaskle |
|
#13
|
|||
|
|||
|
Re: Java wait Function
Quote:
This causes the calling thread to sleep, and thus will cause your robot to hang unless called from a separate thread. Use time stamps as mentioned. System.getCurrentTimeMillis, or the FPGA timer, or anything else in a loop, or spawn a separate thread and call thread.sleep() in the new thread. But do not call Thread.sleep or Timer.Delay in the same thread as your TeleOp/Auto periodic functions. Hope this helps, Kevin |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|