Pneumatics allocation

my pneumatics is wired correctly but when i try to create a new double solenoid object, it says that the ports that my wires are in are already allocated. can anyone help with this?

Please share your code, ideally a link to github (or similar)


package frc.robot.subsystems;

import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.PneumaticsModuleType;
import edu.wpi.first.wpilibj.DoubleSolenoid.Value;
import edu.wpi.first.wpilibj2.command.SubsystemBase;

public class testPiston extends SubsystemBase {
    DoubleSolenoid solenoid = new DoubleSolenoid(PneumaticsModuleType.CTREPCM, 4, 5);
    Compressor compressor = new Compressor(0, PneumaticsModuleType.CTREPCM);

    public testPiston() {

    public void startCompressor() {

    public void setUp() {

    public void setDown() {


package frc.robot.commands;

import java.util.function.BooleanSupplier;

import edu.wpi.first.wpilibj2.command.CommandBase;
import frc.robot.subsystems.testPiston;

public class enablePiston extends CommandBase {
    testPiston tPiston;
    BooleanSupplier aB;
    BooleanSupplier bB;

    public enablePiston(BooleanSupplier a, BooleanSupplier b) {
        aB = a;
        bB = b;
        tPiston = new testPiston();


    public void initialize() {
    public void execute() {
        if (aB.getAsBoolean()) {
        } else if (bB.getAsBoolean()) {

this is the error i’m getting:

ERROR  1  Unhandled exception: edu.wpi.first.hal.util.AllocationException: Channels 4 and 5 already allocated 
ERROR  1  The startCompetition() method (or methods called by it) should have handled the exception above.  

You’re creating an instance of the testPiston subsystem in the command. You’re also likely creating an instance of testPiston subsystem somewhere else (probably in RobotContainer, or possibly another instance of the enablePiston command). This is what causes the exception.

This may be helpful:

1 Like

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