Double Solenoid Switches Constantly



So I made these piston codes that should extend when pressed and retract in when not pressed. However, the double solenoid keeps doing this. Could someone help me?


That is exactly what I would expect that code to do.

Your FrontPiston_Command is the default command for the FrontPistonSubsystem and its isFinished() method always returns false. As such, each time no other command is using the subsystem, it will be started and will run until some other command needs the subsystem. Okay, so far.

As it is running, the command’s execute() method will be called every 20ms. The way you have execute() written, it will alternately call frontLower() and frontRaise() at those 20ms intervals since you are also flipping the frontPiston boolean every 20ms.

I hope this helps,


Ah okay, I’ll try to fix it. Thank you!


Solenoids are only meant to be triggered once for each new state, so you can either remember the old state you set it to, or you can get the current state from the DoubleSolenoid before trying to modify it. You can use the following utility function to simplify this for all DoubleSolenoids:

public static void setPiston(boolean activation, DoubleSolenoid piston) {
    Value newVal = activation ? Value.kReverse : Value.kForward;
    Value lastVal = piston.get();
    if (newVal == lastVal)
1 Like

Ah okay, and this is for the execute() in the commands?


I would be wary of this:

1 Like

I am not sure exactly what the use case is here, but it looks like a climber. If that is the case, I would probably not have these two command set up as default commands. I would rather run them off a button as either whenPressed or whileHeld. Which of those I chose would influence the command design. I would also have separate commands for up and down in order to keep things as simple as possible.

For whenPressed, I would have the command set the proper state for up or down and finish immediately. The state set could even be in initialize and execute could be empty. This would be the easiest.

For whileHeld, I believe the goal would be to have the up or down movement pause when release and not start going the other direction. For this, I will need some help from others on this thread as to the ability to hold a pneumatic piston in an in between state. I know it is possible because I have seen it done but I think it would require a change to the solenoid hardware setup here. But from a software point of view, it would mean setting the proper state in initialize, nothing in execute and in end/interrupted, setting the neutral state.

I hope this helps,


I already have it whenPressed in my OI. I did this in my commands and test it in a few hours. I’ll see if this works.



And they are no longer the default commands for the two subsystems?



Yes, I removed the default command. That hastebin suppose to show that it’s commented but I guess not. Thank you!


Thanks for the tip