public class Relay extends SendableBase implements MotorSafety, Sendable
Modifier and Type | Class and Description |
---|---|
static class |
Relay.Direction
The Direction(s) that a relay is configured to operate in.
|
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.
|
DEFAULT_SAFETY_EXPIRATION
Constructor and Description |
---|
Relay(int channel)
Relay constructor given a channel, allowing both directions.
|
Relay(int channel,
Relay.Direction direction)
Relay constructor given a channel.
|
Modifier and Type | Method and Description |
---|---|
void |
free()
Free the resources used by this object.
|
Relay.Value |
get()
Get the Relay State.
|
int |
getChannel()
Get the channel number.
|
java.lang.String |
getDescription() |
double |
getExpiration() |
void |
initSendable(SendableBuilder builder)
Initializes this
Sendable object. |
boolean |
isAlive() |
boolean |
isSafetyEnabled() |
void |
set(Relay.Value value)
Set the relay state.
|
void |
setDirection(Relay.Direction direction)
Set the Relay Direction.
|
void |
setExpiration(double timeout) |
void |
setSafetyEnabled(boolean enabled) |
void |
stopMotor() |
addChild, getName, getSubsystem, setName, setName, setName, setSubsystem
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getName, getSubsystem, setName, setName, setSubsystem
public Relay(int channel, Relay.Direction direction)
channel
- The channel number for this relay (0 - 3).direction
- The direction that the Relay object will control.public Relay(int channel)
channel
- The channel number for this relay (0 - 3).public void free()
SendableBase
free
in class SendableBase
public void set(Relay.Value value)
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.
value
- The state to set the relay.public Relay.Value get()
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)
public int getChannel()
public void setExpiration(double timeout)
setExpiration
in interface MotorSafety
public double getExpiration()
getExpiration
in interface MotorSafety
public boolean isAlive()
isAlive
in interface MotorSafety
public void stopMotor()
stopMotor
in interface MotorSafety
public boolean isSafetyEnabled()
isSafetyEnabled
in interface MotorSafety
public void setSafetyEnabled(boolean enabled)
setSafetyEnabled
in interface MotorSafety
public java.lang.String getDescription()
getDescription
in interface MotorSafety
public void setDirection(Relay.Direction direction)
Changes which values the relay can be set to depending on which direction is used
Valid inputs are kBothDirections, kForwardOnly, and kReverseOnly
direction
- The direction for the relay to operate inpublic void initSendable(SendableBuilder builder)
Sendable
Sendable
object.initSendable
in interface Sendable
builder
- sendable builder