mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-19 00:41:41 +00:00
Allow file uploads of any size and better report active cameras in PhotonCamera error print (#1298)
Previously reported itself which was confusing. New print: ``` Error at org.photonvision.PhotonCamera.verifyVersion(PhotonCamera.java:378): Found the following PhotonVision cameras active on NetworkTables: ==> HD_Pro_Webcam_C920 ==> Arducam_OV9281_USB_Camera ```
This commit is contained in:
@@ -46,8 +46,9 @@ import edu.wpi.first.networktables.StringSubscriber;
|
||||
import edu.wpi.first.wpilibj.DriverStation;
|
||||
import edu.wpi.first.wpilibj.RobotController;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import org.photonvision.common.hardware.VisionLEDMode;
|
||||
import org.photonvision.common.networktables.PacketSubscriber;
|
||||
import org.photonvision.targeting.PhotonPipelineResult;
|
||||
@@ -75,6 +76,8 @@ public class PhotonCamera implements AutoCloseable {
|
||||
IntegerSubscriber heartbeatEntry;
|
||||
DoubleArraySubscriber cameraIntrinsicsSubscriber;
|
||||
DoubleArraySubscriber cameraDistortionSubscriber;
|
||||
MultiSubscriber topicNameSubscriber;
|
||||
NetworkTable rootPhotonTable;
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
@@ -98,6 +101,7 @@ public class PhotonCamera implements AutoCloseable {
|
||||
pipelineIndexRequest.close();
|
||||
cameraIntrinsicsSubscriber.close();
|
||||
cameraDistortionSubscriber.close();
|
||||
topicNameSubscriber.close();
|
||||
}
|
||||
|
||||
private final String path;
|
||||
@@ -125,8 +129,8 @@ public class PhotonCamera implements AutoCloseable {
|
||||
*/
|
||||
public PhotonCamera(NetworkTableInstance instance, String cameraName) {
|
||||
name = cameraName;
|
||||
var photonvision_root_table = instance.getTable(kTableName);
|
||||
this.cameraTable = photonvision_root_table.getSubTable(cameraName);
|
||||
rootPhotonTable = instance.getTable(kTableName);
|
||||
this.cameraTable = rootPhotonTable.getSubTable(cameraName);
|
||||
path = cameraTable.getPath();
|
||||
var rawBytesEntry =
|
||||
cameraTable
|
||||
@@ -148,12 +152,12 @@ public class PhotonCamera implements AutoCloseable {
|
||||
cameraDistortionSubscriber =
|
||||
cameraTable.getDoubleArrayTopic("cameraDistortion").subscribe(null);
|
||||
|
||||
ledModeRequest = photonvision_root_table.getIntegerTopic("ledModeRequest").publish();
|
||||
ledModeState = photonvision_root_table.getIntegerTopic("ledModeState").subscribe(-1);
|
||||
versionEntry = photonvision_root_table.getStringTopic("version").subscribe("");
|
||||
ledModeRequest = rootPhotonTable.getIntegerTopic("ledModeRequest").publish();
|
||||
ledModeState = rootPhotonTable.getIntegerTopic("ledModeState").subscribe(-1);
|
||||
versionEntry = rootPhotonTable.getStringTopic("version").subscribe("");
|
||||
|
||||
// Existing is enough to make this multisubscriber do its thing
|
||||
MultiSubscriber m_topicNameSubscriber =
|
||||
topicNameSubscriber =
|
||||
new MultiSubscriber(
|
||||
instance, new String[] {"/photonvision/"}, PubSubOption.topicsOnly(true));
|
||||
|
||||
@@ -333,10 +337,10 @@ public class PhotonCamera implements AutoCloseable {
|
||||
// Heartbeat entry is assumed to always be present. If it's not present, we
|
||||
// assume that a camera with that name was never connected in the first place.
|
||||
if (!heartbeatEntry.exists()) {
|
||||
Set<String> cameraNames = cameraTable.getInstance().getTable(kTableName).getSubTables();
|
||||
var cameraNames = getTablesThatLookLikePhotonCameras();
|
||||
if (cameraNames.isEmpty()) {
|
||||
DriverStation.reportError(
|
||||
"Could not find any PhotonVision coprocessors on NetworkTables. Double check that PhotonVision is running, and that your camera is connected!",
|
||||
"Could not find **any** PhotonVision coprocessors on NetworkTables. Double check that PhotonVision is running, and that your camera is connected!",
|
||||
false);
|
||||
} else {
|
||||
DriverStation.reportError(
|
||||
@@ -344,9 +348,17 @@ public class PhotonCamera implements AutoCloseable {
|
||||
+ path
|
||||
+ " not found on NetworkTables. Double check that your camera names match!",
|
||||
true);
|
||||
|
||||
var cameraNameStr = new StringBuilder();
|
||||
for (var c : cameraNames) {
|
||||
cameraNameStr.append(" ==> ");
|
||||
cameraNameStr.append(c);
|
||||
cameraNameStr.append("\n");
|
||||
}
|
||||
|
||||
DriverStation.reportError(
|
||||
"Found the following PhotonVision cameras on NetworkTables:\n"
|
||||
+ String.join("\n", cameraNames),
|
||||
+ cameraNameStr.toString(),
|
||||
false);
|
||||
}
|
||||
}
|
||||
@@ -391,4 +403,13 @@ public class PhotonCamera implements AutoCloseable {
|
||||
throw new UnsupportedOperationException(versionMismatchMessage);
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getTablesThatLookLikePhotonCameras() {
|
||||
return rootPhotonTable.getSubTables().stream()
|
||||
.filter(
|
||||
it -> {
|
||||
return rootPhotonTable.getSubTable(it).getEntry("rawBytes").exists();
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user