Skip to content
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 4 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions relay/robot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/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"""

self.relay = wpilib.Relay(0)

self.joystick = wpilib.Joystick(0)

self.relayForwardButton = 1
self.relayReverseButton = 2

def teleopPeriodic(self):
# 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:
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)
1 change: 1 addition & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ BASE_TESTS="
physics-4wheel/src
physics-mecanum/src
physics-spi/src
relay
shuffleboard
stateful-autonomous
state-space-flywheel
Expand Down