Log in

View Full Version : Using Spike Relays in Java?


Negative 9
16-02-2013, 12:51
Can anyone explain to me the best way to use Relays in code? The API confuses me. There are several ways to construct the relays and set them to values and I'm having trouble understanding the differences between them.

I'm trying to use a relay to control a window motor so from what I can tell I am supposed to construct the relay like this:

relay = new Relay(1, Relay.Direction.kBoth);

and I'm supposed to control the Relay by doing something like this:

if(joyRight.getRawButton(4)) {
relay.set(Relay.Value.kON);
relay.set(Relay.Direction.kForward);
} else if(joyRight.getRawButton(5)) {
relay.set(Relay.Value.kON);
relay.set(Relay.Direction.kReverse);
} else {
relay.set(Relay.Value.kOff);
}

If that's all good then the other possibility is that it's wired incorrectly. Does anyone know which section of the DigitalSidecar the triple wire is supposed to be plugged in? The diagnostic light on the Relay is a solid yellow-orange color which I assume mean that it's been initialized but isn't receiving any signals.

Any and all help is appreciated!

gixxy
16-02-2013, 14:37
The Relay is hooked up to the Relay section on the Digital Sidecar (With the LED Recess).

Orange Light beens it is receiving no signal (or the kOff signal) which means it is powered.

In my code I usually don't use the direction part, I stick to:


Relay relay = new Relay(1); //Constructor
relay.set(Relay.Value.kForward); //Power flows Positive to Negative, light green
relay.set(Relay.Value.kOff); //No power flows, light orange
relay.set(Relay.Value.kReverse); //Power flows Negative to Positive, light red

ClockworkPirate
16-02-2013, 20:04
The Relay is hooked up to the Relay section on the Digital Sidecar (With the LED Recess).

Orange Light beens it is receiving no signal (or the kOff signal) which means it is powered.

In my code I usually don't use the direction part, I stick to:


Relay relay = new Relay(1); //Constructor
relay.set(Relay.Value.kForward); //Power flows Positive to Negative, light green
relay.set(Relay.Value.kOff); //No power flows, light orange
relay.set(Relay.Value.kReverse); //Power flows Negative to Positive, light red


We have our relays wired what seems to be correctly (PWMs from relay area on the sidecar, orange light), and my code is exactly like yours (besides variable names :P), but the relays won't do anything. No matter what I call set() with (I've tried all four Relay.Value values), the light stays orange. What am I doing wrong?

gixxy
16-02-2013, 20:18
I would have to see your code in its entirety.

ClockworkPirate
16-02-2013, 21:05
I have a field in my Shooter class with a field Relay pneuRelay, which I initialize in Shooter's constructor with pneuRelay = new Relay(1); (we have a relay plugged into the first plug on the sidecar). I call public void setForward()
{
pneuRelay.set(Relay.Value.kForward);
} on it, nothing happens.

There is kind of a bunch of abstracted stuff down to that "real" call, but nothing happens even when I put the call (new Relay(1).set(Relay.Value.kForward)) right in the constructor of our SimpleRobot subclass... It seems to me that either I'm not using the library right or the relay isn't wired correctly.

Here's Pastebins of my code if you still want to see it (this is with the port 1 initialization in the SimpleRobot constructor, so the one in Shooter.java is changed to 2 to avoid a conflict):
Robot2013.java (http://pastebin.com/mBJti8Zj) (SimpleRobot subclass)
DriveStation.java (http://pastebin.com/ikJ0CFM7) (has Shooter, DriveTrain, etc objects, interprets joystick controls)
Shooter.java (http://pastebin.com/XbbmEZuj) (controls the shooter motors, I'm trying to add the relay to control some related pneumatics)

Negative 9
17-02-2013, 16:06
The Relay is hooked up to the Relay section on the Digital Sidecar (With the LED Recess).

Orange Light beens it is receiving no signal (or the kOff signal) which means it is powered.

In my code I usually don't use the direction part, I stick to:


Relay relay = new Relay(1); //Constructor
relay.set(Relay.Value.kForward); //Power flows Positive to Negative, light green
relay.set(Relay.Value.kOff); //No power flows, light orange
relay.set(Relay.Value.kReverse); //Power flows Negative to Positive, light red

Thanks, this got our code working!