|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Re: How to time an action in teleop without delaying teleop.
You can use java.util.Timer and java.util.TimerTask to schedule something to happen in the future while your program still runs.
Code:
// local or class variables
final int solenoidDelay = 65; // milliseconds
final Timer myTimer = new Timer();
final TimerTask closeSolenoidTask = new TimerTask() {
@Override
public void run() {
closeSolenoid();
}
};
...
mySolenoid.open();
myTimer.schedule(closeSolenoidTask, solenoidDelay);
Last edited by SamCarlberg : 20-11-2015 at 11:17. |
|
#2
|
|||
|
|||
|
Re: How to time an action in teleop without delaying teleop.
Quote:
Also: Hi Sam! |
|
#3
|
||||
|
||||
|
Re: How to time an action in teleop without delaying teleop.
Quote:
Solenoid methods are thread-safe. I'd be more worried about scheduling a close, doing some stuff, then opening the solenoid (and expecting it to stay open) before the scheduled close happens. In this case, the methods for opening/closing the solenoid should have checks to see if it's been claimed by a different call. Code:
private boolean claimed = false;
public void openSolenoid() {
if (!claimed) {
claimed = true;
// open it
}
}
public void closeSolenoid() {
if (claimed) {
claimed = false;
// close it
}
}
But I don't think it's a problem for something this simple. |
|
#4
|
|||
|
|||
|
Re: How to time an action in teleop without delaying teleop.
Definitely need to switch to command-based robot and don't forget to use requires(); with your commands and subsystems, otherwise your whole robot will still pause. WPIlib documentation should be able to take it from there.
|
|
#5
|
||||
|
||||
|
Re: How to time an action in teleop without delaying teleop.
Quote:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|