Skip to content

Commit 7055a39

Browse files
authored
Merge pull request #29 from wmironpatriots/feat/subsystems-cleanup
Feat/subsystems cleanup
2 parents db5a457 + 187a3ae commit 7055a39

File tree

22 files changed

+896
-345
lines changed

22 files changed

+896
-345
lines changed

build.gradle

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,27 @@ deploy {
3535
jvmArgs.add("-XX:+UseSerialGC")
3636
jvmArgs.add("-XX:MaxGCPauseMillis=50")
3737

38-
// Enable VisualVM connection
39-
jvmArgs.add("-Dcom.sun.management.jmxremote=true")
40-
jvmArgs.add("-Dcom.sun.management.jmxremote.port=1198")
41-
jvmArgs.add("-Dcom.sun.management.jmxremote.local.only=false")
42-
jvmArgs.add("-Dcom.sun.management.jmxremote.ssl=false")
43-
jvmArgs.add("-Dcom.sun.management.jmxremote.authenticate=false")
44-
jvmArgs.add("-Djava.rmi.server.hostname=10.64.23.2")
38+
// TO ENTER PROFILING MODE:
39+
// Run ./gradlew deploy -PprofileMode
40+
if (frc.project.hasProperty("profileMode")) {
41+
project.logger.lifecycle("\u001B[31m~~~~ PROFILING MODE ENABLED ~~~~\u001B[0m")
42+
project.logger.lifecycle("Connect JMX client to roborio-6423-frc-local:1099 or 10.64.23.2:1099 for profiling")
43+
// Enable VisualVM connection
44+
jvmArgs.add("-Dcom.sun.management.jmxremote=true")
45+
jvmArgs.add("-Dcom.sun.management.jmxremote.port=1198")
46+
jvmArgs.add("-Dcom.sun.management.jmxremote.local.only=false")
47+
jvmArgs.add("-Dcom.sun.management.jmxremote.ssl=false")
48+
jvmArgs.add("-Dcom.sun.management.jmxremote.authenticate=false")
49+
jvmArgs.add("-Djava.rmi.server.hostname=10.64.23.2")
50+
}
4551

4652
// RIO 2.0 ONLY
4753
// final MAX_JAVA_HEAP_SIZE_MB = 100;
4854
// jvmArgs.add("-Xmx" + MAX_JAVA_HEAP_SIZE_MB + "M")
4955
// jvmArgs.add("-Xms" + MAX_JAVA_HEAP_SIZE_MB + "M")
56+
// jvmArgs.add("-XX:GCTimeRatio=5")
57+
// jvmArgs.add("-XX:+UseSerialGC")
58+
// jvmArgs.add("-XX:MaxGCPauseMillis=50")
5059
// jvmArgs.add("-XX:+AlwaysPreTouch")
5160
}
5261

@@ -136,9 +145,6 @@ tasks.withType(JavaCompile) {
136145

137146
// Configure pre-commit hooks on first build
138147
task installGitHooks(type: Copy) {
139-
logger.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
140-
logger.info("~~~ Installing Git Hooks ~~~")
141-
logger.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
142148
from '.scripts'
143149
into '.git/hooks'
144150
logger.info("Successfully Installed Hooks!")

src/main/java/org/frc6423/lib/subsystems/Roller.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import edu.wpi.first.epilogue.Logged;
1010
import edu.wpi.first.math.filter.LinearFilter;
1111
import edu.wpi.first.wpilibj2.command.Command;
12-
import edu.wpi.first.wpilibj2.command.Commands;
1312
import edu.wpi.first.wpilibj2.command.SubsystemBase;
1413
import java.util.function.DoubleSupplier;
1514

@@ -94,14 +93,7 @@ protected Command runSpeed(double speedRpm) {
9493
* @return {@link Command}
9594
*/
9695
protected Command holdSpeed() {
97-
return Commands.sequence(
98-
this.run(
99-
() -> {
100-
var currentSpeed = hardware.getSpeedRpm();
101-
hardware.setSpeed(currentSpeed);
102-
})
103-
.until(() -> true),
104-
this.run(() -> {}));
96+
return runSpeed(() -> hardware.getSpeedRpm());
10597
}
10698

10799
@Override
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) 2025 FRC 6423 - Ward Melville Iron Patriots
2+
// https://github.com/wmironpatriots
3+
//
4+
// Open Source Software; you can modify and/or share it under the terms of
5+
// MIT license file in the root directory of this project
6+
7+
package org.frc6423.lib.utilities;
8+
9+
import com.ctre.phoenix6.StatusCode;
10+
import edu.wpi.first.wpilibj.DriverStation;
11+
import java.util.function.Supplier;
12+
13+
/** Utilities for CTRe devices */
14+
public class CtreUtils {
15+
/**
16+
* Try to run {@link StatusCode} supplier until it returns a {@link StatusCode} of OK
17+
*
18+
* @param function {@link StatusCode} supplier
19+
* @param maxRetries maximum amount of retries before giving up
20+
* @param deviceId Id of device being controlled
21+
* @return {@link StatusCode} representing error code
22+
*/
23+
public static StatusCode tryUntilOk(Supplier<StatusCode> function, int maxRetries, int deviceId) {
24+
StatusCode statusCode = StatusCode.OK;
25+
for (int i = 0; i == maxRetries; i++) {
26+
statusCode = function.get();
27+
if (statusCode == StatusCode.OK) break;
28+
}
29+
if (statusCode != StatusCode.OK) {
30+
DriverStation.reportError("ERROR: Device ID " + deviceId + " could not be configured", true);
31+
}
32+
33+
return statusCode;
34+
}
35+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright (c) 2025 FRC 6423 - Ward Melville Iron Patriots
2+
// https://github.com/wmironpatriots
3+
//
4+
// Open Source Software; you can modify and/or share it under the terms of
5+
// MIT license file in the root directory of this project
6+
7+
package org.frc6423.lib.utilities;
8+
9+
import edu.wpi.first.networktables.BooleanEntry;
10+
import edu.wpi.first.networktables.DoubleArrayEntry;
11+
import edu.wpi.first.networktables.DoubleEntry;
12+
import edu.wpi.first.networktables.IntegerEntry;
13+
import edu.wpi.first.networktables.NetworkTableInstance;
14+
15+
/** Utilities for {@link NetworkTables} */
16+
public class NtUtils {
17+
/**
18+
* Create a new {@link IntegerEntry}
19+
*
20+
* @param path {@link String} representing topic path
21+
* @param defaultValue default entry value
22+
* @return {@link DoubleEntry}
23+
*/
24+
public static IntegerEntry createIntegerEntry(String path, int defaultValue) {
25+
var entry = NetworkTableInstance.getDefault().getIntegerTopic(path).getEntry(defaultValue);
26+
entry.set(defaultValue);
27+
28+
return entry;
29+
}
30+
31+
/**
32+
* Create a new {@link DoubleEntry}
33+
*
34+
* @param path {@link String} representing topic path
35+
* @param defaultValue default entry value
36+
* @return {@link DoubleEntry}
37+
*/
38+
public static DoubleEntry createDoubleEntry(String path, double defaultValue) {
39+
var entry = NetworkTableInstance.getDefault().getDoubleTopic(path).getEntry(defaultValue);
40+
entry.set(defaultValue);
41+
42+
return entry;
43+
}
44+
45+
/**
46+
* Create a new {@link BooleanEntry}
47+
*
48+
* @param path {@link String} representing topic path
49+
* @param defaultValue default entry value
50+
* @return {@link BooleanEntry}
51+
*/
52+
public static BooleanEntry createBooleanEntry(String path, boolean defaultValue) {
53+
var entry = NetworkTableInstance.getDefault().getBooleanTopic(path).getEntry(defaultValue);
54+
entry.set(defaultValue);
55+
56+
return entry;
57+
}
58+
59+
/**
60+
* Create a new {@link DoubleArrayEntry}
61+
*
62+
* @param path {@link String} representing topic path
63+
* @param defaultValue default entry value
64+
* @return {@link DoubleArrayEntry}
65+
*/
66+
public static DoubleArrayEntry createDoubleArrayEntry(String path, double[] defaultValue) {
67+
var entry = NetworkTableInstance.getDefault().getDoubleArrayTopic(path).getEntry(defaultValue);
68+
entry.set(defaultValue);
69+
70+
return entry;
71+
}
72+
}

src/main/java/org/frc6423/robot/Constants.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818
* <p>When creating a new constant, make sure it is static and final
1919
*/
2020
public class Constants {
21-
/** Constants that affect robot behavior during runtime */
21+
/** Constants that affect robot bhavior during runtime */
2222
public class Flags {
23-
/** Represents how often periodic robot logic will run */
23+
/** Represents how often periodic robot logic will run 0.02 Seconds by default */
2424
public static final Time PERIOD = Seconds.of(0.02);
2525

2626
/** When true, the robot will enable debug menus and log debug information */
2727
@Deprecated public static final boolean debugMode = false;
28+
29+
/** When true, tunable entries will be added to NT for subsystems Should be false by default */
30+
public static final boolean TUNE_MODE = false;
2831
}
2932

3033
/** Constants representing port IDs that devices are connected to */
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Copyright (c) 2025 FRC 6423 - Ward Melville Iron Patriots
2+
// https://github.com/wmironpatriots
3+
//
4+
// Open Source Software; you can modify and/or share it under the terms of
5+
// MIT license file in the root directory of this project
6+
7+
package org.frc6423.robot.subsystems.superstructure;
8+
9+
import edu.wpi.first.wpilibj2.command.Command;
10+
import java.util.function.DoubleSupplier;
11+
import org.frc6423.lib.subsystems.Roller;
12+
import org.frc6423.lib.subsystems.RollerIO;
13+
import org.frc6423.lib.subsystems.RollerIONeo;
14+
import org.frc6423.lib.subsystems.RollerIONone;
15+
import org.frc6423.robot.Robot;
16+
17+
/** {@link Roller} subsystem representing the rollers on the chute */
18+
public class Chute extends Roller {
19+
/** CONSTANTS */
20+
public static final double MINIMUM_STALL_CURRENT_AMPS = 30.0;
21+
22+
/**
23+
* @return fake {@link Chute} subsystem
24+
*/
25+
public static Chute none() {
26+
return new Chute(new RollerIONone());
27+
}
28+
29+
/**
30+
* Factory for creating a {@link Arm} subsystem
31+
*
32+
* @return {@link Arm} Subsystem
33+
*/
34+
public static Chute create() {
35+
if (Robot.isReal()) {
36+
return new Chute(new RollerIONeo());
37+
} else {
38+
return new Chute(new RollerIONone());
39+
}
40+
}
41+
42+
private Chute(RollerIO hardware) {
43+
super("ArmRoller", hardware);
44+
}
45+
46+
/**
47+
* @return true if roller motor is stalling
48+
*/
49+
public boolean isStalling() {
50+
return super.isStalling(MINIMUM_STALL_CURRENT_AMPS);
51+
}
52+
53+
/**
54+
* Run roller at specified volts
55+
*
56+
* @param volts desired volts
57+
* @return {@link Command}
58+
*/
59+
public Command runVolts(DoubleSupplier volts) {
60+
return super.runVolts(volts);
61+
}
62+
63+
/**
64+
* Run roller at specified volts
65+
*
66+
* @param volts desired volts
67+
* @return {@link Command}
68+
*/
69+
public Command runVolts(double volts) {
70+
return super.runVolts(volts);
71+
}
72+
73+
/**
74+
* Run roller at specified speed
75+
*
76+
* @param speedRpm desired speed in revs per minute
77+
* @return {@link Command}
78+
*/
79+
public Command runSpeed(DoubleSupplier speedRpm) {
80+
return super.runSpeed(speedRpm);
81+
}
82+
83+
/**
84+
* Run roller at specified speed
85+
*
86+
* @param speedRpm desired speed in revs per minute
87+
* @return {@link Command}
88+
*/
89+
public Command runSpeed(double speedRpm) {
90+
return super.runSpeed(speedRpm);
91+
}
92+
93+
/**
94+
* Hold roller at current speed
95+
*
96+
* @return {@link Command}
97+
*/
98+
public Command holdSpeed() {
99+
return super.holdSpeed();
100+
}
101+
}

src/main/java/org/frc6423/robot/subsystems/superstructure/Superstructure.java

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

src/main/java/org/frc6423/robot/subsystems/superstructure/Visualizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
package org.frc6423.robot.subsystems.superstructure;
88

99
import static edu.wpi.first.units.Units.Centimeters;
10-
import static org.frc6423.robot.subsystems.superstructure.arm.ArmPivot.*;
10+
import static org.frc6423.robot.subsystems.superstructure.arm.Arm.*;
1111
import static org.frc6423.robot.subsystems.superstructure.elevator.Elevator.MAX_EXTENSION_HEIGHT;
1212

1313
import edu.wpi.first.math.geometry.Rotation2d;

0 commit comments

Comments
 (0)