From 5cd29a45860688a777817cda4f15e51e6b1db5fb Mon Sep 17 00:00:00 2001 From: Samuel Li Date: Tue, 26 Nov 2019 13:05:11 -0800 Subject: [PATCH 1/2] initial commit for lightshow --- .../main/java/com/team2813/frc2019/Robot.java | 13 +++++----- .../frc2019/subsystems/Lightshow.java | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 OffSeasonBot2019/src/main/java/com/team2813/frc2019/subsystems/Lightshow.java diff --git a/OffSeasonBot2019/src/main/java/com/team2813/frc2019/Robot.java b/OffSeasonBot2019/src/main/java/com/team2813/frc2019/Robot.java index 2a9b3a8..2875005 100644 --- a/OffSeasonBot2019/src/main/java/com/team2813/frc2019/Robot.java +++ b/OffSeasonBot2019/src/main/java/com/team2813/frc2019/Robot.java @@ -9,10 +9,7 @@ import com.ctre.phoenix.CANifier; import com.team2813.frc2019.loops.Loop; -import com.team2813.frc2019.subsystems.Drive; -import com.team2813.frc2019.subsystems.MainIntake; -import com.team2813.frc2019.subsystems.Subsystem; -import com.team2813.frc2019.subsystems.Subsystems; +import com.team2813.frc2019.subsystems.*; import com.team2813.lib.config.MotorConfigs; import com.team2813.lib.util.CrashTracker; import edu.wpi.first.wpilibj.Compressor; @@ -39,7 +36,7 @@ public class Robot extends TimedRobot { private static final double MIN_DISABLED_VOLTAGE = 12.0; private static boolean batteryTooLow = false; - private CANifier caNifier = new CANifier(0); + private static Lightshow lightshow = new Lightshow(new CANifier(1)); /** * This function is run when the robot is first started up and should be @@ -50,6 +47,7 @@ public void robotInit() { try { CrashTracker.logRobotInit(); MotorConfigs.read(); + lightshow.test(); Subsystems.initializeSubsystems(); for (Subsystem subsystem : allSubsystems) { LOOPER.addLoop(subsystem); @@ -109,8 +107,8 @@ public void autonomousInit() { // A: Green // B: Red // C: Blue - caNifier.setLEDOutput(255, CANifier.LEDChannel.LEDChannelA); - CrashTracker.logAutoInit(); +// caNifier.setLEDOutput(255, CANifier.LEDChannel.LEDChannelA); +// CrashTracker.logAutoInit(); Compressor compressor = new Compressor(); // FIXME: 11/02/2019 this shouldn't need to be here compressor.start(); MAIN_INTAKE.setMode(MainIntake.GamePiece.HATCH_PANEL); @@ -157,6 +155,7 @@ public void teleopPeriodic() { * this calls every subsystem's controls method which * should contain any code to invoke driver controls */ + lightshow.test(); for (Subsystem subsystem : allSubsystems) { subsystem.teleopControls(); } diff --git a/OffSeasonBot2019/src/main/java/com/team2813/frc2019/subsystems/Lightshow.java b/OffSeasonBot2019/src/main/java/com/team2813/frc2019/subsystems/Lightshow.java new file mode 100644 index 0000000..278ec61 --- /dev/null +++ b/OffSeasonBot2019/src/main/java/com/team2813/frc2019/subsystems/Lightshow.java @@ -0,0 +1,25 @@ +package com.team2813.frc2019.subsystems; + +import com.ctre.phoenix.CANifier; + +public class Lightshow { + private CANifier caNifier; + private int pwmChannel = CANifier.PWMChannel.PWMChannel1.value; + + public Lightshow(CANifier caNifier) { + this.caNifier = caNifier; + caNifier.enablePWMOutput(pwmChannel, true); + } + + public Lightshow test() { + caNifier.setPWMOutput(pwmChannel, 1); + return this; + } + +// public CANifier setR(int red) { +// caNifier.x +// } +} + + +// 14 \ No newline at end of file From b9695186335d9782425136fcb558a074e462eb47 Mon Sep 17 00:00:00 2001 From: Samuel Li Date: Mon, 2 Dec 2019 16:23:23 -0800 Subject: [PATCH 2/2] got pid to cycle? --- .../main/java/com/team2813/frc2019/Robot.java | 6 +-- .../frc2019/subsystems/Lightshow.java | 51 ++++++++++++++++--- 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/OffSeasonBot2019/src/main/java/com/team2813/frc2019/Robot.java b/OffSeasonBot2019/src/main/java/com/team2813/frc2019/Robot.java index 2875005..16184d8 100644 --- a/OffSeasonBot2019/src/main/java/com/team2813/frc2019/Robot.java +++ b/OffSeasonBot2019/src/main/java/com/team2813/frc2019/Robot.java @@ -36,7 +36,7 @@ public class Robot extends TimedRobot { private static final double MIN_DISABLED_VOLTAGE = 12.0; private static boolean batteryTooLow = false; - private static Lightshow lightshow = new Lightshow(new CANifier(1)); + private static Lightshow lightshow = new Lightshow(9); /** * This function is run when the robot is first started up and should be @@ -47,7 +47,7 @@ public void robotInit() { try { CrashTracker.logRobotInit(); MotorConfigs.read(); - lightshow.test(); + lightshow.enable(); Subsystems.initializeSubsystems(); for (Subsystem subsystem : allSubsystems) { LOOPER.addLoop(subsystem); @@ -155,7 +155,7 @@ public void teleopPeriodic() { * this calls every subsystem's controls method which * should contain any code to invoke driver controls */ - lightshow.test(); +// lightshow.test(); for (Subsystem subsystem : allSubsystems) { subsystem.teleopControls(); } diff --git a/OffSeasonBot2019/src/main/java/com/team2813/frc2019/subsystems/Lightshow.java b/OffSeasonBot2019/src/main/java/com/team2813/frc2019/subsystems/Lightshow.java index 278ec61..279fedd 100644 --- a/OffSeasonBot2019/src/main/java/com/team2813/frc2019/subsystems/Lightshow.java +++ b/OffSeasonBot2019/src/main/java/com/team2813/frc2019/subsystems/Lightshow.java @@ -1,18 +1,55 @@ package com.team2813.frc2019.subsystems; import com.ctre.phoenix.CANifier; +import edu.wpi.first.wpilibj.DigitalOutput; +import edu.wpi.first.wpilibj.PWM; public class Lightshow { - private CANifier caNifier; - private int pwmChannel = CANifier.PWMChannel.PWMChannel1.value; + private DigitalOutput out; - public Lightshow(CANifier caNifier) { - this.caNifier = caNifier; - caNifier.enablePWMOutput(pwmChannel, true); + private double output = 0; + + Thread thread; + + public Lightshow(int channel) { + this.out = new DigitalOutput(channel); + } + + public void enable() { + out.enablePWM(0); + out.setPWMRate(4200); + thread = new Thread(() -> { + try { + while (true) { + out.updateDutyCycle(0); + System.out.println(); + Thread.sleep(1000); + out.updateDutyCycle(.2); + System.out.println(.2); + Thread.sleep(1000); + out.updateDutyCycle(.4); + System.out.println(.4); + Thread.sleep(1000); + out.updateDutyCycle(.6); + System.out.println(out.get()); + Thread.sleep(1000); + out.updateDutyCycle(.8); + System.out.println(.8); + Thread.sleep(1000); + out.updateDutyCycle(1); + System.out.println(1); + Thread.sleep(1000); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + }); + + thread.start(); } - public Lightshow test() { - caNifier.setPWMOutput(pwmChannel, 1); + public Lightshow disable() { + thread.stop(); return this; }