Skip to content
This repository has been archived by the owner on May 19, 2024. It is now read-only.

Commit

Permalink
refactor: Automatically assign column indexes.
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenheroux committed Jan 8, 2024
1 parent b604667 commit 8b065f6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
}
},
],
"java.test.defaultConfig": "WPIlibUnitTests"
"java.test.defaultConfig": "WPIlibUnitTests",
"java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx2G -Xms100m -Xlog:disable"
}
27 changes: 27 additions & 0 deletions src/main/java/frc/lib/Telemetry.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package frc.lib;

import edu.wpi.first.wpilibj.shuffleboard.BuiltInLayouts;
import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard;
import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardLayout;
import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardTab;
import java.util.HashMap;

/** Helper class for managing robot telemetry. */
public class Telemetry {

private static final HashMap<String, Integer> tabColumnCount = new HashMap<>();

/**
* Initializes a subsystem's Shuffleboard tab.
*
Expand All @@ -18,4 +23,26 @@ public static void initializeShuffleboard(Subsystem subsystem) {

subsystem.addToShuffleboard(tab);
}

/**
* Adds a column to a Shuffleboard tab.
*
* @param tab the Shuffleboard tab to add the column to.
* @param columnTitle the title of the column.
* @return the added Shuffleboard column.
*/
public static ShuffleboardLayout addColumn(ShuffleboardTab tab, String columnTitle) {
String tabTitle = tab.getTitle();

int currentColumnCount = tabColumnCount.getOrDefault(tabTitle, 0);
// Increment the column count for the next call
tabColumnCount.put(tabTitle, currentColumnCount + 1);

final int kColumnWidth = 2;
final int kColumnHeight = 4;

return tab.getLayout(columnTitle, BuiltInLayouts.kList)
.withSize(kColumnWidth, kColumnHeight)
.withPosition(currentColumnCount * kColumnWidth, 0);
}
}
11 changes: 4 additions & 7 deletions src/main/java/frc/robot/shooter/Shooter.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package frc.robot.shooter;

import edu.wpi.first.wpilibj.shuffleboard.BuiltInLayouts;
import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardLayout;
import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardTab;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Commands;
import frc.lib.Subsystem;
import frc.lib.Telemetry;
import frc.robot.shooter.BeamBreakSensorIO.BeamBreakSensorIOValues;
import frc.robot.shooter.FlywheelMotorIO.FlywheelMotorIOValues;
import frc.robot.shooter.SerializerMotorIO.SerializerMotorIOValues;
Expand Down Expand Up @@ -92,19 +92,16 @@ private double getFlywheelTangentialSpeed() {

@Override
public void addToShuffleboard(ShuffleboardTab tab) {
ShuffleboardLayout sensors =
tab.getLayout("Sensors", BuiltInLayouts.kList).withPosition(0, 0).withSize(2, 4);
ShuffleboardLayout sensors = Telemetry.addColumn(tab, "Sensors");

sensors.addBoolean("Is Holding Note?", this::isHoldingNote);

ShuffleboardLayout serializer =
tab.getLayout("Serializer", BuiltInLayouts.kList).withPosition(2, 0).withSize(2, 4);
ShuffleboardLayout serializer = Telemetry.addColumn(tab, "Serializer");

serializer.addDouble("Serializer Speed (mps)", this::getSerializerTangentialSpeed);
serializer.addDouble("Serializer Current (A)", () -> serializerMotorValues.currentAmps);

ShuffleboardLayout flywheel =
tab.getLayout("Flywheel", BuiltInLayouts.kList).withPosition(4, 0).withSize(2, 4);
ShuffleboardLayout flywheel = Telemetry.addColumn(tab, "Flywheel");

flywheel.addDouble("Flywheel Speed (mps)", this::getFlywheelTangentialSpeed);
flywheel.addDouble("Flywheel Current (A)", () -> flywheelMotorValues.currentAmps);
Expand Down

0 comments on commit 8b065f6

Please sign in to comment.