From f7e29a1992e3a2d7a49cb377d30e8eaefbdf29a7 Mon Sep 17 00:00:00 2001 From: Chris Gerth Date: Fri, 8 Jan 2021 01:42:05 -0600 Subject: [PATCH] Update which-cam-controls-LEDs logic (#220) Modified VisionModule.java to cause any camera the either has a vendor-defined FOV or the PiCam quirks to control the LED state. This is a bit of a patch, and directly assumes that piCam's are the devices primarily used for vision processing. This fixes a tiny bit of pain experienced with a pi3b + picam v1 + usb Cam where not having the USB cam causes the LED's to be working normally, but plugging in the USB cam causes them to be always off. Parallel issue entered in documentation to add this to known limitations of photon - if you had a set of all usb cameras, we wouldn't know which one is being used for vision processing, and would not be able to control the LED's accordingly. The ultimate solution is just to have teams control the NT entry themselves, which is easy enough. But, docs shouild be updated to reflect that. --- .../vision/processes/VisionModule.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/photon-server/src/main/java/org/photonvision/vision/processes/VisionModule.java b/photon-server/src/main/java/org/photonvision/vision/processes/VisionModule.java index cc06abfa1..8e5afb756 100644 --- a/photon-server/src/main/java/org/photonvision/vision/processes/VisionModule.java +++ b/photon-server/src/main/java/org/photonvision/vision/processes/VisionModule.java @@ -141,7 +141,7 @@ public class VisionModule { } // Configure LED's if supported by the underlying hardware - if (HardwareManager.getInstance().visionLED != null) { + if (HardwareManager.getInstance().visionLED != null && this.camShouldControlLEDs()) { HardwareManager.getInstance() .visionLED .setPipelineModeSupplier(() -> pipelineManager.getCurrentPipelineSettings().ledMode); @@ -277,7 +277,7 @@ public class VisionModule { void setDriverMode(boolean isDriverMode) { pipelineManager.setDriverMode(isDriverMode); - if (isVendorCamera()) setVisionLEDs(!isDriverMode); + setVisionLEDs(!isDriverMode); saveAndBroadcastAll(); } @@ -375,14 +375,21 @@ public class VisionModule { visionSource.getSettables().setGain(Math.max(0, config.cameraGain)); } - if (isVendorCamera()) setVisionLEDs(config.ledMode); + setVisionLEDs(config.ledMode); visionSource.getSettables().getConfiguration().currentPipelineIndex = pipelineManager.getCurrentPipelineIndex(); } + private boolean camShouldControlLEDs() { + // Heuristic - if the camera has a known FOV or is a piCam, assume it's in use for + // vision processing, and should command stuff to the LED's. + // TODO: Make LED control a property of the camera itself and controllable in the UI. + return isVendorCamera() || cameraQuirks.hasQuirk(CameraQuirk.PiCam); + } + private void setVisionLEDs(boolean on) { - if (HardwareManager.getInstance().visionLED != null) + if (camShouldControlLEDs() && HardwareManager.getInstance().visionLED != null) HardwareManager.getInstance().visionLED.setState(on); }