Pause Command

Before we move on, let’s create a new simple command which will allow us to pause the robot for a specified period of time. By now you should have enough experience with creating commands to tackle this one on your own. Let’s call it PauseCommand. You will want the constructor to take one double value to specify the length of time to pause in seconds. The command should terminate when the time has expired. You can use the Timer class to measure the time.

After you have created your version, compare it to the one below:

.

.

.

.

.

This is one possible implementation of the PauseCommand:

package commands;

import robotCore.Logger;
import robotCore.Timer;
import robotWpi.command.Command;

/**
 *
 */
public class PauseCommand extends Command 
{
	Timer	m_timer	= new Timer();
	double	m_time;
	
    public PauseCommand(double time) 
    {
    	Logger.Log("PauseCommand", 3, "PauseCommand()");
    	
    	m_time	= time;
    	
        // Use requires() here to declare subsystem dependencies
//        requires(Robot.m_exampleSubsystem);
    }

    // Called just before this Command runs the first time
    protected void initialize() 
    {
    	Logger.Log("PauseCommand", 2, "initialize()");
    	
    	m_timer.reset();
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() 
    {
    	Logger.Log("PauseCommand", -1, "execute()");
    }

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() 
    {
    	Logger.Log("PauseCommand", -1, "isFinished()");
        
    	return (m_timer.get() > m_time);
    }

    // Called once after isFinished returns true
    protected void end() 
    {
    	Logger.Log("PauseCommand", 2, "end()");
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() 
    {
    	Logger.Log("PauseCommand", 2, "interrupted()");
    }
}

Next: Combining Commands