Skip to content

Structure of a Command

States

When writing a command, you need to specify what the command should do in each of its possible states. To do this, you override the initialize(), execute(), and end() methods. The command should also be able to tell the scheduler when it has finished executing by overriding the isFinished() method.

end() Method

The end() method actually provides a parameter to check if the command ended normally, or was interrupted.

    void end(boolean interrupted){
        if (interrupted == True){
            // The command has been interrupted
        }
        else{
            // The command has ended as expected
        }
    }

Tip

If a command is not finishing correctly, make sure the isFinished() method returns true when the command should terminate

Default Behavior

If you don't want to specify any special behavior for these methods, they are already provided with default behavior. For example, initialize(), execute(), and end() do nothing by default, while isFinished() returns false by default. This creates a command that runs indefinitely until it is interrupted.

Methods in Summary

initialize() --> Called once per scheduling
execute() --> Called every scheduler cycle that the command is scheduled
end() --> Runs once per termination (at the end)
isFinished() --> Called every scheduler cycle (if true --> terminate command)


Last update: April 22, 2023
Created: April 21, 2023