How do you toggle pneumatics on the rev pneumatics hub

My team has been trying to toggle pneumatics on the rev hub. we cant find any sample code and have been messing with it for a while. Any help would be greatly appreciated.

Are you asking how to actuate it at all? Or specifically how to toggle (flip back and forth)?

To actuate them, you would need to create a Solenoid (or DoubleSolenoid depending on your valve) object and set the value

If you need further help, please provide a link to your code and more information about what you’re trying to do and how it’s not working.

here is the code

We are trying to toggle (flip back and forth) What is currently happening is that the solenoid if flipping back and forth rapidly we can’t get it to set.

The code you write in the robotPeriodic method loops at 50 times per second, so when you write solenoid.toggle(), it will toggle back and forth at that rate (20 microseconds each) for as long as the condition is met (since I doubt you can press and release a button in less than 20 microseconds).

As far as solutions, I highly recommend looking into command-based. It’s a bit more complex to figure out, but solves most of these kinds of problems for you.

If switching to that this year isn’t feasible (completely understandable), then what you’re looking for is called a latch. Essentially you need to store the state of your input condition (button press or similar) and add a condition based on that value. So you would end up with something like this… Define “lastState” as a class member (not within robotPeriodic), then use this:

if (squeezer.get() > 0 != lastState) {
  solenoid.toggle();
  lastState = !lastState;
}

Assuming that the triggering device is a joystick or gamepad, this could be simplified by using getRawButtonPressed

Ah good call. I forgot those options were available outside of command-based. That said, squeezer is a SparkMax object in this case, so that wouldn’t work

It seems like in this scenario the code is trying to make sure solenoid commands aren’t in conflict with motor commands. Wouldn’t the better solution here be to always set the solenoid to the desired state, rather than toggling?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.