From 4f1c2ce5498ac5aa1894bd36093c01c0a40fb691 Mon Sep 17 00:00:00 2001 From: Eckart Schneider Date: Fri, 20 Nov 2020 17:37:10 -0500 Subject: [PATCH 1/9] Set up LED --- .../team4099/robot2021/config/Constants.kt | 33 +++++++++++++++++++ .../com/team4099/robot2021/subsystems/LED.kt | 20 +++++++++++ 2 files changed, 53 insertions(+) create mode 100644 src/main/kotlin/com/team4099/robot2021/subsystems/LED.kt diff --git a/src/main/kotlin/com/team4099/robot2021/config/Constants.kt b/src/main/kotlin/com/team4099/robot2021/config/Constants.kt index f27f3f0b..a260d075 100644 --- a/src/main/kotlin/com/team4099/robot2021/config/Constants.kt +++ b/src/main/kotlin/com/team4099/robot2021/config/Constants.kt @@ -31,4 +31,37 @@ object Constants { const val THROTTLE_DEADBAND = 0.04 const val TURN_DEADBAND = 0.035 } + + object LED { + const val PORT = 0 + const val LED_COUNT = 50 + enum class Color(var h: Int, var s: Int, var v: Int) { + // Pink + FIRING(227, 117, 128), + + // Turquoise + READY_FIRE(124, 255, 118), + + // Orange + INTAKE_EMPTY(18, 184, 128), + + // Magenta + ONE_BALL(209, 242, 128), + + // Sky blue + TWO_BALL(145, 242, 128), + + // Tan + THREE_BALL(17, 122, 128), + + // Green + FOUR_BALL(74, 207, 128), + + // Brown + CLIMB(34, 255, 45), + + // Rainbow is for climbing and when 5 balls and to appease the team + RAINBOW(0, 255, 128), + } + } } diff --git a/src/main/kotlin/com/team4099/robot2021/subsystems/LED.kt b/src/main/kotlin/com/team4099/robot2021/subsystems/LED.kt new file mode 100644 index 00000000..07e814c3 --- /dev/null +++ b/src/main/kotlin/com/team4099/robot2021/subsystems/LED.kt @@ -0,0 +1,20 @@ +package com.team4099.robot2021.subsystems + +import com.team4099.robot2021.config.Constants +import edu.wpi.first.wpilibj.AddressableLED +import edu.wpi.first.wpilibj.AddressableLEDBuffer +import edu.wpi.first.wpilibj2.command.SubsystemBase + +object LED: SubsystemBase() { + private val led = AddressableLED(Constants.LED.PORT) + private val ledBuffer = AddressableLEDBuffer(Constants.LED.LED_COUNT) + init { + led.setLength(ledBuffer.length) + led.setData(ledBuffer) + led.start() + } + + override fun periodic() { + + } +} From 36be9b9b178e925b2224450d669485cb6ddfc7d4 Mon Sep 17 00:00:00 2001 From: Eckart Schneider Date: Fri, 27 Nov 2020 16:37:27 -0500 Subject: [PATCH 2/9] current progress (need to switch branch) --- src/main/kotlin/com/team4099/robot2021/subsystems/LED.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/kotlin/com/team4099/robot2021/subsystems/LED.kt b/src/main/kotlin/com/team4099/robot2021/subsystems/LED.kt index 07e814c3..a726246b 100644 --- a/src/main/kotlin/com/team4099/robot2021/subsystems/LED.kt +++ b/src/main/kotlin/com/team4099/robot2021/subsystems/LED.kt @@ -6,6 +6,8 @@ import edu.wpi.first.wpilibj.AddressableLEDBuffer import edu.wpi.first.wpilibj2.command.SubsystemBase object LED: SubsystemBase() { + //using https://www.amazon.com/ALITOVE-Individually-Addressable-Flexible-Waterproof/dp/B018X04ES2 + private val led = AddressableLED(Constants.LED.PORT) private val ledBuffer = AddressableLEDBuffer(Constants.LED.LED_COUNT) init { From 269369be08f2a5f2872ac8ec87b45c11c7c1e277 Mon Sep 17 00:00:00 2001 From: Eckart Schneider Date: Fri, 27 Nov 2020 17:09:45 -0500 Subject: [PATCH 3/9] Change colors --- .../team4099/robot2021/config/Constants.kt | 32 ++++++++----------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/main/kotlin/com/team4099/robot2021/config/Constants.kt b/src/main/kotlin/com/team4099/robot2021/config/Constants.kt index a260d075..02437ad6 100644 --- a/src/main/kotlin/com/team4099/robot2021/config/Constants.kt +++ b/src/main/kotlin/com/team4099/robot2021/config/Constants.kt @@ -36,32 +36,26 @@ object Constants { const val PORT = 0 const val LED_COUNT = 50 enum class Color(var h: Int, var s: Int, var v: Int) { - // Pink - FIRING(227, 117, 128), + //Green + VISION_LOCK(52, 255, 255), - // Turquoise - READY_FIRE(124, 255, 118), + // Blue + SHOOTER_SPEED(120, 255, 255), - // Orange - INTAKE_EMPTY(18, 184, 128), + // White + INTAKE_EMPTY(0, 0, 255), // Magenta - ONE_BALL(209, 242, 128), + ONE_TWO_BALL(154, 255, 255), // Sky blue - TWO_BALL(145, 242, 128), - - // Tan - THREE_BALL(17, 122, 128), - - // Green - FOUR_BALL(74, 207, 128), - - // Brown - CLIMB(34, 255, 45), + THREE_FOUR_BALL(90, 255, 255), + } - // Rainbow is for climbing and when 5 balls and to appease the team - RAINBOW(0, 255, 128), + enum class Health(var h: Int, var s: Int, var v: Int) { + VISION(0, 255, 255), + BEAM_BREAK(60, 255, 255), + OTHER(17, 255, 255) } } } From 4e9a95a450831efc7a7e6e01c2342e989b3f2126 Mon Sep 17 00:00:00 2001 From: Eckart Schneider Date: Fri, 27 Nov 2020 17:21:13 -0500 Subject: [PATCH 4/9] Add rainbow method --- .../com/team4099/robot2021/subsystems/LED.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/kotlin/com/team4099/robot2021/subsystems/LED.kt b/src/main/kotlin/com/team4099/robot2021/subsystems/LED.kt index a726246b..1037a6f0 100644 --- a/src/main/kotlin/com/team4099/robot2021/subsystems/LED.kt +++ b/src/main/kotlin/com/team4099/robot2021/subsystems/LED.kt @@ -10,13 +10,31 @@ object LED: SubsystemBase() { private val led = AddressableLED(Constants.LED.PORT) private val ledBuffer = AddressableLEDBuffer(Constants.LED.LED_COUNT) + private var rainbowFirstPixelHue = 0 + init { led.setLength(ledBuffer.length) led.setData(ledBuffer) led.start() + } override fun periodic() { } + + private fun rainbow() { + // For every pixel + for (i in 0 until ledBuffer.getLength()) { + // Calculate the hue - hue is easier for rainbows because the color + // shape is a circle so only one value needs to precess + val hue = (rainbowFirstPixelHue + i * 180 / ledBuffer.getLength()) % 180 + // Set the value + ledBuffer.setHSV(i, hue, 255, 128) + } + // Increase by to make the rainbow "move" + rainbowFirstPixelHue += 3 + // Check bounds + rainbowFirstPixelHue %= 180 + } } From b0be0e6ebfb44a35b0656770d054ca1ca56aa993 Mon Sep 17 00:00:00 2001 From: Eckart Schneider Date: Tue, 19 Jan 2021 19:31:13 -0500 Subject: [PATCH 5/9] Finish LED subsystem --- .../team4099/robot2021/config/Constants.kt | 9 +++++-- .../com/team4099/robot2021/subsystems/LED.kt | 27 +++++++++++++------ 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/com/team4099/robot2021/config/Constants.kt b/src/main/kotlin/com/team4099/robot2021/config/Constants.kt index 02437ad6..0b2769a9 100644 --- a/src/main/kotlin/com/team4099/robot2021/config/Constants.kt +++ b/src/main/kotlin/com/team4099/robot2021/config/Constants.kt @@ -35,7 +35,8 @@ object Constants { object LED { const val PORT = 0 const val LED_COUNT = 50 - enum class Color(var h: Int, var s: Int, var v: Int) { + const val STATUS_LENGTH = 0 + enum class Status(var h: Int, var s: Int, var v: Int) { //Green VISION_LOCK(52, 255, 255), @@ -50,12 +51,16 @@ object Constants { // Sky blue THREE_FOUR_BALL(90, 255, 255), + + //Weird yellow green + DEFAULT(36, 255, 255) } enum class Health(var h: Int, var s: Int, var v: Int) { VISION(0, 255, 255), BEAM_BREAK(60, 255, 255), - OTHER(17, 255, 255) + OTHER(17, 255, 255), + DEFAULT(36, 255, 255) } } } diff --git a/src/main/kotlin/com/team4099/robot2021/subsystems/LED.kt b/src/main/kotlin/com/team4099/robot2021/subsystems/LED.kt index 1037a6f0..35f0c7b5 100644 --- a/src/main/kotlin/com/team4099/robot2021/subsystems/LED.kt +++ b/src/main/kotlin/com/team4099/robot2021/subsystems/LED.kt @@ -12,23 +12,34 @@ object LED: SubsystemBase() { private val ledBuffer = AddressableLEDBuffer(Constants.LED.LED_COUNT) private var rainbowFirstPixelHue = 0 + var statusState = Constants.LED.Status.DEFAULT + set(value) { + for(i in 0 until Constants.LED.STATUS_LENGTH) { + ledBuffer.setHSV(i, value.h, value.s, value.v) + } + field = value + } + + var healthState = Constants.LED.Health.DEFAULT + set(value) { + for(i in Constants.LED.STATUS_LENGTH + 1 until ledBuffer.length) { + ledBuffer.setHSV(i, value.h, value.s, value.v) + } + field = value + } + init { led.setLength(ledBuffer.length) led.setData(ledBuffer) led.start() - - } - - override fun periodic() { - } - private fun rainbow() { + fun rainbow() { // For every pixel - for (i in 0 until ledBuffer.getLength()) { + for (i in 0 until Constants.LED.STATUS_LENGTH) { // Calculate the hue - hue is easier for rainbows because the color // shape is a circle so only one value needs to precess - val hue = (rainbowFirstPixelHue + i * 180 / ledBuffer.getLength()) % 180 + val hue = (rainbowFirstPixelHue + i * 180 / ledBuffer.length) % 180 // Set the value ledBuffer.setHSV(i, hue, 255, 128) } From 8acc98caaf52162640bd5d30ab2a27ddaa2a596d Mon Sep 17 00:00:00 2001 From: Eckart Schneider Date: Wed, 14 Jul 2021 10:37:59 -0400 Subject: [PATCH 6/9] add comments --- src/main/kotlin/com/team4099/robot2021/config/Constants.kt | 4 ++-- src/main/kotlin/com/team4099/robot2021/subsystems/Shooter.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/team4099/robot2021/config/Constants.kt b/src/main/kotlin/com/team4099/robot2021/config/Constants.kt index bf202681..f1135fd6 100644 --- a/src/main/kotlin/com/team4099/robot2021/config/Constants.kt +++ b/src/main/kotlin/com/team4099/robot2021/config/Constants.kt @@ -232,8 +232,8 @@ object Constants { object LED { const val PORT = 0 - const val LED_COUNT = 50 - const val STATUS_LENGTH = 0 + const val LED_COUNT = 50 // TODO: Determine total amount of LED + const val STATUS_LENGTH = 0 // TODO: Determine length for health enum class Status(var h: Int, var s: Int, var v: Int) { // Green VISION_LOCK(52, 255, 255), diff --git a/src/main/kotlin/com/team4099/robot2021/subsystems/Shooter.kt b/src/main/kotlin/com/team4099/robot2021/subsystems/Shooter.kt index faf6097c..5f5ce6cb 100644 --- a/src/main/kotlin/com/team4099/robot2021/subsystems/Shooter.kt +++ b/src/main/kotlin/com/team4099/robot2021/subsystems/Shooter.kt @@ -95,7 +95,7 @@ object Shooter : SubsystemBase() { // velocity setpoint private var _targetVelocity = 0.rotations.perMinute var targetVelocity - set(velocity) { + set(velocity) { // TODO: Set LED when reaches target velocity _targetVelocity = velocity shooterMotor.set( ControlMode.Velocity, From 71d9587f24010b6a1d64dba0bdf7478cfcec3b0a Mon Sep 17 00:00:00 2001 From: Eckart Schneider Date: Mon, 19 Jul 2021 10:44:35 -0400 Subject: [PATCH 7/9] gradle plz work --- src/main/kotlin/com/team4099/robot2021/config/Constants.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/com/team4099/robot2021/config/Constants.kt b/src/main/kotlin/com/team4099/robot2021/config/Constants.kt index f1135fd6..473aba07 100644 --- a/src/main/kotlin/com/team4099/robot2021/config/Constants.kt +++ b/src/main/kotlin/com/team4099/robot2021/config/Constants.kt @@ -234,6 +234,7 @@ object Constants { const val PORT = 0 const val LED_COUNT = 50 // TODO: Determine total amount of LED const val STATUS_LENGTH = 0 // TODO: Determine length for health + enum class Status(var h: Int, var s: Int, var v: Int) { // Green VISION_LOCK(52, 255, 255), From 264f2610dbf9d61c149852d3ebbaea91eccf80f4 Mon Sep 17 00:00:00 2001 From: Eckart Schneider Date: Wed, 8 Sep 2021 19:22:05 -0400 Subject: [PATCH 8/9] Update Constants.kt test GitHub desktop --- src/main/kotlin/com/team4099/robot2021/config/Constants.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/team4099/robot2021/config/Constants.kt b/src/main/kotlin/com/team4099/robot2021/config/Constants.kt index 473aba07..e3c4a784 100644 --- a/src/main/kotlin/com/team4099/robot2021/config/Constants.kt +++ b/src/main/kotlin/com/team4099/robot2021/config/Constants.kt @@ -231,7 +231,7 @@ object Constants { } object LED { - const val PORT = 0 + const val PORT = 0 // PWM Port const val LED_COUNT = 50 // TODO: Determine total amount of LED const val STATUS_LENGTH = 0 // TODO: Determine length for health From 8cdef089e68e49c72f44e668238eb7541aa16c47 Mon Sep 17 00:00:00 2001 From: Eckart Schneider Date: Thu, 23 Sep 2021 19:51:16 -0400 Subject: [PATCH 9/9] make code build --- src/main/kotlin/com/team4099/robot2021/config/Constants.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/team4099/robot2021/config/Constants.kt b/src/main/kotlin/com/team4099/robot2021/config/Constants.kt index e3c4a784..b3dda451 100644 --- a/src/main/kotlin/com/team4099/robot2021/config/Constants.kt +++ b/src/main/kotlin/com/team4099/robot2021/config/Constants.kt @@ -231,7 +231,7 @@ object Constants { } object LED { - const val PORT = 0 // PWM Port + const val PORT = 0 // PWM Port (could be Arduino) const val LED_COUNT = 50 // TODO: Determine total amount of LED const val STATUS_LENGTH = 0 // TODO: Determine length for health