Piston code I made does not work

So I made this simple code I made using WPI’s screensteps on DoubleSolenoid and I put it in Robot.java. However, when I enabled the robot, the compressor and the PCM already gathering air and the piston comes out immediately before I even pressed the button.

Robot.java

I’m using Command based.

Instead of using koff, try using kreverse… if you are trying to test it moving back and forth

This is expected - simply declaring the solenoid in code will start the compressor automatically.

Okay, I’ll do but when I enable Teleop, the piston already comes out before I even pressed the button.

Do kReverse instead of kOff in your else statement.

You can solve this multiple ways:

  1. Swap the plumbing on the Piston. It sounds like your high/low pipes are reversed.
  2. Use kReverse in your if() statement and kForward in your else statement. Not preferred, but it should work.

you can also initialize to be in desired position by declaring it in the robotinit. then you can make sure that it always starts on the same position