|
Re: Set command to run for a certain amount of time
Here is a command that uses a timer. When you create an instance of the command you pass in the time (seconds) you want it to run.
package edu.rhhs.frc.commands;
/**
* @author rhhs
*/
public class ConveyorTimed extends CommandBase {
private double m_timeout;
public ConveyorTimed(double timeout) {
m_timeout = timeout;
requires(m_conveyor);
}
protected void initialize() {
setTimeout(m_timeout);
m_conveyor.start();
}
protected void execute() {
}
protected boolean isFinished() {
return isTimedOut();
}
protected void end() {
m_conveyor.stop();
}
protected void interrupted() {
m_conveyor.stop();
}
}
|