Hello,
We are trying out command based programming and we have run into an issue that need some assistance. We have a button that triggers an AutoTestCommandGroup in which we get the current angle from the gyro, add 90 and then pass it to a “Turn” command which then rotates the robot 90 degrees.
It works fine but it only works once - the very first time it is run. We would like to be able to do this every time the button is pressed.
In other words, we would like the “target angle” parameter to be passed to the “Turn” command every time the button is pressed. Is there a specific way to format the AutoTestCommandGroup so that a new parameter gets passed every time a button is pressed?
simplified code follows (“testAngle” is the parameter that we would like to get passed every time the button is pressed):
--------AutoTestCommandGroup----------------
public class AutoTestCommandGroup extends CommandGroup {
public AutoTestCommandGroup() {
double testAngle = RobotMap.ahrs.getAngle() + 90;
addSequential(new Turn(testAngle));
------------ Turn command -----------------
public class Turn extends Command {
public double inputAngle;
public double inputAngle2;
public Turn (double inputAngle) {
this.inputAngle=inputAngle;
requires(Robot.driveT);
}
protected void initialize() {
}
protected void execute() {
inputAngle2 =RobotMap.ahrs.getAngle();
if (inputAngle2<inputAngle){
DriveTrainSubsystem.drive.arcadeDrive(0,-.6);
}
protected boolean isFinished() {
return true;
}
protected void end() {
}
protected void interrupted() {
end();