Skip to content

Commit

Permalink
Merge pull request #8 from AlphaKnights/LEDs
Browse files Browse the repository at this point in the history
Implement LED support
  • Loading branch information
JSohn-1 authored Feb 6, 2025
2 parents 7c38761 + 753e818 commit 8ac7d37
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
Expand Down
17 changes: 17 additions & 0 deletions commands/teamcolors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import commands2
import typing
from subsystems.ledsubsystem import LEDSubsystem
class TeamColorsCommand(commands2.Command):
def __init__(self, led_sub: LEDSubsystem) -> None:
super().__init__()
self.led = led_sub
self.addRequirements(led_sub)

def execute(self) -> None:
self.led.teamLights()

def isFinished(self) -> bool:
return False

def end(self, interrupted: bool) -> None:
pass
12 changes: 12 additions & 0 deletions constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,15 @@ class AutoConstants:
kThetaControllerConstraints = TrapezoidProfileRadians.Constraints(
kMaxAngularSpeedRadiansPerSecond, kMaxAngularSpeedRadiansPerSecondSquared
)

class LEDConstants:
kLEDPort = 0
kLEDBuffer = 64

kSilverHue = 0
kSilverSat = 0
kSilverVal = 10

kBlueHue = 90
kBlueSat = 220
kBlueVal = 30
2 changes: 2 additions & 0 deletions robotcontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from commands.auto_align import AutoAlign
from constants import AutoConstants, DriveConstants, OIConstants
from subsystems.drivesubsystem import DriveSubsystem

from subsystems.limelight_subsystem import LimelightSystem
from commands.auto_rotate import AutoRotate
from commands.drivecommand import DriveCommand
Expand All @@ -33,6 +34,7 @@ class RobotContainer:
def __init__(self) -> None:
# The robot's subsystems
self.robotDrive = DriveSubsystem()

self.limelight = LimelightSystem()

self.autoChooser = AutoBuilder.buildAutoChooser()
Expand Down
34 changes: 34 additions & 0 deletions subsystems/ledsubsystem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import math
import typing

import wpilib

from commands2 import Subsystem
from constants import LEDConstants

class LEDSubsystem(Subsystem):
def __init__(self) -> None:
super().__init__()
self.led = wpilib.AddressableLED(LEDConstants.kLEDPort)

self.ledData = [wpilib.AddressableLED.LEDData() for _ in range(LEDConstants.kLEDBuffer)]

self.led.setLength(LEDConstants.kLEDBuffer)

self.led.setData(self.ledData)
self.led.start()


def periodic(self) -> None:
self.led.setData(self.ledData)

def lightAll(self, hue: int, sat: int, val: int) -> None:
for i in range(LEDConstants.kLEDBuffer):
self.ledData[i].setHSV(hue, sat, val)

def teamLights(self) -> None:
for i in range(LEDConstants.kLEDBuffer):
if (i % 2 == 0):
self.ledData[i].setHSV(LEDConstants.kSilverHue, LEDConstants.kSilverSat, LEDConstants.kSilverVal)
else:
self.ledData[i].setHSV(LEDConstants.kBlueHue, LEDConstants.kBlueSat, LEDConstants.kBlueVal)

0 comments on commit 8ac7d37

Please sign in to comment.