View Single Post
  #7   Spotlight this post!  
Unread 08-28-2016, 11:21 PM
euhlmann's Avatar
euhlmann euhlmann is offline
CTO, Programmer
AKA: Erik Uhlmann
FRC #2877 (LigerBots)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2015
Location: United States
Posts: 298
euhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud of
Re: Cancel a command

Whoops, didn't see that section of the docs

There's an easy way to do what you want in your situation though.

Code:
public class ScissorToPosition extends Command {
  // ...
  
  boolean isUnsafe = false;

  public void initialize() {
    if(m_setpoint > 70 && Robot.wristPID.getSetpoint() > 30) { 
      System.out.println("Scissor canceled since wrist > 30"); 
      
      isUnsafe = true;
    } else {
      isUnsafe = false;
      
      // init as usual
    }
  }

  // ...

  public void execute() {
    if(isUnsafe) {
      return;
      // IMPORTANT. execute() will be called once regardless of isFinished() status
    }
    
    // execute as usual
  }

  public void isFinished() {
    if(isUnsafe) {
      return true;
    }
    
    return Robot.scissorPID.onTarget();
  }
}
__________________
Creator of SmartDashboard.js, an extensible nodejs/webkit replacement for SmartDashboard


https://ligerbots.org
Reply With Quote