Package edu.wpi.first.wpilibj
Class Relay
- java.lang.Object
-
- edu.wpi.first.wpilibj.MotorSafety
-
- edu.wpi.first.wpilibj.Relay
-
- All Implemented Interfaces:
Sendable
,AutoCloseable
public class Relay extends MotorSafety implements Sendable, AutoCloseable
Class for VEX Robotics Spike style relay outputs. Relays are intended to be connected to Spikes or similar relays. The relay channels controls a pair of channels that are either both off, one on, the other on, or both on. This translates into two Spike outputs at 0v, one at 12v and one at 0v, one at 0v and the other at 12v, or two Spike outputs at 12V. This allows off, full forward, or full reverse control of motors without variable speed. It also allows the two channels (forward and reverse) to be used independently for something that does not care about voltage polarity (like a solenoid).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Relay.Direction
The Direction(s) that a relay is configured to operate in.static class
Relay.InvalidValueException
This class represents errors in trying to set relay values contradictory to the direction to which the relay is set.static class
Relay.Value
The state to drive a Relay to.
-
Constructor Summary
Constructors Constructor Description Relay(int channel)
Relay constructor given a channel, allowing both directions.Relay(int channel, Relay.Direction direction)
Relay constructor given a channel.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addChild(Object child)
Add a child component.void
close()
Relay.Value
get()
Get the Relay State.int
getChannel()
Get the channel number.String
getDescription()
String
getName()
Gets the name of thisSendable
object.String
getSubsystem()
Gets the subsystem name of thisSendable
object.void
initSendable(SendableBuilder builder)
Initializes thisSendable
object.void
set(Relay.Value value)
Set the relay state.void
setDirection(Relay.Direction direction)
Set the Relay Direction.void
setName(String name)
Sets the name of thisSendable
object.protected void
setName(String moduleType, int channel)
Sets the name of the sensor with a channel number.protected void
setName(String moduleType, int moduleNumber, int channel)
Sets the name of the sensor with a module and channel number.void
setSubsystem(String subsystem)
Sets the subsystem name of thisSendable
object.void
stopMotor()
-
Methods inherited from class edu.wpi.first.wpilibj.MotorSafety
check, checkMotors, feed, getExpiration, isAlive, isSafetyEnabled, setExpiration, setSafetyEnabled
-
-
-
-
Constructor Detail
-
Relay
public Relay(int channel, Relay.Direction direction)
Relay constructor given a channel.- Parameters:
channel
- The channel number for this relay (0 - 3).direction
- The direction that the Relay object will control.
-
Relay
public Relay(int channel)
Relay constructor given a channel, allowing both directions.- Parameters:
channel
- The channel number for this relay (0 - 3).
-
-
Method Detail
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
-
getName
public final String getName()
Description copied from interface:Sendable
Gets the name of thisSendable
object.
-
setName
public final void setName(String name)
Description copied from interface:Sendable
Sets the name of thisSendable
object.
-
setName
protected final void setName(String moduleType, int channel)
Sets the name of the sensor with a channel number.- Parameters:
moduleType
- A string that defines the module name in the label for the valuechannel
- The channel number the device is plugged into
-
setName
protected final void setName(String moduleType, int moduleNumber, int channel)
Sets the name of the sensor with a module and channel number.- Parameters:
moduleType
- A string that defines the module name in the label for the valuemoduleNumber
- The number of the particular module typechannel
- The channel number the device is plugged into (usually PWM)
-
getSubsystem
public final String getSubsystem()
Description copied from interface:Sendable
Gets the subsystem name of thisSendable
object.- Specified by:
getSubsystem
in interfaceSendable
- Returns:
- Subsystem name
-
setSubsystem
public final void setSubsystem(String subsystem)
Description copied from interface:Sendable
Sets the subsystem name of thisSendable
object.- Specified by:
setSubsystem
in interfaceSendable
- Parameters:
subsystem
- subsystem name
-
addChild
protected final void addChild(Object child)
Add a child component.- Parameters:
child
- child component
-
set
public void set(Relay.Value value)
Set the relay state.Valid values depend on which directions of the relay are controlled by the object.
When set to kBothDirections, the relay can be set to any of the four states: 0v-0v, 12v-0v, 0v-12v, 12v-12v
When set to kForwardOnly or kReverseOnly, you can specify the constant for the direction or you can simply specify kOff and kOn. Using only kOff and kOn is recommended.
- Parameters:
value
- The state to set the relay.
-
get
public Relay.Value get()
Get the Relay State.Gets the current state of the relay.
When set to kForwardOnly or kReverseOnly, value is returned as kOn/kOff not kForward/kReverse (per the recommendation in Set)
- Returns:
- The current state of the relay as a Relay::Value
-
getChannel
public int getChannel()
Get the channel number.- Returns:
- The channel number.
-
stopMotor
public void stopMotor()
- Specified by:
stopMotor
in classMotorSafety
-
getDescription
public String getDescription()
- Specified by:
getDescription
in classMotorSafety
-
setDirection
public void setDirection(Relay.Direction direction)
Set the Relay Direction.Changes which values the relay can be set to depending on which direction is used
Valid inputs are kBothDirections, kForwardOnly, and kReverseOnly
- Parameters:
direction
- The direction for the relay to operate in
-
initSendable
public void initSendable(SendableBuilder builder)
Description copied from interface:Sendable
Initializes thisSendable
object.- Specified by:
initSendable
in interfaceSendable
- Parameters:
builder
- sendable builder
-
-