bug fixes in ui and bug fixes in sever handler

-- updated pom
This commit is contained in:
ori agranat
2019-11-27 21:46:07 +02:00
parent ca7f15aeb7
commit e195cce026
5 changed files with 16 additions and 59 deletions

View File

@@ -6,8 +6,8 @@ import com.chameleonvision.vision.camera.CameraCapture;
import com.chameleonvision.vision.camera.CameraStreamer;
import com.chameleonvision.vision.pipeline.*;
import com.chameleonvision.web.ServerHandler;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import edu.wpi.cscore.VideoMode;
import edu.wpi.first.networktables.*;
import edu.wpi.first.wpiutil.CircularBuffer;
@@ -20,7 +20,6 @@ import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;
import static java.lang.Math.min;
public class VisionProcess {
@@ -51,7 +50,7 @@ public class VisionProcess {
private NetworkTableEntry ntAreaEntry;
private NetworkTableEntry ntTimeStampEntry;
private NetworkTableEntry ntValidEntry;
private Gson gson = new GsonBuilder().setPrettyPrinting().create();
private ObjectMapper objectMapper;
VisionProcess(CameraCapture cameraCapture, String name) {
this.cameraCapture = cameraCapture;
@@ -172,6 +171,7 @@ public class VisionProcess {
center.add(bestTarget.rawPoint.center.y);
calculated.put("pitch", bestTarget.pitch);
calculated.put("yaw", bestTarget.yaw);
calculated.put("area", bestTarget.area);
} else if (data instanceof CVPipeline3d.CVPipeline3dResult) {
// TODO: (2.1) 3d stuff in UI
} else {
@@ -205,8 +205,11 @@ public class VisionProcess {
ntPitchEntry.setDouble(targets.get(0).pitch);
ntYawEntry.setDouble(targets.get(0).yaw);
ntAreaEntry.setDouble(targets.get(0).area);
ntAuxListEntry.setString(gson.toJson(targets.subList(0, min(targets.size(), 5))));
try {
ntAreaEntry.setString(objectMapper.writeValueAsString(targets));
} catch (JsonProcessingException e) {
e.printStackTrace();
}
} else if (data instanceof CVPipeline3d.CVPipeline3dResult) {
// TODO: (2.1) 3d stuff...
}

View File

@@ -214,9 +214,9 @@ public class ServerHandler {
broadcastMessage(obj, null);//Broadcasts the message to every user
}
private static HashMap<String, Object> getOrdinalPipeline() throws IllegalAccessException {
private static HashMap<String, Object> getOrdinalPipeline(Class cvClass) throws IllegalAccessException {
HashMap<String, Object> tmp = new HashMap<>();
for (Field field : CVPipelineSettings.class.getFields()) { // iterate over every field in CVPipelineSettings
for (Field field :cvClass.getFields()) { // iterate over every field in CVPipelineSettings
try {
if (!field.getType().isEnum()) { // if the field is not an enum, get it based on the current pipeline
tmp.put(field.getName(), field.get(VisionManager.getCurrentUIVisionProcess().getCurrentPipeline().settings));
@@ -263,45 +263,6 @@ public class ServerHandler {
return tmp;
}
private static Map<String, Object> settingsToMap(GeneralSettings settings) {
Map<String, Object> map = new HashMap<>();
map.put("team_number", settings.teamNumber);
map.put("connection_type", settings.connectionType);
map.put("ip", settings.ip);
map.put("gateway", settings.gateway);
map.put("netmask", settings.netmask);
map.put("hostname", settings.hostname);
map.put("curr_camera", settings.currentCamera);
map.put("curr_pipeline", settings.currentPipeline);
return map;
}
private static Map<String, Object> pipelineToMap(CVPipelineSettings s) {
Map<String, Object> map = new HashMap<>();
map.put("exposure", s.exposure);
map.put("brightness", s.brightness);
if(s instanceof CVPipeline2dSettings) {
var s_ = (CVPipeline2dSettings) s;
map.put("orientation", s.flipMode.name());
map.put("hue", s_.hue);
map.put("saturation", s_.saturation);
map.put("value", s_.value);
map.put("erode", s_.erode);
map.put("dilate", s_.dilate);
map.put("area", s_.area);
map.put("ratio", s_.ratio);
map.put("extent", s_.extent);
map.put("is_binary", s_.isBinary);
map.put("sort_mode", s_.sortMode.name());
map.put("target_group", s_.targetGroup.name());
map.put("target_intersection", s_.targetIntersection.name());
map.put("M", s_.dualTargetCalibrationM);
map.put("B", s_.dualTargetCalibrationB);
map.put("is_calibrated", !s_.calibrationMode.equals(CalibrationMode.None));
}
return map;
}
public static void sendFullSettings() {
//General settings
Map<String, Object> fullSettings = new HashMap<>();
@@ -311,16 +272,15 @@ public class ServerHandler {
CVPipeline currentPipeline = currentProcess.getCurrentPipeline();
try {
fullSettings.putAll(settingsToMap(ConfigManager.settings));
fullSettings.putAll(pipelineToMap(currentPipeline.settings));
// fullSettings.putAll(settingsToMap(ConfigManager.settings));
// fullSettings.putAll(pipelineToMap(currentPipeline.settings));
fullSettings.put("settings", getOrdinalSettings());
fullSettings.put("cameraSettings", getOrdinalCameraSettings());
fullSettings.put("cameraList", VisionManager.getAllCameraNicknames());
fullSettings.put("pipeline", getOrdinalPipeline());
fullSettings.put("pipeline", getOrdinalPipeline(currentPipeline.settings.getClass()));
fullSettings.put("driverMode", getOrdinalDriver());
fullSettings.put("pipelineList", VisionManager.getCurrentCameraPipelineNicknames());
fullSettings.put("resolutionList", VisionManager.getCurrentCameraResolutionList());
fullSettings.put("FOV", currentCamera.getProperties().FOV);
fullSettings.put("port", currentProcess.cameraStreamer.getStreamPort());
fullSettings.put("currentPipelineIndex", VisionManager.getCurrentUIVisionProcess().getCurrentPipelineIndex());
fullSettings.put("currentCameraIndex", VisionManager.getCurrentUIVisionProcessIndex());