View Single Post
  #3   Spotlight this post!  
Unread 02-01-2016, 08:39 PM
Joe Derrick's Avatar
Joe Derrick Joe Derrick is offline
Mentor - Programming
FRC #0319
 
Join Date: Feb 2012
Rookie Year: 2011
Location: Prospect Mountain High School
Posts: 43
Joe Derrick is a glorious beacon of lightJoe Derrick is a glorious beacon of lightJoe Derrick is a glorious beacon of lightJoe Derrick is a glorious beacon of lightJoe Derrick is a glorious beacon of lightJoe Derrick is a glorious beacon of light
Re: Pnuematics Toggle Code Issue

Hey there, try adding or modifying your subsystem to this

Code:
public class Pnuematics extends Subsystem {

public boolean toggle;
	
    public void solenoidIn() {
    	   ds1.set(DoubleSolenoid.Value.kReverse);
	toggle = true;
    }
       
    public void solenoidOut(){
    	   ds1.set(DoubleSolenoid.Value.kForward);
toggle = false;
       }
    	
}
these are two methods which when called will set the solenoid in a direction then flip the state of the boolean

then your Command to this

Code:
public class toggleSolenoid extends Command {

    public toggleSolenoid() {	
    	requires(Robot.pnue);    	
    }

protected void initialize() {
	if (Robot.pnue.toggle == true)
    	{
    	Robot.pnue.solenoidOut();
    	}
    	else if(Robot.pnue.toggle == false){
    	Robot.pnue.solenoidIn();
    	}
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
}

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
return true;
}

    // Called once after isFinished returns true
    protected void end() {
    
    }
protected void interrupted() {
    	end();
    }
}
since solenoids retain their "state" when switched, they do not need to be told continuously what do do. they are set to forward or reverse one time in the "initialize" part of the command depending on the state of the boolean. Then the command finishes immediately.

the OI should be

Code:
toggleSolenoid.whenPressed(new toggleSolenoid());
Best of luck, hope this helps. Once mastered, command based is the way to go!

Also there may be other ways to acheive a "toggle" but this has worked for us in the past. I did see a "toggle option" in the OI this year but have yet to test it.
__________________
2010-2017 Mentor Team 319
2012 - Rockwell Automation Award Winner
2014 - Xerox Creativity in Engineering Winner, Archimedes Division
2015 - Rockwell Automation and Gracious Proffesionalism Winner, Tesla Division
2016 - North Shore and UNH District Event Winner, Carson Division
http://www.frc319.com
Reply With Quote