Our code will deploy and run for about five seconds with the compressor on before our code crashes. Here is our code,
/----------------------------------------------------------------------------/
/* Copyright © 2017-2018 FIRST. All Rights Reserved. /
/ Open Source Software - may be modified and shared by FRC teams. The code /
/ must be accompanied by the FIRST BSD license file in the root directory of /
/ the project. /
/----------------------------------------------------------------------------*/
package frc.robot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.PWMVictorSPX;
import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.drive.MecanumDrive;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.Relay;
import static edu.wpi.first.wpilibj.DoubleSolenoid.Value.*;
/**
- This is a demo program showing how to use Mecanum control with the RobotDrive
- class.
*/
public class Robot extends TimedRobot {
private static final int kFrontLeftChannel = 2;
private static final int kRearLeftChannel = 3;
private static final int kFrontRightChannel = 1;
private static final int kRearRightChannel = 0;
private static final int kJoystickChannel = 0;
private MecanumDrive m_robotDrive;
private Joystick m_stick;
Compressor airTrapper = new Compressor();
DoubleSolenoid Crucifix = new DoubleSolenoid(1, 2);
Solenoid climbyArms = new Solenoid(3);
Relay relay1;
////////////Compressor Stuff///////////////
boolean enabled = airTrapper.enabled();
boolean pressureSwitch = airTrapper.getPressureSwitchValue();
double current = airTrapper.getCompressorCurrent();
@Override
public void robotInit() {
PWMVictorSPX frontLeft = new PWMVictorSPX(kFrontLeftChannel);
PWMVictorSPX rearLeft = new PWMVictorSPX(kRearLeftChannel);
PWMVictorSPX frontRight = new PWMVictorSPX(kFrontRightChannel);
PWMVictorSPX rearRight = new PWMVictorSPX(kRearRightChannel);
Relay relay1 = new Relay(0);
airTrapper.start();
climbyArms.set(true);
climbyArms.set(false);
Crucifix.set(DoubleSolenoid.Value.kOff);
Crucifix.set(DoubleSolenoid.Value.kForward);
Crucifix.set(DoubleSolenoid.Value.kReverse);
frontLeft.setInverted(true);
rearLeft.setInverted(true);
m_robotDrive = new MecanumDrive(frontLeft, rearLeft, frontRight, rearRight);
m_stick = new Joystick(kJoystickChannel);
}
@Override
public void teleopPeriodic() {
// Use the joystick X axis for lateral movement, Y axis for forward
// movement, and Z axis for rotation.
m_robotDrive.driveCartesian(m_stick.getX(), m_stick.getY(),
m_stick.getZ(), 0.0);
Crucifix = new DoubleSolenoid(1, 2);
if (m_stick.getRawButton(1)){
Crucifix.set(DoubleSolenoid.Value.kForward);
}
else if(m_stick.getRawButton(2)){
Crucifix.set(DoubleSolenoid.Value.kReverse);
}
else {
Crucifix.set(DoubleSolenoid.Value.kOff);
}
}
}