-
Notifications
You must be signed in to change notification settings - Fork 0
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
LED Panel! #181
LED Panel! #181
Changes from all commits
eed879a
9f4ac8f
2340638
a0af456
db33723
fab512f
9e21cf3
6fd46d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import wpilib | ||
|
||
|
||
class LEDPanel: | ||
# Key: Match number, Value: Drop Bears match number (<=15) | ||
# TODO: Fill with proper values when the draw comes out | ||
matches: dict[int, int] = {1: 1} | ||
|
||
def __init__(self) -> None: | ||
# Custom packet: 00 000000 | ||
# match state, state specific information | ||
self.match_state = 0 | ||
self.packet = 0b01000000 | ||
self.panel_port = wpilib.SerialPort( | ||
baudRate=9600, port=wpilib.SerialPort.Port.kUSB1, dataBits=8 | ||
) | ||
self.set_match_id() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This happens on robot code start. |
||
|
||
def send_packet(self) -> None: | ||
self.panel_port.write(self.packet.to_bytes()) | ||
|
||
def set_match_state(self) -> None: | ||
self.packet &= 0b00111111 | ||
|
||
if wpilib.DriverStation.isEnabled(): | ||
# During | ||
self.packet |= 0b01 << 6 | ||
if self.match_state != 1: | ||
self.send_packet() | ||
self.match_state = 1 | ||
elif wpilib.DriverStation.getMatchTime() <= 0: | ||
# Post match | ||
Comment on lines
+31
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't this branch be hit before a match, and between auto and teleop, too? |
||
self.packet |= 0b10 << 6 | ||
if self.match_state != 2: | ||
self.send_packet() | ||
self.match_state = 2 | ||
else: | ||
# Pre match | ||
self.packet |= 0b00 << 6 | ||
if self.match_state != 0: | ||
self.send_packet() | ||
self.match_state = 0 | ||
|
||
def set_match_id(self) -> None: | ||
match_type = wpilib.DriverStation.getMatchType() | ||
match_id = 0 | ||
if ( | ||
match_type == wpilib.DriverStation.MatchType.kQualification | ||
or match_type == wpilib.DriverStation.MatchType.kElimination | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will both this robot code and the LED panel code be updated after every playoff match? Sounds tedious. |
||
): | ||
match_number = wpilib.DriverStation.getMatchNumber() | ||
if match_number in self.matches: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks up the match number without using the match type. Is QF4 intended to be considered identical to Q4? |
||
match_id = self.matches[match_number] | ||
# Can't be greater than 15 | ||
match_id = max(match_id, 15) | ||
|
||
self.packet |= match_id | ||
self.send_packet() | ||
|
||
def no_note(self) -> None: | ||
self.packet &= 0b11000000 | ||
self.send_packet() | ||
|
||
def intake_deployed(self) -> None: | ||
self.packet &= 0b11000000 | ||
self.packet |= 0b001 | ||
self.send_packet() | ||
|
||
def in_range(self) -> None: | ||
self.packet &= 0b11000000 | ||
self.packet |= 0b010 | ||
self.send_packet() | ||
|
||
def not_in_range(self) -> None: | ||
self.packet &= 0b11000000 | ||
self.packet |= 0b011 | ||
self.send_packet() | ||
|
||
def climbing_arm_extending(self) -> None: | ||
self.packet &= 0b11000000 | ||
self.packet |= 0b100 | ||
self.send_packet() | ||
|
||
def climbing_arm_fully_extended(self) -> None: | ||
self.packet &= 0b11000000 | ||
self.packet |= 0b101 | ||
self.send_packet() | ||
|
||
def climbing_arm_retracted(self) -> None: | ||
self.packet &= 0b11000000 | ||
self.packet |= 0b110 | ||
self.send_packet() | ||
|
||
def execute(self) -> None: | ||
self.set_match_state() | ||
Comment on lines
+92
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to send a packet multiple times each control loop iteration. Is this necessary? |
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.
The match schedule has been published. Do you intend to fill this in now?