-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added relay example. #80
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5798d7b
Added relay example.
mbardoe ca7e674
comments in greater alignment with the comments in allwpilib examples
mbardoe 24de9d1
Editted out the variable that saved joystick channel for greater alig…
mbardoe e5e2e14
added relay to run_tests.sh
mbardoe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Added relay example.
- Loading branch information
commit 5798d7b4e16f85641de502a31ff4e111e3420c47
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import wpilib | ||
|
||
|
||
class MyRobot(wpilib.TimedRobot): | ||
"""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 | ||
program uses two buttons on a joystick and each button corresponds to one | ||
output; pressing the button sets the output to 12V and releasing sets it to 0V. | ||
""" | ||
|
||
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.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. | ||
""" | ||
|
||
forward = self.joystick.getRawButton(self.relayForwardButton) | ||
reverse = self.joystick.getRawButton(self.relayReverseButton) | ||
|
||
if forward and reverse: | ||
auscompgeek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.relay.set(wpilib.Relay.Value.kOn) | ||
elif forward: | ||
self.relay.set(wpilib.Relay.Value.kForward) | ||
elif reverse: | ||
self.relay.set(wpilib.Relay.Value.kReverse) | ||
else: | ||
self.relay.set(wpilib.Relay.Value.kOff) | ||
|
||
|
||
if __name__ == "__main__": | ||
wpilib.run(MyRobot) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment isn't present in the original example, so let's omit it.