Compressor not activating

My team has assembled a pneumatics system and has wired it according to this diagram:

Untitled

For some reason, the Compressor is not activating automatically, but I am seeing the following warning and error that I think might be the culprit:

 	at frc.robot.Main.main(Main.java:27)  	at edu.wpi.first.wpilibj.RobotBase.startRobot(RobotBase.java:348)  	at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:276)  	at edu.wpi.first.wpilibj.TimedRobot.startCompetition(TimedRobot.java:64)  	at frc.robot.Robot.robotInit(Robot.java:33)  	at frc.robot.RobotContainer.<init>(RobotContainer.java:43)  	at frc.robot.commands.PneumaticsRetractPistonCommand.<init>(PneumaticsRetractPistonCommand.java:15)  	at frc.robot.subsystems.PneumaticsSubsystem.<init>(PneumaticsSubsystem.java:32)  	at edu.wpi.first.wpilibj.DoubleSolenoid.<init>(DoubleSolenoid.java:45)  	at edu.wpi.first.wpilibj.DoubleSolenoid.<init>(DoubleSolenoid.java:64)  	at edu.wpi.first.hal.SolenoidJNI.initializeSolenoidPort(Native Method) 

5:22:44.598 PM
Warning  1  Loop time of 0.02s overrun
  edu.wpi.first.wpilibj.IterativeRobotBase.printLoopOverrunMessage(IterativeRobotBase.java:309)  	disablePeriodic(): 0.005306s  	disabledInit(): 0.006700s  	SmartDashboard.updateValues(): 0.029240s 

Below is our code, which uses a DoubleSolenoid.

package frc.robot.subsystems;

import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj2.command.SubsystemBase;

public class PneumaticsSubsystem extends SubsystemBase {

  /*
  The Pneumatics Control Module (PCM) we will be using has
  been given the default CAN id of 0. This means we do not
  have to specify an id in the DoubleSolenoid constructor.

  In the DoubleSolenoid constructor, we only need to specify
  the port numbers on which the double solenoid is connected
  to the PCM (in our case, 1 and 2).
  */
  private DoubleSolenoid doubleSolenoid;

  /**
   * Creates a new PneumaticsSubsystem.
   */
  public PneumaticsSubsystem() {
    super(); //add this
    try {
      doubleSolenoid = new DoubleSolenoid(0, 1);
    } catch(Exception e) {
      e.printStackTrace();
    }
    
  }

  @Override
  public void periodic() {
    // This method will be called once per scheduler run
  }

  public void extendPiston() {
    //Should extend the piston
    doubleSolenoid.set(DoubleSolenoid.Value.kForward);
  }

  public void retractPiston() {
    //Should retract the piston
    doubleSolenoid.set(DoubleSolenoid.Value.kReverse);
  }
}

package frc.robot.commands;

import edu.wpi.first.wpilibj2.command.CommandBase;

import frc.robot.subsystems.PneumaticsSubsystem;

public class PneumaticsExtendPistonCommand extends CommandBase {

  //Member variables will be subsystems that the command will be executed on:

  PneumaticsSubsystem pneumaticsSubsystem;

  //Pass in an instance of all the required subsystems in the constructor.

  //and set them to the member variables.

  public PneumaticsExtendPistonCommand(PneumaticsSubsystem pneumatics) {

    // Use addRequirements() here to declare subsystem dependencies.

    pneumaticsSubsystem = pneumatics;

    addRequirements(pneumaticsSubsystem);

  }

  // Called when the command is initially scheduled.

  @Override

  public void initialize() {

  }

  // Called every time the scheduler runs while the command is scheduled.

  @Override

  public void execute() {

    pneumaticsSubsystem.extendPiston(); //This is the command to execute -- extend the 

    System.out.println("Extending Piston!");

  }

  // Called once the command ends or is interrupted.

  @Override

  public void end(boolean interrupted) {

  }

  // Returns true when the command should end.

  @Override

  public boolean isFinished() {

    return false;

  }

}

package frc.robot.commands;

import edu.wpi.first.wpilibj2.command.CommandBase;

import frc.robot.subsystems.PneumaticsSubsystem;

public class PneumaticsRetractPistonCommand extends CommandBase {

  private PneumaticsSubsystem pneumaticsSubsystem = new PneumaticsSubsystem();

  /**

   * Creates a new PneumaticsRetractPistonCommand.

   */

  public PneumaticsRetractPistonCommand(PneumaticsSubsystem pneumaticsSubsystem) {

    // Use addRequirements() here to declare subsystem dependencies.

    this.pneumaticsSubsystem = pneumaticsSubsystem;

    addRequirements(this.pneumaticsSubsystem);

  }

  // Called when the command is initially scheduled.

  @Override

  public void initialize() {

  }

  // Called every time the scheduler runs while the command is scheduled.

  @Override

  public void execute() {

    pneumaticsSubsystem.retractPiston();

    System.out.println("Retracting Piston!");

  }

  // Called once the command ends or is interrupted.

  @Override

  public void end(boolean interrupted) {

  }

  // Returns true when the command should end.

  @Override

  public boolean isFinished() {

    return false;

  }

}

public class RobotContainer {

  /*
  Specify what port (as labeled on the FRC Driver's Station)
  the physical controller is connected to. This is listed in
  the Driver Station's "USB order list". If the controller is
  the only thing attached to the computer, then the port is
  almost always 0.  You should double check, though.
  */
  public static Joystick controller = new Joystick(0); //This variable represents the physical game controller

  //Pneumatics Subsystems and Commands
  PneumaticsSubsystem pneumaticsSubsystem = new PneumaticsSubsystem();
  PneumaticsExtendPistonCommand pneumaticsExtendPistonCommand = new PneumaticsExtendPistonCommand(pneumaticsSubsystem);
  PneumaticsRetractPistonCommand pneumaticsRetractPistonCommand = new PneumaticsRetractPistonCommand(pneumaticsSubsystem);



  //robot subsystem variable to be used when it needs to be triggered:
  private final DriveTrainSubsystem driveTrainSubsystem = new DriveTrainSubsystem();

  // The robot's subsystems and commands are defined here...
  private final ExampleSubsystem m_exampleSubsystem = new ExampleSubsystem();
  private final ExampleCommand m_autoCommand = new ExampleCommand(m_exampleSubsystem);



  /**
   * The container for the robot.  Contains subsystems, OI devices, and commands.
   */
  public RobotContainer() {
    // Configure the button bindings
    configureButtonBindings();
  }

  /**
   * Use this method to define your button->command mappings.  Buttons can be created by
   * instantiating a {@link GenericHID} or one of its subclasses ({@link
   * edu.wpi.first.wpilibj.Joystick} or {@link XboxController}), and then passing it to a
   * {@link edu.wpi.first.wpilibj2.command.button.JoystickButton}.
   */
  private void configureButtonBindings() {

    //Map buttons 3 and 4 on the controller to extend and retract the piston, respectively:
    final JoystickButton extendPistonButton = new JoystickButton(controller, 5);
    final JoystickButton retractPistonButton = new JoystickButton(controller, 6);

    //Define each button's behaviour:
    extendPistonButton.whenHeld(pneumaticsExtendPistonCommand);
    retractPistonButton.whenHeld(pneumaticsRetractPistonCommand);

    //---------------------------------------------
    //selecting the gamepad's L1 button
    final JoystickButton L_1Button = new JoystickButton(controller, 4);

    //when pressed, trigger command:
    L_1Button.whenHeld(new MoveMotorCommand(driveTrainSubsystem));
  }


  /**
   * Use this to pass the autonomous command to the main {@link Robot} class.
   *
   * @return the command to run in autonomous
   */
  public Command getAutonomousCommand() {
    // An ExampleCommand will run in autonomous
    return m_autoCommand;
  }
}

What is the CAN id of the PCM?

The CAN id is 0, so there was no need to specify it explicitly (or so we think!)

Does the solenoid work?

Did you call the compressor class? Didn’t see it in your code.

1 Like

Instantiating the Compressor class is not required, you just need at least one solenoid. OP, try shorting the pressure switch momentarily when the robot is enabled. Also use Phoenix Tuner to check for faults / status on the PCM

1 Like

In PneumaticsRetractPistonCommand you creating a second instance of PneumaticsSubsystem at this line:

private PneumaticsSubsystem pneumaticsSubsystem = new PneumaticsSubsystem();

It should just be:

private PneumaticsSubsystem pneumaticsSubsystem;

The second subsystem tries to use the same ports as the first from RobotContainer and results in the exception you are seeing.

I’m not sure why you’ve created another thread here, either way I ask the same questions as in your other thread. Please answer them either here or there.
Or is this thread for a different issue that I’m missing?