mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-20 00:51:41 +00:00
Catch VideoException when setting camera properties (#58)
* Catch VideoException when setting camera properties * Fix test settables, add log message
This commit is contained in:
@@ -19,6 +19,7 @@ package org.photonvision.vision.camera;
|
||||
|
||||
import edu.wpi.cscore.CvSink;
|
||||
import edu.wpi.cscore.UsbCamera;
|
||||
import edu.wpi.cscore.VideoException;
|
||||
import edu.wpi.cscore.VideoMode;
|
||||
import edu.wpi.first.cameraserver.CameraServer;
|
||||
import java.util.*;
|
||||
@@ -71,38 +72,35 @@ public class USBCameraSource implements VisionSource {
|
||||
frameStaticProperties = new FrameStaticProperties(getCurrentVideoMode(), getFOV());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getExposure() {
|
||||
return camera.getProperty("exposure").get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExposure(int exposure) {
|
||||
camera.setExposureManual(exposure);
|
||||
camera.setExposureManual(exposure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBrightness() {
|
||||
return camera.getBrightness();
|
||||
try {
|
||||
camera.setExposureManual(exposure);
|
||||
camera.setExposureManual(exposure);
|
||||
} catch (VideoException e) {
|
||||
logger.error("Failed to set camera exposure!", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBrightness(int brightness) {
|
||||
camera.setBrightness(brightness);
|
||||
camera.setBrightness(brightness);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGain() {
|
||||
return !cameraQuirks.hasQuirk(CameraQuirk.Gain) ? -1 : camera.getProperty("gain").get();
|
||||
try {
|
||||
camera.setBrightness(brightness);
|
||||
camera.setBrightness(brightness);
|
||||
} catch (VideoException e) {
|
||||
logger.error("Failed to set camera brightness!", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGain(int gain) {
|
||||
if (cameraQuirks.hasQuirk(CameraQuirk.Gain)) {
|
||||
camera.getProperty("gain_automatic").set(0);
|
||||
camera.getProperty("gain").set(gain);
|
||||
try {
|
||||
if (cameraQuirks.hasQuirk(CameraQuirk.Gain)) {
|
||||
camera.getProperty("gain_automatic").set(0);
|
||||
camera.getProperty("gain").set(gain);
|
||||
}
|
||||
} catch (VideoException e) {
|
||||
logger.error("Failed to set camera gain!", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,12 +111,16 @@ public class USBCameraSource implements VisionSource {
|
||||
|
||||
@Override
|
||||
public void setCurrentVideoMode(VideoMode videoMode) {
|
||||
if (videoMode == null) {
|
||||
logger.error("Got a null video mode! Doing nothing...");
|
||||
return;
|
||||
try {
|
||||
if (videoMode == null) {
|
||||
logger.error("Got a null video mode! Doing nothing...");
|
||||
return;
|
||||
}
|
||||
camera.setVideoMode(videoMode);
|
||||
this.frameStaticProperties = new FrameStaticProperties(getCurrentVideoMode(), getFOV());
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to set video mode!", e);
|
||||
}
|
||||
camera.setVideoMode(videoMode);
|
||||
this.frameStaticProperties = new FrameStaticProperties(getCurrentVideoMode(), getFOV());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -36,16 +36,10 @@ public abstract class VisionSourceSettables {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
public abstract int getExposure();
|
||||
|
||||
public abstract void setExposure(int exposure);
|
||||
|
||||
public abstract int getBrightness();
|
||||
|
||||
public abstract void setBrightness(int brightness);
|
||||
|
||||
public abstract int getGain();
|
||||
|
||||
public abstract void setGain(int gain);
|
||||
|
||||
public abstract VideoMode getCurrentVideoMode();
|
||||
|
||||
Reference in New Issue
Block a user