Skip to content

Commit 1ab02fc

Browse files
committed
Add thermal throttling alert and improve documentation in SystemMonitor
1 parent f0ff093 commit 1ab02fc

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

photon-core/src/main/java/org/photonvision/common/hardware/metrics/SystemMonitor.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import edu.wpi.first.cscore.CameraServerJNI;
2121
import edu.wpi.first.networktables.NetworkTable;
2222
import edu.wpi.first.networktables.ProtobufPublisher;
23+
import edu.wpi.first.wpilibj.Alert;
24+
import edu.wpi.first.wpilibj.Alert.AlertType;
2325
import java.io.IOException;
2426
import java.nio.file.FileStore;
2527
import java.nio.file.Files;
@@ -62,6 +64,9 @@ private record NetworkTraffic(double sentBitRate, double recvBitRate) {}
6264
.getProtobufTopic(CameraServerJNI.getHostname(), DeviceMetrics.proto)
6365
.publish();
6466

67+
private final Alert thermalThrottlingAlert =
68+
new Alert("PhotonAlerts", "Thermal throttling detected!", AlertType.kWarning);
69+
6570
private SystemInfo si;
6671
private CentralProcessor cpu;
6772
private OperatingSystem os;
@@ -140,7 +145,7 @@ protected SystemMonitor() {
140145
}
141146

142147
/**
143-
* Returns a comma-separated list of addtional thermal zone types that should be checked to get
148+
* Returns a comma-separated list of additional thermal zone types that should be checked to get
144149
* the CPU temperature on Unix systems. The temperature will be reported for the first temperature
145150
* zone with a type that matches an item of this list. If the CPU temperature isn't being
146151
* reported correctly for a coprocessor, override this method to return a string with type
@@ -210,6 +215,8 @@ private void publishMetrics() {
210215

211216
metricPublisher.set(metrics);
212217

218+
thermalThrottlingAlert.set(this.isThermallyThrottling());
219+
213220
if (writeMetricsToLog) {
214221
logMetrics(metrics);
215222
}
@@ -446,6 +453,16 @@ public String getCpuThrottleReason() {
446453
return "";
447454
}
448455

456+
/**
457+
* Returns true if the device is currently experiencing thermal throttling. Platforms that support
458+
* thermal throttling detection will override this method.
459+
*
460+
* @return true if thermally throttling, false otherwise.
461+
*/
462+
public boolean isThermallyThrottling() {
463+
return false;
464+
}
465+
449466
/**
450467
* Returns the total GPU memory in MiB.
451468
*
@@ -562,4 +579,4 @@ private double timeIt(StringBuilder sb, Supplier<String> source) {
562579
sb.append(String.format(" %7.3f ms >> %s\n", delta, resp));
563580
return delta;
564581
}
565-
}
582+
}

0 commit comments

Comments
 (0)