[backend] Check file existance, use underscores in camera unique name (#33)

* Add more comments and logging, fix configManager barf, add underscores

* apply spotless

* Add more verbose logging

* Update VisionSourceManager.java
This commit is contained in:
Matt
2020-07-13 16:41:36 -07:00
committed by GitHub
parent f93ec6665f
commit aed92e7132
5 changed files with 126 additions and 87 deletions

View File

@@ -33,12 +33,20 @@ import org.photonvision.vision.processes.PipelineManager;
public class CameraConfiguration {
private static final Logger logger = new Logger(CameraConfiguration.class, LogGroup.Camera);
/** Name as reported by CSCore */
public String baseName = "";
/** Name used to title the subfolder of this config */
public String uniqueName = "";
/** User-set nickname */
public String nickname = "";
public double FOV = 70;
/** Can be either path (ex /dev/videoX) or index (ex 1). */
public String path = "";
public CameraType cameraType = CameraType.UsbCamera;
public double FOV = 70;
public CameraCalibrationCoefficients calibration;
public List<Integer> cameraLeds = new ArrayList<>();
public int currentPipelineIndex = -1;

View File

@@ -22,10 +22,7 @@ import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
import org.photonvision.common.logging.LogGroup;
import org.photonvision.common.logging.Logger;
@@ -172,7 +169,8 @@ public class ConfigManager {
// Delete old pipe configs so that we don't get any conflicts
try {
var pipelineFolder = Path.of(subdir.toString(), "pipelines");
Files.list(pipelineFolder).forEach(it -> it.toFile().delete());
if (pipelineFolder.toFile().exists())
Files.list(pipelineFolder).map(Path::toFile).filter(File::exists).forEach(File::delete);
} catch (IOException e) {
logger.error("Exception while deleting old configs!");
e.printStackTrace();
@@ -240,26 +238,31 @@ public class ConfigManager {
// Load pipelines by mapping the files within the pipelines subdir
// to their deserialized equivalents
var pipelineSubdirectory = Path.of(subdir.toString(), "pipelines");
List<CVPipelineSettings> settings =
Files.list(Path.of(subdir.toString(), "pipelines"))
.filter(p -> p.toFile().isFile())
.map(
p -> {
var relativizedFilePath =
getRootFolder().toAbsolutePath().relativize(p).toString();
try {
return JacksonUtils.deserialize(p, CVPipelineSettings.class);
} catch (JsonProcessingException e) {
logger.error("Exception while deserializing " + relativizedFilePath);
e.printStackTrace();
} catch (IOException e) {
logger.warn(
"Could not load pipeline at " + relativizedFilePath + "! Skipping...");
}
return null;
})
.filter(Objects::nonNull)
.collect(Collectors.toList());
pipelineSubdirectory.toFile().exists()
? Files.list(pipelineSubdirectory)
.filter(p -> p.toFile().isFile())
.map(
p -> {
var relativizedFilePath =
getRootFolder().toAbsolutePath().relativize(p).toString();
try {
return JacksonUtils.deserialize(p, CVPipelineSettings.class);
} catch (JsonProcessingException e) {
logger.error("Exception while deserializing " + relativizedFilePath);
e.printStackTrace();
} catch (IOException e) {
logger.warn(
"Could not load pipeline at "
+ relativizedFilePath
+ "! Skipping...");
}
return null;
})
.filter(Objects::nonNull)
.collect(Collectors.toList())
: Collections.emptyList();
loadedConfig.driveModeSettings = driverMode;
loadedConfig.addPipelineSettings(settings);