Operating Pneumatic Cylinders

FRC teams can use a solenoid valve as part of performing a variety of tasks, including shifting gearboxes and moving robot mechanisms. A solenoid valve is used to electronically switch a pressurized air line “on” or “off”. Solenoids are controlled by a robot’s Pneumatics Control Module, or Pneumatic Hub, which is in turn connected to the robot’s roboRIO via CAN. The easiest way to see a solenoid’s state is via the LEDs on the PCM or PH (which indicates if the valve is “on” or not). When un-powered, solenoids can be manually actuated with the small button on the valve body.

Single acting solenoids apply or vent pressure from a single output port. They are typically used either when an external force will provide the return action of the cylinder (spring, gravity, separate mechanism) or in pairs to act as a double solenoid. A double solenoid switches air flow between two output ports (many also have a center position where neither output is vented or connected to the input). Double solenoid valves are commonly used when you wish to control both the extend and retract actions of a cylinder using air pressure. Double solenoid valves have two electrical inputs which connect back to two separate channels on the solenoid breakout.

Single Solenoids in WPILib

Single solenoids in WPILib are controlled using the Solenoid class (Java / C++). To construct a Solenoid object, simply pass the desired port number (assumes default CAN ID) and pneumatics module type or CAN ID, pneumatics module type, and port number to the constructor. To set the value of the solenoid call set(true) to enable or set(false) to disable the solenoid output.

30  // Solenoid corresponds to a single solenoid.
31  // In this case, it's connected to channel 0 of a PH with the default CAN ID.
32  private final Solenoid m_solenoid = new Solenoid(PneumaticsModuleType.REVPH, 0);
88    /*
89     * The output of GetRawButton is true/false depending on whether
90     * the button is pressed; Set takes a boolean for whether
91     * to retract the solenoid (false) or extend it (true).
92     */
93    m_solenoid.set(m_stick.getRawButton(kSolenoidButton));
44  // Solenoid corresponds to a single solenoid.
45  // In this case, it's connected to channel 0 of a PH with the default CAN
46  // ID.
47  frc::Solenoid m_solenoid{frc::PneumaticsModuleType::REVPH, 0};
42  /*
43   * The output of GetRawButton is true/false depending on whether
44   * the button is pressed; Set takes a boolean for whether
45   * to retract the solenoid (false) or extend it (true).
46   */
47  m_solenoid.Set(m_stick.GetRawButton(kSolenoidButton));

Double Solenoids in WPILib

Double solenoids are controlled by the DoubleSolenoid class in WPILib (Java / C++). These are constructed similarly to the single solenoid but there are now two port numbers to pass to the constructor, a forward channel (first) and a reverse channel (second). The state of the valve can then be set to kOff (neither output activated), kForward (forward channel enabled) or kReverse (reverse channel enabled). Additionally, the CAN ID can be passed to the DoubleSolenoid if teams have a non-default CAN ID.

37  // DoubleSolenoid corresponds to a double solenoid.
38  // In this case, it's connected to channels 1 and 2 of a PH with the default CAN ID.
39  private final DoubleSolenoid m_doubleSolenoid =
40      new DoubleSolenoid(PneumaticsModuleType.REVPH, 1, 2);
100      m_doubleSolenoid.set(DoubleSolenoid.Value.kForward);
101      m_doubleSolenoid.set(DoubleSolenoid.Value.kReverse);
49  // DoubleSolenoid corresponds to a double solenoid.
50  // In this case, it's connected to channels 1 and 2 of a PH with the default
51  // CAN ID.
52  frc::DoubleSolenoid m_doubleSolenoid{frc::PneumaticsModuleType::REVPH, 1, 2};
54    m_doubleSolenoid.Set(frc::DoubleSolenoid::kForward);
55    m_doubleSolenoid.Set(frc::DoubleSolenoid::kReverse);

Toggling Solenoids

Solenoids can be switched from one output to the other (known as toggling) by using the .toggle() method.

Note

Since a DoubleSolenoid defaults to off, you will have to set it before it can be toggled.

Solenoid exampleSingle = new Solenoid(PneumaticsModuleType.CTREPCM, 0);
DoubleSolenoid exampleDouble = new DoubleSolenoid(PneumaticsModuleType.CTREPCM, 1, 2);

// Initialize the DoubleSolenoid so it knows where to start.  Not required for single solenoids.
exampleDouble.set(kReverse);

if (m_controller.getYButtonPressed()) {
   exampleSingle.toggle();
   exampleDouble.toggle();
}
frc::Solenoid exampleSingle{frc::PneumaticsModuleType::CTREPCM, 0};
frc::DoubleSolenoid exampleDouble{frc::PneumaticsModuleType::CTREPCM, 1, 2};

// Initialize the DoubleSolenoid so it knows where to start.  Not required for single solenoids.
exampleDouble.Set(frc::DoubleSolenoid::Value::kReverse);

if (m_controller.GetYButtonPressed()) {
   exampleSingle.Toggle();
   exampleDouble.Toggle();
}