Should this code be working? - Beginner


package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Relay;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Victor;
public class RobotTemplate extends SimpleRobot {
    RobotDrive theRobot = new RobotDrive(2,1); //#
    Joystick driveStick = new Joystick(1); //# 
    Compressor compressor1 = new Compressor(1,1); //# 
    Relay spike = new Relay (1,1); //#
    Jaguar motorOne = new Jaguar(7); //#
    Jaguar motorTwo = new Jaguar(8); //# 
    Victor victor1 = new Victor(3);
    Victor victor2 = new Victor(4);
    public void autonomous() { //checks code every 50 seconds
        theRobot.setSafetyEnabled(false); //allows timer to function, 0.0); //-1 means drive forward
        Timer.delay(2.0); // allows robot to drive forward, 0.0); // sets drive speed to 0 (stops robot)
        Timer.delay(2.0);, 0.0);, 0.0);
        for (int x = 0; x < 5; x++) {
    public void operatorControl() {
    theRobot.setSafetyEnabled(false); //allows for tele-op to work
        theRobot.arcadeDrive(driveStick.getAxis(Joystick.AxisType.kY), -driveStick.getAxis(Joystick.AxisType.kX)); //functionality to drive robot
        while (isOperatorControl()) {
            theRobot.arcadeDrive(driveStick.getAxis(Joystick.AxisType.kY), -driveStick.getAxis(Joystick.AxisType.kX));
            if (driveStick.getTrigger()){
            //    spike.set(Relay.Value.kForward);
               // spike.set(Relay.Value.kReverse); 
            else {
            if (driveStick.getRawButton(4)){

 public void test() {

I want to know if two functions will work:


Currently, the driving is working and the motors are working but the compressor/relay/spike aren’t working.

Can someone also explain this:

Sometimes when I edit the compressor object and do something like (2,1) as parameters, it says output not updated often enough repeatedly. When I do 1,1 - the program starts with no errors and everything works except compressor and relay/spike. When I do 1,2 --> IT ALSO works except compressor/relay/spike… I double checked with the electrical team and they say the port numbers should be 1,1 but I’m not sure. I tested with 2,1 - 1,1 - 1,2 and nothing worked. For some port numbers, it would say output not updated enough and some combinations it wouldn’t. Does that mean it does connect to compressor or is a connection loose?

I’m thinking of switching over to iterative because it might be a bit easier.

You are telling the compressor to use Relay 1, and also allocate Relay 1 as an individual relay. You need to make sure they are using different relays. The code will cause an exception if you allocate a relay twice, which will cause the print of output not updated enough repeatedly. If you scroll back to the beginning, you would see the exception message and traceback.

Make sure to pay attention to the constructors you are using. Relay(1,1) allocates Relay 1 on Digital Module 1. Relay(2,1) allocates Relay 1 on Digital Module 2 (which you more then likely don’t have). Relay(1,2) allocates Relay 2 on Digital Module 1. Compressor(1,1) allocates a digital input for the pressure switch on digital input 1 and and a relay on relay 1, using the default digital module (1).

The compressor monitors the pressure switch on the digital input that you specify, and only turns on the compressor when the pressure is low. You need the pressure switch connected for the compressor to come on. Additionally, the start method should not be called in a loop. It creates it’s own look in a new task. You should move it before the while loop in teleop.

Do you think if I get this fixed, the code should work?

What if I do:

Compressor compressor1 = new Compressor(1,1); //#
Relay spike = new Relay (1,2); //#

This will keep there from being conflicts. Make sure your electrical team moves the compressor to relay 1 and the spike to relay 2.

You can look at the relay LEDs on the Digital Sidecar to see if the code is working, even if there isn’t a relay connected.

So it’s now just the matter of getting the constructor parameters correct?