View Full Version : Help Please!(Rookie Team)
I am looking for basic java programming code to turn on and off compressor. I have power from compressor connected to a spike relay per rules. I understand how to talk to a Jaguar, but believe that I plug PWM from spike into digital sidecar relay slots. IS this correct and if so please send a simple program that will use joystick(2) buttons 10 and 11 to turn power on and off to compressor using spike.
Thanks a million. NEAL
and or anyone else that can help
I don't really know the electrical side of things here, but I do know that there's a pretty simple method for using Spike relays: the Relay class.
Basically, you initialize one with the required port and the direction:
Relay relay = new Relay(PORT,direction); // direction can be Relay.Direction.kFoward,Relay.Direction.kReverse, or Relay.Direction.kBoth
Then you set it to one of four options (but it will throw an InvalidValueException if you set it to a direction it isn't configured for):
relay.set(Relay.Value.kOff); // 0v-0v, any direction
relay.set(Relay.Value.kForward); // 12v-0v, kForward or kBoth
relay.set(Relay.Value.kReverse); // 0v-12v, kReverse or kBoth
relay.set(Relay.Value.kOn); // 12v-12v, any direction
NS_Radication
18-02-2012, 00:23
I don't really know the electrical side of things here, but I do know that there's a pretty simple method for using Spike relays: the Relay class.
Basically, you initialize one with the required port and the direction:
Relay relay = new Relay(PORT,direction); // direction can be Relay.Direction.kFoward,Relay.Direction.kReverse, or Relay.Direction.kBoth
Then you set it to one of four options (but it will throw an InvalidValueException if you set it to a direction it isn't configured for):
relay.set(Relay.Value.kOff); // 0v-0v, any direction
relay.set(Relay.Value.kForward); // 12v-0v, kForward or kBoth
relay.set(Relay.Value.kReverse); // 0v-12v, kReverse or kBoth
relay.set(Relay.Value.kOn); // 12v-12v, any direction
Correction:
relay.set(Relay.Value.kForward or kReverse)
Should be
relay.setDirection(Relay.Direction.kForward or kReverse, or kBoth);
Hope this helps! Happy Competitions!
Correction:
relay.set(Relay.Value.kForward or kReverse)
Should be
relay.setDirection(Relay.Direction.kForward or kReverse, or kBoth);
Hope this helps! Happy Competitions!
setDirection() tells it what directions it CAN go in, while set() tells it which direction to actually go. If you're only setting your relay to Value.kOn or Value.kOff, then setting the direction is ok, but it still isn't a good idea because the relay is reinitialized and its value effectively set to kOff on every call to setDirection.
I'm getting all my info about the relay from the source (from sunspotfrcsdk/lib/WPILibJ/src/edu/wpi/first/wpilibj/Relay.java in this case), in case you want to check my info ;)
jesusrambo
18-02-2012, 14:30
Correction:
relay.set(Relay.Value.kForward or kReverse)
Should be
relay.setDirection(Relay.Direction.kForward or kReverse, or kBoth);
As much as I love your avatar, I have to say you're wrong on this. .set() is what actually sets the value of the relay, .setDirection() is just the possible directions it can be set. Many a screwup on our team has been caused by mixing those up.
Patrickwhite
18-02-2012, 16:29
There is a compressor method that handles the relay for you. Compressor(int pressureSwitchChannel, int compressorRelayChannel) is the constructor for a Compressor. It reads the pressure switch and handles the compressor relay.
Compressor compressor = new Compressor(1,1);
...
compressor.start();
is enough to get the compressor started. It will automatically be stopped when the pressure switch tells it to.
Iron Drakes
18-02-2012, 21:27
Awesome, but where does the code go ?
Fletch1373
18-02-2012, 23:09
Awesome, but where does the code go ?
You can add that code in the constructor.
if (!airCompressor.getPressureSwitchValue())//check if the compressor is working
{
airCompressor.setRelayValue(Relay.Value.kOn);
}
else
{
airCompressor.setRelayValue(Relay.Value.kOff);
}
^^^ You also need this in the continuous function
Fletch1373
29-02-2012, 00:28
if (!airCompressor.getPressureSwitchValue())//check if the compressor is working
{
airCompressor.setRelayValue(Relay.Value.kOn);
}
else
{
airCompressor.setRelayValue(Relay.Value.kOff);
}
^^^ You also need this in the continuous function
no you don't... if the Compressor object is constructed properly, it will handle turning itself on and off automatically based on the pressure switch value.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.