Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashboard #17

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
7 changes: 7 additions & 0 deletions .Glass/glass.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"NetworkTables": {
"transitory": {
"Faults": {
"open": true
},
"Robot": {
"drive": {
"frontRight": {
Expand Down Expand Up @@ -49,6 +52,7 @@
"/Robot/drive/rearRight/turnFeedback": "PIDController",
"/Robot/drive/rotationController": "PIDController",
"/Robot/drive/translationController": "ProfiledPIDController",
"/SmartDashboard/Alerts": "Alerts",
"/SmartDashboard/Scheduler": "Scheduler",
"/SmartDashboard/VisionSystemSim-main/Sim Field": "Field2d",
"/SmartDashboard/drive dynamic backward": "Command",
Expand All @@ -70,6 +74,9 @@
}
},
"NetworkTables Info": {
"Clients": {
"open": true
},
"visible": true
},
"NetworkTables Settings": {
Expand Down
28 changes: 11 additions & 17 deletions simgui.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@
"/FMSInfo": "FMSInfo",
"/Faults/Active Faults": "Alerts",
"/Faults/Total Faults": "Alerts",
<<<<<<< HEAD
"/Robot/arm/armCanvas": "Mechanism2d",
"/Robot/arm/fb": "ProfiledPIDController",
=======
>>>>>>> main
"/Robot/autos": "String Chooser",
"/Robot/drive/field2d": "Field2d",
"/Robot/drive/rotationController": "PIDController",
Expand All @@ -34,8 +31,6 @@
"/SmartDashboard/Alerts": "Alerts",
"/SmartDashboard/Scheduler": "Scheduler",
"/SmartDashboard/VisionSystemSim-main/Sim Field": "Field2d",
<<<<<<< HEAD
=======
"/SmartDashboard/drive dynamic backward": "Command",
"/SmartDashboard/drive dynamic forward": "Command",
"/SmartDashboard/drive quasistatic backward": "Command",
Expand All @@ -44,7 +39,6 @@
"/SmartDashboard/pivot dynamic forward": "Command",
"/SmartDashboard/pivot quasistatic backward": "Command",
"/SmartDashboard/pivot quasistatic forward": "Command",
>>>>>>> main
"/SmartDashboard/rotation dynamic backward": "Command",
"/SmartDashboard/rotation dynamic forward": "Command",
"/SmartDashboard/rotation quasistatic backward": "Command",
Expand Down Expand Up @@ -104,6 +98,9 @@
"open": false
},
"transitory": {
"Dashboard": {
"open": true
},
"Robot": {
"drive": {
"Pose2d##v_/Robot/drive/getPose": {
Expand Down Expand Up @@ -177,19 +174,20 @@
},
"open": true
},
"open": true,
"vision": {
"open": true
}
},
"Shuffleboard": {
"open": true
},
"SmartDashboard": {
"open": true
}
}
},
"NetworkTables Info": {
"Clients": {
"open": true
},
"example client@1": {
"open": true
},
"visible": true
},
"Plot": {
Expand All @@ -202,11 +200,7 @@
0.0,
0.8500000238418579
],
<<<<<<< HEAD
"height": 0,
=======
"height": 405,
>>>>>>> main
"height": 354,
"series": [
{
"color": [
Expand Down
20 changes: 16 additions & 4 deletions src/main/java/org/sciborgs1155/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import static org.sciborgs1155.robot.Constants.DEADBAND;
import static org.sciborgs1155.robot.Constants.Field.*;
import static org.sciborgs1155.robot.Constants.PERIOD;
import static org.sciborgs1155.robot.commands.Dashboard.Branches.*;
import static org.sciborgs1155.robot.commands.Dashboard.Levels.*;
import static org.sciborgs1155.robot.drive.DriveConstants.*;

import edu.wpi.first.wpilibj.DataLogManager;
Expand All @@ -34,6 +36,7 @@
import org.sciborgs1155.robot.Ports.OI;
import org.sciborgs1155.robot.arm.Arm;
import org.sciborgs1155.robot.commands.Autos;
import org.sciborgs1155.robot.commands.Dashboard;
import org.sciborgs1155.robot.coroller.Coroller;
import org.sciborgs1155.robot.drive.Drive;
import org.sciborgs1155.robot.elevator.Elevator;
Expand Down Expand Up @@ -82,6 +85,7 @@ private void configureGameBehavior() {
// Configure logging with DataLogManager, Monologue, URCL, and FaultLogger
DataLogManager.start();
Monologue.setupMonologue(this, "/Robot", false, true);
Dashboard.configure();
addPeriodic(Monologue::updateAll, PERIOD.in(Seconds));
addPeriodic(FaultLogger::update, 2);

Expand All @@ -103,14 +107,22 @@ private void configureGameBehavior() {
DriverStation.silenceJoystickConnectionWarning(true);
addPeriodic(() -> vision.simulationPeriodic(drive.pose()), PERIOD.in(Seconds));
}

addPeriodic(
() -> {
Dashboard.info.get("closestBranch").setString(drive.closestBranch());
Dashboard.tick();
},
PERIOD.in(Seconds));
// addPeriodic(() -> , PERIOD.in(Seconds));
}

/** Configures trigger -> command bindings. */
private void configureBindings() {
operator.a().onTrue(elevator.scoreLevel(Level.L1));
operator.b().onTrue(elevator.scoreLevel(Level.L2));
operator.x().onTrue(elevator.scoreLevel(Level.L3));
operator.y().onTrue(elevator.scoreLevel(Level.L4));
L1.trigger.onTrue(elevator.scoreLevel(Level.L1));
L2.trigger.onTrue(elevator.scoreLevel(Level.L2));
L3.trigger.onTrue(elevator.scoreLevel(Level.L3));
L4.trigger.onTrue(elevator.scoreLevel(Level.L4));

// x and y are switched: we use joystick Y axis to control field x motion
InputStream x = InputStream.of(driver::getLeftY).negate();
Expand Down
126 changes: 126 additions & 0 deletions src/main/java/org/sciborgs1155/robot/commands/Dashboard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package org.sciborgs1155.robot.commands;

import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.wpilibj.DriverStation.Alliance;
import edu.wpi.first.wpilibj2.command.button.Trigger;
import java.util.HashMap;
import org.sciborgs1155.robot.Constants;

/**
* Dashboard listens to NetworkTable information from the Reefscape-2025-Dashboard, which can be
* used as Triggers. Must call the configure() method.
*/
public class Dashboard {
private static NetworkTable base;
private static NetworkTableEntry entryTargetBranch;
private static NetworkTableEntry entryTargetLevel;
private static NetworkTableEntry entryProcessor;
private static NetworkTableEntry entryRobotTick;
private static int tick;
private static NetworkTableEntry entryBlueAlliance;
public static final HashMap<String, NetworkTableEntry> info = new HashMap<>();
public static Trigger processorTrigger;

/** Sets up the dashboard. */
public static void configure() {
base = NetworkTableInstance.getDefault().getTable("Dashboard");

entryTargetBranch = base.getEntry("branch");
entryTargetBranch.setString("");

entryTargetLevel = base.getEntry("level");
entryTargetLevel.setInteger(0);

entryProcessor = base.getEntry("processor");
entryProcessor.setBoolean(false);
processorTrigger = new Trigger(() -> entryProcessor.getBoolean(false));

entryRobotTick = base.getEntry("robotTick");
entryRobotTick.setInteger(0);
tick = 0;

entryBlueAlliance = base.getEntry("blueAlliance");
entryBlueAlliance.setBoolean(Constants.alliance() == Alliance.Blue);

// info setup
transmit("closestBranch");
}

/** Increments the robot tick value. Used by Dashboard to detect disconnects. */
public static void tick() {
tick += 1;
entryRobotTick.setInteger(tick);
}

/**
* Adds a key/entry pair to the info hashmap.
*
* @param key the key of the NetworkTables entry
*/
public static void transmit(String key) {
NetworkTableEntry entry = base.getEntry(key);
info.put(key, entry);
}

/**
* Returns a Trigger, given a reef branch.
*
* @param branch the branch for the trigger (A-L)
* @return a Trigger for that branch
*/
private static Trigger setTriggerBranch(String branch) {
return new Trigger(() -> (branch.equals(entryTargetBranch.getString(""))));
}

/**
* Returns a Trigger, given a reef branch level.
*
* @param level the level for the trigger (1-4)
* @return a Trigger for that level
*/
private static Trigger setTriggerLevel(int level) {
return new Trigger(() -> (level == entryTargetLevel.getInteger(0)));
}

/** An enum for each branch of the alliance's reef. */
public static enum Branches {
A("A"),
B("B"),
C("C"),
D("D"),
E("E"),
F("F"),
G("G"),
H("H"),
I("I"),
J("J"),
K("K"),
L("L");

public final String branch;
public final Trigger trigger;

private Branches(String branch) {
this.branch = branch;
this.trigger = setTriggerBranch(branch);
}
}

/** An enum for each level of a branch of the alliance's reef. */
public static enum Levels {
L1(1),
L2(2),
L3(3),
L4(4);

public final int level;
public final Trigger trigger;

private Levels(int level) {
this.level = level;
this.trigger = setTriggerLevel(level);
}
}
}
10 changes: 10 additions & 0 deletions src/main/java/org/sciborgs1155/robot/drive/Drive.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import monologue.Logged;
import org.photonvision.EstimatedRobotPose;
import org.sciborgs1155.lib.Assertion;
import org.sciborgs1155.lib.Assertion.EqualityAssertion;
import org.sciborgs1155.lib.Assertion.TruthAssertion;
import org.sciborgs1155.lib.InputStream;
import org.sciborgs1155.lib.Test;
import org.sciborgs1155.robot.Constants;
Expand Down Expand Up @@ -413,6 +415,14 @@ public ChassisSpeeds fieldRelativeChassisSpeeds() {
return ChassisSpeeds.fromRobotRelativeSpeeds(robotRelativeChassisSpeeds(), heading());
}

public String closestBranch() {
if (pose().getX() < 3) {
return "A";
} else {
return "B";
}
}

/**
* Updates pose estimate based on vision-provided {@link EstimatedRobotPose}s.
*
Expand Down