Skip to content

Commit

Permalink
comments in greater alignment with the comments in allwpilib examples
Browse files Browse the repository at this point in the history
mbardoe committed Dec 2, 2023
1 parent 5798d7b commit ca7e674
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions relay/robot.py
Original file line number Diff line number Diff line change
@@ -4,7 +4,8 @@


class MyRobot(wpilib.TimedRobot):
"""This is a sample program which uses joystick buttons to control a relay.
"""
This is a sample program which uses joystick buttons to control a relay.
A Relay (generally a spike) has two outputs, each of which can be at either
0V or 12V and so can be used for actions such as turning a motor off, full
forwards, or full reverse, and is generally used on the compressor. This
@@ -14,26 +15,29 @@ class MyRobot(wpilib.TimedRobot):

def robotInit(self):
"""Robot initialization function"""
# create Relay object

self.relay = wpilib.Relay(0)

# create joystick object
self.joystickChannel = 0 # usb number in DriverStation
self.joystickChannel = 0
self.joystick = wpilib.Joystick(self.joystickChannel)

# create variables to define the buttons
self.relayForwardButton = 1
self.relayReverseButton = 2

def teleopPeriodic(self):
"""
The relay can be set several ways. It has two outputs which each can be set for either 0V or 12V.
This code uses buttons on a joystick to set each of the outputs.
"""
# Retrieve the button values. GetRawButton will
# return true if the button is pressed and false if not.

forward = self.joystick.getRawButton(self.relayForwardButton)
reverse = self.joystick.getRawButton(self.relayReverseButton)

##
# Depending on the button values, we want to use one of
# kOn, kOff, kForward, or kReverse. kOn sets both outputs to 12V,
# kOff sets both to 0V, kForward sets forward to 12V
# and reverse to 0V, and kReverse sets reverse to 12V and forward to 0V.
##

if forward and reverse:
self.relay.set(wpilib.Relay.Value.kOn)
elif forward:

0 comments on commit ca7e674

Please sign in to comment.