Skip to content

Commit b02eaee

Browse files
committed
photonvision memory leak again
1 parent bdbf385 commit b02eaee

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ deploy {
3333
jvmArgs.add("-XX:GCTimeRatio=5")
3434
jvmArgs.add("-XX:+UseSerialGC")
3535
jvmArgs.add("-XX:MaxGCPauseMillis=50")
36+
// Enable automatic heap dumps on OutOfMemoryError
37+
// Note: the heap dump path here is a path on a USB flash drive, see below
38+
// jvmArgs.add("-XX:+HeapDumpOnOutOfMemoryError")
39+
// jvmArgs.add("-XX:HeapDumpPath=/tmp/frc-usercode.hprof")
3640

3741
// The options below may improve performance, but should only be enabled on the RIO 2
3842
//

src/main/java/frc/robot/Robot.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
package frc.robot;
99

10+
import edu.wpi.first.wpilibj.Timer;
1011
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
1112
import edu.wpi.first.wpilibj2.command.Command;
1213
import edu.wpi.first.wpilibj2.command.CommandScheduler;
@@ -26,8 +27,10 @@
2627
public class Robot extends LoggedRobot {
2728
private Command autonomousCommand;
2829
private RobotContainer robotContainer;
30+
Timer gcTimer = new Timer();
2931

3032
public Robot() {
33+
gcTimer.start();
3134
// Record metadata
3235
Logger.recordMetadata("ProjectName", BuildConstants.MAVEN_NAME);
3336
Logger.recordMetadata("BuildDate", BuildConstants.BUILD_DATE);
@@ -88,6 +91,11 @@ public void robotPeriodic() {
8891

8992
// Return to non-RT thread priority (do not modify the first argument)
9093
// Threads.setCurrentThreadPriority(false, 10);
94+
95+
// run the garbage collector every 5 seconds
96+
if (gcTimer.advanceIfElapsed(5)) {
97+
System.gc();
98+
}
9199
}
92100

93101
/** This function is called once when the robot is disabled. */

src/main/java/frc/robot/RobotContainer.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@ public RobotContainer() {
100100
new ModuleIOTalonFX(TunerConstants.BackRight));
101101
vision =
102102
new Vision(
103-
drive::addVisionMeasurement,
104-
new VisionIOPhotonVision(
105-
VisionConstants.camera0Name, VisionConstants.robotToCamera0),
106-
new VisionIOPhotonVision(
107-
VisionConstants.camera1Name, VisionConstants.robotToCamera1),
108-
new VisionIOPhotonVision(
109-
VisionConstants.camera2Name, VisionConstants.robotToCamera2),
110-
new VisionIOPhotonVision(
111-
VisionConstants.camera3Name, VisionConstants.robotToCamera3));
103+
drive::addVisionMeasurement, new VisionIO(){});
104+
// new VisionIOPhotonVision(
105+
// VisionConstants.camera0Name, VisionConstants.robotToCamera0),
106+
// new VisionIOPhotonVision(
107+
// VisionConstants.camera1Name, VisionConstants.robotToCamera1));
108+
// new VisionIOPhotonVision(
109+
// VisionConstants.camera2Name, VisionConstants.robotToCamera2),
110+
// new VisionIOPhotonVision(
111+
// VisionConstants.camera3Name, VisionConstants.robotToCamera3));
112112
shooter = new Shooter();
113113
hopper = new Hopper();
114114
configureShooterTestBindings(); // configureButtonBindings();

src/main/java/frc/robot/subsystems/drive/Drive.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import edu.wpi.first.wpilibj.Alert;
3030
import edu.wpi.first.wpilibj.Alert.AlertType;
3131
import edu.wpi.first.wpilibj.DriverStation;
32+
import edu.wpi.first.wpilibj.smartdashboard.Field2d;
33+
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
3234
// import edu.wpi.first.wpilibj.DriverStation.Alliance;
3335
import edu.wpi.first.wpilibj2.command.Command;
3436
import edu.wpi.first.wpilibj2.command.SubsystemBase;
@@ -46,6 +48,7 @@ public class Drive extends SubsystemBase {
4648
private final PIDController xController = new PIDController(10.0, 0.0, 0.0);
4749
private final PIDController yController = new PIDController(10.0, 0.0, 0.0);
4850
private final PIDController headingController = new PIDController(7.5, 0.0, 0.0);
51+
private final Field2d loggedField = new Field2d();
4952

5053
// TunerConstants doesn't include these constants, so they are declared locally
5154
static final double ODOMETRY_FREQUENCY = TunerConstants.kCANBus.isNetworkFD() ? 250.0 : 100.0;
@@ -117,6 +120,8 @@ public Drive(
117120
// Start odometry thread
118121
PhoenixOdometryThread.getInstance().start();
119122

123+
SmartDashboard.putData("Field", loggedField);
124+
120125
// Configure AutoBuilder for PathPlanner
121126
// AutoBuilder.configure(
122127
// this::getPose,
@@ -233,6 +238,8 @@ public void periodic() {
233238

234239
// Update gyro alert
235240
gyroDisconnectedAlert.set(!gyroInputs.connected && Constants.currentMode != Mode.SIM);
241+
242+
loggedField.setRobotPose(getPose());
236243
}
237244

238245
/**

0 commit comments

Comments
 (0)