Quote:
|
From my understanding, you would use either a Relay or the Solenoid class, but not both. Is that correct? Assuming the OP's solenoid valve is wired to a Spike Relay, the code should work but the Solenoid instance "piston" is not serving any purpose and could be removed.
|
Yes, I should have paid more attention to the original code.
You would choose either the Relay or Solenoid class to control the output device. Using both classes simultaneously and wiring both hardware outputs to a solenoid valve would be like wiring two motor controllers to a single motor.
Code:
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Relay;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.Victor;
public class MyRobot extends SimpleRobot {
RobotDrive theRobot;
SpeedController leftMotor, rightMotor;
Compressor compressor;
Relay piston;
//These need to match your wiring on the DSC
//Digital Inputs/Outputs
int compressorSwitchChan = 1;
//Relay Channels
int compressorRelayChan = 1;
int pistonRelayChan = 2;
//PWM Channels
int leftMotorChan = 1;
int rightMotorChan = 2;
robotInit() {
//These need to match the motor type you are using.
//If you are using Jaguars or Talons, use thier respective class.
leftMotor = new Victor(leftMotorChan);
rightMotor = new Victor(rightMotorChan);
theRobot = new RobotDrive(leftMotor, rightMotor);
piston = new Relay(pistonRelayChan);
compressor = new Compressor(compressorSwitchChan, compressorRelayChan);
compressor.start();
}
public void autonomous() { //checks code every 50 seconds
theRobot.setSafetyEnabled(false);
theRobot.drive(-0.5, 0.0);
Timer.delay(2.0);
theRobot.drive(0.0, 0.0);
for (int x = 0; x < 5; x++) {
piston.set(Relay.Value.kForward);
timer.delay(1.0);
piston.set(Relay.Value.kReverse);
timer.delay(1.0);
}
}
public void operatorControl() {
//your teleoperated code here...
}
}
This isn't tested, but should be pretty close to correct.