Quote:
Originally Posted by Team 4939
Sorry for not replying earlier, but I just haven't been able to test the code that you all helped out with yet, due to exams and such. I should be able to test the system out tomorrow and I will post a reply letting you know how it worked out. I was able to get a picture: http://postimg.org/image/wvu8lykol/ . If that makes a difference to the code.
Also I was wondering something about where to plug the spike in, I pluged one end to the solenoid, and the other end into port 5 on my Digital side car.
I noticed in the code that Domenic Rodriguez posted :
Code:
// Pneumatics
Compressor compressor = new Compressor(1, 1);
Solenoid solenoid = new Solenoid(1);
DoubleSolenoid doubleSolenoid = new DoubleSolenoid(2, 3);
Ports 1, 2, and 3 are labeled.
Where should I plug my Spike into?
Thank You to all that helped me get this far, just a little more help is needed.
|
To clarify, are you planning on controlling your solenoid with a Spike Relay, or with the solenoid module on the cRIO?
The Solenoid and DoubleSolenoid classes only work for controlling solenoids through the solenoid module. If you are controlling your solenoid through a relay, you will need to use the
Relay class instead.
Judging by your picture, it looks like you are using a double solenoid. I've never controlled a solenoid through Spikes before,
but I believe you will need two Spikes, one for each side. Edit: Nope, see Mark McLeod's post below.
Updated 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;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.Relay;
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);
Relay spike = new Relay(2);
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 = mainStick.getY();
double 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
if (mainStick.getRawButton(1))
spike.set(Relay.Value.kForward);
else if (mainStick.getRawButton(2))
spike.set(Relay.Value.kReverse);
}
}
}