class wpilib.Relay(channel: int, direction: wpilib._wpilib.Relay.Direction = <Direction.kBothDirections: 0>) → None

Bases: wpilib.MotorSafety, wpilib.Sendable

Class for Spike style relay outputs.

Relays are intended to be connected to spikes or similar relays. The relay channels controls a pair of pins 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).

Relay constructor given a channel.

This code initializes the relay and reserves all resources that need to be locked. Initially the relay is set to both lines at 0v.

  • channel – The channel number (0-3).

  • direction – The direction that the Relay object will control.

class Direction(self: wpilib._wpilib.Relay.Direction, value: int) → None

Bases: pybind11_builtins.pybind11_object





kBothDirections = <Direction.kBothDirections: 0>
kForwardOnly = <Direction.kForwardOnly: 1>
kReverseOnly = <Direction.kReverseOnly: 2>
property name
class Value(self: wpilib._wpilib.Relay.Value, value: int) → None

Bases: pybind11_builtins.pybind11_object






kForward = <Value.kForward: 2>
kOff = <Value.kOff: 0>
kOn = <Value.kOn: 1>
kReverse = <Value.kReverse: 3>
property name
get(self: wpilib.Relay) → wpilib._wpilib.Relay.Value

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


The current state of the relay as a Relay::Value

getChannel(self: wpilib.Relay) → int
getDescription(self: wpilib.Relay) → str
initSendable(self: wpilib.Relay, builder: wpilib.SendableBuilder) → None
set(self: wpilib.Relay, value: wpilib._wpilib.Relay.Value) → None

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 any of the four states: 0v-0v, 0v-12v, 12v-0v, 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.

stopMotor(self: wpilib.Relay) → None