Okay so when I press the button associated with the toggleSolenoid command the cylinder occasionally actually toggles back and forth at the touch of the button - but more often than not it just spazzes back and forth repeatedly.
What is wrong??
Pnuematics Subsystem:
package org.usfirst.frc.team4623.robot.subsystems;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.command.Subsystem;
/**
*
*/
public class Pnuematics extends Subsystem {
// Put methods for controlling this subsystem
// here. Call these from Commands.
Compressor comp = new Compressor(0);
DoubleSolenoid ds1 = new DoubleSolenoid(0, 1);
public Pnuematics() {
comp.setClosedLoopControl(true);
}
public void initDefaultCommand() {
// Set the default command for a subsystem here.
//setDefaultCommand(new MySpecialCommand());
}
public void toggleSolenoid() {
if(ds1.get() == DoubleSolenoid.Value.kForward) {
ds1.set(DoubleSolenoid.Value.kReverse);
}
else {
ds1.set(DoubleSolenoid.Value.kForward);
}
}
public void stop1() {
ds1.set(DoubleSolenoid.Value.kOff);
}
}
toggleSolenoid Command:
package org.usfirst.frc.team4623.robot.commands;
import org.usfirst.frc.team4623.robot.Robot;
import edu.wpi.first.wpilibj.command.Command;
/**
*
*/
public class toggleSolenoid extends Command {
public toggleSolenoid() {
// Use requires() here to declare subsystem dependencies
// eg. requires(chassis);
requires(Robot.pnue);
}
// 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.pnue.toggleSolenoid();
}
// Make this return true when this Command no longer needs to run execute()
protected boolean isFinished() {
return isTimedOut();
}
// Called once after isFinished returns true
protected void end() {
Robot.pnue.stop1();
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
protected void interrupted() {
end();
}
}
Connection between Button and Command:
toggleSolenoid.whileActive(new toggleSolenoid());
Thanks so much for the help!