Will a command enter "end" when using withTimeout()

In autonomous period, our team wants to do a seires of actions . We are using command to control it and we want an action to stop after a specific second. For example, we want our intaker to intake balls for 1 second and automatically goes back after 1 second. We use a command.withTimeOut(1) and set the turning off state in the commnad’s end method. But it seems that the command won’t enter the end mode. Is there any solution to it?

You can see from the documentation here that it will cause the command to be interrupted.

Are you saying you have tried this and it didn’t work for you?

Yeah , l have tried it. Since l want my intaker to stop after 1 seconds. And l use a state machine to control my intake. So l will need to change the intaker’s current state to stop after the command is end or interrupted. But by using the withTimeout() function, the command won’t enter the “end” mode(where l change my intaker’'s current state to stop)

Without code I can’t really help you. I just double checked with a test:

public class timeouttest extends CommandBase {
  /** Creates a new timeouttest. */
  public timeouttest() {
    // Use addRequirements() here to declare subsystem dependencies.

  // Called when the command is initially scheduled.
  public void initialize() {

  // Called every time the scheduler runs while the command is scheduled.
  public void execute() {

  // Called once the command ends or is interrupted.
  public void end(boolean interrupted) {

  // Returns true when the command should end.
  public boolean isFinished() {
    return false;


If l use this to do my auto. And l want my shooter to run for 1 second at the end of each trajectory and stop and then run the next trajectory. But the shooter won’t stop after one second of the first trajectory.

But l don’t use the execute method. l just use the initialize method to set my state on and use the end method to set my state stop.

This is why we ask for links to the code. This snippet that you have shown doesn’t really capture anything interesting except that it is curious that you have two .addCommands but without seeing all of it I really can’t say. Help me help you!

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.