FRC5263 / 2018Robot

0 stars 1 forks source link

WaitFor command #17

Open elodotwe opened 6 years ago

elodotwe commented 6 years ago

This command should do nothing but sit and wait a number of seconds before completing.

My recommendation would be to use the [currentTimeMillis() function built into Java](https://docs.oracle.com/javase/7/docs/api/java/lang/System.html#currentTimeMillis()). When the command starts, you'll need to save (into a variable) the current time, and in the execute() function of the command you'll need to check whether the specified number of seconds have elapsed since you saved that time (if (currentTimeMillis() - startTime >= howLongWeShouldWait or something like that).

The constructor for this Command should take a number of milliseconds as a parameter: public Command(long waitTimeMsec)

In case it's new to you, a millisecond is 1/1000 seconds, so 1000 milliseconds is 1 second for example.

I anticipate using this block in a list of commands--we'll do a WaitFor(500) followed by DriveTo(12) etc.

isaiahkahler commented 6 years ago

I think there may be a better solution: WPI Library comes with a 'setTimeout()' function

in the constructor

public waitFor(double seconds){
    setTimeout(seconds); //amount in seconds
}

isFinished method:

protected boolean isFinished() {
    return isTimedOut();    
}
elodotwe commented 6 years ago

Has anyone tested the Wait command?

EvanGeiss commented 6 years ago

Untested, but I don't see any reason why it won't work.