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

Updated Hydrogen #25

Merged
merged 15 commits into from
Sep 4, 2024
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
# Hydrogen
The SciBorgs' base repository.

WIP
The SciBorgs' base repository. It is a living document that should be updated yearly for new libraries and other changes.

## Structure
Our robot code is centered around [Robot.java](src/main/java/org/sciborgs1155/robot/Robot.java)
Our robot code is centered around [Robot.java](src/main/java/org/sciborgs1155/robot/Robot.java).

This project currently contains drive, vision, and autos. You are expected to add/modify code supporting existing files and new subsystems when using this template. Some of these files include but are not limited to:
- **[Autos.java](src/main/java/org/sciborgs1155/robot/commands/Autos.java)** Add code for new subsystems in `configureAutos`, such as commands for `NamedCommands`
- **[DriveConstants.java](src/main/java/org/sciborgs1155/robot/drive/DriveConstants.java)** Modify control constants yearly for each new robot, and all drivetrain constants for each new drivetrain as needed.
- **[VisionConstants.java](src/main/java/org/sciborgs1155/robot/vision/VisionConstants.java)** Add new `CameraConfig` fields representing cameras on the robot, and change the `create` method in [Vision](src/main/java/org/sciborgs1155/robot/vision/Vision.java). Also modify any camera configurations or constants if needed.
- **[Constants.java](src/main/java/org/sciborgs1155/robot/Constants.java)** Modify the class `Field` to be updated for each year's game, and any other constants if needed.
- **[Ports.java](src/main/java/org/sciborgs1155/robot/Ports.java)** Modify existing OI and drive ports, as well as adding new ports.
- **[Robot.java](src/main/java/org/sciborgs1155/robot/Robot.java)** A lot: subsystems, command files, related triggers & bindings, interactions with other subsystems & files, library configurations/starting, etc..

## Dependencies
- [WPILib](https://docs.wpilib.org/)
- [Spotless](https://github.com/diffplug/spotless/blob/main/plugin-gradle/README.md)
- [Monologue](https://github.com/shueja/Monologue)
- [REVLib](https://docs.revrobotics.com/sparkmax/software-resources/spark-max-api-information)
- [PathPlannerLib](https://github.com/mjansen4857/pathplanner/wiki)
- [PathPlannerLib](https://pathplanner.dev/home.html)
- [PhotonLib](https://docs.photonvision.org/en/latest/docs/programming/photonlib/adding-vendordep.html)
- [Phoenix6](https://v6.docs.ctr-electronics.com/en/stable/)
- [URCL](https://github.com/Mechanical-Advantage/URCL)
- [NavX](https://pdocs.kauailabs.com/navx-mxp/software/roborio-libraries/java/)
- [Spotless](https://github.com/diffplug/spotless/blob/main/plugin-gradle/README.md)
- [Monologue](https://github.com/shueja/Monologue)
18 changes: 7 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id "java"
id "edu.wpi.first.GradleRIO" version "2024.1.1"
id 'com.diffplug.spotless' version '6.23.3'
id "edu.wpi.first.GradleRIO" version "2024.3.2"
id 'com.diffplug.spotless' version '6.24.0'
}

sourceCompatibility = JavaVersion.VERSION_17
Expand Down Expand Up @@ -55,6 +55,7 @@ repositories {
dependencies {
implementation wpi.java.deps.wpilib()
implementation wpi.java.vendor.java()
implementation 'org.junit.jupiter:junit-jupiter-api:5.+'

roborioDebug wpi.java.deps.wpilibJniDebug(wpi.platforms.roborio)
roborioDebug wpi.java.vendor.jniDebug(wpi.platforms.roborio)
Expand All @@ -71,17 +72,12 @@ dependencies {
simulationRelease wpi.sim.enableRelease()

// Junit testing
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.+'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.+'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5+'

// Monologue
implementation 'com.github.shueja:Monologue:v1.0.0-beta1'
}

test {
useJUnitPlatform()
systemProperty 'junit.jupiter.extensions.autodetection.enabled', 'true'
implementation 'com.github.shueja:Monologue:+'
}

// Simulation configuration (e.g. environment variables).
Expand Down
4 changes: 3 additions & 1 deletion networktables.json
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
[]
[

]
3 changes: 3 additions & 0 deletions networktables.json.bck
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[

]
19 changes: 9 additions & 10 deletions simgui-ds.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"visible": false
}
},
"Joysticks": {
"Keyboard 0 Settings": {
"window": {
"visible": false
"visible": true
}
},
"System Joysticks": {
Expand All @@ -18,12 +18,12 @@
{
"axisConfig": [
{
"decKey": 68,
"incKey": 65
"decKey": 83,
"incKey": 87
},
{
"decKey": 87,
"incKey": 83
"decKey": 65,
"incKey": 68
},
{
"decKey": 69,
Expand All @@ -33,8 +33,8 @@
},
{},
{
"decKey": 76,
"incKey": 74
"decKey": 74,
"incKey": 75
}
],
"axisCount": 6,
Expand Down Expand Up @@ -63,8 +63,7 @@
"axisConfig": [
{},
{
"decKey": 73,
"incKey": 75
"decKey": 73
}
],
"axisCount": 4,
Expand Down
74 changes: 73 additions & 1 deletion simgui.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,32 @@
"/Robot/drive/rearLeft/turnFeedback": "PIDController",
"/Robot/drive/rearRight/driveFeedback": "PIDController",
"/Robot/drive/rearRight/turnFeedback": "PIDController",
"/Robot/drive/rotationController": "PIDController",
"/Robot/drive/translationController": "ProfiledPIDController",
"/SmartDashboard/Scheduler": "Scheduler",
"/SmartDashboard/VisionSystemSim-main/Sim Field": "Field2d",
"/SmartDashboard/drive dynamic backward": "Command",
"/SmartDashboard/drive dynamic forward": "Command",
"/SmartDashboard/drive quasistatic backward": "Command",
"/SmartDashboard/drive quasistatic forward": "Command",
"/SmartDashboard/rotation dynamic backward": "Command",
"/SmartDashboard/rotation dynamic forward": "Command",
"/SmartDashboard/rotation quasistatic backward": "Command",
"/SmartDashboard/rotation quasistatic forward": "Command",
"/SmartDashboard/translation dynamic backward": "Command",
"/SmartDashboard/translation dynamic forward": "Command",
"/SmartDashboard/translation quasistatic backward": "Command",
"/SmartDashboard/translation quasistatic forward": "Command",
"/SmartDashboard/turn dynamic backward": "Command",
"/SmartDashboard/turn dynamic forward": "Command",
"/SmartDashboard/turn quasistatic backward": "Command",
"/SmartDashboard/turn quasistatic forward": "Command"
},
"windows": {
"/Robot/drive/field2d": {
"bottom": 1476,
"height": 8.210550308227539,
"left": 150,
"module- FL": {
"style": "Line"
},
Expand All @@ -42,6 +57,9 @@
"module-RL": {
"style": "Line"
},
"right": 2961,
"top": 79,
"width": 16.541748046875,
"window": {
"visible": true
}
Expand All @@ -59,6 +77,9 @@
}
},
"NetworkTables": {
"Retained Values": {
"open": false
},
"transitory": {
"Robot": {
"drive": {
Expand All @@ -68,6 +89,54 @@
},
"open": true
},
"Pose2d##v_/Robot/drive/pose": {
"Rotation2d##v_rotation": {
"open": true
},
"Translation2d##v_translation": {
"open": true
},
"open": true
},
"SwerveModulePosition[]##v_/Robot/drive/getModulePositions": {
"SwerveModulePosition##v_[1]": {
"Rotation2d##v_angle": {
"open": true
}
}
},
"SwerveModuleState[]##v_/Robot/drive/getModuleSetpoints": {
"SwerveModuleState##v_[0]": {
"Rotation2d##v_angle": {
"open": true
}
},
"SwerveModuleState##v_[1]": {
"open": true
},
"SwerveModuleState##v_[2]": {
"Rotation2d##v_angle": {
"open": true
},
"open": true
},
"SwerveModuleState##v_[3]": {
"Rotation2d##v_angle": {
"open": true
},
"open": true
},
"open": true
},
"SwerveModuleState[]##v_/Robot/drive/getModuleStates": {
"SwerveModuleState##v_[0]": {
"Rotation2d##v_angle": {
"open": true
},
"open": true
},
"open": true
},
"frontRight": {
"SwerveModulePosition##v_/Robot/drive/frontRight/position": {
"Rotation2d##v_angle": {
Expand All @@ -85,7 +154,10 @@
},
"open": true
},
"open": true
"open": true,
"vision": {
"open": true
}
},
"Shuffleboard": {
"open": true
Expand Down
90 changes: 90 additions & 0 deletions src/main/java/org/sciborgs1155/lib/Assertion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package org.sciborgs1155.lib;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.function.BooleanSupplier;
import java.util.function.DoubleSupplier;
import org.sciborgs1155.lib.FaultLogger.FaultType;

public sealed interface Assertion {
public void apply(boolean unitTest);

/**
* Asserts that a condition is true and reports to FaultLogger.
*
* @param condition
* @param faultName
* @param description
*/
private static void reportTrue(boolean condition, String faultName, String description) {
FaultLogger.report(
faultName,
(condition ? "success! " : "") + description,
condition ? FaultType.INFO : FaultType.WARNING);
}

/**
* Asserts that two values are equal (with some tolerance) and reports to FaultLogger.
*
* @param faultName
* @param expected
* @param actual
* @param delta tolerance
*/
private static void reportEquals(String faultName, double expected, double actual, double delta) {
reportTrue(
Math.abs(expected - actual) <= delta,
faultName,
"expected: " + expected + "; actual: " + actual);
}

public static record TruthAssertion(
BooleanSupplier condition, String faultName, String description) implements Assertion {
@Override
public void apply(boolean unitTest) {
if (unitTest) {
assertTrue(condition, faultName + ": " + description);
} else {
reportTrue(condition.getAsBoolean(), faultName, description);
}
}
}

public static record EqualityAssertion(
String faultName, DoubleSupplier expected, DoubleSupplier actual, double delta)
implements Assertion {
@Override
public void apply(boolean unitTest) {
if (unitTest) {
assertEquals(expected.getAsDouble(), actual.getAsDouble(), delta, faultName);
} else {
reportEquals(faultName, expected.getAsDouble(), actual.getAsDouble(), delta);
}
}
}

/**
* @return a truth assertion
*/
public static TruthAssertion tAssert(
BooleanSupplier condition, String faultName, String description) {
return new TruthAssertion(condition, faultName, description);
}

/**
* @return an equality assertion
*/
public static EqualityAssertion eAssert(
String faultName, DoubleSupplier expected, DoubleSupplier actual, double delta) {
return new EqualityAssertion(faultName, expected, actual, delta);
}

/**
* @return an equality assertion
*/
public static EqualityAssertion eAssert(
String faultName, DoubleSupplier expected, DoubleSupplier actual) {
return eAssert(faultName, expected, actual, 0);
}
}
Loading
Loading