Quote:
Originally Posted by cstelter
Since your command is ending when done==true, how are you getting another command to run? I think if you tie it to a button with whenPressed() or something like that, it reuses the same object each time. So you have to reinitialize everything in initialize.
Code:
protected void initialize() {
//reset fields to values defaulted to on construction
go=0;
done=false;
count=0;
System.out.println(this);
}
I suspect you will also want to remember your setpoint and assign that to tcount in the initializer as well since it is being reassigned during execute()
Code:
public class MagicElevator extends Command {
...
int mySetpoint;
...
public MagicElevator(int setpoint) {
// Use requires() here to declare subsystem dependencies
requires(Robot.elevator);
mySetpoint=setpoint;
}
// Called just before this Command runs the first time
protected void initialize() {
go=0;
done=false;
count=0;
tcount=mySetpoint;
System.out.println(this);
}
|
Thanks cstelter, I did forget to reset the done variable didn't I! I will test your suggestions when I get out of class. Also what would setting another mySetpoint variable do? Would this one carry over between reintialization? Wouldn't it cause the tcount variable to keep adding without resetting on each press of the button that sets the setpoint to (1 -1 or 0)?