4
4
5
5
6
6
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.
8
9
A Relay (generally a spike) has two outputs, each of which can be at either
9
10
0V or 12V and so can be used for actions such as turning a motor off, full
10
11
forwards, or full reverse, and is generally used on the compressor. This
@@ -14,26 +15,29 @@ class MyRobot(wpilib.TimedRobot):
14
15
15
16
def robotInit (self ):
16
17
"""Robot initialization function"""
17
- # create Relay object
18
+
18
19
self .relay = wpilib .Relay (0 )
19
20
20
- # create joystick object
21
- self .joystickChannel = 0 # usb number in DriverStation
21
+ self .joystickChannel = 0
22
22
self .joystick = wpilib .Joystick (self .joystickChannel )
23
23
24
- # create variables to define the buttons
25
24
self .relayForwardButton = 1
26
25
self .relayReverseButton = 2
27
26
28
27
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.
33
30
34
31
forward = self .joystick .getRawButton (self .relayForwardButton )
35
32
reverse = self .joystick .getRawButton (self .relayReverseButton )
36
33
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
+
37
41
if forward and reverse :
38
42
self .relay .set (wpilib .Relay .Value .kOn )
39
43
elif forward :
0 commit comments