whileHeld() works as advertised, you just need to remember to shut down things in end() and interrupted()...
Our experience last summer was whileHeld called init() once, (execute(), getFinished()) repeatedly, and interrupted() is called when the button is released. We used whileHeld reliably with commands like this (note that we stop the motor from end() and interrupted().
We would see multiple init() if several whileHelds fired off commands that required the same subsystem(s) and those buttons were held at the same time. I don't remember the exact details.
Code:
package org.usfirst.frc3620.FRC36202013RobotRedo.commands;
import edu.wpi.first.wpilibj.command.Command;
import org.usfirst.frc3620.FRC36202013RobotRedo.Robot;
/**
*
*/
public class FlipperBackwardCommand extends Command {
public FlipperBackwardCommand() {
// Use requires() here to declare subsystem dependencies
// eg. requires(chassis);
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=REQUIRES
requires(Robot.flipperSubsystem);
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=REQUIRES
}
// Called just before this Command runs the first time
protected void initialize() {
}
// Called repeatedly when this Command is scheduled to run
protected void execute() {
Robot.flipperSubsystem.flipperBackward();
}
// Make this return true when this Command no longer needs to run execute()
protected boolean isFinished() {
return false;
}
// Called once after isFinished returns true
protected void end() {
Robot.flipperSubsystem.flipperStop();
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
protected void interrupted() {
end();
}
}