Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Help Please!(Rookie Team) (http://www.chiefdelphi.com/forums/showthread.php?t=103124)

obot 17-02-2012 23:19

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

Ginto8 17-02-2012 23:42

Re: Help Please!(Rookie Team)
 
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:
Code:

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):
Code:

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

Re: Help Please!(Rookie Team)
 
Quote:

Originally Posted by Ginto8 (Post 1129227)
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:
Code:

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):
Code:

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!

Ginto8 18-02-2012 08:46

Re: Help Please!(Rookie Team)
 
Quote:

Originally Posted by NS_Radication (Post 1129254)
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

Re: Help Please!(Rookie Team)
 
Quote:

Originally Posted by NS_Radication (Post 1129254)
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

Re: Help Please!(Rookie Team)
 
There is a compressor method that handles the relay for you.
Code:

Compressor(int pressureSwitchChannel, int compressorRelayChannel)
is the constructor for a Compressor. It reads the pressure switch and handles the compressor relay.
Code:

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

Re: Help Please!(Rookie Team)
 
Awesome, but where does the code go ?

Fletch1373 18-02-2012 23:09

Re: Help Please!(Rookie Team)
 
Quote:

Originally Posted by Iron Drakes (Post 1129817)
Awesome, but where does the code go ?

You can add that code in the constructor.

jase728 19-02-2012 16:43

Re: Help Please!(Rookie Team)
 
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

Re: Help Please!(Rookie Team)
 
Quote:

Originally Posted by jase728 (Post 1130303)
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.


All times are GMT -5. The time now is 09:54.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi