4545import edu .wpi .first .networktables .StringSubscriber ;
4646import edu .wpi .first .wpilibj .DriverStation ;
4747import edu .wpi .first .wpilibj .Timer ;
48+ import java .util .List ;
4849import java .util .Optional ;
49- import java .util .Set ;
50+ import java .util .stream . Collectors ;
5051import org .photonvision .common .hardware .VisionLEDMode ;
5152import org .photonvision .common .networktables .PacketSubscriber ;
5253import org .photonvision .targeting .PhotonPipelineResult ;
@@ -74,6 +75,8 @@ public class PhotonCamera implements AutoCloseable {
7475 IntegerSubscriber heartbeatEntry ;
7576 DoubleArraySubscriber cameraIntrinsicsSubscriber ;
7677 DoubleArraySubscriber cameraDistortionSubscriber ;
78+ MultiSubscriber m_topicNameSubscriber ;
79+ NetworkTable rootPhotonTable ;
7780
7881 @ Override
7982 public void close () {
@@ -97,6 +100,7 @@ public void close() {
97100 pipelineIndexRequest .close ();
98101 cameraIntrinsicsSubscriber .close ();
99102 cameraDistortionSubscriber .close ();
103+ m_topicNameSubscriber .close ();
100104 }
101105
102106 private final String path ;
@@ -124,8 +128,8 @@ public static void setVersionCheckEnabled(boolean enabled) {
124128 */
125129 public PhotonCamera (NetworkTableInstance instance , String cameraName ) {
126130 name = cameraName ;
127- var photonvision_root_table = instance .getTable (kTableName );
128- this .cameraTable = photonvision_root_table .getSubTable (cameraName );
131+ rootPhotonTable = instance .getTable (kTableName );
132+ this .cameraTable = rootPhotonTable .getSubTable (cameraName );
129133 path = cameraTable .getPath ();
130134 var rawBytesEntry =
131135 cameraTable
@@ -147,14 +151,17 @@ public PhotonCamera(NetworkTableInstance instance, String cameraName) {
147151 cameraDistortionSubscriber =
148152 cameraTable .getDoubleArrayTopic ("cameraDistortion" ).subscribe (null );
149153
150- ledModeRequest = photonvision_root_table .getIntegerTopic ("ledModeRequest" ).publish ();
151- ledModeState = photonvision_root_table .getIntegerTopic ("ledModeState" ).subscribe (-1 );
152- versionEntry = photonvision_root_table .getStringTopic ("version" ).subscribe ("" );
154+ ledModeRequest = rootPhotonTable .getIntegerTopic ("ledModeRequest" ).publish ();
155+ ledModeState = rootPhotonTable .getIntegerTopic ("ledModeState" ).subscribe (-1 );
156+ versionEntry = rootPhotonTable .getStringTopic ("version" ).subscribe ("" );
153157
154158 // Existing is enough to make this multisubscriber do its thing
155- MultiSubscriber m_topicNameSubscriber =
159+ m_topicNameSubscriber =
156160 new MultiSubscriber (
157- instance , new String [] {"/photonvision/" }, PubSubOption .topicsOnly (true ));
161+ instance ,
162+ new String [] {"/photonvision/" },
163+ PubSubOption .topicsOnly (true ),
164+ PubSubOption .disableLocal (true ));
158165
159166 HAL .report (tResourceType .kResourceType_PhotonCamera , InstanceCount );
160167 InstanceCount ++;
@@ -346,20 +353,28 @@ private void verifyVersion() {
346353 // Heartbeat entry is assumed to always be present. If it's not present, we
347354 // assume that a camera with that name was never connected in the first place.
348355 if (!heartbeatEntry .exists ()) {
349- Set < String > cameraNames = cameraTable . getInstance (). getTable ( kTableName ). getSubTables ();
356+ var cameraNames = getTablesThatLookLikePhotonCameras ();
350357 if (cameraNames .isEmpty ()) {
351358 DriverStation .reportError (
352- "Could not find any PhotonVision coprocessors on NetworkTables. Double check that PhotonVision is running, and that your camera is connected!" ,
359+ "Could not find ** any** PhotonVision coprocessors on NetworkTables. Double check that PhotonVision is running, and that your camera is connected!" ,
353360 false );
354361 } else {
355362 DriverStation .reportError (
356363 "PhotonVision coprocessor at path "
357364 + path
358365 + " not found on NetworkTables. Double check that your camera names match!" ,
359366 true );
367+
368+ var cameraNameStr = new StringBuilder ();
369+ for (var c : cameraNames ) {
370+ cameraNameStr .append (" ==> " );
371+ cameraNameStr .append (c );
372+ cameraNameStr .append ("\n " );
373+ }
374+
360375 DriverStation .reportError (
361- "Found the following PhotonVision cameras on NetworkTables:\n "
362- + String .join ("\n " , cameraNames ),
376+ "Found the following PhotonVision cameras active on NetworkTables:\n "
377+ + String .join ("\n " , cameraNameStr ),
363378 false );
364379 }
365380 }
@@ -404,4 +419,13 @@ else if (!isConnected()) {
404419 throw new UnsupportedOperationException (versionMismatchMessage );
405420 }
406421 }
422+
423+ private List <String > getTablesThatLookLikePhotonCameras () {
424+ return rootPhotonTable .getSubTables ().stream ()
425+ .filter (
426+ it -> {
427+ return rootPhotonTable .getSubTable (it ).getEntry ("rawBytes" ).exists ();
428+ })
429+ .collect (Collectors .toList ());
430+ }
407431}
0 commit comments