Telling WPILib Which Module You Have#
Every pneumatics class takes a PneumaticsModuleType — REVPH for the REV Pneumatic Hub or CTREPCM for the CTRE PCM. WPILib's Solenoid, DoubleSolenoid, and Compressor classes do the rest; the controller hardware handles closed-loop compressor control automatically.
Single Solenoid#
A Solenoid controls one channel. Construct it with the module type and channel, then turn it on or off:
Solenoid exampleSolenoid = new Solenoid(PneumaticsModuleType.REVPH, 0);
exampleSolenoid.set(true); // energize
exampleSolenoid.set(false); // de-energize (springs back)
exampleSolenoid.toggle(); // flip current state
Double Solenoid#
A DoubleSolenoid takes a forward channel and a reverse channel, and is set to one of three states: kForward, kReverse, or kOff:
DoubleSolenoid exampleDouble =
new DoubleSolenoid(PneumaticsModuleType.CTREPCM, 1, 2);
exampleDouble.set(DoubleSolenoid.Value.kForward);
exampleDouble.set(DoubleSolenoid.Value.kReverse);
exampleDouble.set(DoubleSolenoid.Value.kOff); // both off, holds last air state
A DoubleSolenoid defaults to kOff, so you must set() it before toggle() will work. You can also pass an explicit CAN ID, e.g. new DoubleSolenoid(9, PneumaticsModuleType.REVPH, 4, 5).
Running the Compressor#
The Compressor class manages automatic compressor control. There are three modes:
Compressor compressor = new Compressor(PneumaticsModuleType.REVPH);
// 1) Digital: run until the pressure switch reports full. Works on PH and PCM.
compressor.enableDigital();
// 2) Analog: PH only - run while pressure is between min and max (psi)
compressor.enableAnalog(70, 120);
// 3) Hybrid: PH only - analog range AND the digital switch agree it is not full
compressor.enableHybrid(70, 120);
compressor.disable(); // stop automatic control
double psi = compressor.getPressure(); // live pressure (PH analog only)
Closed-loop (digital) control is enabled by default when a Compressor is constructed, so simply creating the object usually starts the compressor running under pressure-switch control once the robot is enabled.
Best Practices#
- Put solenoid objects in a subsystem and expose methods like
extend()/retract()rather than callingset()from all over your code. - For double solenoids, decide a sensible disabled/init state (
kForward,kReverse, orkOff). getPressure()returns valid data only with the REV analog sensor on a PH; on a PCM use the digital switch state instead.- Test on the bench with the REV Hardware Client before relying on robot code.
the part worth keeping
Key takeaways
- Every pneumatics class takes PneumaticsModuleType.REVPH or CTREPCM; the hardware handles compressor closed-loop control.
- Single solenoid: Solenoid(module, channel) with set(true/false) and toggle().
- Double solenoid: DoubleSolenoid(module, fwd, rev) set to kForward, kReverse, or kOff; it defaults to kOff.
- Compressor modes: enableDigital() (any module), enableAnalog(min,max) and enableHybrid(min,max) (PH only); getPressure() needs the PH analog sensor.
Mechanical, Build & PneumaticsBuilding, Wiring, and Programming a Pneumatic Systemlesson 3 of 4
Keep going
Take the quiz+10 XP with an accountMore in Building, Wiring, and Programming a Pneumatic System
where this came from
Sources and corrections
This lesson is AI-assisted: drafted from primary sources, then reviewed and edited by hand. Errors still get through. When one is reported we fix it and write down what changed, in public, in the corrections log.
sources and further reading
- docs.wpilib.orgWPILib Docs - Operating pneumatic cylinders (Solenoids)
- docs.wpilib.orgWPILib Docs - Generating and Storing Pressure (Compressor)
- github.wpilib.orgWPILib API - Solenoid / DoubleSolenoid / Compressor
clipped to this lesson
Articles that go further on this
The lesson gets you through the topic. These go wider on it, and they read in one sitting.
- 9 min readFRC Pneumatics: How to Design, Wire, and Program a Pneumatic SystemComplete FRC pneumatics guide: components, the REV Pneumatic Hub vs PCM, single vs double solenoids, safe wiring, WPILib programming, and the 60/120 psi limits./blogread it
- 7 min readFRC Programming Languages: Java vs C++ vs PythonAn honest, beginner-friendly comparison of the three WPILib-supported FRC languages — Java, C++, and Python (RobotPy) — with vendor support and how to choose./blogread it
- 7 min readPractice FRC Programming Without a Robot: WPILib SimulationPractice FRC programming without a robot using WPILib simulation: run real robot code on your laptop, drive a virtual robot, model physics, and test./blogread it
answer sheet
Lesson quiz
All 3 right completes the lesson. Miss one and only that question comes back, anything you already answered correctly stays banked.
0 of 3 answered
01In WPILib, how many output channels does a DoubleSolenoid use and what states can it hold?
02Which value must you pass for the PneumaticsModuleType when constructing a Solenoid on a REV Pneumatic Hub?
03What is true about closed-loop compressor control in WPILib by default?
Answer every question to submit.
All 47 lessons in Mechanical, Build & Pneumaticsopenclose
01 / prerequisites
02 / drivetrains
03 / power-transmission
04 / structure-materials-fasteners
05 / mechanisms-fabrication-assembly
06 / pneumatics-fundamentals
07 / pneumatic-components
08 / build-wire-program
09 / safety-rules-testing
10 / worked-examples-mini-projects
- Not read yet:Mini-Project 1: A Single-Jointed Arm From Math to Motion
- Not read yet:Mini-Project 2: A Two-Stage Cascade Elevator
- Not read yet:Mini-Project 3: A Velocity-Controlled Flywheel Shooter
- Not read yet:Mini-Project 4: A Pivoting Roller Intake
- Not read yet:Mini-Project 5: Integrating a COTS Swerve Module
11 / common-mistakes-troubleshooting
- Not read yet:Pneumatics Won't Fire: A Full Diagnostic Tree
- Not read yet:The Robot Won't Drive Straight (and Other Drivetrain Sins)
- Not read yet:Gearboxes That Grenade and Fasteners That Vibrate Loose
- Not read yet:Closed-Loop Mechanisms That Oscillate, Sag, or Stall
- Not read yet:Field-Ready Reliability: Inspection, Spares, and the Pit Checklist
12 / advanced-techniques-case-studies
- Not read yet:Characterizing Any Mechanism with SysId
- Not read yet:Simulation-Driven Design with WPILib Physics Models
- Not read yet:Motion Profiling and Superstructure Coordination
- Not read yet:Designing for Weight, Stiffness, and Manufacturability
- Not read yet:Case Studies: Learning From Open Alliance Robots