-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Another config matching bug #1518
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
import org.photonvision.common.dataflow.DataChangeService; | ||
import org.photonvision.common.dataflow.events.OutgoingUIEvent; | ||
import org.photonvision.common.hardware.Platform; | ||
import org.photonvision.common.hardware.Platform.OSType; | ||
import org.photonvision.common.logging.LogGroup; | ||
import org.photonvision.common.logging.Logger; | ||
import org.photonvision.common.util.TimedTaskManager; | ||
|
@@ -128,20 +129,26 @@ protected List<VisionSource> tryMatchCamImpl() { | |
return tryMatchCamImpl(null); | ||
} | ||
|
||
protected List<VisionSource> tryMatchCamImpl(ArrayList<CameraInfo> cameraInfos) { | ||
return tryMatchCamImpl(cameraInfos, Platform.getCurrentPlatform()); | ||
} | ||
|
||
/** | ||
* @param cameraInfos Used to feed camera info for unit tests. | ||
* @return New VisionSources. | ||
*/ | ||
protected List<VisionSource> tryMatchCamImpl(ArrayList<CameraInfo> cameraInfos) { | ||
protected List<VisionSource> tryMatchCamImpl( | ||
ArrayList<CameraInfo> cameraInfos, Platform platform) { | ||
boolean createSources = true; | ||
List<CameraInfo> connectedCameras; | ||
if (cameraInfos == null) { | ||
// Detect USB cameras using CSCore | ||
connectedCameras = new ArrayList<>(filterAllowedDevices(getConnectedUSBCameras())); | ||
connectedCameras = new ArrayList<>(filterAllowedDevices(getConnectedUSBCameras(), platform)); | ||
// Detect CSI cameras using libcamera | ||
connectedCameras.addAll(new ArrayList<>(filterAllowedDevices(getConnectedCSICameras()))); | ||
connectedCameras.addAll( | ||
new ArrayList<>(filterAllowedDevices(getConnectedCSICameras(), platform))); | ||
} else { | ||
connectedCameras = new ArrayList<>(filterAllowedDevices(cameraInfos)); | ||
connectedCameras = new ArrayList<>(filterAllowedDevices(cameraInfos, platform)); | ||
createSources = | ||
false; // Dont create sources if we are using supplied camerainfo for unit tests. | ||
} | ||
|
@@ -162,15 +169,15 @@ protected List<VisionSource> tryMatchCamImpl(ArrayList<CameraInfo> cameraInfos) | |
// All cameras are already loaded return no new sources. | ||
if (connectedCameras.isEmpty()) return null; | ||
|
||
logger.debug("Matching " + connectedCameras.size() + " new cameras!"); | ||
logger.debug("Matching " + connectedCameras.size() + " new camera(s)!"); | ||
|
||
// Debug prints | ||
for (var info : connectedCameras) { | ||
logger.info("Detected unmatched physical camera: " + info.toString()); | ||
} | ||
|
||
if (!unmatchedLoadedConfigs.isEmpty()) | ||
logger.debug("Trying to match " + unmatchedLoadedConfigs.size() + " unmatched configs..."); | ||
logger.debug("Trying to match " + unmatchedLoadedConfigs.size() + " unmatched config(s)..."); | ||
|
||
// Match camera configs to physical cameras | ||
List<CameraConfiguration> matchedCameras = | ||
|
@@ -182,7 +189,7 @@ protected List<VisionSource> tryMatchCamImpl(ArrayList<CameraInfo> cameraInfos) | |
() -> | ||
"After matching, " | ||
+ unmatchedLoadedConfigs.size() | ||
+ " configs remained unmatched. Is your camera disconnected?"); | ||
+ " config(s) remained unmatched. Is your camera disconnected?"); | ||
logger.warn( | ||
"Unloaded configs: " | ||
+ unmatchedLoadedConfigs.stream() | ||
|
@@ -233,7 +240,7 @@ private final Predicate<CameraInfo> getCameraMatcher( | |
if (checkUSBPath && savedConfig.getUSBPath().isEmpty()) { | ||
logger.debug( | ||
"WARN: Camera has empty USB path, but asked to match by name: " | ||
+ camCfgToString(savedConfig)); | ||
+ savedConfig.toShortString()); | ||
} | ||
|
||
return (CameraInfo physicalCamera) -> { | ||
|
@@ -277,22 +284,6 @@ public List<CameraConfiguration> matchCameras( | |
ConfigManager.getInstance().getConfig().getNetworkConfig().matchCamerasOnlyByPath); | ||
} | ||
|
||
private static final String camCfgToString(CameraConfiguration c) { | ||
return new StringBuilder() | ||
.append("[baseName=") | ||
.append(c.baseName) | ||
.append(", uniqueName=") | ||
.append(c.uniqueName) | ||
.append(", otherPaths=") | ||
.append(Arrays.toString(c.otherPaths)) | ||
.append(", vid=") | ||
.append(c.usbVID) | ||
.append(", pid=") | ||
.append(c.usbPID) | ||
.append("]") | ||
.toString(); | ||
} | ||
|
||
/** | ||
* Create {@link CameraConfiguration}s based on a list of detected USB cameras and the configs on | ||
* disk. | ||
|
@@ -423,7 +414,7 @@ private List<CameraConfiguration> matchCamerasByStrategy( | |
logger.debug( | ||
String.format( | ||
"Trying to find a match for loaded camera %s (%s) with camera config: %s", | ||
config.baseName, config.uniqueName, camCfgToString(config))); | ||
config.baseName, config.uniqueName, config.toShortString())); | ||
|
||
// Get matcher and filter against it, picking out the first match | ||
Predicate<CameraInfo> matches = | ||
|
@@ -463,7 +454,7 @@ private List<CameraConfiguration> createConfigsForCameras( | |
List<CameraConfiguration> loadedConfigs) { | ||
List<CameraConfiguration> ret = new ArrayList<CameraConfiguration>(); | ||
logger.debug( | ||
"After matching loaded configs, these configs remained unmatched: " | ||
"After matching loaded configs, these cameras remained unmatched: " | ||
+ detectedCameraList.stream() | ||
.map(n -> String.valueOf(n)) | ||
.collect(Collectors.joining("-", "{", "}"))); | ||
|
@@ -537,7 +528,7 @@ public void setIgnoredCamerasRegex(String ignoredCamerasRegex) { | |
* @param allDevices | ||
* @return list of devices with blacklisted or ignore devices removed. | ||
*/ | ||
private List<CameraInfo> filterAllowedDevices(List<CameraInfo> allDevices) { | ||
private List<CameraInfo> filterAllowedDevices(List<CameraInfo> allDevices, Platform platform) { | ||
List<CameraInfo> filteredDevices = new ArrayList<>(); | ||
for (var device : allDevices) { | ||
if (deviceBlacklist.contains(device.name)) { | ||
|
@@ -546,6 +537,13 @@ private List<CameraInfo> filterAllowedDevices(List<CameraInfo> allDevices) { | |
} else if (device.name.matches(ignoredCamerasRegex)) { | ||
logger.trace("Skipping ignored device: \"" + device.name + "\" at \"" + device.path); | ||
} else if (device.getIsV4lCsiCamera()) { | ||
} else if (device.otherPaths.length == 0 | ||
&& platform.osType == OSType.LINUX | ||
&& device.cameraType == CameraType.UsbCamera) { | ||
logger.trace( | ||
"Skipping device with no other paths: \"" + device.name + "\" at \"" + device.path); | ||
// If cscore hasnt passed this other paths aka a path by id or a path as in usb port then we | ||
// cant guarantee it is a valid camera. | ||
Comment on lines
+545
to
+546
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to make any assertions to check that otherPaths does not contain "by-id" or "by-path", or will the otherPaths length always be empty? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question. This specific problem is hard to recreate. I believe if we get either a by-id or by-path we should be good to assume we can read from the camera. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to merge this as-is, or explicitly check only that there are no by-ids or by-paths? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. im fine doing it as is |
||
} else { | ||
filteredDevices.add(device); | ||
logger.trace( | ||
|
@@ -559,8 +557,6 @@ private static List<VisionSource> loadVisionSourcesFromCamConfigs( | |
List<CameraConfiguration> camConfigs, boolean createSources) { | ||
var cameraSources = new ArrayList<VisionSource>(); | ||
for (var configuration : camConfigs) { | ||
logger.debug("Creating VisionSource for " + camCfgToString(configuration)); | ||
|
||
// In unit tests, create dummy | ||
if (!createSources) { | ||
cameraSources.add(new TestSource(configuration)); | ||
|
@@ -580,6 +576,7 @@ private static List<VisionSource> loadVisionSourcesFromCamConfigs( | |
cameraSources.add(newCam); | ||
} | ||
} | ||
logger.debug("Creating VisionSource for " + configuration.toShortString()); | ||
} | ||
return cameraSources; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double else-if - syntax error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
skill issue, this is a complete statement, just a confusing one with an empty body. add a comment