001/* 002 * Copyright (C) Photon Vision. 003 * 004 * This program is free software: you can redistribute it and/or modify 005 * it under the terms of the GNU General Public License as published by 006 * the Free Software Foundation, either version 3 of the License, or 007 * (at your option) any later version. 008 * 009 * This program is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 * GNU General Public License for more details. 013 * 014 * You should have received a copy of the GNU General Public License 015 * along with this program. If not, see <https://www.gnu.org/licenses/>. 016 */ 017 018package org.photonvision.vision.camera.USBCameras; 019 020import edu.wpi.first.cscore.UsbCamera; 021import edu.wpi.first.cscore.VideoException; 022import edu.wpi.first.math.MathUtil; 023import org.photonvision.common.configuration.CameraConfiguration; 024 025/* 026 * This class holds the windows specific camera quirks for the Arducam ov2311. A windows version is needed because windows doesn't expose the auto exposure properties of the arducam. 027 */ 028public class ArduOV2311WindowsCameraSettables extends GenericUSBCameraSettables { 029 public ArduOV2311WindowsCameraSettables(CameraConfiguration configuration, UsbCamera camera) { 030 super(configuration, camera); 031 } 032 033 @Override 034 protected void setUpExposureProperties() { 035 var expProp = 036 findProperty( 037 "raw_exposure_absolute", 038 "raw_exposure_time_absolute", 039 "exposure", 040 "raw_Exposure", 041 "Exposure"); 042 043 exposureAbsProp = expProp.get(); 044 autoExposureProp = null; 045 this.minExposure = 1; 046 this.maxExposure = 140; 047 } 048 049 @Override 050 public void setExposureRaw(double exposureRaw) { 051 if (exposureRaw >= 0.0) { 052 try { 053 int propVal = (int) MathUtil.clamp(exposureRaw, minExposure, maxExposure); 054 camera.setExposureManual(propVal); 055 this.lastExposureRaw = exposureRaw; 056 } catch (VideoException e) { 057 logger.error("Failed to set camera exposure!", e); 058 } 059 } 060 } 061 062 public void setAutoExposure(boolean cameraAutoExposure) { 063 logger.debug("Setting auto exposure to " + cameraAutoExposure); 064 065 if (!cameraAutoExposure) { 066 // Most cameras leave exposure time absolute at the last value from their AE 067 // algorithm. 068 // Set it back to the exposure slider value 069 camera.setExposureManual((int) this.lastExposureRaw); 070 } else { 071 camera.setExposureAuto(); 072 } 073 } 074}