Programming the Air Compressor and Pressure Switch

I am from a rookie team in Canada, and we are having trouble programming the air compressor and the pressure switch. I have a background in programming, and I am fairly fluent with Java and have been using the FRC WPI library Documentation. Here is part of my code:

import edu.wpi.first.wpilibj.Compressor;

Compressor compress = new Compressor(1, 1);

public void robotInit(){

It might also be something to do with the wiring. Here is the thread about the wiring in the Electrical Section:

Look at the status lights on the Digital Sidecar for the Relay.
The lights are in the trough in front of the Relay pins.
You should see a green LED if the software is trying to start the compressor.

Is the robot enabled from the Driver Station?
Is the Spike status light glowing orange?

There is a test program you can use to make sure it’s not a code issue.
From the Getting Started window -> Support -> Find FRC examples…
Look under the pneumatics folder and pick an example with a compressor.
Change the example’s cRIO IP to match your cRIO, i.e., right-click on cRIO Target and choose Properties to change the IP.

Just use the Run button to test it on your cRIO.

Yes, the Robot was enabled from the Driver Station, and the light on the spike relay was orange the whole time. From what I know about the robotMain funcion is that it calls the robotInit function once and so according to my code it should be running. I will check out the examples. Thank you for your help.

The Spikes orange status light only tells us that the Spike is receiving 12v power.
The Spike status light isn’t like the motor controller statuses where they indicate a loss of communication by blinking.

The Relay status on the Digital Sidecar will tell you if the code is ordering the compressor on or not.
The robot does have to be Enabled by the Driver Station for the compressor to be allowed to start.

Sorry, the examples I pointed you to were for LabVIEW.
There aren’t any pre-made out-of-the-box Java test programs.
(We should write and publish some of those for the more basic function tests.)

How we did it was we made a compressor object.

Compressor myCompressor = new Compressor(1,1); //the first number being the digitalIO port for the compressor, and the second being the relay port the spike is plugged into

And then in operatorControl() and where ever else before you start looping do myCompressor.start();

If that doesn’t make sense please tell me and I’ll clarify.

Also we had a problem where our code was correct but the ribbon cable from the c-rio to the sidecar was not working, and when we replaced that it worked.

EDIT: example

package edu.wpi.first.wpilibj.templates;

import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.Relay;
import edu.wpi.first.wpilibj.SimpleRobot;

public class RobotTemplate extends SimpleRobot 

    private int spikePort = 1;
    private int compressorPort = 1;

    private Compressor airCompressor;

    public void robotInit()
        airCompressor = new Compressor(compressorPort, spikePort);
    public void autonomous() 
        System.err.println("Entering autonomous:");
    public void operatorControl() 
        System.err.println("Entering teleop:");
   public void test()
       System.err.println("Entering Test:");

We are using the same code as that which was given on the WPI tutorials. However, when we enable the robot, the compressor does not turn on and the LED’s beside the relay ports on the sidecar do not turn on either. However, I am sure that there isn’t any errors with the code since it is identical to the tutorials. Does anyone know what could be happening? Could the spike relay or the sidecar be faulty?

1 Like

If there is no light on the DSC relay channel the spike isn’t malfunctioning (not yet at least).

How is your pressure switch wired?

You should have a signal wire and ground wire going to the switch. This cable should plug into a digital I/O port on the DSC.
See the wires on the pressure switch in this figure

  1. put together a test project in RobotBuilder that has one subsystem, one relay output (where the compressor is) and one digital input (where the switch is).
  2. Load the project into the robot.
  3. Put the robot into test mode
  4. Go into the livewindow and manually try to turn the compressor on.
  5. If the compressor doesn’t fire up, you’ve got data flow or power problem; if the compressor fires up, you know your wiring is good.