Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kytpbs committed Apr 30, 2024
2 parents f648078 + a9e3a3a commit 98d0f29
Show file tree
Hide file tree
Showing 30 changed files with 915 additions and 88 deletions.
21 changes: 20 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id "java"
id "jacoco"
id "edu.wpi.first.GradleRIO" version "2024.2.1"
id "com.diffplug.spotless" version "6.23.3"
}
Expand All @@ -8,7 +9,7 @@ spotless {
java {
target fileTree('.') {
include '**/*.java'
exclude '**/build/**', '**/build-*/**'
exclude '**/build/**', '**/build-*/**', '**/logs/**'
}
toggleOffOn()
googleJavaFormat('1.19.1')
Expand All @@ -25,6 +26,19 @@ java {
targetCompatibility = JavaVersion.VERSION_17
}

jacoco {
toolVersion = "0.8.11"
reportsDirectory = layout.projectDirectory.dir("logs/jacoco")
}

jacocoTestReport {
reports {
xml.required = false
csv.required = false
html.outputLocation = layout.projectDirectory.dir("logs/jacocoHtml")
}
}

def ROBOT_MAIN_CLASS = "frc.robot.Main"

// Define my targets (RoboRIO) and artifacts (deployable files)
Expand Down Expand Up @@ -91,6 +105,11 @@ dependencies {
test {
useJUnitPlatform()
systemProperty 'junit.jupiter.extensions.autodetection.enabled', 'true'
finalizedBy jacocoTestReport // report is always generated after tests run
}

jacocoTestReport {
dependsOn test // tests are required to run before generating the report
}

// Simulation configuration (e.g. environment variables).
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import frc.robot.Constants.IntakeConstants;
import frc.robot.commands.ArmIdleCommand;
import frc.robot.commands.BasicIntakeCommand;
import frc.robot.commands.ReallySimpleAuto;
import frc.robot.commands.ShootToAmpCommand;
import frc.robot.commands.SmartIntakeCommand;
import frc.robot.commands.SmartShootCommand;
Expand Down Expand Up @@ -58,9 +57,6 @@ public RobotContainer() {
"Shoot To Shooter",
new SmartShootCommand(shooterSubsystem, intakeSubsystem, armSubsystem, driveSubsystem));
PhotonCameraSystem.getAprilTagWithID(0); // Load the class before enable.
autoChooser.addOption(
"Shoot & Back",
new ReallySimpleAuto(armSubsystem, intakeSubsystem, shooterSubsystem, driveSubsystem));
SmartDashboard.putData("Auto Chooser", autoChooser);
if (RobotBase.isSimulation()) {
simInit();
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/frc/robot/commands/BasicRunShooterCommand.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
package frc.robot.commands;

import edu.wpi.first.wpilibj2.command.ParallelRaceGroup;
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
import frc.robot.Constants.ShooterConstants;
import frc.robot.commands.led_commands.LEDLoadingWaitCommand;
import frc.robot.subsystems.ShooterSubsystem;

public class BasicRunShooterCommand extends SequentialCommandGroup {
BasicRunShooterCommand(ShooterSubsystem shooterSubsystem) {
public BasicRunShooterCommand(ShooterSubsystem shooterSubsystem) {
super(
shooterSubsystem.run(
() -> shooterSubsystem.setShooterSpeed(ShooterConstants.kShooterSpeed)));
}

BasicRunShooterCommand(ShooterSubsystem shooterSubsystem, double untilTimeSeconds) {
public BasicRunShooterCommand(ShooterSubsystem shooterSubsystem, double untilTimeSeconds) {
super(
shooterSubsystem
.run(() -> shooterSubsystem.setShooterSpeed(ShooterConstants.kShooterSpeed))
.raceWith(new LEDLoadingWaitCommand(untilTimeSeconds)));
new ParallelRaceGroup(
new BasicRunShooterCommand(shooterSubsystem), // Run the shooter
new LEDLoadingWaitCommand(untilTimeSeconds)),
shooterSubsystem.runOnce(
() -> shooterSubsystem.setShooterSpeed(0) // Stop the shooter after the wait
));
}
}
2 changes: 1 addition & 1 deletion src/main/java/frc/robot/commands/MoveArmToAmp.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import frc.robot.subsystems.ArmSubsystem;

public class MoveArmToAmp extends SequentialCommandGroup {
MoveArmToAmp(ArmSubsystem armSubsystem) {
public MoveArmToAmp(ArmSubsystem armSubsystem) {
super(
armSubsystem
.run(() -> armSubsystem.setArmToPosition(0.5))
Expand Down
20 changes: 0 additions & 20 deletions src/main/java/frc/robot/commands/ReallySimpleAuto.java

This file was deleted.

20 changes: 9 additions & 11 deletions src/main/java/frc/robot/commands/VibrateControllerCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
import edu.wpi.first.wpilibj2.command.WaitCommand;
import frc.robot.commands.util_commands.RepeatForCommand;

public class VibrateControllerCommand extends SequentialCommandGroup {
public VibrateControllerCommand(
Expand All @@ -24,16 +25,13 @@ public VibrateControllerCommand(XboxController controller, int repetitions) {
private static Command createVibrateControllerCommand(
XboxController controller, int repetitions, double intensity, double duration) {

Command command =
new InstantCommand(() -> controller.setRumble(RumbleType.kBothRumble, intensity));
for (int i = 0; i < repetitions; i++) {
command =
command
.andThen(new WaitCommand(duration))
.andThen(() -> controller.setRumble(RumbleType.kBothRumble, 0))
.andThen(new WaitCommand(duration))
.andThen(() -> controller.setRumble(RumbleType.kBothRumble, intensity));
}
return command.finallyDo(() -> controller.setRumble(RumbleType.kBothRumble, 0));
SequentialCommandGroup toRepeatCommand =
new SequentialCommandGroup(
new InstantCommand(() -> controller.setRumble(RumbleType.kBothRumble, intensity)), //
new WaitCommand(duration),
new InstantCommand(() -> controller.setRumble(RumbleType.kBothRumble, 0)),
new WaitCommand(duration));

return new RepeatForCommand(toRepeatCommand, repetitions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
public class LEDLoadingWaitCommand extends WaitCommand {
private double seconds;
private Color colorToFill;
public static final Color DEFAULT_COLOR = new Color(0, 200, 255);

public LEDLoadingWaitCommand(double seconds, Color colorToFill) {
super(seconds);
Expand All @@ -16,7 +17,7 @@ public LEDLoadingWaitCommand(double seconds, Color colorToFill) {
}

public LEDLoadingWaitCommand(double seconds) {
this(seconds, new Color(0, 200, 255));
this(seconds, DEFAULT_COLOR);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package frc.robot.commands.util_commands;

import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.RepeatCommand;

public class RepeatForCommand extends RepeatCommand {
private double count;
private Command command;

/**
* Repeats a command for a specified number of times
*
* @param command The command to repeat
* @param count The number of times to repeat the command
*/
public RepeatForCommand(Command command, int count) {
super(command);
this.command = command;
this.count = count;
}

@Override
public void execute() {
// only decrement the count if the command has finished
if (command.isFinished()) {
count--;
}
super.execute();
}

@Override
public boolean isFinished() {
return count <= 0;
}
}
8 changes: 7 additions & 1 deletion src/main/java/frc/robot/subsystems/ArmSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import frc.utils.ExtraFunctions;
import frc.utils.sim_utils.CANSparkMAXWrapped;

public class ArmSubsystem extends SubsystemBase {
public class ArmSubsystem extends SubsystemBase implements AutoCloseable {
// We only have RelativeEncoder for now. Its better than nothing.
private final CANSparkMAXWrapped arm;
private final CANSparkMAXWrapped armFollower;
Expand Down Expand Up @@ -63,6 +63,12 @@ private void setupSparkMax() {
arm.burnFlash();
}

@Override
public void close() {
arm.close();
armFollower.close();
}

/**
* Sets the arm to a position. This is a wrapper for the Spark Max's set method.
*
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/frc/robot/subsystems/IntakeSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class IntakeSubsystem extends SubsystemBase implements AutoCloseable {
private final CANSparkMAXWrapped armIntake;
private final CANSparkMAXWrapped groundIntake;
private final ColorSensorV3Wrapped colorSensor;
private final Thread fastColorCheckThread;
private boolean isForced = false;

public IntakeSubsystem() {
Expand All @@ -29,14 +30,16 @@ public IntakeSubsystem() {
setupIntakeMotors();
colorSensor = new ColorSensorV3Wrapped(ColorSensorConstants.kColorSensorPort);

new Thread(
fastColorCheckThread =
new Thread(
() -> {
while (true) {
fastPeriodic();
}
},
"Fast Color Check Loop")
.start();
"Fast Color Check Loop");
fastColorCheckThread.setDaemon(true);
fastColorCheckThread.start();
}

private void setupIntakeMotors() {
Expand All @@ -57,6 +60,7 @@ private void setupIntakeMotors() {

@Override
public void close() {
fastColorCheckThread.interrupt();
armIntake.close();
groundIntake.close();
colorSensor.close();
Expand Down Expand Up @@ -127,7 +131,7 @@ public void periodic() {
SmartDashboard.putNumber("ColorSensor - Blue", colorSensor.getBlue());
SmartDashboard.putNumber("ColorSensor - IR", colorSensor.getIR());
SmartDashboard.putBoolean("Note Detected", hasNote());
checkIfHasNote();
// don't check for a note here cause it breaks the unit tests SOMEHOW!
}

private void fastPeriodic() {
Expand Down
25 changes: 22 additions & 3 deletions src/main/java/frc/robot/subsystems/LEDSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import frc.robot.Constants.LEDConstants;
import frc.utils.BetterLED;

public class LEDSubsystem extends SubsystemBase {
public class LEDSubsystem extends SubsystemBase implements AutoCloseable {
BetterLED strip;
Color lastSetColor = new Color();
Color lastSetBlinkingColor = new Color();
Expand All @@ -22,6 +22,15 @@ public void periodic() {
SmartDashboard.putString("LED Currently Running", strip.getCurrentCommandName());
}

@Override
public void close() {
strip.close();
}

public int getLedCount() {
return strip.getLedCount();
}

public void fill(Color color) {
if (lastSetColor.equals(color)) {
return;
Expand Down Expand Up @@ -68,13 +77,17 @@ public void setStatusColor(boolean status) {
}
}

public void blink(Color color) {
public void blink(Color color, double delaySeconds) {
if (lastSetBlinkingColor.equals(color)) {
return;
}
lastSetColor = new Color(); // Reset back to 0
lastSetBlinkingColor = color;
strip.blink(color);
strip.blink(color, delaySeconds);
}

public void blink(Color color) {
blink(color, 0.2);
}

public void blinkRed() {
Expand All @@ -84,6 +97,12 @@ public void blinkRed() {
blink(new Color(255, 0, 0));
}

/**
* Fills the led's until the given percentage.
*
* @param percentage a value between 0 and 1
* @param color the color to fill with
*/
public void fillPercentageWithColor(double percentage, Color color) {
fill(color, (int) (strip.getLedCount() * percentage), true);
}
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/frc/robot/subsystems/LEDSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import edu.wpi.first.wpilibj2.command.Command;

public final class LEDSystem {
private static final LEDSubsystem ledSubsystemInstance = new LEDSubsystem();
private static LEDSubsystem ledSubsystemInstance = new LEDSubsystem();

private LEDSystem() {}

Expand All @@ -18,4 +18,17 @@ public static Command run(Runnable toRun) {
public static Command getBlinkRedCommand() {
return ledSubsystemInstance.getRedBlinkCommand();
}

public static void resetLEDSubsystem() {
if (ledSubsystemInstance == null) {
ledSubsystemInstance = new LEDSubsystem();
return;
}
ledSubsystemInstance.close();
ledSubsystemInstance = new LEDSubsystem();
}

public static void changeLEDSubsystemInstance(LEDSubsystem ledSubsystem) {
ledSubsystemInstance = ledSubsystem;
}
}
7 changes: 6 additions & 1 deletion src/main/java/frc/robot/subsystems/ShooterSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
import edu.wpi.first.wpilibj.motorcontrol.Spark;
import edu.wpi.first.wpilibj2.command.SubsystemBase;

public class ShooterSubsystem extends SubsystemBase {
public class ShooterSubsystem extends SubsystemBase implements AutoCloseable {
private final Spark shooterMotor;

public ShooterSubsystem() {
shooterMotor = new Spark(0);
}

@Override
public void close() {
shooterMotor.close();
}

public void setShooterSpeed(double speed) {
shooterMotor.set(speed);
}
Expand Down
Loading

0 comments on commit 98d0f29

Please sign in to comment.