Quote:
Originally Posted by fireXtract
Now i'm able to get the elevator to stop in response to the hall effect sensor, but once it use it to go up i cant press it to go up again, and if i go down i can only go down once. Pressing the button multiple times to add to count does nothing. What am i missing here?
|
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);
}