CSI Camera Timeout & Auto-Recreate (#1102)

Adds logic that will reset the CSI camera in the case that it doesn't receive any new frames from the camera in 3 seconds. This is very helpful for cases where the camera cable was bumped enough to cause a temporary disconnect. Most of the time (if not all the time) the camera needs to be recreated for it to start sending frames again.

Goes with PhotonVision/photon-libcamera-gl-driver#13
This commit is contained in:
Programmers3539
2024-01-05 06:27:12 -08:00
committed by GitHub
parent d85bafa0eb
commit 4d9f2284da
2 changed files with 18 additions and 5 deletions

View File

@@ -27,7 +27,7 @@ ext {
openCVversion = "4.8.0-2"
joglVersion = "2.4.0-rc-20200307"
javalinVersion = "5.6.2"
photonGlDriverLibVersion = "dev-v2023.1.0-8-g38bbe74"
photonGlDriverLibVersion = "dev-v2023.1.0-9-g75fc678"
frcYear = "2024"
pubVersion = versionString

View File

@@ -18,6 +18,8 @@
package org.photonvision.vision.frame.provider;
import org.opencv.core.Mat;
import org.photonvision.common.logging.LogGroup;
import org.photonvision.common.logging.Logger;
import org.photonvision.common.util.math.MathUtils;
import org.photonvision.raspi.LibCameraJNI;
import org.photonvision.vision.camera.LibcameraGpuSettables;
@@ -31,6 +33,8 @@ import org.photonvision.vision.pipe.impl.HSVPipe.HSVParams;
public class LibcameraGpuFrameProvider implements FrameProvider {
private final LibcameraGpuSettables settables;
static final Logger logger = new Logger(LibcameraGpuFrameProvider.class, LogGroup.Camera);
public LibcameraGpuFrameProvider(LibcameraGpuSettables visionSettables) {
this.settables = visionSettables;
@@ -43,21 +47,30 @@ public class LibcameraGpuFrameProvider implements FrameProvider {
return "AcceleratedPicamFrameProvider";
}
int i = 0;
int badFrameCounter = 0;
@Override
public Frame get() {
// We need to make sure that other threads don't try to change video modes while
// we're waiting
// for a frame
// we're waiting for a frame
// System.out.println("GET!");
synchronized (settables.CAMERA_LOCK) {
var p_ptr = LibCameraJNI.awaitNewFrame(settables.r_ptr);
if (p_ptr == 0) {
System.out.println("No new frame");
logger.error("No new frame from " + settables.getConfiguration().nickname);
badFrameCounter++;
if (badFrameCounter > 3) {
logger.error(
"No new frame from "
+ settables.getConfiguration().nickname
+ " for 3 seconds attempting recreate!");
settables.setVideoMode(settables.getCurrentVideoMode());
badFrameCounter = 0;
}
return new Frame();
}
badFrameCounter = 0;
var colorMat = new CVMat(new Mat(LibCameraJNI.takeColorFrame(p_ptr)));
var processedMat = new CVMat(new Mat(LibCameraJNI.takeProcessedFrame(p_ptr)));