Skip to content

Commit e9507a7

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents 9da69e3 + 71b99c3 commit e9507a7

23 files changed

Lines changed: 257 additions & 736 deletions

.idea/codeStyles/Project.xml

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//file:noinspection GroovyAssignabilityCheck
2+
//file:noinspection DependencyNotationArgument
13
plugins {
24
id 'java'
35
id 'edu.wpi.first.GradleRIO' version '2025.3.1'
@@ -139,6 +141,7 @@ dependencies {
139141
testImplementation 'junit:junit:4.13.2'
140142
testImplementation 'org.mockito:mockito-core:5.14.2'
141143
testImplementation 'com.google.truth:truth:1.4.4'
144+
testImplementation 'com.team2813:testing'
142145

143146
implementation 'com.team2813:lib2813'
144147
implementation 'com.team2813:limelight'
@@ -152,7 +155,9 @@ test {
152155
// Simulation configuration (e.g. environment variables).
153156
wpi.sim.addGui().defaultEnabled = true
154157
wpi.sim.addDriverstation()
158+
155159
downloadDepsPreemptively.dependsOn gradle.includedBuild('lib2813').task(':lib:jar')
160+
downloadDepsPreemptively.dependsOn gradle.includedBuild('lib2813').task(':testing:jar')
156161
downloadDepsPreemptively.dependsOn gradle.includedBuild('lib2813').task(':limelight:jar')
157162

158163
// Setting up my Jar File. In this case, adding all libraries into the main jar ('fat jar')

lib2813

Submodule lib2813 updated 37 files

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ includeBuild('lib2813') {
3333
dependencySubstitution {
3434
substitute module('com.team2813:lib2813') using project(':lib')
3535
substitute module('com.team2813:limelight') using project(':limelight')
36+
substitute module('com.team2813:testing') using project(':testing')
3637
}
3738
}

src/main/java/com/team2813/AllPreferences.java

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.team2813;
22

33
import edu.wpi.first.wpilibj.Preferences;
4+
import java.util.List;
45
import java.util.Map;
56
import java.util.Set;
67

@@ -24,23 +25,64 @@ class AllPreferences {
2425
private static final Set<String> REMOVED_PREFERENCES =
2526
Set.of("USE_LIMELIGHT_LOCATION", "DRIVE_ADD_LIMELIGHT_MEASUREMENT");
2627

28+
public static final List<String> DRIVE_BOOLEAN_PREFERENCE_KEYS =
29+
List.of(
30+
"addLimelightMeasurement", "usePhotonVisionLocation", "usePnpDistanceTrigSolveStrategy");
31+
public static final List<String> DRIVE_DOUBLE_PREFERENCE_KEYS =
32+
List.of(
33+
"maxLimelightDifferenceMeters", "maxRotationsPerSecond", "maxVelocityInMetersPerSecond");
34+
35+
/** Migrate Preferences stored on the robot from older keys to current keys. */
2736
static synchronized void migrateLegacyPreferences() {
2837
for (var entry : LEGACY_BOOLEAN_PREFERENCES.entrySet()) {
2938
String oldKey = entry.getKey().name();
3039
String newKey = entry.getValue();
31-
if (Preferences.containsKey(oldKey)) {
32-
if (!Preferences.containsKey(newKey)) {
33-
boolean value = Preferences.getBoolean(oldKey, false);
34-
Preferences.initBoolean(newKey, value);
35-
}
36-
Preferences.remove(oldKey);
37-
}
40+
migratePreference(oldKey, newKey, AllPreferences::booleanPreferenceMigrator);
3841
}
42+
3943
for (var key : REMOVED_PREFERENCES) {
4044
if (Preferences.containsKey(key)) {
4145
Preferences.remove(key);
4246
}
4347
}
48+
49+
migrateDrivePreferences(
50+
DRIVE_BOOLEAN_PREFERENCE_KEYS, AllPreferences::booleanPreferenceMigrator);
51+
migrateDrivePreferences(DRIVE_DOUBLE_PREFERENCE_KEYS, AllPreferences::doublePreferenceMigrator);
52+
}
53+
54+
@FunctionalInterface
55+
private interface PreferenceMigrator {
56+
void migrate(String oldKey, String newKey);
57+
}
58+
59+
private static void migrateDrivePreferences(List<String> keys, PreferenceMigrator migrator) {
60+
for (String key : keys) {
61+
String oldKey = "subsystems.Drive.DriveConfiguration." + key;
62+
String newKey = "Drive/" + key;
63+
migratePreference(oldKey, newKey, migrator);
64+
}
65+
}
66+
67+
private static void booleanPreferenceMigrator(String oldKey, String newKey) {
68+
boolean value = Preferences.getBoolean(oldKey, false);
69+
Preferences.initBoolean(newKey, value);
70+
}
71+
72+
private static void doublePreferenceMigrator(String oldKey, String newKey) {
73+
double value = Preferences.getDouble(oldKey, -1);
74+
if (value > 0) {
75+
Preferences.initDouble(newKey, value);
76+
}
77+
}
78+
79+
private static void migratePreference(String oldKey, String newKey, PreferenceMigrator migrator) {
80+
if (Preferences.containsKey(oldKey)) {
81+
if (!Preferences.containsKey(newKey)) {
82+
migrator.migrate(oldKey, newKey);
83+
}
84+
Preferences.remove(oldKey);
85+
}
4486
}
4587

4688
private enum Key {

src/main/java/com/team2813/BuildConstantsPublisher.java

Lines changed: 0 additions & 112 deletions
This file was deleted.

src/main/java/com/team2813/Robot.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package com.team2813;
66

77
import com.ctre.phoenix6.SignalLogger;
8+
import com.team2813.lib2813.util.BuildConstantsPublisher;
89
import edu.wpi.first.cameraserver.CameraServer;
910
import edu.wpi.first.networktables.NetworkTableInstance;
1011
import edu.wpi.first.wpilibj.DataLogManager;
@@ -16,8 +17,6 @@
1617
import edu.wpi.first.wpilibj2.command.CommandScheduler;
1718

1819
public class Robot extends TimedRobot {
19-
private static final BuildConstantsPublisher m_buildConstantsPublisher =
20-
new BuildConstantsPublisher(NetworkTableInstance.getDefault());
2120
private Command m_autonomousCommand;
2221

2322
private final RobotContainer m_robotContainer;
@@ -41,8 +40,10 @@ public void robotInit() {
4140
}
4241
CameraServer.startAutomaticCapture();
4342
// Publish build constants to the Metadata table on NetworkTables and print them in system log.
44-
m_buildConstantsPublisher.publish();
45-
m_buildConstantsPublisher.log();
43+
BuildConstantsPublisher buildConstantsPublisher =
44+
new BuildConstantsPublisher(BuildConstants.class);
45+
buildConstantsPublisher.publish(NetworkTableInstance.getDefault());
46+
buildConstantsPublisher.log();
4647
}
4748

4849
@Override

src/main/java/com/team2813/RobotContainer.java

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -347,33 +347,20 @@ private void configureBindings(RobotLocalization localization) {
347347

348348
// Every subsystem should be in the set; we don't know what subsystem will be controlled, so
349349
// assume we control all of them
350+
// TODO: Reimplement with photonvision.
350351
AUTO_ALIGN_LEFT.onTrue(
351-
new SequentialCommandGroup(
352-
new InstantCommand(
353-
() ->
354-
Limelight.getDefaultLimelight()
355-
.getLocationalData()
356-
.getBotpose()
357-
.map(Pose3d::toPose2d)
358-
.map(RobotContainer::toBotposeBlue)
359-
.ifPresent(drive::setPose)),
360-
new WaitCommand(0.02),
361-
new DeferredCommand(
362-
() -> localization.getLeftAutoAlignCommand(drive::getPose), Set.of(drive))));
363-
352+
new InstantCommand(
353+
() ->
354+
DriverStation.reportWarning(
355+
"Attempted to auto align left, but there is no limelight implementation.",
356+
false)));
357+
// TODO: Reimplement with photonvision.
364358
AUTO_ALIGN_RIGHT.onTrue(
365-
new SequentialCommandGroup(
366-
new InstantCommand(
367-
() ->
368-
Limelight.getDefaultLimelight()
369-
.getLocationalData()
370-
.getBotpose()
371-
.map(Pose3d::toPose2d)
372-
.map(RobotContainer::toBotposeBlue)
373-
.ifPresent(drive::setPose)),
374-
new WaitCommand(0.02),
375-
new DeferredCommand(
376-
() -> localization.getRightAutoAlignCommand(drive::getPose), Set.of(drive))));
359+
new InstantCommand(
360+
() ->
361+
DriverStation.reportWarning(
362+
"Attempted to auto align right, but there is no limelight implementation.",
363+
false)));
377364

378365
SYSID_RUN.whileTrue(
379366
new DeferredCommand(

0 commit comments

Comments
 (0)