edu.wpi.first.wpilibj

## Class Relay

- java.lang.Object
- - edu.wpi.first.wpilibj.SensorBase
  - - edu.wpi.first.wpilibj.Relay

- All Implemented Interfaces:
    LiveWindowSendable, MotorSafety, Sendable

      public class Relay
      extends SensorBase
      implements MotorSafety, LiveWindowSendable

  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 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.

  - ### Field Summary

    - ### Fields inherited from class edu.wpi.first.wpilibj.SensorBase

      `kAnalogInputChannels, kAnalogOutputChannels, kDigitalChannels, kPCMModules, kPDPChannels, kPDPModules, kPwmChannels, kRelayChannels, kSolenoidChannels, kSystemClockTicksPerMicrosecond`

    - ### Fields inherited from interface edu.wpi.first.wpilibj.MotorSafety

      `DEFAULT_SAFETY_EXPIRATION`

  - ### Constructor Summary

    Constructors
    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.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    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()`
    `java.lang.String` | `getSmartDashboardType()` The string representation of the named data type that will be used by the smart dashboard for this `Sendable`.
    `void` | `initTable(NetworkTable subtable)` Initializes a table for 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` | `startLiveWindowMode()` Start having this sendable object automatically respond to value changes reflect the value on the table.
    `void` | `stopLiveWindowMode()` Stop having this sendable object automatically respond to value changes.
    `void` | `stopMotor()`
    `void` | `updateTable()` Update the table for this sendable object with the latest values.

    - ### Methods inherited from class edu.wpi.first.wpilibj.SensorBase

      `checkAnalogInputChannel, checkAnalogOutputChannel, checkDigitalChannel, checkPDPChannel, checkPDPModule, checkPWMChannel, checkRelayChannel, checkSolenoidChannel, checkSolenoidModule, getDefaultSolenoidModule, setDefaultSolenoidModule`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 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

    - #### free

          public void free()

      Description copied from class: `SensorBase`
      Free the resources used by this object.
      Overrides:
        `free` in class `SensorBase`

    - #### 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.

    - #### setExpiration

          public void setExpiration(double timeout)

      Specified by:
        `setExpiration` in interface `MotorSafety`

    - #### getExpiration

          public double getExpiration()

      Specified by:
        `getExpiration` in interface `MotorSafety`

    - #### isAlive

          public boolean isAlive()

      Specified by:
        `isAlive` in interface `MotorSafety`

    - #### stopMotor

          public void stopMotor()

      Specified by:
        `stopMotor` in interface `MotorSafety`

    - #### isSafetyEnabled

          public boolean isSafetyEnabled()

      Specified by:
        `isSafetyEnabled` in interface `MotorSafety`

    - #### setSafetyEnabled

          public void setSafetyEnabled(boolean enabled)

      Specified by:
        `setSafetyEnabled` in interface `MotorSafety`

    - #### getDescription

          public java.lang.String getDescription()

      Specified by:
        `getDescription` in interface `MotorSafety`

    - #### 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

    - #### getSmartDashboardType

          public java.lang.String getSmartDashboardType()

      Description copied from interface: `Sendable`
      The string representation of the named data type that will be used by the smart dashboard for this `Sendable`.
      Specified by:
        `getSmartDashboardType` in interface `Sendable`
      Returns:
        The type of this `Sendable`.

    - #### initTable

          public void initTable(NetworkTable subtable)

      Description copied from interface: `Sendable`
      Initializes a table for this `Sendable` object.
      Specified by:
        `initTable` in interface `Sendable`
      Parameters:
        `subtable` - The table to put the values in.

    - #### updateTable

          public void updateTable()

      Description copied from interface: `LiveWindowSendable`
      Update the table for this sendable object with the latest values.
      Specified by:
        `updateTable` in interface `LiveWindowSendable`

    - #### startLiveWindowMode

          public void startLiveWindowMode()

      Description copied from interface: `LiveWindowSendable`
      Start having this sendable object automatically respond to value changes reflect the value on the table.
      Specified by:
        `startLiveWindowMode` in interface `LiveWindowSendable`

    - #### stopLiveWindowMode

          public void stopLiveWindowMode()

      Description copied from interface: `LiveWindowSendable`
      Stop having this sendable object automatically respond to value changes.
      Specified by:
        `stopLiveWindowMode` in interface `LiveWindowSendable`