Skip to content

Commit

Permalink
Run garbage collector regularly
Browse files Browse the repository at this point in the history
  • Loading branch information
viggy96 committed Sep 19, 2024
1 parent b23c2ba commit 1a902e4
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/org/lasarobotics/hardware/PurpleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@
import edu.wpi.first.wpilibj.Notifier;
import edu.wpi.first.wpilibj.PowerDistribution;
import edu.wpi.first.wpilibj.RobotBase;
import edu.wpi.first.wpilibj.Timer;

/** PurpleLib Hardware Logging Manager */
public class PurpleManager {
private static double GARBAGE_COLLECTION_SEC = 5.0;
private static List<LoggableHardware> m_hardware = new ArrayList<>();
private static List<Monitorable> m_monitored = new ArrayList<>();
private static List<Runnable> m_callbacks = new ArrayList<>();
private static List<Runnable> m_simCallbacks = new ArrayList<>();
private static VisionSystemSim m_visionSim = new VisionSystemSim("PurpleManager");
private static Supplier<Pose2d> m_poseSupplier = null;
private static Timer m_garbageTimer = new Timer();

/**
* Monitor health of components
Expand Down Expand Up @@ -211,10 +214,15 @@ public static void addCallbackSim(Runnable callback) {
* Call this peridically, preferably in the beginning of <code>robotPeriodic()</code> every loop
*/
public static void update() {
// Run garbage collector regularly
if (m_garbageTimer.advanceIfElapsed(GARBAGE_COLLECTION_SEC)) System.gc();

// Monitor health and run periodic logic
monitorHealth();
m_hardware.stream().forEach((device) -> device.periodic());
m_callbacks.stream().forEach(Runnable::run);

// If not real robot, run simulation logic
if (RobotBase.isReal()) return;
m_simCallbacks.stream().forEach(Runnable::run);
}
Expand Down

0 comments on commit 1a902e4

Please sign in to comment.