mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-20 00:51:41 +00:00
Changed all pipeline sets to integer
This commit is contained in:
@@ -16,8 +16,10 @@ import java.io.*;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CameraManager {
|
||||
|
||||
@@ -49,38 +51,38 @@ public class CameraManager {
|
||||
public static boolean initializeCameras() {
|
||||
if (AllUsbCameraInfosByName.size() == 0) return false;
|
||||
FileHelper.CheckPath(CamConfigPath);
|
||||
for (var entry : AllUsbCameraInfosByName.entrySet()) {
|
||||
var camPath = Paths.get(CamConfigPath.toString(), String.format("%s.json", entry.getKey()));
|
||||
AllUsbCameraInfosByName.forEach((key, value) -> {
|
||||
var camPath = Paths.get(CamConfigPath.toString(), String.format("%s.json", key));
|
||||
File camJsonFile = new File(camPath.toString());
|
||||
if (camJsonFile.exists() && camJsonFile.length() != 0) {
|
||||
try {
|
||||
Gson gson = new GsonBuilder().registerTypeAdapter(Camera.class, new CameraDeserializer()).create();
|
||||
var camJsonFileReader = new FileReader(camPath.toString());
|
||||
var gsonRead = gson.fromJson(camJsonFileReader, Camera.class);
|
||||
AllCamerasByName.put(entry.getKey(), gsonRead);
|
||||
AllCamerasByName.put(key, gsonRead);
|
||||
} catch (FileNotFoundException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
if (!addCamera(new Camera(entry.getKey()), entry.getKey())) {
|
||||
if (!addCamera(new Camera(key), key)) {
|
||||
System.err.println("Failed to add camera! Already exists!");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void initializeThreads(){
|
||||
for (var camSet : AllCamerasByName.entrySet()) {
|
||||
VisionProcess visionProcess = new VisionProcess(camSet.getValue());
|
||||
AllVisionProcessesByName.put(camSet.getKey(),visionProcess);
|
||||
AllCamerasByName.forEach((key, value) -> {
|
||||
VisionProcess visionProcess = new VisionProcess(value);
|
||||
AllVisionProcessesByName.put(key, visionProcess);
|
||||
new Thread(visionProcess).start();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static boolean addCamera(Camera camera, String cameraName) {
|
||||
if (AllCamerasByName.containsKey(cameraName)) return false;
|
||||
for (int i = 0; i < 10;i++){
|
||||
for (int i = 0; i < 10; i++){
|
||||
camera.addPipeline(); // simple fix to create more pipelines for now
|
||||
}
|
||||
AllCamerasByName.put(cameraName, camera);
|
||||
@@ -118,11 +120,8 @@ public class CameraManager {
|
||||
|
||||
public static List<String> getResolutionList() throws CameraException {
|
||||
if (!SettingsManager.GeneralSettings.curr_camera.equals("")) {
|
||||
List<String> list = new ArrayList<>();
|
||||
for (var res : CameraManager.getCamera(SettingsManager.GeneralSettings.curr_camera).getAvailableVideoModes()) {
|
||||
list.add(String.format("%s X %s at %s fps", res.width, res.height, res.fps));
|
||||
}
|
||||
return list;
|
||||
return Arrays.stream(CameraManager.getCamera(SettingsManager.GeneralSettings.curr_camera).getAvailableVideoModes())
|
||||
.map(res -> String.format("%s X %s at %s fps", res.width, res.height, res.fps)).collect(Collectors.toList());
|
||||
}
|
||||
throw new CameraException(CameraException.CameraExceptionType.NO_CAMERA);
|
||||
}
|
||||
|
||||
@@ -8,5 +8,6 @@ public class PipelineResult {
|
||||
public double CalibratedY = 0.0;
|
||||
public double Pitch = 0.0;
|
||||
public double Yaw = 0.0;
|
||||
public double Area = 0.0;
|
||||
RotatedRect RawPoint;
|
||||
}
|
||||
|
||||
@@ -46,17 +46,17 @@ public class VisionProcess implements Runnable {
|
||||
|
||||
// NetworkTables
|
||||
NetworkTable ntTable = NetworkTableInstance.getDefault().getTable("/chameleon-vision/" + cameraName);
|
||||
ntPipelineEntry = ntTable.getEntry("Pipeline");
|
||||
ntDriverModeEntry = ntTable.getEntry("Driver_Mode");
|
||||
ntPitchEntry = ntTable.getEntry("Pitch");
|
||||
ntYawEntry = ntTable.getEntry("Yaw");
|
||||
ntDistanceEntry = ntTable.getEntry("Distance");
|
||||
ntTimeStampEntry = ntTable.getEntry("TimeStamp");
|
||||
ntValidEntry = ntTable.getEntry("Valid");
|
||||
ntPipelineEntry = ntTable.getEntry("pipeline");
|
||||
ntDriverModeEntry = ntTable.getEntry("driver_mode");
|
||||
ntPitchEntry = ntTable.getEntry("pitch");
|
||||
ntYawEntry = ntTable.getEntry("yaw");
|
||||
ntDistanceEntry = ntTable.getEntry("distance");
|
||||
ntTimeStampEntry = ntTable.getEntry("timestamp");
|
||||
ntValidEntry = ntTable.getEntry("is_valid");
|
||||
ntDriverModeEntry.addListener(this::DriverModeListener, EntryListenerFlags.kUpdate);
|
||||
ntPipelineEntry.addListener(this::PipelineListener, EntryListenerFlags.kUpdate);
|
||||
ntDriverModeEntry.setBoolean(false);
|
||||
ntPipelineEntry.setString("pipeline" + camera.getCurrentPipelineIndex());
|
||||
ntPipelineEntry.setNumber(camera.getCurrentPipelineIndex());
|
||||
|
||||
// camera settings
|
||||
cvProcess = new CVProcess(camera.getCamVals());
|
||||
@@ -75,7 +75,7 @@ public class VisionProcess implements Runnable {
|
||||
}
|
||||
|
||||
private void PipelineListener(EntryNotification entryNotification) {
|
||||
var ntPipelineIndex = Integer.parseInt(entryNotification.value.getString().replace("pipeline", ""));
|
||||
var ntPipelineIndex = (int) entryNotification.value.getDouble();
|
||||
if (camera.getPipelines().containsKey(ntPipelineIndex)) {
|
||||
// camera.setEntryNotification.value.getString());
|
||||
var pipeline = camera.getCurrentPipeline();
|
||||
@@ -93,10 +93,9 @@ public class VisionProcess implements Runnable {
|
||||
pipeChange.put("curr_pipeline", ntPipelineIndex);
|
||||
ServerHandler.broadcastMessage(pipeChange);
|
||||
ServerHandler.sendFullSettings();
|
||||
|
||||
}
|
||||
} else {
|
||||
ntPipelineEntry.setString("pipeline" + camera.getCurrentPipelineIndex());
|
||||
ntPipelineEntry.setNumber(camera.getCurrentPipelineIndex());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,6 +114,7 @@ public class VisionProcess implements Runnable {
|
||||
if (pipelineResult.IsValid) {
|
||||
ntYawEntry.setNumber(pipelineResult.Yaw);
|
||||
ntPitchEntry.setNumber(pipelineResult.Pitch);
|
||||
ntDistanceEntry.setNumber(pipelineResult.Area);
|
||||
}
|
||||
ntTimeStampEntry.setNumber(TimeStamp);
|
||||
}
|
||||
@@ -161,6 +161,7 @@ public class VisionProcess implements Runnable {
|
||||
}
|
||||
pipelineResult.Pitch = camera.getCamVals().CalculatePitch(finalRect.center.y, pipelineResult.CalibratedY);
|
||||
pipelineResult.Yaw = camera.getCamVals().CalculateYaw(finalRect.center.x, pipelineResult.CalibratedX);
|
||||
pipelineResult.Area = finalRect.size.area();
|
||||
drawContour(outputImage, finalRect);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,12 +99,10 @@ public class ServerHandler {
|
||||
sendFullSettings();
|
||||
break;
|
||||
case "curr_pipeline":
|
||||
String newPipeline = value.toString();
|
||||
var pipelineNumber = Integer.parseInt(newPipeline.replace("pipeline", ""));
|
||||
int newPipeline = (int) value;
|
||||
System.out.printf("Changing pipeline to %s\n", newPipeline);
|
||||
CameraManager.setCurrentPipeline(pipelineNumber);
|
||||
var Proccess = CameraManager.getCurrentCameraProcess();
|
||||
Proccess.ntPipelineEntry.setString("pipeline"+pipelineNumber);
|
||||
CameraManager.setCurrentPipeline(newPipeline);
|
||||
CameraManager.getCurrentCameraProcess().ntPipelineEntry.setNumber(newPipeline);
|
||||
broadcastMessage(allFieldsToMap(CameraManager.getCurrentPipeline()));
|
||||
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user