Pneumatic code

I need help with my code
I need help 1st on how to control the manifold valve to be closed in the beginning and second I need help on making the piston go forward and back
This is my code.
if (shiftState) {
} else {

	if(stick.getRawButton(5)) { 
		shiftState = true;
	if(stick.getRawButton(6)) { 

First, a few sanity checks:

Are all the ports on your manifold covered, either with a solenoid valve or a blank cover plate? Are all of the outputs from the manifold covered, either with a tube or a plug/cap? If any of these are open, you will just be blowing air and almost certainly will not be doing any useful pneumatic work.

Verify that your pneumatic primary plumbing looks like one of the pictures in R84, R91 or R92.
What does your wiring look like? Your code looks to me more like old “spike relay” code than PCM-based code. A photo or schematic would be great.

Is your solenoid valve a single or double? If using Vex, single would be 217-3233, if double 217-2948. Otherwise - how many pairs of wires can run to your solenoid valve? One pair (usually at one end) is single, two pairs (usually at opposite ends) is double. The code fragment you listed might work for single if the declarations are right, but would definitely not work for double.

Please also post code which shows the declaration and initialization of shifter, and, as you’re worried about an initial state, shiftstate. A link to your full codebase (e.g. a github repository) would be even better.

Have you read the pneumatics sections of screensteps live, particularly these two pages?

In general, most of this code for robotics follows the pattern:


// Get Inputs

// Do some calculation

// Assign outputs


In your case, inputs involve the getRawButton() calls. Calculation involves the IF statements that map two buttons to your boolean shiftState. Assigning outputs is where you call shifter.set().

Depending on how the posted chunk of code is being called, what shifter is declared as, where shiftState is declared at (and lots of others), I could see this going sideways very quickly. Can you post at least the full code file, or link to github as GeeTwo mentioned?

It is a double solenoid and here is the code :

package org.usfirst.frc.team7193.robot;

import com.ctre.phoenix.motorcontrol.ControlMode;
import com.ctre.phoenix.motorcontrol.can.TalonSRX;
import com.ctre.phoenix.motorcontrol.can.VictorSPX;

import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.DoubleSolenoid.Value;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;

public class Robot extends IterativeRobot {
private Joystick stick;
private TalonSRX leftTalon;
private VictorSPX leftVictor;
private TalonSRX rightTalon;
private VictorSPX rightVictor;
private DoubleSolenoid piston;
private boolean shiftState; // True High speed False low speed
private Compressor compressor;

public void robotInit() {
	leftTalon = new TalonSRX(1);
	leftVictor = new VictorSPX(2);
	rightTalon = new TalonSRX(3);
	rightVictor = new VictorSPX(4);
	stick = new Joystick(0);
	piston = new DoubleSolenoid(0,1);
	Compressor comp = new Compressor(0);
	// Setting Inverted
	leftTalon.setInverted(false); // making sure
	rightTalon.setInverted(false); // 
	leftVictor.setInverted(false); //
	rightVictor.setInverted(false); //
	// Slave Mode
	leftVictor.follow(leftTalon); // setting up following mode so we can use encoders
	rightVictor.follow(rightTalon); // same ^^
 // init ends
	private void tankDrive(double left, double right) {
		// do this for each motor
		leftTalon.set(ControlMode.PercentOutput, -left);

// left2Motor.set(ControlMode.PercentOutput, -left);
rightTalon.set(ControlMode.PercentOutput, -right);
// right2Motor.set(ControlMode.PercentOutput, -right);

	public void disabledInit() {


	public void disabledPeriodic() {


Just looking at the code, I wonder why you’re negating the left and right inputs and setting those motor controllers as not inverted. It is cleaner to use inverted to do the negation.

Double solenoid valves are typically not receiving electricity except when changing state. In some cases (check the specs on your solenoid valve) they aren’t designed to handle 100% duty cycle. As such, double solenoid valves are typically strobed to make them change state. That is, to open it, you change the state to DoubleSolenoid.Value.kForward for a fraction of a second (0.1s to 0.5s IIRC), then return it to DoubleSolenoid.Value.kOff until next time you want to (in this case) shift gears.

I also see that you are using IterativeRobot. This means that in order to achieve the results above, you will need to set up your own timeouts so you know when to return the kOff state - you will definitely NOT want to stay in a single pass of your iterative robot that long, as all the other functions are suspended at this time. This is especially a big deal if you are doing anything other than driving. I will suggest here that commandBasedRobot is much simpler for this function - just make three commands, shiftUp(), shiftDown(), and shiftDefault() which set the state to kForward, kReverse and kOff respectively, and the shiftUp() and shiftDown() will self terminate when they learn that enough time has passed.

I’m not particularly adept at iterative, so I’m not going to do this during lunch break. If no one else has answered with code, I’ll give it a crack this evening. Some clues: in your Init() functions, set the state to what you want as a default, and start a timer so you know when to turn it off. In the periodic() functions, check to see if the timer is still running; if so, set the solenoid state as indicated in shiftState, otherwise, set it to kOff. Note that whenever you change the state (e.g. based on a button press), you will want to not only change shiftState, but start a timer.