Example Command
A function-by-function discussion of a Command's essential components
public class ExampleCommand extends CommandBase {
private final double timeout;
private Timing.Timer timer;
// Constructor
public ExampleCommand(double timeout) {
this.timeout = timeout;
// configure any other instance variables that may be helpful
// which subsystem(s) are required for this command?
addRequirements(subsystem);
}
// Initialization
@Override
public void initialize() {
timer.start(); // Start the timer
// set any other starting variables required
}
// Execution loop
@Override
public void execute() {
// command logic may as simple as keep power on and update sensors
}
// Check for completion
@Override
public boolean isFinished() {
return timer.elapsedTime() > timeout;
// add additional conditions to this to see if you're done
}
// Post-execution actions
@Override
public void end(boolean interrupted) {
// cut power and clean up
}
}
Constructor
Initialize
Execute
isFinished + end
Last updated
Was this helpful?