Go to Post Coming soon to an Earth near you; an Australian team (or 2). Stay tuned. - Elgin Clock [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 17-02-2012, 23:19
obot obot is offline
Registered User
FRC #4181
 
Join Date: Feb 2012
Location: Blackduck
Posts: 5
obot is an unknown quantity at this point
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
Reply With Quote
  #2   Spotlight this post!  
Unread 17-02-2012, 23:42
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
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
Reply With Quote
  #3   Spotlight this post!  
Unread 18-02-2012, 00:23
NS_Radication's Avatar
NS_Radication NS_Radication is offline
Student
AKA: Marco Schoener
FRC #1369 (Minotaur)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2009
Location: Tampa
Posts: 88
NS_Radication is an unknown quantity at this point
Re: Help Please!(Rookie Team)

Quote:
Originally Posted by Ginto8 View Post
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!
__________________
Team 1369
Senior
Head Programmer (Java)
Head Electrician
Reply With Quote
  #4   Spotlight this post!  
Unread 18-02-2012, 08:46
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
Re: Help Please!(Rookie Team)

Quote:
Originally Posted by NS_Radication View Post
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
Reply With Quote
  #5   Spotlight this post!  
Unread 18-02-2012, 14:30
jesusrambo jesusrambo is offline
Self-Proclaimed Programmer Messiah
AKA: JD Russo
FRC #2035 (Robo Rockin' Bots)
Team Role: Programmer
 
Join Date: Feb 2012
Rookie Year: 2010
Location: Carmel, CA
Posts: 114
jesusrambo is an unknown quantity at this point
Re: Help Please!(Rookie Team)

Quote:
Originally Posted by NS_Radication View Post
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.
Reply With Quote
  #6   Spotlight this post!  
Unread 18-02-2012, 16:29
Patrickwhite's Avatar
Patrickwhite Patrickwhite is offline
May the North be with you
FRC #0610 (The Coyotes)
Team Role: Programmer
 
Join Date: Dec 2008
Rookie Year: 2008
Location: Toronto
Posts: 88
Patrickwhite is a glorious beacon of lightPatrickwhite is a glorious beacon of lightPatrickwhite is a glorious beacon of lightPatrickwhite is a glorious beacon of lightPatrickwhite is a glorious beacon of lightPatrickwhite is a glorious beacon of light
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.
__________________
while(!going.isTough());
tough.exit();

What will we do tonight, Warfa?
The same thing we do every night, Patrick. Sit and wait for Electrical.
Reply With Quote
  #7   Spotlight this post!  
Unread 18-02-2012, 21:27
Iron Drakes Iron Drakes is offline
Registered User
FRC #4181
 
Join Date: Jan 2012
Location: Blackduck, MN
Posts: 5
Iron Drakes is an unknown quantity at this point
Re: Help Please!(Rookie Team)

Awesome, but where does the code go ?
Reply With Quote
  #8   Spotlight this post!  
Unread 18-02-2012, 23:09
Fletch1373's Avatar
Fletch1373 Fletch1373 is offline
Registered User
AKA: Fletch
FRC #3181 (Panthers)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2004
Location: Rochester, NY
Posts: 251
Fletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud of
Re: Help Please!(Rookie Team)

Quote:
Originally Posted by Iron Drakes View Post
Awesome, but where does the code go ?
You can add that code in the constructor.
__________________
Student:
<04: FRC0213> <05-08: FRC1373>
Mentor:
<09-10: FRC0809> <11-12: FRC3555> <12-14: FRC0073> <15-??: FRC3181>
Volunteer:
<FTAA> <CSA> <Defense Coordinator> <Scorekeeper> <Robot Inspector> <Official Scorer>
2016 Tour:
CTWAT [DefCoord] > Pittsburgh[Mentor/DefCoord] > TVR[FTAA] > FLR[CSA] > NE DCMP[CSA] > CMP[CSA]
Reply With Quote
  #9   Spotlight this post!  
Unread 19-02-2012, 16:43
jase728 jase728 is offline
Registered User
AKA: Jase728
FRC #3210 (Falcons)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2009
Location: Hillsboro
Posts: 11
jase728 is an unknown quantity at this point
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
__________________
"In theory there is reality, but in reality there is no theory" - Erich Keane (FRC 2010 Build Season - Team 3210)
Reply With Quote
  #10   Spotlight this post!  
Unread 29-02-2012, 00:28
Fletch1373's Avatar
Fletch1373 Fletch1373 is offline
Registered User
AKA: Fletch
FRC #3181 (Panthers)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2004
Location: Rochester, NY
Posts: 251
Fletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud ofFletch1373 has much to be proud of
Re: Help Please!(Rookie Team)

Quote:
Originally Posted by jase728 View Post
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.
__________________
Student:
<04: FRC0213> <05-08: FRC1373>
Mentor:
<09-10: FRC0809> <11-12: FRC3555> <12-14: FRC0073> <15-??: FRC3181>
Volunteer:
<FTAA> <CSA> <Defense Coordinator> <Scorekeeper> <Robot Inspector> <Official Scorer>
2016 Tour:
CTWAT [DefCoord] > Pittsburgh[Mentor/DefCoord] > TVR[FTAA] > FLR[CSA] > NE DCMP[CSA] > CMP[CSA]
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 12:49.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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