From 3c2f0ce659493f70765e9488c5fc21a3311c824c Mon Sep 17 00:00:00 2001 From: Max <> Date: Fri, 20 Oct 2023 23:17:57 -0700 Subject: [PATCH 1/6] simple lights red when we are in endgame --- src/main/java/com/team766/robot/OI.java | 5 +++++ src/main/java/com/team766/robot/Robot.java | 2 ++ src/main/java/com/team766/robot/mechanisms/Lights.java | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/src/main/java/com/team766/robot/OI.java b/src/main/java/com/team766/robot/OI.java index 92b6186..bbc987a 100644 --- a/src/main/java/com/team766/robot/OI.java +++ b/src/main/java/com/team766/robot/OI.java @@ -14,6 +14,7 @@ import edu.wpi.first.wpilibj.DriverStation; import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; + /** * This class is the glue that binds the controls on the physical operator * interface to the code that allow control of the robot. @@ -66,6 +67,7 @@ public void run(Context context) { context.takeOwnership(Robot.drive); // context.takeOwnership(Robot.intake); context.takeOwnership(Robot.gyro); + context.takeOwnership(Robot.lights); while (true) { context.waitFor(() -> RobotProvider.instance.hasNewDriverStationData()); @@ -87,6 +89,9 @@ public void run(Context context) { // SmartDashboard.putString("Alliance", "NULLLLLLLLL"); // } + if(DriverStation.isTeleop() && DriverStation.getMatchTime() < 30){ + Robot.lights.red(); + } if (leftJoystick.getButtonPressed(InputConstants.RESET_GYRO)) { Robot.gyro.resetGyro(); diff --git a/src/main/java/com/team766/robot/Robot.java b/src/main/java/com/team766/robot/Robot.java index baa970e..9bd0d5a 100644 --- a/src/main/java/com/team766/robot/Robot.java +++ b/src/main/java/com/team766/robot/Robot.java @@ -7,11 +7,13 @@ public class Robot { // public static Intake intake; public static Drive drive; public static Gyro gyro; + public static Lights lights; public static void robotInit() { // Initialize mechanisms here // intake = new Intake(); drive = new Drive(); gyro = new Gyro(); + lights = new Lights(); } } diff --git a/src/main/java/com/team766/robot/mechanisms/Lights.java b/src/main/java/com/team766/robot/mechanisms/Lights.java index 4e83f45..bbe8ea7 100644 --- a/src/main/java/com/team766/robot/mechanisms/Lights.java +++ b/src/main/java/com/team766/robot/mechanisms/Lights.java @@ -27,4 +27,9 @@ public void yellow(){ checkContextOwnership(); candle.setLEDs(255, 255, 0); } + + public void red(){ + checkContextOwnership(); + candle.setLEDs(255, 0, 0); + } } From 4dfa62bd7e7de68d4e68188d6b3f7d9660d4444f Mon Sep 17 00:00:00 2001 From: Max <> Date: Sat, 21 Oct 2023 16:04:13 -0700 Subject: [PATCH 2/6] eh --- src/main/java/com/team766/robot/OI.java | 2 +- .../com/team766/robot/mechanisms/Lights.java | 22 +++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/team766/robot/OI.java b/src/main/java/com/team766/robot/OI.java index bbc987a..b722f7f 100644 --- a/src/main/java/com/team766/robot/OI.java +++ b/src/main/java/com/team766/robot/OI.java @@ -90,7 +90,7 @@ public void run(Context context) { // } if(DriverStation.isTeleop() && DriverStation.getMatchTime() < 30){ - Robot.lights.red(); + Robot.lights.signalMalfunction(); } if (leftJoystick.getButtonPressed(InputConstants.RESET_GYRO)) { diff --git a/src/main/java/com/team766/robot/mechanisms/Lights.java b/src/main/java/com/team766/robot/mechanisms/Lights.java index bbe8ea7..098ef04 100644 --- a/src/main/java/com/team766/robot/mechanisms/Lights.java +++ b/src/main/java/com/team766/robot/mechanisms/Lights.java @@ -1,5 +1,6 @@ package com.team766.robot.mechanisms; import com.ctre.phoenix.led.CANdle; +import com.ctre.phoenix.led.RainbowAnimation; import com.team766.framework.Mechanism; @@ -7,29 +8,42 @@ public class Lights extends Mechanism{ private CANdle candle; private static final int CANID = 5; + private int numLEDs = 8; + RainbowAnimation rainbowAnim = new RainbowAnimation(1, 0.5, numLEDs); public Lights(){ candle = new CANdle(CANID); } - public void purple(){ + public void setNumLEDs(int num){ + checkContextOwnership(); + numLEDs = num; + rainbowAnim.setNumLed(num); + } + + public void signalCube(){ checkContextOwnership(); candle.setLEDs(128, 0, 128); } - public void white(){ + public void resetLights(){ checkContextOwnership(); candle.setLEDs(255, 255, 255); } - public void yellow(){ + public void signalCone(){ checkContextOwnership(); candle.setLEDs(255, 255, 0); } - public void red(){ + public void signalMalfunction(){ checkContextOwnership(); candle.setLEDs(255, 0, 0); } + + public void signalBalance(){ + checkContextOwnership(); + candle.animate(rainbowAnim); + } } From bea352f9128347c7cea82ba5618165ed26038c47 Mon Sep 17 00:00:00 2001 From: TTVMixmix00 <68516760+TTVMixmix00@users.noreply.github.com> Date: Sat, 21 Oct 2023 19:24:12 -0700 Subject: [PATCH 3/6] Create AutonLED.java --- .../com/team766/robot/procedures/AutonLED.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/main/java/com/team766/robot/procedures/AutonLED.java diff --git a/src/main/java/com/team766/robot/procedures/AutonLED.java b/src/main/java/com/team766/robot/procedures/AutonLED.java new file mode 100644 index 0000000..f3c699d --- /dev/null +++ b/src/main/java/com/team766/robot/procedures/AutonLED.java @@ -0,0 +1,14 @@ +package com.team766.robot.procedures; + +import com.team766.framework.Context; +import com.team766.framework.Procedure; +import com.team766.robot.Robot; + +public class AutonLED extends Procedure { + public void run (Context context) { + context.takeOwnership(Robot.lights); + Robot.lights.clearAnimation(); + Robot.lights.auton(); + } + +} From 5ce06989fc9839e66f134cf122ea0d5c5a900ea9 Mon Sep 17 00:00:00 2001 From: TTVMixmix00 <68516760+TTVMixmix00@users.noreply.github.com> Date: Sat, 21 Oct 2023 19:24:52 -0700 Subject: [PATCH 4/6] Update Lights.java --- .../com/team766/robot/mechanisms/Lights.java | 149 +++++++++++++++++- 1 file changed, 142 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/team766/robot/mechanisms/Lights.java b/src/main/java/com/team766/robot/mechanisms/Lights.java index 098ef04..b84987c 100644 --- a/src/main/java/com/team766/robot/mechanisms/Lights.java +++ b/src/main/java/com/team766/robot/mechanisms/Lights.java @@ -1,16 +1,23 @@ package com.team766.robot.mechanisms; +import org.apache.commons.math3.analysis.function.Ceil; +import org.apache.commons.math3.stat.correlation.StorelessCovariance; import com.ctre.phoenix.led.CANdle; import com.ctre.phoenix.led.RainbowAnimation; +import com.ctre.phoenix.led.StrobeAnimation; +import com.ctre.phoenix.led.TwinkleAnimation; +import com.ctre.phoenix.led.TwinkleAnimation.TwinklePercent; import com.team766.framework.Mechanism; +import edu.wpi.first.wpilibj.DriverStation; public class Lights extends Mechanism{ private CANdle candle; private static final int CANID = 5; - private int numLEDs = 8; - RainbowAnimation rainbowAnim = new RainbowAnimation(1, 0.5, numLEDs); - + private int numLEDs = 42; + RainbowAnimation rainbowAnim = new RainbowAnimation(1, 5, numLEDs); + + int curAnimation = -1; public Lights(){ candle = new CANdle(CANID); @@ -24,7 +31,25 @@ public void setNumLEDs(int num){ public void signalCube(){ checkContextOwnership(); - candle.setLEDs(128, 0, 128); + if(DriverStation.getMatchTime() > 30){ + if(curAnimation != -1){candle.clearAnimation(curAnimation);} + candle.setLEDs(128, 0, 128); + }else{ + candle.clearAnimation(curAnimation); + if(DriverStation.getMatchTime() > 15){ + if((int) (DriverStation.getMatchTime() * 2) % 2 == 0){ + candle.setLEDs(128, 0, 128); + }else{ + candle.setLEDs(0, 0, 0); + } + }else{ + if((int) (DriverStation.getMatchTime() * 4) % 2 == 0){ + candle.setLEDs(128, 0, 128); + }else{ + candle.setLEDs(0, 0, 0); + } + } + } } public void resetLights(){ @@ -34,16 +59,126 @@ public void resetLights(){ public void signalCone(){ checkContextOwnership(); - candle.setLEDs(255, 255, 0); + if(DriverStation.getMatchTime() > 30){ + if(curAnimation != -1){candle.clearAnimation(curAnimation);} + candle.setLEDs(255, 255, 0); + }else{ + candle.clearAnimation(curAnimation); + if(DriverStation.getMatchTime() > 15){ + if((int) (DriverStation.getMatchTime() * 2) % 2 == 0){ + candle.setLEDs(225, 225, 0); + }else{ + candle.setLEDs(0, 0, 0); + } + }else{ + if((int) (DriverStation.getMatchTime() * 4) % 2 == 0){ + candle.setLEDs(225,225,0); + }else{ + candle.setLEDs(0, 0, 0); + } + } + } + } + public void auton(){ + candle.setLEDs(0, 255, 0); + } public void signalMalfunction(){ checkContextOwnership(); candle.setLEDs(255, 0, 0); } - public void signalBalance(){ + public void rainbow(){ + checkContextOwnership(); + candle.clearAnimation(curAnimation); + candle.animate(rainbowAnim,0); + curAnimation = 0; + + } + + public void clearAnimation(){ checkContextOwnership(); - candle.animate(rainbowAnim); + if(curAnimation != -1){ + candle.clearAnimation(curAnimation); + curAnimation = -1; + } + + + + } + + public void hybridScore(){ + checkContextOwnership(); + + if(DriverStation.getMatchTime() > 30){ + if(curAnimation != -1){candle.clearAnimation(curAnimation);} + candle.setLEDs(165, 128, 65); + }else{ + candle.clearAnimation(curAnimation); + if(DriverStation.getMatchTime() > 15){ + if((int) (DriverStation.getMatchTime() * 2) % 2 == 0){ + candle.setLEDs(165, 128, 65); + }else{ + candle.setLEDs(0, 0, 0); + } + }else{ + if((int) (DriverStation.getMatchTime() * 4) % 2 == 0){ + candle.setLEDs(165, 128, 65); + }else{ + candle.setLEDs(0, 0, 0); + } + } + } } + + //color of justin and kapils shirts + public void midScore(){ + checkContextOwnership(); + + if(DriverStation.getMatchTime() > 30){ + if(curAnimation != -1){candle.clearAnimation(curAnimation);} + candle.setLEDs(81,102,52); + }else{ + candle.clearAnimation(curAnimation); + if(DriverStation.getMatchTime() > 15){ + if((int) (DriverStation.getMatchTime() * 2) % 2 == 0){ + candle.setLEDs(81,102,52); + }else{ + candle.setLEDs(0, 0, 0); + } + }else{ + if((int) (DriverStation.getMatchTime() * 4) % 2 == 0){ + candle.setLEDs(81,102,52); + }else{ + candle.setLEDs(0, 0, 0); + } + } + } + } + + public void highScore(){ + checkContextOwnership(); + + if(DriverStation.getMatchTime() > 30){ + if(curAnimation != -1){candle.clearAnimation(curAnimation);} + candle.setLEDs(202, 39, 75); + }else{ + candle.clearAnimation(curAnimation); + if(DriverStation.getMatchTime() > 15){ + if((int) (DriverStation.getMatchTime() * 2) % 2 == 0){ + candle.setLEDs(202, 39, 75); + }else{ + candle.setLEDs(0, 0, 0); + } + }else{ + if((int) (DriverStation.getMatchTime() * 4) % 2 == 0){ + candle.setLEDs(202, 39, 75); + }else{ + candle.setLEDs(0, 0, 0); + } + } + } + } + } From 3d0a4ab4ca357a104bb53f39872749336f8f215d Mon Sep 17 00:00:00 2001 From: TTVMixmix00 <68516760+TTVMixmix00@users.noreply.github.com> Date: Sat, 21 Oct 2023 19:26:24 -0700 Subject: [PATCH 5/6] Update OI.java --- src/main/java/com/team766/robot/OI.java | 44 +++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/main/java/com/team766/robot/OI.java b/src/main/java/com/team766/robot/OI.java index b722f7f..c9acdd9 100644 --- a/src/main/java/com/team766/robot/OI.java +++ b/src/main/java/com/team766/robot/OI.java @@ -37,6 +37,7 @@ public class OI extends Procedure { private static final double HighConeArm1 = 0; private static final double CHA2 = 0; private static final double CMA1 = 0; + private int state = 0; // enum generalControl{ // CONE_HIGH_NODE, // CUBE_HIGH_NODE, @@ -73,6 +74,49 @@ public void run(Context context) { context.waitFor(() -> RobotProvider.instance.hasNewDriverStationData()); RobotProvider.instance.refreshDriverStationData(); + //TODO: ADD CODE DEPENDING ON WHAT THE STATE SHOULD BE FOR WHICH BUTTONS + if(DriverStation.getMatchTime() < 30 && DriverStation.getMatchTime() > 29){ + Robot.lights.rainbow(); + log("" + DriverStation.getMatchTime()); + ignoreState = true; + } + + if(DriverStation.getMatchTime() <29 && DriverStation.getMatchTime() > 28.7){ + Robot.lights.clearAnimation(); + ignoreState = false; + } + switch (state){ + case 1: + if(ignoreState){ break;} + Robot.lights.signalCube(); + break; + case 2: + if(ignoreState){ break;} + Robot.lights.signalCone(); + break; + case 3: + if(ignoreState){ break;} + Robot.lights.rainbow(); + break; + case 4: + if(ignoreState){ break;} + Robot.lights.hybridScore(); + break; + case 5: + if(ignoreState){ break;} + Robot.lights.midScore(); + break; + case 6: + if(ignoreState){ break;} + Robot.lights.highScore(); + break; + default: + if(!ignoreState){ + Robot.lights.resetLights(); + } + } + + // Add driver controls here - make sure to take/release ownership // of mechanisms when appropriate. From 9fc5e508a249ef9d4924e13ed82ab54b6ffa5388 Mon Sep 17 00:00:00 2001 From: 1yd1a <90945906+1yd1a@users.noreply.github.com> Date: Sat, 21 Oct 2023 20:29:44 -0700 Subject: [PATCH 6/6] slight color and syntax fixes for now --- src/main/java/com/team766/robot/OI.java | 2 + .../com/team766/robot/mechanisms/Lights.java | 59 ++++++++++--------- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/team766/robot/OI.java b/src/main/java/com/team766/robot/OI.java index c9acdd9..55b541a 100644 --- a/src/main/java/com/team766/robot/OI.java +++ b/src/main/java/com/team766/robot/OI.java @@ -37,7 +37,9 @@ public class OI extends Procedure { private static final double HighConeArm1 = 0; private static final double CHA2 = 0; private static final double CMA1 = 0; + private int state = 0; + private boolean ignoreState = false; // enum generalControl{ // CONE_HIGH_NODE, // CUBE_HIGH_NODE, diff --git a/src/main/java/com/team766/robot/mechanisms/Lights.java b/src/main/java/com/team766/robot/mechanisms/Lights.java index b84987c..1c0af62 100644 --- a/src/main/java/com/team766/robot/mechanisms/Lights.java +++ b/src/main/java/com/team766/robot/mechanisms/Lights.java @@ -15,12 +15,12 @@ public class Lights extends Mechanism{ private CANdle candle; private static final int CANID = 5; private int numLEDs = 42; - RainbowAnimation rainbowAnim = new RainbowAnimation(1, 5, numLEDs); + RainbowAnimation rainbowAnim = new RainbowAnimation(1, 3, numLEDs); int curAnimation = -1; + public Lights(){ candle = new CANdle(CANID); - } public void setNumLEDs(int num){ @@ -33,19 +33,19 @@ public void signalCube(){ checkContextOwnership(); if(DriverStation.getMatchTime() > 30){ if(curAnimation != -1){candle.clearAnimation(curAnimation);} - candle.setLEDs(128, 0, 128); - }else{ + candle.setLEDs(142, 38, 252); + } else { candle.clearAnimation(curAnimation); if(DriverStation.getMatchTime() > 15){ if((int) (DriverStation.getMatchTime() * 2) % 2 == 0){ - candle.setLEDs(128, 0, 128); - }else{ + candle.setLEDs(142, 38, 252); + } else { candle.setLEDs(0, 0, 0); } - }else{ + } else { if((int) (DriverStation.getMatchTime() * 4) % 2 == 0){ - candle.setLEDs(128, 0, 128); - }else{ + candle.setLEDs(142, 38, 252); + } else { candle.setLEDs(0, 0, 0); } } @@ -61,19 +61,19 @@ public void signalCone(){ checkContextOwnership(); if(DriverStation.getMatchTime() > 30){ if(curAnimation != -1){candle.clearAnimation(curAnimation);} - candle.setLEDs(255, 255, 0); - }else{ + candle.setLEDs(250, 196, 32); + } else { candle.clearAnimation(curAnimation); if(DriverStation.getMatchTime() > 15){ if((int) (DriverStation.getMatchTime() * 2) % 2 == 0){ - candle.setLEDs(225, 225, 0); - }else{ + candle.setLEDs(250, 196, 32); + } else { candle.setLEDs(0, 0, 0); } - }else{ + } else { if((int) (DriverStation.getMatchTime() * 4) % 2 == 0){ - candle.setLEDs(225,225,0); - }else{ + candle.setLEDs(250, 196, 32); + } else { candle.setLEDs(0, 0, 0); } } @@ -82,8 +82,9 @@ public void signalCone(){ } public void auton(){ - candle.setLEDs(0, 255, 0); + candle.setLEDs(0, 223, 247); } + public void signalMalfunction(){ checkContextOwnership(); candle.setLEDs(255, 0, 0); @@ -114,18 +115,18 @@ public void hybridScore(){ if(DriverStation.getMatchTime() > 30){ if(curAnimation != -1){candle.clearAnimation(curAnimation);} candle.setLEDs(165, 128, 65); - }else{ + } else { candle.clearAnimation(curAnimation); if(DriverStation.getMatchTime() > 15){ if((int) (DriverStation.getMatchTime() * 2) % 2 == 0){ candle.setLEDs(165, 128, 65); - }else{ + } else { candle.setLEDs(0, 0, 0); } - }else{ + } else { if((int) (DriverStation.getMatchTime() * 4) % 2 == 0){ candle.setLEDs(165, 128, 65); - }else{ + } else { candle.setLEDs(0, 0, 0); } } @@ -139,18 +140,18 @@ public void midScore(){ if(DriverStation.getMatchTime() > 30){ if(curAnimation != -1){candle.clearAnimation(curAnimation);} candle.setLEDs(81,102,52); - }else{ + } else { candle.clearAnimation(curAnimation); if(DriverStation.getMatchTime() > 15){ if((int) (DriverStation.getMatchTime() * 2) % 2 == 0){ candle.setLEDs(81,102,52); - }else{ + } else { candle.setLEDs(0, 0, 0); } - }else{ + } else { if((int) (DriverStation.getMatchTime() * 4) % 2 == 0){ candle.setLEDs(81,102,52); - }else{ + } else { candle.setLEDs(0, 0, 0); } } @@ -163,18 +164,18 @@ public void highScore(){ if(DriverStation.getMatchTime() > 30){ if(curAnimation != -1){candle.clearAnimation(curAnimation);} candle.setLEDs(202, 39, 75); - }else{ + } else { candle.clearAnimation(curAnimation); if(DriverStation.getMatchTime() > 15){ if((int) (DriverStation.getMatchTime() * 2) % 2 == 0){ candle.setLEDs(202, 39, 75); - }else{ + } else { candle.setLEDs(0, 0, 0); } - }else{ + } else { if((int) (DriverStation.getMatchTime() * 4) % 2 == 0){ candle.setLEDs(202, 39, 75); - }else{ + } else { candle.setLEDs(0, 0, 0); } }