Skip to content

Commit ca7e674

Browse files
committed
comments in greater alignment with the comments in allwpilib examples
1 parent 5798d7b commit ca7e674

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

relay/robot.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55

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

1516
def robotInit(self):
1617
"""Robot initialization function"""
17-
# create Relay object
18+
1819
self.relay = wpilib.Relay(0)
1920

20-
# create joystick object
21-
self.joystickChannel = 0 # usb number in DriverStation
21+
self.joystickChannel = 0
2222
self.joystick = wpilib.Joystick(self.joystickChannel)
2323

24-
# create variables to define the buttons
2524
self.relayForwardButton = 1
2625
self.relayReverseButton = 2
2726

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

3431
forward = self.joystick.getRawButton(self.relayForwardButton)
3532
reverse = self.joystick.getRawButton(self.relayReverseButton)
3633

34+
##
35+
# Depending on the button values, we want to use one of
36+
# kOn, kOff, kForward, or kReverse. kOn sets both outputs to 12V,
37+
# kOff sets both to 0V, kForward sets forward to 12V
38+
# and reverse to 0V, and kReverse sets reverse to 12V and forward to 0V.
39+
##
40+
3741
if forward and reverse:
3842
self.relay.set(wpilib.Relay.Value.kOn)
3943
elif forward:

0 commit comments

Comments
 (0)