The compressor is controlled automatically through the
Compressor class. Simply pass the Pressure Switch and Relay channels to the constructor and call Compressor#start() in robotInit() and you should be good to go. If desired, it can be disabled with Compressor#stop().
Solenoids come in two varieties:
Solenoids and
DoubleSolenoids. Single solenoids can be set true or false, while double solenoids are typically set to DoubleSolenoid.Value.kForward, DoubleSolenoid.Value.kReverse, or DoubleSolenoid.Value.kOff.
A simple example incorporating your code:
Code:
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Timer;
public class RobotTemplate extends SimpleRobot {
RobotDrive chassis = new RobotDrive(1,2);
Joystick mainStick = new Joystick(1);
Jaguar jaguar = new Jaguar(3);
Jaguar jag = new Jaguar(4);
// Pneumatics
Compressor compressor = new Compressor(1, 1);
Solenoid solenoid = new Solenoid(1);
DoubleSolenoid doubleSolenoid = new DoubleSolenoid(2, 3);
public void robotInit() {
compressor.start();
}
public void autonomous(){
chassis.setSafetyEnabled(false);
chassis.drive (-0.5, 0.08);
Timer.delay(2.0);
chassis.drive (0, 0.0);
}
public void operatorControl() {
chassis.setSafetyEnabled(true);
while (isOperatorControl() && isEnabled()) {
double speed;
double rot;
speed = mainStick.getY();
rot = -mainStick.getX();
chassis.arcadeDrive (speed, rot);
if (mainStick.getRawButton(3)){
jag.set(1);
jaguar.set(-1);
}
else if (mainStick.getRawButton(4)){
jaguar.set(-1);
jag.set(1);
}
else{
jaguar.set(0);
jag.set(0);
}
// Solenoid
solenoid.set(mainStick.getRawButton(1);
if (mainStick.getRawButton(2))
doubleSolenoid.set(DoubleSolnoid.Value.kForward);
else
doubleSolenoid.set(DoubleSolenoid.Value.kOff);
}
}
public void test() {
}
}
Also, you might want to check out these articles from the WPILib docs at ScreenSteps Live:
http://wpilib.screenstepslive.com/s/...for-pneumatics
http://wpilib.screenstepslive.com/s/...ders-solenoids